From 9e8216acb0bc011cc32097d1286ad5a739d9f3c6 Mon Sep 17 00:00:00 2001 From: FineFindus Date: Wed, 11 Oct 2023 18:04:25 +0200 Subject: [PATCH 1/2] feat(comments): show if creator replied --- .../main/java/com/github/libretube/api/obj/Comment.kt | 3 ++- .../com/github/libretube/ui/adapters/CommentsAdapter.kt | 6 ++++++ .../libretube/ui/fragments/CommentsMainFragment.kt | 1 + .../libretube/ui/fragments/CommentsRepliesFragment.kt | 1 + .../com/github/libretube/ui/fragments/PlayerFragment.kt | 1 + .../com/github/libretube/ui/models/CommentsViewModel.kt | 1 + app/src/main/res/layout/comments_row.xml | 9 +++++++++ 7 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/Comment.kt b/app/src/main/java/com/github/libretube/api/obj/Comment.kt index 75c29ab687..422f9c6f19 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Comment.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Comment.kt @@ -18,5 +18,6 @@ data class Comment( val pinned: Boolean, val thumbnail: String, val verified: Boolean, - val replyCount: Long + val replyCount: Long, + val creatorReplied: Boolean = false, ) : Parcelable diff --git a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt index 617319d805..522d135a3a 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/CommentsAdapter.kt @@ -35,6 +35,7 @@ import com.github.libretube.util.TextUtils class CommentsAdapter( private val fragment: Fragment?, private val videoId: String, + private val channelAvatar: String?, private val comments: MutableList, private val isRepliesAdapter: Boolean = false, private val handleLink: ((url: String) -> Unit)?, @@ -80,6 +81,11 @@ class CommentsAdapter( ImageHelper.loadImage(comment.thumbnail, commentorImage) likesTextView.text = comment.likeCount.formatShort() + if (comment.creatorReplied && !channelAvatar.isNullOrBlank()) { + ImageHelper.loadImage(channelAvatar, creatorReplyImageView) + creatorReplyImageView.isVisible = true + } + if (comment.verified) verifiedImageView.isVisible = true if (comment.pinned) pinnedImageView.isVisible = true if (comment.hearted) heartedImageView.isVisible = true diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt index 1366db0932..33e9d9945d 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsMainFragment.kt @@ -64,6 +64,7 @@ class CommentsMainFragment : Fragment() { commentsAdapter = CommentsAdapter( this, viewModel.videoId ?: return, + viewModel.channelAvatar ?: return, viewModel.commentsPage.value?.comments.orEmpty().toMutableList(), handleLink = viewModel.handleLink ) { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt index 295b3ef855..a301d1242c 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/CommentsRepliesFragment.kt @@ -58,6 +58,7 @@ class CommentsRepliesFragment : Fragment() { repliesAdapter = CommentsAdapter( null, videoId, + viewModel.channelAvatar, mutableListOf(comment), true, viewModel.handleLink diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index ae1dce6e6f..f44df88bcb 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -402,6 +402,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { commentsViewModel.handleLink = this::handleLink updateMaxSheetHeight() commentsViewModel.videoId = videoId + commentsViewModel.channelAvatar = streams.uploaderAvatar CommentsSheet().show(childFragmentManager) } diff --git a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt index 9348390c21..7f69ea86ab 100644 --- a/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/CommentsViewModel.kt @@ -16,6 +16,7 @@ class CommentsViewModel : ViewModel() { val commentSheetExpand = MutableLiveData() var videoId: String? = null + var channelAvatar: String? = null private var nextPage: String? = null private var isLoading = false var currentCommentsPosition = 0 diff --git a/app/src/main/res/layout/comments_row.xml b/app/src/main/res/layout/comments_row.xml index 6436bdcadd..bfd8b1c847 100644 --- a/app/src/main/res/layout/comments_row.xml +++ b/app/src/main/res/layout/comments_row.xml @@ -104,6 +104,15 @@ app:srcCompat="@drawable/ic_hearted" tools:visibility="visible" /> + + Date: Wed, 11 Oct 2023 18:13:32 +0200 Subject: [PATCH 2/2] style: run ktlint --- .../java/com/github/libretube/api/PipedApi.kt | 16 ++---- .../com/github/libretube/api/obj/Comment.kt | 2 +- .../com/github/libretube/api/obj/Streams.kt | 2 +- .../com/github/libretube/db/Converters.kt | 4 +- .../com/github/libretube/db/DatabaseHelper.kt | 51 ++++++++++--------- .../github/libretube/extensions/LocalDate.kt | 2 +- .../github/libretube/helpers/DashHelper.kt | 11 +--- .../libretube/helpers/NavigationHelper.kt | 11 +--- .../libretube/helpers/NotificationHelper.kt | 5 +- .../github/libretube/helpers/PlayerHelper.kt | 36 +++++++------ .../github/libretube/helpers/ThemeHelper.kt | 10 ++-- .../services/OfflinePlayerService.kt | 1 - .../libretube/services/OnlinePlayerService.kt | 1 - .../ui/activities/OfflinePlayerActivity.kt | 2 +- .../libretube/ui/adapters/VideosAdapter.kt | 4 +- .../libretube/ui/dialogs/ColorPickerDialog.kt | 17 ++----- .../libretube/ui/dialogs/ShareDialog.kt | 4 +- .../libretube/ui/fragments/PlayerFragment.kt | 6 +-- .../ui/fragments/PlaylistFragment.kt | 5 +- .../ui/fragments/WatchHistoryFragment.kt | 5 +- .../ui/sheets/ChaptersBottomSheet.kt | 7 +-- .../ui/sheets/VideoOptionsBottomSheet.kt | 2 +- .../libretube/util/NowPlayingNotification.kt | 5 +- .../util/YouTubeHlsPlaylistParser.kt | 5 +- 24 files changed, 79 insertions(+), 135 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/PipedApi.kt b/app/src/main/java/com/github/libretube/api/PipedApi.kt index 4c1046bf8b..6d90402a03 100644 --- a/app/src/main/java/com/github/libretube/api/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/api/PipedApi.kt @@ -47,9 +47,7 @@ interface PipedApi { ): SegmentData @GET("dearrow") - suspend fun getDeArrowContent( - @Query("videoIds") videoIds: String - ): JsonObject + suspend fun getDeArrowContent(@Query("videoIds") videoIds: String): JsonObject @GET("nextpage/comments/{videoId}") suspend fun getCommentsNextPage( @@ -116,14 +114,10 @@ interface PipedApi { suspend fun getFeed(@Query("authToken") token: String?): List @GET("feed/unauthenticated") - suspend fun getUnauthenticatedFeed( - @Query("channels") channels: String - ): List + suspend fun getUnauthenticatedFeed(@Query("channels") channels: String): List @POST("feed/unauthenticated") - suspend fun getUnauthenticatedFeed( - @Body channels: List - ): List + suspend fun getUnauthenticatedFeed(@Body channels: List): List @GET("subscribed") suspend fun isSubscribed( @@ -140,9 +134,7 @@ interface PipedApi { ): List @POST("subscriptions/unauthenticated") - suspend fun unauthenticatedSubscriptions( - @Body channels: List - ): List + suspend fun unauthenticatedSubscriptions(@Body channels: List): List @POST("subscribe") suspend fun subscribe( diff --git a/app/src/main/java/com/github/libretube/api/obj/Comment.kt b/app/src/main/java/com/github/libretube/api/obj/Comment.kt index 422f9c6f19..37a8fad045 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Comment.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Comment.kt @@ -19,5 +19,5 @@ data class Comment( val thumbnail: String, val verified: Boolean, val replyCount: Long, - val creatorReplied: Boolean = false, + val creatorReplied: Boolean = false ) : Parcelable diff --git a/app/src/main/java/com/github/libretube/api/obj/Streams.kt b/app/src/main/java/com/github/libretube/api/obj/Streams.kt index 2f78f508dd..aa4ef6fce5 100644 --- a/app/src/main/java/com/github/libretube/api/obj/Streams.kt +++ b/app/src/main/java/com/github/libretube/api/obj/Streams.kt @@ -6,8 +6,8 @@ import com.github.libretube.extensions.toLocalDateSafe import com.github.libretube.extensions.toMillis import com.github.libretube.helpers.ProxyHelper import com.github.libretube.parcelable.DownloadData -import kotlinx.serialization.Serializable import kotlin.io.path.Path +import kotlinx.serialization.Serializable @Serializable data class Streams( diff --git a/app/src/main/java/com/github/libretube/db/Converters.kt b/app/src/main/java/com/github/libretube/db/Converters.kt index cb7286a602..c3e56a6901 100644 --- a/app/src/main/java/com/github/libretube/db/Converters.kt +++ b/app/src/main/java/com/github/libretube/db/Converters.kt @@ -3,10 +3,10 @@ package com.github.libretube.db import androidx.room.TypeConverter import com.github.libretube.api.JsonHelper import com.github.libretube.extensions.toLocalDateSafe -import kotlinx.datetime.LocalDate -import kotlinx.serialization.encodeToString import java.nio.file.Path import kotlin.io.path.Path +import kotlinx.datetime.LocalDate +import kotlinx.serialization.encodeToString object Converters { @TypeConverter diff --git a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt index cd38120704..168b618fe9 100644 --- a/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt +++ b/app/src/main/java/com/github/libretube/db/DatabaseHelper.kt @@ -21,33 +21,34 @@ object DatabaseHelper { videoId, streams.toStreamItem(videoId) ) - suspend fun addToWatchHistory( - videoId: String, - stream: StreamItem - ) = withContext(Dispatchers.IO) { - val watchHistoryItem = WatchHistoryItem( - videoId, - stream.title, - Instant.fromEpochMilliseconds(stream.uploaded) - .toLocalDateTime(TimeZone.currentSystemDefault()).date, - stream.uploaderName, - stream.uploaderUrl?.toID(), - stream.uploaderAvatar, - stream.thumbnail, - stream.duration - ) - Database.watchHistoryDao().insert(watchHistoryItem) - val maxHistorySize = PreferenceHelper.getString(PreferenceKeys.WATCH_HISTORY_SIZE, "100") - if (maxHistorySize == "unlimited") { - return@withContext - } + suspend fun addToWatchHistory(videoId: String, stream: StreamItem) = + withContext(Dispatchers.IO) { + val watchHistoryItem = WatchHistoryItem( + videoId, + stream.title, + Instant.fromEpochMilliseconds(stream.uploaded) + .toLocalDateTime(TimeZone.currentSystemDefault()).date, + stream.uploaderName, + stream.uploaderUrl?.toID(), + stream.uploaderAvatar, + stream.thumbnail, + stream.duration + ) + Database.watchHistoryDao().insert(watchHistoryItem) + val maxHistorySize = PreferenceHelper.getString( + PreferenceKeys.WATCH_HISTORY_SIZE, + "100" + ) + if (maxHistorySize == "unlimited") { + return@withContext + } - // delete the first watch history entry if the limit is reached - val watchHistory = Database.watchHistoryDao().getAll() - if (watchHistory.size > maxHistorySize.toInt()) { - Database.watchHistoryDao().delete(watchHistory.first()) + // delete the first watch history entry if the limit is reached + val watchHistory = Database.watchHistoryDao().getAll() + if (watchHistory.size > maxHistorySize.toInt()) { + Database.watchHistoryDao().delete(watchHistory.first()) + } } - } suspend fun addToSearchHistory(searchHistoryItem: SearchHistoryItem) { Database.searchHistoryDao().insert(searchHistoryItem) diff --git a/app/src/main/java/com/github/libretube/extensions/LocalDate.kt b/app/src/main/java/com/github/libretube/extensions/LocalDate.kt index 089a6f7bb5..338cec6c76 100644 --- a/app/src/main/java/com/github/libretube/extensions/LocalDate.kt +++ b/app/src/main/java/com/github/libretube/extensions/LocalDate.kt @@ -7,4 +7,4 @@ import kotlinx.datetime.toLocalDate fun LocalDate.toMillis() = this.atStartOfDayIn(TimeZone.UTC).toEpochMilliseconds() -fun String.toLocalDateSafe() = this.substring(0, 10).toLocalDate() \ No newline at end of file +fun String.toLocalDateSafe() = this.substring(0, 10).toLocalDate() diff --git a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt index 70f7d2c000..77b91d27a7 100644 --- a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt @@ -25,11 +25,7 @@ object DashHelper { val audioLocale: String? = null ) - fun createManifest( - streams: Streams, - supportsHdr: Boolean, - rewriteUrls: Boolean - ): String { + fun createManifest(streams: Streams, supportsHdr: Boolean, rewriteUrls: Boolean): String { val builder = builderFactory.newDocumentBuilder() val doc = builder.newDocument() @@ -173,10 +169,7 @@ object DashHelper { return representation } - private fun createSegmentBaseElement( - document: Document, - stream: PipedStream - ): Element { + private fun createSegmentBaseElement(document: Document, stream: PipedStream): Element { val segmentBase = document.createElement("SegmentBase") segmentBase.setAttribute("indexRange", "${stream.indexStart}-${stream.indexEnd}") diff --git a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt index 9361582c29..a89892520a 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -25,10 +25,7 @@ import com.github.libretube.ui.views.SingleViewTouchableMotionLayout object NavigationHelper { private val handler = Handler(Looper.getMainLooper()) - fun navigateChannel( - context: Context, - channelId: String? - ) { + fun navigateChannel(context: Context, channelId: String?) { if (channelId == null) return val activity = ContextHelper.unwrapActivity(context) @@ -85,11 +82,7 @@ object NavigationHelper { } } - fun navigatePlaylist( - context: Context, - playlistId: String?, - playlistType: PlaylistType - ) { + fun navigatePlaylist(context: Context, playlistId: String?, playlistType: PlaylistType) { if (playlistId == null) return val activity = ContextHelper.unwrapActivity(context) diff --git a/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt b/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt index e262e21d8a..059fa3c6fe 100644 --- a/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NotificationHelper.kt @@ -16,10 +16,7 @@ object NotificationHelper { /** * Enqueue the work manager task */ - fun enqueueWork( - context: Context, - existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy - ) { + fun enqueueWork(context: Context, existingPeriodicWorkPolicy: ExistingPeriodicWorkPolicy) { // get the notification preferences PreferenceHelper.initialize(context) val notificationsEnabled = PreferenceHelper.getBoolean( diff --git a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt index be0128e1ca..f78b3ffd3f 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -40,11 +40,11 @@ import com.github.libretube.enums.SbSkipOptions import com.github.libretube.extensions.updateParameters import com.github.libretube.obj.VideoStats import com.github.libretube.util.TextUtils -import kotlinx.coroutines.runBlocking import java.util.Locale import java.util.concurrent.Executors import kotlin.math.absoluteValue import kotlin.math.roundToInt +import kotlinx.coroutines.runBlocking object PlayerHelper { private const val ACTION_MEDIA_CONTROL = "media_control" @@ -65,11 +65,7 @@ object PlayerHelper { /** * Create a base64 encoded DASH stream manifest */ - fun createDashSource( - streams: Streams, - context: Context, - disableProxy: Boolean - ): Uri { + fun createDashSource(streams: Streams, context: Context, disableProxy: Boolean): Uri { val manifest = DashHelper.createManifest( streams, DisplayHelper.supportsHdr(context), @@ -330,10 +326,12 @@ object PlayerHelper { ) fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean { - return autoPlayEnabled || (isPlaylist && PreferenceHelper.getBoolean( - PreferenceKeys.AUTOPLAY_PLAYLISTS, - false - )) + return autoPlayEnabled || ( + isPlaylist && PreferenceHelper.getBoolean( + PreferenceKeys.AUTOPLAY_PLAYLISTS, + false + ) + ) } private val handleAudioFocus @@ -547,9 +545,9 @@ object PlayerHelper { if (currentPosition in segmentStart until segmentEnd) { if (sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC || ( - sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && - !segment.skipped - ) + sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && + !segment.skipped + ) ) { if (sponsorBlockNotifications) { runCatching { @@ -561,9 +559,9 @@ object PlayerHelper { segment.skipped = true } else if (sponsorBlockConfig[segment.category] == SbSkipOptions.MANUAL || ( - sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && - segment.skipped - ) + sponsorBlockConfig[segment.category] == SbSkipOptions.AUTOMATIC_ONCE && + segment.skipped + ) ) { return segment } @@ -747,9 +745,9 @@ object PlayerHelper { */ fun haveAudioTrackRoleFlagSet(@C.RoleFlags roleFlags: Int): Boolean { return isFlagSet(roleFlags, C.ROLE_FLAG_DESCRIBES_VIDEO) || - isFlagSet(roleFlags, C.ROLE_FLAG_DUB) || - isFlagSet(roleFlags, C.ROLE_FLAG_MAIN) || - isFlagSet(roleFlags, C.ROLE_FLAG_ALTERNATE) + isFlagSet(roleFlags, C.ROLE_FLAG_DUB) || + isFlagSet(roleFlags, C.ROLE_FLAG_MAIN) || + isFlagSet(roleFlags, C.ROLE_FLAG_ALTERNATE) } @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) diff --git a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt index 602a11d2be..28b86aa7a7 100644 --- a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt @@ -33,9 +33,7 @@ object ThemeHelper { /** * Update the accent color of the app and apply dynamic colors if needed */ - private fun updateAccentColor( - activity: AppCompatActivity - ) { + private fun updateAccentColor(activity: AppCompatActivity) { var accentColor = PreferenceHelper.getString(PreferenceKeys.ACCENT_COLOR, "") // automatically choose an accent color on the first app startup @@ -117,10 +115,8 @@ object ThemeHelper { /** * Get a color by a color resource attr */ - fun getThemeColor( - context: Context, - colorCode: Int - ) = MaterialColors.getColor(context, colorCode, Color.TRANSPARENT) + fun getThemeColor(context: Context, colorCode: Int) = + MaterialColors.getColor(context, colorCode, Color.TRANSPARENT) /** * Get the styled app name diff --git a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt index 748023cea3..7dd64acaf8 100644 --- a/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OfflinePlayerService.kt @@ -19,7 +19,6 @@ import com.github.libretube.enums.FileType import com.github.libretube.extensions.toAndroidUri import com.github.libretube.extensions.updateParameters import com.github.libretube.helpers.PlayerHelper -import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams import com.github.libretube.obj.PlayerNotificationData import com.github.libretube.util.NowPlayingNotification import com.github.libretube.util.NowPlayingNotification.Companion.PLAYER_NOTIFICATION_ID diff --git a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt index dd00404dab..f557f46e81 100644 --- a/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt +++ b/app/src/main/java/com/github/libretube/services/OnlinePlayerService.kt @@ -35,7 +35,6 @@ import com.github.libretube.extensions.toID import com.github.libretube.extensions.updateParameters import com.github.libretube.helpers.PlayerHelper import com.github.libretube.helpers.PlayerHelper.checkForSegments -import com.github.libretube.helpers.PlayerHelper.loadPlaybackParams import com.github.libretube.helpers.ProxyHelper import com.github.libretube.obj.PlayerNotificationData import com.github.libretube.parcelable.PlayerData diff --git a/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt index 3db1db7a30..48aaeee844 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/OfflinePlayerActivity.kt @@ -36,10 +36,10 @@ import com.github.libretube.ui.interfaces.TimeFrameReceiver import com.github.libretube.ui.listeners.SeekbarPreviewListener import com.github.libretube.ui.models.PlayerViewModel import com.github.libretube.util.OfflineTimeFrameReceiver +import kotlin.io.path.exists import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import kotlin.io.path.exists @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) class OfflinePlayerActivity : BaseActivity() { diff --git a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt index ce8ec06c72..dab5a629e3 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/VideosAdapter.kt @@ -113,9 +113,9 @@ class VideosAdapter( } val context = ( - holder.videoRowBinding ?: holder.trendingRowBinding + holder.videoRowBinding ?: holder.trendingRowBinding ?: holder.allCaughtUpBinding - )!!.root.context + )!!.root.context val activity = (context as BaseActivity) val fragmentManager = activity.supportFragmentManager diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ColorPickerDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ColorPickerDialog.kt index 1e44d7d193..e3c68416aa 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ColorPickerDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ColorPickerDialog.kt @@ -39,19 +39,10 @@ class ColorPickerDialog : DialogFragment(), SeekBar.OnSeekBarChangeListener { // Add listener to text input binding.colorHexInput.addTextChangedListener(object : TextWatcher { - override fun beforeTextChanged( - s: CharSequence?, - start: Int, - count: Int, - after: Int - ) = Unit - - override fun onTextChanged( - s: CharSequence?, - start: Int, - before: Int, - count: Int - ) = Unit + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = + Unit + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) = Unit var isValid = true var oldHex = "" diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt index 908b5de2ea..9663e0aea6 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/ShareDialog.kt @@ -61,8 +61,8 @@ class ShareDialog : DialogFragment() { var url = when { shareObjectType == ShareObjectType.VIDEO && host == YOUTUBE_SHORT_URL -> "$YOUTUBE_SHORT_URL/$id" shareObjectType == ShareObjectType.VIDEO -> "$host/watch?v=$id" - shareObjectType == ShareObjectType.PLAYLIST -> "${host}/playlist?list=$id" - else -> "${host}/channel/$id" + shareObjectType == ShareObjectType.PLAYLIST -> "$host/playlist?list=$id" + else -> "$host/channel/$id" } if (shareObjectType == ShareObjectType.VIDEO && binding.timeCodeSwitch.isChecked) { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt index f44df88bcb..3166432f25 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlayerFragment.kt @@ -15,7 +15,6 @@ import android.os.Looper import android.os.PowerManager import android.text.format.DateUtils import android.text.util.Linkify -import android.util.Log import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -1112,10 +1111,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { /** * Set up the description text with video links and timestamps */ - private fun setupDescription( - descTextView: TextView, - description: String - ) { + private fun setupDescription(descTextView: TextView, description: String) { // detect whether the description is html formatted if (description.contains("<") && description.contains(">")) { descTextView.movementMethod = LinkMovementMethodCompat.getInstance() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt index cbdeffd876..5d5bdd378b 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/PlaylistFragment.kt @@ -356,10 +356,7 @@ class PlaylistFragment : Fragment() { return false } - override fun onSwiped( - viewHolder: RecyclerView.ViewHolder, - direction: Int - ) { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { playlistAdapter!!.removeFromPlaylist( requireContext(), viewHolder.absoluteAdapterPosition diff --git a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt index 4f23555c4c..cca4c4ac56 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/WatchHistoryFragment.kt @@ -127,10 +127,7 @@ class WatchHistoryFragment : Fragment() { return false } - override fun onSwiped( - viewHolder: RecyclerView.ViewHolder, - direction: Int - ) { + override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) { val position = viewHolder.absoluteAdapterPosition watchHistoryAdapter.removeFromWatchHistory(position) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/ChaptersBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/ChaptersBottomSheet.kt index f3f64f1d0e..bf7d961032 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/ChaptersBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/ChaptersBottomSheet.kt @@ -53,9 +53,10 @@ class ChaptersBottomSheet : UndimmedBottomSheet() { super.onViewCreated(view, savedInstanceState) binding.optionsRecycler.layoutManager = LinearLayoutManager(context) - val adapter = ChaptersAdapter(playerViewModel.chapters, playerViewModel.player?.duration ?: 0) { - playerViewModel.player?.seekTo(it) - } + val adapter = + ChaptersAdapter(playerViewModel.chapters, playerViewModel.player?.duration ?: 0) { + playerViewModel.player?.seekTo(it) + } binding.optionsRecycler.adapter = adapter binding.bottomSheetTitle.text = context?.getString(R.string.chapters) diff --git a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt index 6b63ca478f..a1dd6e3a52 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/VideoOptionsBottomSheet.kt @@ -43,7 +43,7 @@ class VideoOptionsBottomSheet : BaseBottomSheet() { val videoId = streamItem.url?.toID() ?: return // List that stores the different menu options. In the future could be add more options here. val optionsList = mutableListOf( - getString(R.string.playOnBackground), + getString(R.string.playOnBackground) ) // Check whether the player is running and add queue options diff --git a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt index d9fddac0fa..9f21605758 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -315,10 +315,7 @@ class NowPlayingNotification( /** * Updates or creates the [notificationBuilder] */ - fun updatePlayerNotification( - videoId: String, - data: PlayerNotificationData - ) { + fun updatePlayerNotification(videoId: String, data: PlayerNotificationData) { this.videoId = videoId this.notificationData = data // reset the thumbnail bitmap in order to become reloaded for the new video diff --git a/app/src/main/java/com/github/libretube/util/YouTubeHlsPlaylistParser.kt b/app/src/main/java/com/github/libretube/util/YouTubeHlsPlaylistParser.kt index 9f83b66098..dd82c0fdce 100644 --- a/app/src/main/java/com/github/libretube/util/YouTubeHlsPlaylistParser.kt +++ b/app/src/main/java/com/github/libretube/util/YouTubeHlsPlaylistParser.kt @@ -213,10 +213,7 @@ class YoutubeHlsPlaylistParser : ParsingLoadable.Parser { * @param acontValue the value of the `acont` property * @return the full audio role flags of the audio track like described above */ - private fun getFullAudioRoleFlags( - roleFlags: Int, - acontValue: String - ): Int { + private fun getFullAudioRoleFlags(roleFlags: Int, acontValue: String): Int { val acontRoleFlags = when (acontValue.lowercase()) { "dubbed" -> C.ROLE_FLAG_DUB "descriptive" -> C.ROLE_FLAG_DESCRIBES_VIDEO