From 8046ba97db129213ef25ae0881497a528d5a4e4a Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 5 Nov 2022 14:42:41 +0100 Subject: [PATCH 1/2] expand options by default --- .../libretube/ui/fragments/PlayerFragment.kt | 6 ++--- .../ui/fragments/SubscriptionsFragment.kt | 4 ++-- .../BaseBottomSheet.kt} | 24 +++++++++++++++++-- .../ui/sheets/PlaylistOptionsBottomSheet.kt | 3 +-- .../ui/sheets/VideoOptionsBottomSheet.kt | 3 +-- .../libretube/ui/views/CustomExoPlayerView.kt | 9 +++---- 6 files changed, 34 insertions(+), 15 deletions(-) rename app/src/main/java/com/github/libretube/ui/{views/BottomSheet.kt => sheets/BaseBottomSheet.kt} (69%) 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 707ee7edc..fd71d1b38 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 @@ -68,8 +68,8 @@ import com.github.libretube.ui.base.BaseFragment import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog +import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.ui.sheets.PlayingQueueSheet -import com.github.libretube.ui.views.BottomSheet import com.github.libretube.util.BackgroundHelper import com.github.libretube.util.ImageHelper import com.github.libretube.util.NowPlayingNotification @@ -1345,7 +1345,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { subtitleCodesList += it.code!! } - BottomSheet() + BaseBottomSheet() .setSimpleItems(subtitlesNamesList) { index -> val newParams = if (index != 0) { // caption selected @@ -1376,7 +1376,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions { // Dialog for quality selection val lastPosition = exoPlayer.currentPosition - BottomSheet() + BaseBottomSheet() .setSimpleItems( videosNameArray.toList() ) { which -> 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 edabcd63d..5af8d30bc 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,7 @@ import com.github.libretube.ui.adapters.LegacySubscriptionAdapter import com.github.libretube.ui.adapters.SubscriptionChannelAdapter import com.github.libretube.ui.adapters.VideosAdapter import com.github.libretube.ui.base.BaseFragment -import com.github.libretube.ui.views.BottomSheet +import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.util.LayoutHelper import com.github.libretube.util.PreferenceHelper @@ -120,7 +120,7 @@ class SubscriptionsFragment : BaseFragment() { private fun showSortDialog() { val sortOptions = resources.getStringArray(R.array.sortOptions) - val bottomSheet = BottomSheet().apply { + val bottomSheet = BaseBottomSheet().apply { setSimpleItems(sortOptions.toList()) { index -> binding.sortTV.text = sortOptions[index] sortOrder = index diff --git a/app/src/main/java/com/github/libretube/ui/views/BottomSheet.kt b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt similarity index 69% rename from app/src/main/java/com/github/libretube/ui/views/BottomSheet.kt rename to app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt index af1890c2e..fc1f1ba43 100644 --- a/app/src/main/java/com/github/libretube/ui/views/BottomSheet.kt +++ b/app/src/main/java/com/github/libretube/ui/sheets/BaseBottomSheet.kt @@ -1,17 +1,22 @@ -package com.github.libretube.ui.views +package com.github.libretube.ui.sheets +import android.app.Dialog import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.FrameLayout import androidx.fragment.app.FragmentManager import androidx.recyclerview.widget.LinearLayoutManager import com.github.libretube.databinding.BottomSheetBinding import com.github.libretube.obj.BottomSheetItem import com.github.libretube.ui.adapters.BottomSheetAdapter +import com.google.android.material.R +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialogFragment -open class BottomSheet : BottomSheetDialogFragment() { +open class BaseBottomSheet : BottomSheetDialogFragment() { private lateinit var items: List private lateinit var listener: (index: Int) -> Unit private lateinit var binding: BottomSheetBinding @@ -32,6 +37,21 @@ open class BottomSheet : BottomSheetDialogFragment() { binding.optionsRecycler.adapter = BottomSheetAdapter(items, listener) } + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog + + dialog.setOnShowListener { + (it as BottomSheetDialog).let { d -> + (d.findViewById(R.id.design_bottom_sheet) as FrameLayout?)?.let { + BottomSheetBehavior.from(it).state = + BottomSheetBehavior.STATE_EXPANDED + } + } + } + + return dialog + } + fun setItems(items: List, listener: ((index: Int) -> Unit)?) = apply { this.items = items this.listener = { index -> 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 2bb1b75fe..fc95e5df2 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 @@ -13,7 +13,6 @@ import com.github.libretube.extensions.TAG import com.github.libretube.extensions.toID import com.github.libretube.obj.ShareData import com.github.libretube.ui.dialogs.ShareDialog -import com.github.libretube.ui.views.BottomSheet import com.github.libretube.util.BackgroundHelper import com.github.libretube.util.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -28,7 +27,7 @@ class PlaylistOptionsBottomSheet( private val playlistId: String, private val playlistName: String, private val isOwner: Boolean -) : BottomSheet() { +) : BaseBottomSheet() { private val shareData = ShareData(currentPlaylist = playlistName) override fun onCreate(savedInstanceState: Bundle?) { // options for the dialog 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 1e6751743..8fb42b5dc 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 @@ -11,7 +11,6 @@ import com.github.libretube.obj.ShareData import com.github.libretube.ui.dialogs.AddToPlaylistDialog import com.github.libretube.ui.dialogs.DownloadDialog import com.github.libretube.ui.dialogs.ShareDialog -import com.github.libretube.ui.views.BottomSheet import com.github.libretube.util.BackgroundHelper import com.github.libretube.util.PlayingQueue import com.github.libretube.util.PreferenceHelper @@ -27,7 +26,7 @@ import kotlinx.coroutines.launch class VideoOptionsBottomSheet( private val videoId: String, private val videoName: String -) : BottomSheet() { +) : BaseBottomSheet() { private val shareData = ShareData(currentVideo = videoName) override fun onCreate(savedInstanceState: Bundle?) { // List that stores the different menu options. In the future could be add more options here. 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 bebb7d4e7..67bf0f4d3 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 @@ -18,6 +18,7 @@ import com.github.libretube.models.interfaces.OnlinePlayerOptions import com.github.libretube.models.interfaces.PlayerOptions import com.github.libretube.obj.BottomSheetItem import com.github.libretube.ui.activities.MainActivity +import com.github.libretube.ui.sheets.BaseBottomSheet import com.github.libretube.ui.sheets.PlaybackSpeedSheet import com.github.libretube.util.DoubleTapListener import com.github.libretube.util.PlayerHelper @@ -209,7 +210,7 @@ internal class CustomExoPlayerView( ) } - val bottomSheetFragment = BottomSheet().setItems(items, null) + val bottomSheetFragment = BaseBottomSheet().setItems(items, null) bottomSheetFragment.show(childFragmentManager, null) } } @@ -311,7 +312,7 @@ internal class CustomExoPlayerView( override fun onAutoplayClicked() { // autoplay options dialog - BottomSheet() + BaseBottomSheet() .setSimpleItems( listOf( context.getString(R.string.enabled), @@ -341,7 +342,7 @@ internal class CustomExoPlayerView( AspectRatioFrameLayout.RESIZE_MODE_FILL ) - BottomSheet() + BaseBottomSheet() .setSimpleItems(aspectRatioModeNames) { index -> resizeMode = aspectRatioModes[index] } @@ -360,7 +361,7 @@ internal class CustomExoPlayerView( ) // repeat mode options dialog - BottomSheet() + BaseBottomSheet() .setSimpleItems(repeatModeNames) { index -> player?.repeatMode = repeatModes[index] } From 7704b8f40b24b3c7f6c4923bc01c44844a8152ce Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 5 Nov 2022 14:48:18 +0100 Subject: [PATCH 2/2] better backup title --- .../github/libretube/ui/preferences/AdvancedSettings.kt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt b/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt index 3480a7f25..6835dd7f5 100644 --- a/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt +++ b/app/src/main/java/com/github/libretube/ui/preferences/AdvancedSettings.kt @@ -17,6 +17,8 @@ import com.github.libretube.util.BackupHelper import com.github.libretube.util.ImageHelper import com.github.libretube.util.PreferenceHelper import com.google.android.material.dialog.MaterialAlertDialogBuilder +import java.time.LocalDate +import java.time.LocalTime class AdvancedSettings : BasePreferenceFragment() { @@ -64,7 +66,7 @@ class AdvancedSettings : BasePreferenceFragment() { advancesBackup?.setOnPreferenceClickListener { BackupDialog { backupFile = it - createBackupFile.launch("backup.json") + createBackupFile.launch(getBackupFileName()) } .show(childFragmentManager, null) true @@ -93,4 +95,9 @@ class AdvancedSettings : BasePreferenceFragment() { } .show() } + + private fun getBackupFileName(): String { + val time = LocalTime.now().toString().split(".").firstOrNull() + return "libretube-backup-${LocalDate.now()}-$time.json" + } }