From 67d82c28ac08fc43d1b544fd5f213ae0c1fb3ae2 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sun, 10 Sep 2023 14:36:29 +0200 Subject: [PATCH] style: fix formatting --- .../com/github/libretube/api/obj/StreamItem.kt | 2 +- .../com/github/libretube/extensions/Player.kt | 4 ++-- .../github/libretube/helpers/BackgroundHelper.kt | 10 ++++++++-- .../com/github/libretube/helpers/DashHelper.kt | 4 ++-- .../com/github/libretube/helpers/ImageHelper.kt | 2 +- .../com/github/libretube/helpers/ImportHelper.kt | 2 +- .../libretube/ui/adapters/PlaylistAdapter.kt | 5 ++++- .../github/libretube/ui/adapters/SearchAdapter.kt | 5 ++++- .../github/libretube/ui/adapters/VideosAdapter.kt | 10 ++++++++-- .../libretube/ui/adapters/WatchHistoryAdapter.kt | 5 ++++- .../github/libretube/ui/dialogs/BackupDialog.kt | 1 - .../libretube/ui/dialogs/DeletePlaylistDialog.kt | 1 - .../libretube/ui/fragments/AudioPlayerFragment.kt | 2 +- .../libretube/ui/fragments/PlayerFragment.kt | 10 +++++----- .../libretube/ui/preferences/MainSettings.kt | 4 ---- .../ui/sheets/PlaylistOptionsBottomSheet.kt | 15 ++++++++++++--- .../libretube/ui/views/AutoplayCountdownView.kt | 5 +++-- .../libretube/util/OnlineTimeFrameReceiver.kt | 8 +++++++- 18 files changed, 63 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/com/github/libretube/api/obj/StreamItem.kt b/app/src/main/java/com/github/libretube/api/obj/StreamItem.kt index 77ef0dee3..d9307c19e 100644 --- a/app/src/main/java/com/github/libretube/api/obj/StreamItem.kt +++ b/app/src/main/java/com/github/libretube/api/obj/StreamItem.kt @@ -23,7 +23,7 @@ data class StreamItem( val uploaded: Long? = null, val shortDescription: String? = null, val isShort: Boolean = false -): Parcelable { +) : Parcelable { fun toLocalPlaylistItem(playlistId: String): LocalPlaylistItem { return LocalPlaylistItem( playlistId = playlistId.toInt(), diff --git a/app/src/main/java/com/github/libretube/extensions/Player.kt b/app/src/main/java/com/github/libretube/extensions/Player.kt index f30a5cb7f..60a1ea17e 100644 --- a/app/src/main/java/com/github/libretube/extensions/Player.kt +++ b/app/src/main/java/com/github/libretube/extensions/Player.kt @@ -9,11 +9,11 @@ fun Player.togglePlayPauseState() { play() } - !isPlaying && playbackState == Player.STATE_ENDED -> { + !isPlaying && playbackState == Player.STATE_ENDED -> { seekTo(0) } !isPlaying && !isLoading -> play() else -> pause() } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/github/libretube/helpers/BackgroundHelper.kt b/app/src/main/java/com/github/libretube/helpers/BackgroundHelper.kt index fc2ab98ed..01015e65a 100644 --- a/app/src/main/java/com/github/libretube/helpers/BackgroundHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/BackgroundHelper.kt @@ -49,7 +49,10 @@ object BackgroundHelper { /** * Stop the [OnlinePlayerService] service if it is running. */ - fun stopBackgroundPlay(context: Context, serviceClass: Class<*> = OnlinePlayerService::class.java) { + fun stopBackgroundPlay( + context: Context, + serviceClass: Class<*> = OnlinePlayerService::class.java + ) { if (isBackgroundServiceRunning(context, serviceClass)) { // Intent to stop background mode service val intent = Intent(context, serviceClass) @@ -60,7 +63,10 @@ object BackgroundHelper { /** * Check if the [OnlinePlayerService] service is currently running. */ - fun isBackgroundServiceRunning(context: Context, serviceClass: Class<*> = OnlinePlayerService::class.java): Boolean { + fun isBackgroundServiceRunning( + context: Context, + serviceClass: Class<*> = OnlinePlayerService::class.java + ): Boolean { @Suppress("DEPRECATION") return context.getSystemService()!!.getRunningServices(Int.MAX_VALUE) .any { serviceClass.name == it.service.className } 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 5c2812bc6..70f7d2c00 100644 --- a/app/src/main/java/com/github/libretube/helpers/DashHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/DashHelper.kt @@ -2,13 +2,13 @@ package com.github.libretube.helpers import com.github.libretube.api.obj.PipedStream import com.github.libretube.api.obj.Streams -import org.w3c.dom.Document -import org.w3c.dom.Element import java.io.StringWriter import javax.xml.parsers.DocumentBuilderFactory import javax.xml.transform.TransformerFactory import javax.xml.transform.dom.DOMSource import javax.xml.transform.stream.StreamResult +import org.w3c.dom.Document +import org.w3c.dom.Element // Based off of https://github.com/TeamPiped/Piped/blob/master/src/utils/DashUtils.js 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 9970892e1..74200f259 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImageHelper.kt @@ -16,9 +16,9 @@ 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.nio.file.Path import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext -import java.nio.file.Path 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 cad4b9f42..51906cafa 100644 --- a/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt +++ b/app/src/main/java/com/github/libretube/helpers/ImportHelper.kt @@ -19,11 +19,11 @@ import com.github.libretube.obj.NewPipeSubscription import com.github.libretube.obj.NewPipeSubscriptions import com.github.libretube.obj.PipedImportPlaylist import com.github.libretube.obj.PipedImportPlaylistFile +import java.util.Date import java.util.stream.Collectors import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.encodeToStream -import java.util.Date object ImportHelper { /** diff --git a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt index 58f2c6357..7eac58b45 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/PlaylistAdapter.kt @@ -87,7 +87,10 @@ class PlaylistAdapter( val activity = (root.context as BaseActivity) val fragmentManager = activity.supportFragmentManager root.setOnLongClickListener { - fragmentManager.setFragmentResultListener(VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ -> + fragmentManager.setFragmentResultListener( + VIDEO_OPTIONS_SHEET_REQUEST_KEY, + activity + ) { _, _ -> notifyItemChanged(position) } val sheet = VideoOptionsBottomSheet() diff --git a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt index b045f7a92..994b60fb3 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/SearchAdapter.kt @@ -102,7 +102,10 @@ class SearchAdapter( val activity = (root.context as BaseActivity) val fragmentManager = activity.supportFragmentManager root.setOnLongClickListener { - fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ -> + fragmentManager.setFragmentResultListener( + VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, + activity + ) { _, _ -> notifyItemChanged(position) } val sheet = VideoOptionsBottomSheet() 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 bea968b22..28870c503 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 @@ -151,7 +151,10 @@ class VideosAdapter( } root.setOnLongClickListener { - fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ -> + fragmentManager.setFragmentResultListener( + VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, + activity + ) { _, _ -> notifyItemChanged(position) } val sheet = VideoOptionsBottomSheet() @@ -191,7 +194,10 @@ class VideosAdapter( } root.setOnLongClickListener { - fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ -> + fragmentManager.setFragmentResultListener( + VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, + activity + ) { _, _ -> notifyItemChanged(position) } val sheet = VideoOptionsBottomSheet() diff --git a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt index 0133a2a12..a29620050 100644 --- a/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt +++ b/app/src/main/java/com/github/libretube/ui/adapters/WatchHistoryAdapter.kt @@ -73,7 +73,10 @@ class WatchHistoryAdapter( val activity = (root.context as BaseActivity) val fragmentManager = activity.supportFragmentManager root.setOnLongClickListener { - fragmentManager.setFragmentResultListener(VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, activity) { _, _ -> + fragmentManager.setFragmentResultListener( + VideoOptionsBottomSheet.VIDEO_OPTIONS_SHEET_REQUEST_KEY, + activity + ) { _, _ -> notifyItemChanged(position) } val sheet = VideoOptionsBottomSheet() diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt index 7b206d52b..87d48c5ca 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/BackupDialog.kt @@ -16,7 +16,6 @@ import com.github.libretube.obj.PreferenceItem import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonNull diff --git a/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt b/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt index c48966c2a..cdbb41900 100644 --- a/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt +++ b/app/src/main/java/com/github/libretube/ui/dialogs/DeletePlaylistDialog.kt @@ -16,7 +16,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import kotlinx.coroutines.withContext class DeletePlaylistDialog : DialogFragment() { private lateinit var playlistId: String diff --git a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt index c6c8699bd..333c23600 100644 --- a/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/ui/fragments/AudioPlayerFragment.kt @@ -52,8 +52,8 @@ import com.github.libretube.ui.sheets.VideoOptionsBottomSheet import com.github.libretube.util.DataSaverMode import com.github.libretube.util.PlayingQueue import com.google.android.material.elevation.SurfaceColors -import kotlinx.coroutines.launch import kotlin.math.abs +import kotlinx.coroutines.launch class AudioPlayerFragment : Fragment(), AudioPlayerOptions { private var _binding: FragmentAudioPlayerBinding? = null 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 ef31eb0b2..2d62df2a1 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 @@ -121,16 +121,16 @@ import com.github.libretube.util.TextUtils.toTimeInSeconds import com.github.libretube.util.YoutubeHlsPlaylistParser import com.github.libretube.util.deArrow import com.google.android.material.elevation.SurfaceColors +import java.io.IOException +import java.util.* +import java.util.concurrent.Executors +import kotlin.math.abs import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import kotlinx.serialization.encodeToString import retrofit2.HttpException -import java.io.IOException -import java.util.* -import java.util.concurrent.Executors -import kotlin.math.abs @androidx.annotation.OptIn(androidx.media3.common.util.UnstableApi::class) class PlayerFragment : Fragment(), OnlinePlayerOptions { @@ -1012,7 +1012,7 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions { binding.relPlayerDownload.setOnClickListener { if (streams.duration <= 0) { Toast.makeText(context, R.string.cannotDownload, Toast.LENGTH_SHORT).show() - } else { + } else { val newFragment = DownloadDialog() newFragment.arguments = bundleOf(IntentData.videoId to videoId) newFragment.show(childFragmentManager, DownloadDialog::class.java.name) 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 0d6c7de7d..fa95d7214 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 @@ -2,8 +2,6 @@ package com.github.libretube.ui.preferences import android.os.Bundle import androidx.annotation.StringRes -import androidx.fragment.app.Fragment -import androidx.fragment.app.commitNow import androidx.core.os.bundleOf import androidx.lifecycle.lifecycleScope import androidx.preference.Preference @@ -18,8 +16,6 @@ import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext -import kotlinx.serialization.encodeToString -import kotlinx.serialization.json.Json class MainSettings : BasePreferenceFragment() { override val titleResourceId: Int = R.string.settings diff --git a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt index d71209cec..13179f6b5 100644 --- a/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/PlaylistOptionsBottomSheet.kt @@ -105,7 +105,10 @@ class PlaylistOptionsBottomSheet( } getString(R.string.deletePlaylist) -> { - mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle -> + mFragmentManager.setFragmentResultListener( + PLAYLIST_OPTIONS_REQUEST_KEY, + context as BaseActivity + ) { _, bundle -> if (bundle.getBoolean(IntentData.playlistTask, true)) onDelete() // forward the result the playlists adapter if visible mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle) @@ -119,7 +122,10 @@ class PlaylistOptionsBottomSheet( } getString(R.string.renamePlaylist) -> { - mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle -> + mFragmentManager.setFragmentResultListener( + PLAYLIST_OPTIONS_REQUEST_KEY, + context as BaseActivity + ) { _, bundle -> onRename(bundle.getString(IntentData.playlistName, "")) // forward the result the playlists adapter if visible mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle) @@ -133,7 +139,10 @@ class PlaylistOptionsBottomSheet( } getString(R.string.change_playlist_description) -> { - mFragmentManager.setFragmentResultListener(PLAYLIST_OPTIONS_REQUEST_KEY, context as BaseActivity) { _, bundle -> + mFragmentManager.setFragmentResultListener( + PLAYLIST_OPTIONS_REQUEST_KEY, + context as BaseActivity + ) { _, bundle -> onChangeDescription(bundle.getString(IntentData.playlistName, "")) // forward the result the playlists adapter if visible mFragmentManager.setFragmentResult(PLAYLISTS_ADAPTER_REQUEST_KEY, bundle) diff --git a/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt b/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt index f85f45fad..337c6e98a 100644 --- a/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt +++ b/app/src/main/java/com/github/libretube/ui/views/AutoplayCountdownView.kt @@ -13,7 +13,6 @@ import androidx.lifecycle.get import com.github.libretube.R import com.github.libretube.databinding.AutoplayCountdownBinding import com.github.libretube.ui.activities.MainActivity -import com.github.libretube.ui.base.BaseActivity import com.github.libretube.ui.models.PlayerViewModel class AutoplayCountdownView( @@ -21,7 +20,9 @@ class AutoplayCountdownView( attributeSet: AttributeSet? ) : FrameLayout(context, attributeSet) { private val layoutInflater = LayoutInflater.from(context) - private val playerViewModel: PlayerViewModel get() = ViewModelProvider(context as MainActivity).get() + private val playerViewModel: PlayerViewModel get() = ViewModelProvider( + context as MainActivity + ).get() val binding = AutoplayCountdownBinding.inflate(layoutInflater, this, true) private var onCountdownEnd: () -> Unit = {} diff --git a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt index c00890193..732afa65e 100644 --- a/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt +++ b/app/src/main/java/com/github/libretube/util/OnlineTimeFrameReceiver.kt @@ -25,7 +25,13 @@ class OnlineTimeFrameReceiver( val offsetY = previewFrame.positionY * previewFrame.frameHeight return runCatching { - Bitmap.createBitmap(bitmap, offsetX, offsetY, previewFrame.frameWidth, previewFrame.frameHeight) + Bitmap.createBitmap( + bitmap, + offsetX, + offsetY, + previewFrame.frameWidth, + previewFrame.frameHeight + ) }.getOrNull() }