From 70bfaddb2e66af25c8c8a79e8c36471f1f24ba83 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 28 Feb 2024 13:39:55 +0100 Subject: [PATCH] chore: reformat code using ktlint --- .../java/com/github/libretube/api/PipedApi.kt | 1 - .../github/libretube/api/PlaylistsHelper.kt | 4 ++- .../github/libretube/api/obj/PipedInstance.kt | 2 +- .../libretube/db/obj/LocalSubscription.kt | 6 ++-- .../github/libretube/enums/NotificationId.kt | 2 +- .../extensions/MutableLiveDataExt.kt | 2 +- .../github/libretube/extensions/RunSafely.kt | 4 +-- .../github/libretube/helpers/ImageHelper.kt | 3 +- .../github/libretube/helpers/ImportHelper.kt | 6 +++- .../github/libretube/helpers/NavBarHelper.kt | 1 - .../libretube/helpers/NavigationHelper.kt | 7 ++-- .../github/libretube/helpers/NetworkHelper.kt | 4 +-- .../github/libretube/helpers/PlayerHelper.kt | 24 +++++++------- .../github/libretube/helpers/ThemeHelper.kt | 20 +++++++++--- .../com/github/libretube/obj/BackupFile.kt | 2 +- .../github/libretube/obj/SelectableOption.kt | 2 +- .../github/libretube/obj/update/UpdateInfo.kt | 2 +- .../PlaylistDownloadEnqueueService.kt | 6 ++-- .../libretube/ui/activities/MainActivity.kt | 2 +- .../libretube/ui/adapters/VideosAdapter.kt | 4 +-- .../github/libretube/ui/base/BaseActivity.kt | 3 +- .../ui/dialogs/AddToPlaylistDialog.kt | 1 - .../libretube/ui/dialogs/DownloadDialog.kt | 2 +- .../ui/dialogs/DownloadPlaylistDialog.kt | 29 +++++++++++------ .../ui/dialogs/SubmitSegmentDialog.kt | 1 - .../ui/dialogs/VoteForSegmentDialog.kt | 3 +- .../libretube/ui/extensions/RecyclerView.kt | 2 +- .../libretube/ui/extensions/ViewAnimations.kt | 2 +- .../libretube/ui/fragments/ChannelFragment.kt | 2 +- .../ui/fragments/CommentsMainFragment.kt | 2 +- .../ui/fragments/CommentsRepliesFragment.kt | 2 +- .../ui/fragments/DownloadsFragment.kt | 14 ++++---- .../libretube/ui/fragments/HomeFragment.kt | 12 +++---- .../libretube/ui/fragments/PlayerFragment.kt | 20 +++++++----- .../ui/fragments/SearchResultFragment.kt | 30 +++++++++-------- .../ui/fragments/SubscriptionsFragment.kt | 16 +++++++--- .../libretube/ui/models/CommentsViewModel.kt | 1 + .../libretube/ui/models/HomeViewModel.kt | 4 +-- .../libretube/ui/models/PlayerViewModel.kt | 2 +- .../ui/models/SearchResultViewModel.kt | 2 ++ .../libretube/ui/models/TrendsViewModel.kt | 14 ++++---- .../sources/CommentRepliesPagingSource.kt | 2 +- .../ui/models/sources/SearchPagingSource.kt | 2 +- .../ui/preferences/InstanceSettings.kt | 5 +-- .../libretube/ui/preferences/MainSettings.kt | 1 - .../ui/sheets/DownloadOptionsBottomSheet.kt | 3 -- .../ui/sheets/FilterSortBottomSheet.kt | 6 ++-- .../libretube/ui/views/CustomExoPlayerView.kt | 4 ++- .../views/SingleViewTouchableMotionLayout.kt | 1 - .../libretube/util/NowPlayingNotification.kt | 32 ++++++++++++------- .../github/libretube/util/PauseableTimer.kt | 16 ++++++---- .../github/libretube/util/UpdateChecker.kt | 4 +-- .../baselineprofile/StartupBenchmarks.kt | 3 +- 53 files changed, 201 insertions(+), 146 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 bc374110b..7daac2e6b 100644 --- a/app/src/main/java/com/github/libretube/api/PipedApi.kt +++ b/app/src/main/java/com/github/libretube/api/PipedApi.kt @@ -1,7 +1,6 @@ package com.github.libretube.api import com.github.libretube.api.obj.* -import kotlinx.serialization.json.JsonObject import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.Header diff --git a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt index d93100045..3cce0d4d5 100644 --- a/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt +++ b/app/src/main/java/com/github/libretube/api/PlaylistsHelper.kt @@ -187,7 +187,9 @@ object PlaylistsHelper { } else { // if not logged in, all video information needs to become fetched manually // Only do so with `MAX_CONCURRENT_IMPORT_CALLS` videos at once to prevent performance issues - val streams = playlist.videos.chunked(MAX_CONCURRENT_IMPORT_CALLS).map { videos -> + val streams = playlist.videos.chunked( + MAX_CONCURRENT_IMPORT_CALLS + ).map { videos -> videos.parallelMap { runCatching { RetrofitInstance.api.getStreams(it) } .getOrNull() diff --git a/app/src/main/java/com/github/libretube/api/obj/PipedInstance.kt b/app/src/main/java/com/github/libretube/api/obj/PipedInstance.kt index fa9a0479b..52f203ad1 100644 --- a/app/src/main/java/com/github/libretube/api/obj/PipedInstance.kt +++ b/app/src/main/java/com/github/libretube/api/obj/PipedInstance.kt @@ -20,5 +20,5 @@ data class PipedInstance( @SerialName("uptime_24h") val uptimeToday: Float? = null, @SerialName("uptime_7d") val uptimeWeek: Float? = null, @SerialName("uptime_30d") val uptimeMonth: Float? = null, - val isCurrentlyDown: Boolean = false, + val isCurrentlyDown: Boolean = false ) diff --git a/app/src/main/java/com/github/libretube/db/obj/LocalSubscription.kt b/app/src/main/java/com/github/libretube/db/obj/LocalSubscription.kt index cb7056b8c..aa12bed09 100644 --- a/app/src/main/java/com/github/libretube/db/obj/LocalSubscription.kt +++ b/app/src/main/java/com/github/libretube/db/obj/LocalSubscription.kt @@ -10,7 +10,9 @@ import kotlinx.serialization.Serializable @Entity(tableName = "localSubscription") data class LocalSubscription( @PrimaryKey val channelId: String, - @Ignore val url: String = "", + @Ignore val url: String = "" ) { - constructor(channelId: String): this(channelId, "${ShareDialog.YOUTUBE_FRONTEND_URL}/channel/$channelId") + constructor( + channelId: String + ) : this(channelId, "${ShareDialog.YOUTUBE_FRONTEND_URL}/channel/$channelId") } diff --git a/app/src/main/java/com/github/libretube/enums/NotificationId.kt b/app/src/main/java/com/github/libretube/enums/NotificationId.kt index bcf9b403b..d9b4a340a 100644 --- a/app/src/main/java/com/github/libretube/enums/NotificationId.kt +++ b/app/src/main/java/com/github/libretube/enums/NotificationId.kt @@ -4,4 +4,4 @@ enum class NotificationId(val id: Int) { PLAYER_PLAYBACK(1), DOWNLOAD_IN_PROGRESS(2), ENQUEUE_PLAYLIST_DOWNLOAD(3) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/extensions/MutableLiveDataExt.kt b/app/src/main/java/com/github/libretube/extensions/MutableLiveDataExt.kt index 51b2a374f..a85aa78bd 100644 --- a/app/src/main/java/com/github/libretube/extensions/MutableLiveDataExt.kt +++ b/app/src/main/java/com/github/libretube/extensions/MutableLiveDataExt.kt @@ -4,4 +4,4 @@ import androidx.lifecycle.MutableLiveData fun MutableLiveData.updateIfChanged(newValue: T) { if (value != newValue) value = newValue -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/extensions/RunSafely.kt b/app/src/main/java/com/github/libretube/extensions/RunSafely.kt index 66db73236..303450f11 100644 --- a/app/src/main/java/com/github/libretube/extensions/RunSafely.kt +++ b/app/src/main/java/com/github/libretube/extensions/RunSafely.kt @@ -5,7 +5,7 @@ import kotlinx.coroutines.withContext suspend fun runSafely( onSuccess: (List) -> Unit = { }, - ioBlock: suspend () -> List, + ioBlock: suspend () -> List ) { withContext(Dispatchers.IO) { val result = runCatching { ioBlock.invoke() } @@ -18,4 +18,4 @@ suspend fun runSafely( } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt index 75eeb38b4..b95fd7514 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt @@ -9,7 +9,6 @@ import android.widget.ImageView import androidx.core.graphics.drawable.toBitmapOrNull import coil.ImageLoader import coil.disk.DiskCache -import coil.load import coil.request.CachePolicy import coil.request.ImageRequest import com.github.libretube.api.CronetHelper @@ -17,10 +16,10 @@ import com.github.libretube.constants.PreferenceKeys import com.github.libretube.extensions.toAndroidUri import com.github.libretube.extensions.toAndroidUriOrNull import com.github.libretube.util.DataSaverMode +import java.io.File import java.nio.file.Path import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import java.io.File object ImageHelper { lateinit var imageLoader: ImageLoader diff --git a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt index cd1268921..dff2dd702 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt @@ -116,7 +116,11 @@ object ImportHelper { ImportFormat.FREETUBE -> { val freeTubeChannels = subs.map { - FreetubeSubscription(it.name, "", "${ShareDialog.YOUTUBE_FRONTEND_URL}${it.url}") + FreetubeSubscription( + it.name, + "", + "${ShareDialog.YOUTUBE_FRONTEND_URL}${it.url}" + ) } val freeTubeSubscriptions = FreetubeSubscriptions(subscriptions = freeTubeChannels) activity.contentResolver.openOutputStream(uri)?.use { diff --git a/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt b/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt index d0d24bf02..a09e01831 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavBarHelper.kt @@ -139,5 +139,4 @@ object NavBarHelper { .getString(PreferenceKeys.NAVBAR_ITEMS, "") .split(SEPARATOR) } - } 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 092c71bfb..9e446806a 100644 --- a/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NavigationHelper.kt @@ -73,7 +73,8 @@ object NavigationHelper { return } - val playerData = PlayerData(videoUrlOrId.toID(), playlistId, channelId, keepQueue, timestamp) + val playerData = + PlayerData(videoUrlOrId.toID(), playlistId, channelId, keepQueue, timestamp) val bundle = bundleOf(IntentData.playerData to playerData) val activity = ContextHelper.unwrapActivity(context) @@ -86,7 +87,9 @@ object NavigationHelper { if (playlistUrlOrId == null) return val activity = ContextHelper.unwrapActivity(context) - activity.navController.navigate(NavDirections.openPlaylist(playlistUrlOrId.toID(), playlistType)) + activity.navController.navigate( + NavDirections.openPlaylist(playlistUrlOrId.toID(), playlistType) + ) } /** diff --git a/app/src/main/java/com/github/libretube/helpers/NetworkHelper.kt b/app/src/main/java/com/github/libretube/helpers/NetworkHelper.kt index c500bbab1..9c90864d8 100644 --- a/app/src/main/java/com/github/libretube/helpers/NetworkHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/NetworkHelper.kt @@ -18,8 +18,8 @@ object NetworkHelper { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { val activeNetwork = connectivityManager.activeNetwork val caps = connectivityManager.getNetworkCapabilities(activeNetwork) ?: return false - return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) - || caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN) + return caps.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) || + caps.hasTransport(NetworkCapabilities.TRANSPORT_VPN) } else { // activeNetworkInfo might return null instead of the VPN, so better check it explicitly val networkInfo = connectivityManager.activeNetworkInfo 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 c9e558779..8ab1ab45b 100644 --- a/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/PlayerHelper.kt @@ -42,14 +42,14 @@ 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.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking import java.util.Locale import java.util.concurrent.Executors import kotlin.math.absoluteValue import kotlin.math.roundToInt +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking object PlayerHelper { private const val ACTION_MEDIA_CONTROL = "media_control" @@ -344,11 +344,11 @@ object PlayerHelper { fun shouldPlayNextVideo(isPlaylist: Boolean = false): Boolean { return autoPlayEnabled || ( - isPlaylist && PreferenceHelper.getBoolean( - PreferenceKeys.AUTOPLAY_PLAYLISTS, - false - ) - ) + isPlaylist && PreferenceHelper.getBoolean( + PreferenceKeys.AUTOPLAY_PLAYLISTS, + false + ) + ) } private val handleAudioFocus @@ -760,9 +760,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 381503540..d9fb78b44 100644 --- a/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt @@ -36,20 +36,30 @@ object ThemeHelper { window.statusBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { getThemeColor(context, android.R.attr.colorBackground) } else { - if (isDarkMode(context)) getThemeColor(context, android.R.attr.colorBackground) - else getThemeColor(context, com.google.android.material.R.attr.colorOnBackground) + if (isDarkMode(context)) { + getThemeColor(context, android.R.attr.colorBackground) + } else { + getThemeColor(context, com.google.android.material.R.attr.colorOnBackground) + } } } /** * Set the background color of the navigation bar */ - private fun setNavigationBarColor(context: Context, window: Window, isBottomNavVisible: Boolean) { + private fun setNavigationBarColor( + context: Context, + window: Window, + isBottomNavVisible: Boolean + ) { window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) { getThemeColor(context, com.google.android.material.R.attr.colorOnBackground) } else { - if (isBottomNavVisible) getThemeColor(context, com.google.android.material.R.attr.colorSurfaceContainer) - else getThemeColor(context, android.R.attr.colorBackground) + if (isBottomNavVisible) { + getThemeColor(context, com.google.android.material.R.attr.colorSurfaceContainer) + } else { + getThemeColor(context, android.R.attr.colorBackground) + } } } diff --git a/app/src/main/java/com/github/libretube/obj/BackupFile.kt b/app/src/main/java/com/github/libretube/obj/BackupFile.kt index 90e3be598..0bc1d0871 100644 --- a/app/src/main/java/com/github/libretube/obj/BackupFile.kt +++ b/app/src/main/java/com/github/libretube/obj/BackupFile.kt @@ -46,5 +46,5 @@ data class BackupFile( // playlists are exported in two different formats because the formats differ too much unfortunately var localPlaylists: List? = emptyList(), - var playlists: List? = emptyList(), + var playlists: List? = emptyList() ) diff --git a/app/src/main/java/com/github/libretube/obj/SelectableOption.kt b/app/src/main/java/com/github/libretube/obj/SelectableOption.kt index 2378c3dea..21b7bd542 100644 --- a/app/src/main/java/com/github/libretube/obj/SelectableOption.kt +++ b/app/src/main/java/com/github/libretube/obj/SelectableOption.kt @@ -7,4 +7,4 @@ import kotlinx.parcelize.Parcelize data class SelectableOption( val isSelected: Boolean, val name: String -): Parcelable \ No newline at end of file +) : Parcelable diff --git a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt index caec9aa49..729dced36 100644 --- a/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt +++ b/app/src/main/java/com/github/libretube/obj/update/UpdateInfo.kt @@ -10,5 +10,5 @@ import kotlinx.serialization.Serializable data class UpdateInfo( val name: String, val body: String, - @SerialName("html_url") val htmlUrl: String, + @SerialName("html_url") val htmlUrl: String ) : Parcelable diff --git a/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt b/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt index 81b7129e8..2fa6b2b4e 100644 --- a/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt +++ b/app/src/main/java/com/github/libretube/services/PlaylistDownloadEnqueueService.kt @@ -72,7 +72,9 @@ class PlaylistDownloadEnqueueService : LifecycleService() { private fun buildNotification(): Notification { return NotificationCompat.Builder(this, PLAYLIST_DOWNLOAD_ENQUEUE_CHANNEL_NAME) .setSmallIcon(R.drawable.ic_download) - .setContentTitle(getString(R.string.enqueueing_playlist_download, playlistName ?: "...")) + .setContentTitle( + getString(R.string.enqueueing_playlist_download, playlistName ?: "...") + ) .setProgress(amountOfVideos, amountOfVideosDone, false) .setOnlyAlertOnce(true) .build() @@ -183,4 +185,4 @@ class PlaylistDownloadEnqueueService : LifecycleService() { super.onDestroy() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index a3a7d6307..62ceb82c9 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -168,7 +168,7 @@ class MainActivity : BaseActivity() { R.id.searchResultFragment -> { navController.popBackStack(R.id.searchFragment, true) || - navController.popBackStack() + navController.popBackStack() } else -> { 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 f93f8486c..8f7360ff0 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 @@ -112,9 +112,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/base/BaseActivity.kt b/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt index c1e4e98f5..37e091d6a 100644 --- a/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/base/BaseActivity.kt @@ -40,8 +40,9 @@ open class BaseActivity : AppCompatActivity() { ThemeHelper.updateTheme(this) // Set the navigation and statusBar color if SDK < 23 - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { ThemeHelper.setSystemBarColors(this, window, false) + } // set the apps language LocaleHelper.updateLanguage(this) diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt index 5360837f0..90f237f50 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/AddToPlaylistDialog.kt @@ -5,7 +5,6 @@ import android.app.Dialog import android.content.DialogInterface import android.os.Bundle import android.util.Log -import android.widget.ArrayAdapter import android.widget.Toast import androidx.fragment.app.DialogFragment import androidx.fragment.app.activityViewModels diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt index ad5759529..d0503dd2a 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadDialog.kt @@ -24,11 +24,11 @@ import com.github.libretube.helpers.PreferenceHelper import com.github.libretube.parcelable.DownloadData import com.github.libretube.util.TextUtils import com.google.android.material.dialog.MaterialAlertDialogBuilder +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import retrofit2.HttpException -import java.io.IOException class DownloadDialog : DialogFragment() { private lateinit var videoId: String diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadPlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadPlaylistDialog.kt index 9c2e5c06d..d7b53a699 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DownloadPlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DownloadPlaylistDialog.kt @@ -52,21 +52,31 @@ class DownloadPlaylistDialog : DialogFragment() { .setView(binding.root) .setPositiveButton(R.string.download) { _, _ -> with(binding) { - val maxVideoQuality = if (videoSpinner.selectedItemPosition >= 1) + val maxVideoQuality = if (videoSpinner.selectedItemPosition >= 1) { possibleVideoQualities[videoSpinner.selectedItemPosition - 1] - .getWhileDigit() else null + .getWhileDigit() + } else { + null + } - val maxAudioQuality = if (audioSpinner.selectedItemPosition >= 1) + val maxAudioQuality = if (audioSpinner.selectedItemPosition >= 1) { possibleAudioQualities[audioSpinner.selectedItemPosition - 1] - .getWhileDigit() else null + .getWhileDigit() + } else { + null + } - val captionLanguage = if (subtitleSpinner.selectedItemPosition >= 1) + val captionLanguage = if (subtitleSpinner.selectedItemPosition >= 1) { availableLanguages[subtitleSpinner.selectedItemPosition - 1].code - else null + } else { + null + } - val audioLanguage = if (audioLanguageSpinner.selectedItemPosition >= 1) + val audioLanguage = if (audioLanguageSpinner.selectedItemPosition >= 1) { availableLanguages[audioLanguageSpinner.selectedItemPosition - 1].code - else null + } else { + null + } if (maxVideoQuality == null && maxAudioQuality == null) { Toast.makeText(context, R.string.nothing_selected, Toast.LENGTH_SHORT) @@ -89,6 +99,5 @@ class DownloadPlaylistDialog : DialogFragment() { } .setNegativeButton(R.string.cancel, null) .show() - } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/SubmitSegmentDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/SubmitSegmentDialog.kt index 06359f47e..235f582b4 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/SubmitSegmentDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/SubmitSegmentDialog.kt @@ -4,7 +4,6 @@ import android.app.Dialog import android.content.DialogInterface import android.os.Bundle import android.util.Log -import android.widget.ArrayAdapter import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/VoteForSegmentDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/VoteForSegmentDialog.kt index 728bd6c20..c2820aeb0 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/VoteForSegmentDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/VoteForSegmentDialog.kt @@ -5,7 +5,6 @@ import android.content.DialogInterface import android.os.Bundle import android.text.format.DateUtils import android.util.Log -import android.widget.ArrayAdapter import android.widget.Toast import androidx.fragment.app.DialogFragment import androidx.lifecycle.lifecycleScope @@ -100,7 +99,7 @@ class VoteForSegmentDialog : DialogFragment() { binding.segmentsDropdown.items = segments.map { val (start, end) = it.segmentStartAndEnd val (startStr, endStr) = DateUtils.formatElapsedTime(start.toLong()) to - DateUtils.formatElapsedTime(end.toLong()) + DateUtils.formatElapsedTime(end.toLong()) "${it.category} ($startStr - $endStr)" } } diff --git a/app/src/main/java/com/github/libretube/ui/extensions/RecyclerView.kt b/app/src/main/java/com/github/libretube/ui/extensions/RecyclerView.kt index 127abbbb6..a6250eba7 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/RecyclerView.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/RecyclerView.kt @@ -6,4 +6,4 @@ fun RecyclerView.addOnBottomReachedListener(onBottomReached: () -> Unit) { viewTreeObserver.addOnScrollChangedListener { if (!canScrollVertically(1)) onBottomReached() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/extensions/ViewAnimations.kt b/app/src/main/java/com/github/libretube/ui/extensions/ViewAnimations.kt index 9cb78ba0e..dc2e9f7b0 100644 --- a/app/src/main/java/com/github/libretube/ui/extensions/ViewAnimations.kt +++ b/app/src/main/java/com/github/libretube/ui/extensions/ViewAnimations.kt @@ -20,4 +20,4 @@ fun View.animateDown( .y(dy) .setDuration(duration) .start() -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt index b36e86005..2870742d7 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/ChannelFragment.kt @@ -34,11 +34,11 @@ import com.github.libretube.ui.extensions.addOnBottomReachedListener import com.github.libretube.ui.extensions.setupSubscriptionButton import com.github.libretube.ui.sheets.AddChannelToGroupSheet import com.github.libretube.util.deArrow +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import retrofit2.HttpException -import java.io.IOException class ChannelFragment : DynamicLayoutManagerFragment() { private var _binding: FragmentChannelBinding? = null 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 973fda531..3684a7f53 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 @@ -62,7 +62,7 @@ class CommentsMainFragment : Fragment() { this, viewModel.videoIdLiveData.value ?: return, viewModel.channelAvatar ?: return, - handleLink = viewModel.handleLink, + handleLink = viewModel.handleLink ) { viewModel.commentsSheetDismiss?.invoke() } 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 69d67bdc8..32d9bf75c 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 @@ -56,7 +56,7 @@ class CommentsRepliesFragment : Fragment() { videoId, viewModel.channelAvatar, comment, - viewModel.handleLink, + viewModel.handleLink ) { viewModel.commentsSheetDismiss?.invoke() } diff --git a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt index 4de9a64ea..d18a4b7e3 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/DownloadsFragment.kt @@ -156,15 +156,13 @@ class DownloadsFragment : DynamicLayoutManagerFragment() { } ) - - if (dbDownloads.isNotEmpty()){ + if (dbDownloads.isNotEmpty()) { binding.deleteAll.isVisible = true - binding.deleteAll.setOnClickListener{ + binding.deleteAll.setOnClickListener { showDeleteAllDialog(binding.root.context, adapter) } } - binding.shuffleBackground.setOnClickListener { BackgroundHelper.playOnBackgroundOffline(requireContext(), null) } @@ -191,7 +189,6 @@ class DownloadsFragment : DynamicLayoutManagerFragment() { super.onStart() } - override fun onResume() { super.onResume() @@ -199,7 +196,12 @@ class DownloadsFragment : DynamicLayoutManagerFragment() { addAction(DownloadService.ACTION_SERVICE_STARTED) addAction(DownloadService.ACTION_SERVICE_STOPPED) } - ContextCompat.registerReceiver(requireContext(), downloadReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED) + ContextCompat.registerReceiver( + requireContext(), + downloadReceiver, + filter, + ContextCompat.RECEIVER_NOT_EXPORTED + ) } fun bindDownloadService(ids: IntArray? = null) { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt index c397b1614..f6805eeaa 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/HomeFragment.kt @@ -95,7 +95,7 @@ class HomeFragment : Fragment() { } private fun observeChanges() { - with (homeViewModel) { + with(homeViewModel) { trending.observe(viewLifecycleOwner, ::showTrending) feed.observe(viewLifecycleOwner, ::showFeed) bookmarks.observe(viewLifecycleOwner, ::showBookmarks) @@ -111,7 +111,7 @@ class HomeFragment : Fragment() { } private fun stopObservingChanges() { - with (homeViewModel) { + with(homeViewModel) { trending.removeObserver(::showTrending) feed.removeObserver(::showFeed) bookmarks.removeObserver(::showBookmarks) @@ -151,11 +151,11 @@ class HomeFragment : Fragment() { } private fun showFeed(streamItems: List?) { - if (streamItems == null) return + if (streamItems == null) return makeVisible(binding.featuredRV, binding.featuredTV) val feedVideos = streamItems.take(20).toMutableList() - with (binding.featuredRV) { + with(binding.featuredRV) { layoutManager = LinearLayoutManager(context, HORIZONTAL, false) adapter = VideosAdapter(feedVideos, forceMode = LayoutMode.RELATED_COLUMN) } @@ -165,7 +165,7 @@ class HomeFragment : Fragment() { if (bookmarks == null) return makeVisible(binding.bookmarksTV, binding.bookmarksRV) - with (binding.bookmarksRV) { + with(binding.bookmarksRV) { layoutManager = LinearLayoutManager(context, HORIZONTAL, false) adapter = PlaylistBookmarkAdapter( bookmarks.toMutableList(), @@ -263,4 +263,4 @@ class HomeFragment : Fragment() { private fun makeVisible(vararg views: View) { views.forEach { it.isVisible = true } } -} \ No newline at end of file +} 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 5c01fef0c..4bc96498f 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 @@ -113,12 +113,12 @@ import com.github.libretube.util.PlayingQueue import com.github.libretube.util.TextUtils import com.github.libretube.util.TextUtils.toTimeInSeconds import com.github.libretube.util.YoutubeHlsPlaylistParser -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import java.util.* import java.util.concurrent.Executors import kotlin.math.abs +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) class PlayerFragment : Fragment(), OnlinePlayerOptions { @@ -497,7 +497,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { .animateDown( duration = 300L, dy = 500F, - onEnd = ::onManualPlayerClose, + onEnd = ::onManualPlayerClose ) } @@ -868,7 +868,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { handler.postDelayed(this::checkForSegments, 100) if (!sponsorBlockEnabled || viewModel.segments.isEmpty()) return - exoPlayer.checkForSegments(requireContext(), viewModel.segments, viewModel.sponsorBlockConfig) + exoPlayer.checkForSegments( + requireContext(), + viewModel.segments, + viewModel.sponsorBlockConfig + ) ?.let { segment -> if (viewModel.isMiniPlayerVisible.value == true) return@let binding.sbSkipBtn.isVisible = true @@ -913,7 +917,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { val videoStream = streams.videoStreams.firstOrNull() val isShort = PlayingQueue.getCurrent()?.isShort == true || - (videoStream?.height ?: 0) > (videoStream?.width ?: 0) + (videoStream?.height ?: 0) > (videoStream?.width ?: 0) PlayingQueue.setOnQueueTapListener { streamItem -> streamItem.url?.toID()?.let { playNextVideo(it) } @@ -950,7 +954,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { if (binding.playerMotionLayout.progress != 1.0f) { // show controllers when not in picture in picture mode val inPipMode = PlayerHelper.pipEnabled && - PictureInPictureCompat.isInPictureInPictureMode(requireActivity()) + PictureInPictureCompat.isInPictureInPictureMode(requireActivity()) if (!inPipMode) { binding.player.useController = true } @@ -1621,7 +1625,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { private fun shouldStartPiP(): Boolean { return shouldUsePip() && exoPlayer.isPlaying && - !BackgroundHelper.isBackgroundServiceRunning(requireContext()) + !BackgroundHelper.isBackgroundServiceRunning(requireContext()) } private fun killPlayerFragment() { diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt index 8e74fc990..17dce290a 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SearchResultFragment.kt @@ -61,20 +61,22 @@ class SearchResultFragment : DynamicLayoutManagerFragment() { // filter options binding.filterChipGroup.setOnCheckedStateChangeListener { _, _ -> - viewModel.setFilter(when ( - binding.filterChipGroup.checkedChipId - ) { - R.id.chip_all -> "all" - R.id.chip_videos -> "videos" - R.id.chip_channels -> "channels" - R.id.chip_playlists -> "playlists" - R.id.chip_music_songs -> "music_songs" - R.id.chip_music_videos -> "music_videos" - R.id.chip_music_albums -> "music_albums" - R.id.chip_music_playlists -> "music_playlists" - R.id.chip_music_artists -> "music_artists" - else -> throw IllegalArgumentException("Filter out of range") - }) + viewModel.setFilter( + when ( + binding.filterChipGroup.checkedChipId + ) { + R.id.chip_all -> "all" + R.id.chip_videos -> "videos" + R.id.chip_channels -> "channels" + R.id.chip_playlists -> "playlists" + R.id.chip_music_songs -> "music_songs" + R.id.chip_music_videos -> "music_videos" + R.id.chip_music_albums -> "music_albums" + R.id.chip_music_playlists -> "music_playlists" + R.id.chip_music_artists -> "music_artists" + else -> throw IllegalArgumentException("Filter out of range") + } + ) } val timeStamp = args.query.toHttpUrlOrNull()?.queryParameter("t")?.toTimeInSeconds() diff --git a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt index fcbddfb3c..c9a9feecc 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/SubscriptionsFragment.kt @@ -17,7 +17,6 @@ import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.R -import com.github.libretube.api.obj.Channel import com.github.libretube.api.obj.StreamItem import com.github.libretube.api.obj.Subscription import com.github.libretube.constants.IntentData @@ -191,7 +190,10 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() { val fragManager = activityCompat .supportFragmentManager .apply { - setFragmentResultListener(FILTER_SORT_REQUEST_KEY, activityCompat) { _, resultBundle -> + setFragmentResultListener( + FILTER_SORT_REQUEST_KEY, + activityCompat + ) { _, resultBundle -> selectedSortOrder = resultBundle.getInt(IntentData.sortOptions) hideWatched = resultBundle.getBoolean(IntentData.hideWatched) showFeed() @@ -301,9 +303,13 @@ class SubscriptionsFragment : DynamicLayoutManagerFragment() { } } - return if (hideWatched) runBlocking { - DatabaseHelper.filterUnwatched(streamItems) - } else streamItems + return if (hideWatched) { + runBlocking { + DatabaseHelper.filterUnwatched(streamItems) + } + } else { + streamItems + } } private fun List.sortedBySelectedOrder() = when (selectedSortOrder) { 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 e1b8614fc..1e5c23963 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 @@ -25,6 +25,7 @@ class CommentsViewModel : ViewModel() { }.flow } .cachedIn(viewModelScope) + @OptIn(ExperimentalCoroutinesApi::class) val commentRepliesFlow = videoIdLiveData.asFlow() .combine(selectedCommentLiveData.asFlow()) { videoId, comment -> videoId to comment } diff --git a/app/src/main/java/com/github/libretube/ui/models/HomeViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/HomeViewModel.kt index 412224704..a9119315e 100644 --- a/app/src/main/java/com/github/libretube/ui/models/HomeViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/HomeViewModel.kt @@ -28,7 +28,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -class HomeViewModel: ViewModel() { +class HomeViewModel : ViewModel() { private val hideWatched get() = PreferenceHelper.getBoolean(HIDE_WATCHED_FROM_FEED, false) val trending: MutableLiveData> = MutableLiveData(null) @@ -147,4 +147,4 @@ class HomeViewModel: ViewModel() { private const val BOOKMARKS = "bookmarks" private const val PLAYLISTS = "playlists" } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt index 7cf9d84c7..180c09c1e 100644 --- a/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/PlayerViewModel.kt @@ -19,11 +19,11 @@ import com.github.libretube.api.obj.Subtitle import com.github.libretube.helpers.PlayerHelper import com.github.libretube.util.NowPlayingNotification import com.github.libretube.util.deArrow +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.encodeToString import retrofit2.HttpException -import java.io.IOException class PlayerViewModel : ViewModel() { var player: ExoPlayer? = null diff --git a/app/src/main/java/com/github/libretube/ui/models/SearchResultViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/SearchResultViewModel.kt index 413dce69a..70972c0b0 100644 --- a/app/src/main/java/com/github/libretube/ui/models/SearchResultViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/SearchResultViewModel.kt @@ -17,11 +17,13 @@ import kotlinx.coroutines.flow.flatMapLatest class SearchResultViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { private val args = SearchResultFragmentArgs.fromSavedStateHandle(savedStateHandle) + // parse search URLs from YouTube entered in the search bar private val videoId = TextUtils.getVideoIdFromUri(args.query.toUri()) ?: args.query private val searchQuery = "${ShareDialog.YOUTUBE_FRONTEND_URL}/watch?v=$videoId" private val filterMutableData = MutableStateFlow("all") + @OptIn(ExperimentalCoroutinesApi::class) val searchResultsFlow = filterMutableData.flatMapLatest { Pager( diff --git a/app/src/main/java/com/github/libretube/ui/models/TrendsViewModel.kt b/app/src/main/java/com/github/libretube/ui/models/TrendsViewModel.kt index f9341bd15..3f634807d 100644 --- a/app/src/main/java/com/github/libretube/ui/models/TrendsViewModel.kt +++ b/app/src/main/java/com/github/libretube/ui/models/TrendsViewModel.kt @@ -13,24 +13,24 @@ import com.github.libretube.api.obj.StreamItem import com.github.libretube.extensions.TAG import com.github.libretube.helpers.LocaleHelper import com.github.libretube.util.deArrow +import java.io.IOException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import retrofit2.HttpException -import java.io.IOException -class TrendsViewModel: ViewModel() { +class TrendsViewModel : ViewModel() { val trendingVideos = MutableLiveData>() var recyclerViewState: Parcelable? = null fun fetchTrending(context: Context) { viewModelScope.launch { try { - val region = LocaleHelper.getTrendingRegion(context) - val response = withContext(Dispatchers.IO) { - RetrofitInstance.api.getTrending(region).deArrow() - } - trendingVideos.postValue(response) + val region = LocaleHelper.getTrendingRegion(context) + val response = withContext(Dispatchers.IO) { + RetrofitInstance.api.getTrending(region).deArrow() + } + trendingVideos.postValue(response) } catch (e: IOException) { println(e) Log.e(TAG(), "IOException, you might not have internet connection") diff --git a/app/src/main/java/com/github/libretube/ui/models/sources/CommentRepliesPagingSource.kt b/app/src/main/java/com/github/libretube/ui/models/sources/CommentRepliesPagingSource.kt index 5884754a6..32774ae1f 100644 --- a/app/src/main/java/com/github/libretube/ui/models/sources/CommentRepliesPagingSource.kt +++ b/app/src/main/java/com/github/libretube/ui/models/sources/CommentRepliesPagingSource.kt @@ -7,7 +7,7 @@ import com.github.libretube.api.obj.Comment class CommentRepliesPagingSource( private val videoId: String, - private val commentNextPage: String?, + private val commentNextPage: String? ) : PagingSource() { override fun getRefreshKey(state: PagingState) = null diff --git a/app/src/main/java/com/github/libretube/ui/models/sources/SearchPagingSource.kt b/app/src/main/java/com/github/libretube/ui/models/sources/SearchPagingSource.kt index fd9a97cee..af98fb474 100644 --- a/app/src/main/java/com/github/libretube/ui/models/sources/SearchPagingSource.kt +++ b/app/src/main/java/com/github/libretube/ui/models/sources/SearchPagingSource.kt @@ -10,7 +10,7 @@ import retrofit2.HttpException class SearchPagingSource( private val searchQuery: String, private val searchFilter: String -): PagingSource() { +) : PagingSource() { override fun getRefreshKey(state: PagingState) = null override suspend fun load(params: LoadParams): LoadResult { diff --git a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt index 963eb49cd..7ea02f59e 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/InstanceSettings.kt @@ -30,13 +30,14 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import okhttp3.HttpUrl.Companion.toHttpUrl -import okhttp3.HttpUrl.Companion.toHttpUrlOrNull class InstanceSettings : BasePreferenceFragment() { override val titleResourceId: Int = R.string.instance private val token get() = PreferenceHelper.getToken() private var instances = mutableListOf() - private val authInstanceToggle get() = findPreference(PreferenceKeys.AUTH_INSTANCE_TOGGLE)!! + private val authInstanceToggle get() = findPreference( + PreferenceKeys.AUTH_INSTANCE_TOGGLE + )!! override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.instance_settings, rootKey) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt index d7ea55129..7d22a6aaf 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/MainSettings.kt @@ -21,7 +21,6 @@ class MainSettings : BasePreferenceFragment() { // check app update manually update?.setOnPreferenceClickListener { - lifecycleScope.launch(Dispatchers.IO) { UpdateChecker(requireContext()).checkUpdate(true) } diff --git a/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt index edcfbcc0c..66095580f 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/DownloadOptionsBottomSheet.kt @@ -1,8 +1,6 @@ package com.github.libretube.ui.sheets -import android.content.Intent import android.os.Bundle -import androidx.core.content.ContextCompat import androidx.core.os.bundleOf import androidx.fragment.app.setFragmentResult import com.github.libretube.R @@ -11,7 +9,6 @@ import com.github.libretube.enums.ShareObjectType import com.github.libretube.helpers.BackgroundHelper import com.github.libretube.helpers.NavigationHelper import com.github.libretube.obj.ShareData -import com.github.libretube.services.OfflinePlayerService import com.github.libretube.ui.dialogs.ShareDialog class DownloadOptionsBottomSheet : BaseBottomSheet() { diff --git a/app/src/main/java/com/github/libretube/ui/sheets/FilterSortBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/FilterSortBottomSheet.kt index 5b0404631..59c3dd863 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/FilterSortBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/FilterSortBottomSheet.kt @@ -13,7 +13,7 @@ import com.github.libretube.enums.ContentFilter import com.github.libretube.extensions.parcelableArrayList import com.github.libretube.obj.SelectableOption -class FilterSortBottomSheet: ExpandedBottomSheet() { +class FilterSortBottomSheet : ExpandedBottomSheet() { private var _binding: FilterSortSheetBinding? = null private val binding get() = _binding!! @@ -83,7 +83,7 @@ class FilterSortBottomSheet: ExpandedBottomSheet() { private fun setInitialFiltersState() { binding.filterVideos.isChecked = ContentFilter.VIDEOS.isEnabled - binding.filterShorts.isChecked = ContentFilter.SHORTS.isEnabled + binding.filterShorts.isChecked = ContentFilter.SHORTS.isEnabled binding.filterLivestreams.isChecked = ContentFilter.LIVESTREAMS.isEnabled binding.hideWatchedCheckbox.isChecked = hideWatched } @@ -115,4 +115,4 @@ class FilterSortBottomSheet: ExpandedBottomSheet() { companion object { const val FILTER_SORT_REQUEST_KEY = "filter_sort_request_key" } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt index 7b63c6468..2910a9127 100644 --- a/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/CustomExoPlayerView.kt @@ -171,7 +171,9 @@ open class CustomExoPlayerView( Player.EVENT_PLAY_WHEN_READY_CHANGED ) ) { - binding.playPauseBTN.setImageResource(PlayerHelper.getPlayPauseActionIcon(player)) + binding.playPauseBTN.setImageResource( + PlayerHelper.getPlayPauseActionIcon(player) + ) // keep screen on if the video is playing keepScreenOn = player.isPlaying == true diff --git a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt index 7a7f05dac..414c7b0d4 100644 --- a/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt +++ b/app/src/main/java/com/github/libretube/ui/views/SingleViewTouchableMotionLayout.kt @@ -67,7 +67,6 @@ class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeS distanceX: Float, distanceY: Float ): Boolean { - if (isStrictlyDownSwipe && distanceY > 0) { isStrictlyDownSwipe = false } 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 d30197f29..06d90b406 100644 --- a/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt +++ b/app/src/main/java/com/github/libretube/util/NowPlayingNotification.kt @@ -262,13 +262,13 @@ class NowPlayingNotification( private fun createPlaybackState(@PlaybackStateCompat.State state: Int): PlaybackStateCompat { val stateActions = PlaybackStateCompat.ACTION_SKIP_TO_NEXT or - PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or - PlaybackStateCompat.ACTION_REWIND or - PlaybackStateCompat.ACTION_FAST_FORWARD or - PlaybackStateCompat.ACTION_PLAY_PAUSE or - PlaybackStateCompat.ACTION_PAUSE or - PlaybackStateCompat.ACTION_PLAY or - PlaybackStateCompat.ACTION_SEEK_TO + PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS or + PlaybackStateCompat.ACTION_REWIND or + PlaybackStateCompat.ACTION_FAST_FORWARD or + PlaybackStateCompat.ACTION_PLAY_PAUSE or + PlaybackStateCompat.ACTION_PAUSE or + PlaybackStateCompat.ACTION_PLAY or + PlaybackStateCompat.ACTION_SEEK_TO return PlaybackStateCompat.Builder() .setActions(stateActions) @@ -302,8 +302,13 @@ class NowPlayingNotification( STOP -> { when (notificationType) { - NowPlayingNotificationType.AUDIO_ONLINE -> BackgroundHelper.stopBackgroundPlay(context) - NowPlayingNotificationType.AUDIO_OFFLINE -> BackgroundHelper.stopBackgroundPlay(context, OfflinePlayerService::class.java) + NowPlayingNotificationType.AUDIO_ONLINE -> BackgroundHelper.stopBackgroundPlay( + context + ) + NowPlayingNotificationType.AUDIO_OFFLINE -> BackgroundHelper.stopBackgroundPlay( + context, + OfflinePlayerService::class.java + ) else -> Unit } } @@ -381,7 +386,12 @@ class NowPlayingNotification( addAction(it) } } - ContextCompat.registerReceiver(context, notificationActionReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED) + ContextCompat.registerReceiver( + context, + notificationActionReceiver, + filter, + ContextCompat.RECEIVER_NOT_EXPORTED + ) } /** @@ -417,7 +427,7 @@ class NowPlayingNotification( VIDEO_ONLINE, VIDEO_OFFLINE, AUDIO_ONLINE, - AUDIO_OFFLINE, + AUDIO_OFFLINE } } } diff --git a/app/src/main/java/com/github/libretube/util/PauseableTimer.kt b/app/src/main/java/com/github/libretube/util/PauseableTimer.kt index e64d5bb32..e90644f9e 100644 --- a/app/src/main/java/com/github/libretube/util/PauseableTimer.kt +++ b/app/src/main/java/com/github/libretube/util/PauseableTimer.kt @@ -20,11 +20,15 @@ class PauseableTimer( fun resume() { if (timer == null) timer = Timer() - timer?.scheduleAtFixedRate(object : TimerTask() { - override fun run() { - handler.post(onTick) - } - }, delayMillis, delayMillis) + timer?.scheduleAtFixedRate( + object : TimerTask() { + override fun run() { + handler.post(onTick) + } + }, + delayMillis, + delayMillis + ) } fun pause() { @@ -36,4 +40,4 @@ class PauseableTimer( timer?.cancel() timer = null } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt index e93203784..70a260a9a 100644 --- a/app/src/main/java/com/github/libretube/util/UpdateChecker.kt +++ b/app/src/main/java/com/github/libretube/util/UpdateChecker.kt @@ -12,9 +12,9 @@ import com.github.libretube.constants.IntentData.appUpdateURL import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toastFromMainDispatcher import com.github.libretube.ui.dialogs.UpdateAvailableDialog +import java.util.Locale import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import java.util.Locale class UpdateChecker(private val context: Context) { suspend fun checkUpdate(isManualCheck: Boolean = false) { @@ -40,7 +40,7 @@ class UpdateChecker(private val context: Context) { private fun showUpdateAvailableDialog( changelog: String, - url: String, + url: String ) { val dialog = UpdateAvailableDialog() val args = diff --git a/baselineProfile/src/main/java/com/github/libretube/baselineprofile/StartupBenchmarks.kt b/baselineProfile/src/main/java/com/github/libretube/baselineprofile/StartupBenchmarks.kt index 56b06dd46..6b67d807d 100644 --- a/baselineProfile/src/main/java/com/github/libretube/baselineprofile/StartupBenchmarks.kt +++ b/baselineProfile/src/main/java/com/github/libretube/baselineprofile/StartupBenchmarks.kt @@ -7,7 +7,6 @@ import androidx.benchmark.macro.StartupTimingMetric import androidx.benchmark.macro.junit4.MacrobenchmarkRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest - import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -72,4 +71,4 @@ class StartupBenchmarks { } ) } -} \ No newline at end of file +}