Merge pull request #1762 from Bnyro/master

Expand bottom sheets by default, better backup file name
This commit is contained in:
Bnyro 2022-11-05 14:48:58 +01:00 committed by GitHub
commit 4a3953bef8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 16 deletions

View File

@ -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 ->

View File

@ -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

View File

@ -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"
}
}

View File

@ -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<BottomSheetItem>
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<View>(R.id.design_bottom_sheet) as FrameLayout?)?.let {
BottomSheetBehavior.from(it).state =
BottomSheetBehavior.STATE_EXPANDED
}
}
}
return dialog
}
fun setItems(items: List<BottomSheetItem>, listener: ((index: Int) -> Unit)?) = apply {
this.items = items
this.listener = { index ->

View File

@ -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

View File

@ -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.

View File

@ -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]
}