mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 03:39:19 +01:00
Using a download fab to play/pause instead of menu item
Co-Authored-By: arkon <4098258+arkon@users.noreply.github.com>
This commit is contained in:
parent
a6ff4f7518
commit
b95009052f
@ -6,6 +6,7 @@ import android.util.AttributeSet
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.LinearLayout
|
||||
import androidx.core.view.isVisible
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||
@ -85,6 +86,14 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
sheetBehavior?.collapse()
|
||||
}
|
||||
}
|
||||
binding.downloadFab.setOnClickListener {
|
||||
if (!isRunning) {
|
||||
DownloadService.start(context)
|
||||
} else {
|
||||
DownloadService.stop(context)
|
||||
presenter.pauseDownloads()
|
||||
}
|
||||
}
|
||||
update()
|
||||
setInformationView()
|
||||
if (!controller.hasQueue()) {
|
||||
@ -96,6 +105,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
fun update() {
|
||||
presenter.getItems()
|
||||
onQueueStatusChange(!presenter.downloadManager.isPaused())
|
||||
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun updateDLTitle() {
|
||||
@ -115,6 +125,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
private fun onQueueStatusChange(running: Boolean) {
|
||||
val oldRunning = isRunning
|
||||
isRunning = running
|
||||
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
|
||||
if (oldRunning != running) {
|
||||
activity?.invalidateOptionsMenu()
|
||||
|
||||
@ -180,11 +191,8 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
fun prepareMenu(menu: Menu) {
|
||||
// Set start button visibility.
|
||||
menu.findItem(R.id.start_queue)?.isVisible = !isRunning && !presenter.downloadQueue.isEmpty()
|
||||
|
||||
// Set pause button visibility.
|
||||
menu.findItem(R.id.pause_queue)?.isVisible = isRunning && !presenter.downloadQueue.isEmpty()
|
||||
binding.downloadFab.text = context.getString(if (isRunning) R.string.pause else R.string.resume)
|
||||
binding.downloadFab.setIconResource(if (isRunning) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp)
|
||||
|
||||
// Set clear button visibility.
|
||||
menu.findItem(R.id.clear_queue)?.isVisible = !presenter.downloadQueue.isEmpty()
|
||||
@ -196,11 +204,6 @@ class DownloadBottomSheet @JvmOverloads constructor(
|
||||
fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
val context = activity ?: return false
|
||||
when (item.itemId) {
|
||||
R.id.start_queue -> DownloadService.start(context)
|
||||
R.id.pause_queue -> {
|
||||
DownloadService.stop(context)
|
||||
presenter.pauseDownloads()
|
||||
}
|
||||
R.id.clear_queue -> {
|
||||
DownloadService.stop(context)
|
||||
presenter.clearQueue()
|
||||
|
@ -162,9 +162,6 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
binding.recycler.updatePaddingRelative(
|
||||
bottom = activityBinding?.bottomNav?.height ?: 0
|
||||
)
|
||||
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(
|
||||
bottom = activityBinding?.bottomNav?.height ?: 0
|
||||
)
|
||||
binding.recentsEmptyView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
topMargin = headerHeight
|
||||
bottomMargin = activityBinding?.bottomNav?.height ?: 0
|
||||
@ -303,6 +300,13 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
}
|
||||
}
|
||||
|
||||
if (presenter.downloadManager.hasQueue()) {
|
||||
if (state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
binding.downloadBottomSheet.downloadFab.show()
|
||||
} else {
|
||||
binding.downloadBottomSheet.downloadFab.hide()
|
||||
}
|
||||
}
|
||||
if (state == BottomSheetBehavior.STATE_HIDDEN || state == BottomSheetBehavior.STATE_COLLAPSED) {
|
||||
binding.shadow2.alpha =
|
||||
if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f
|
||||
@ -353,6 +357,13 @@ class RecentsController(bundle: Bundle? = null) :
|
||||
binding.downloadBottomSheet.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = -pad.toInt()
|
||||
}
|
||||
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(
|
||||
bottom = max(-pad.toInt(), view?.rootWindowInsets?.systemWindowInsetBottom ?: 0) +
|
||||
binding.downloadBottomSheet.downloadFab.height + 20.dpToPx
|
||||
)
|
||||
binding.downloadBottomSheet.downloadFab.updateLayoutParams<ViewGroup.MarginLayoutParams> {
|
||||
bottomMargin = max(-pad.toInt(), view?.rootWindowInsets?.systemWindowInsetBottom ?: 0) + 16.dpToPx
|
||||
}
|
||||
}
|
||||
|
||||
fun setRefreshing(refresh: Boolean) {
|
||||
|
@ -56,7 +56,7 @@
|
||||
tools:text="Downloads" />
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/recycler_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@ -81,5 +81,11 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:fastScrollerBubbleEnabled="true" />
|
||||
</FrameLayout>
|
||||
|
||||
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
||||
android:id="@+id/download_fab"
|
||||
style="@style/Theme.Widget.FAB"
|
||||
android:text="@string/resume"
|
||||
app:icon="@drawable/ic_play_arrow_24dp"/>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
</eu.kanade.tachiyomi.ui.download.DownloadBottomSheet>
|
@ -2,18 +2,6 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item android:title="@string/start"
|
||||
android:id="@+id/start_queue"
|
||||
android:icon="@drawable/ic_play_arrow_24dp"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item android:title="@string/pause"
|
||||
android:id="@+id/pause_queue"
|
||||
android:icon="@drawable/ic_pause_24dp"
|
||||
android:visible="false"
|
||||
app:showAsAction="ifRoom"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/reorder"
|
||||
android:title="@string/reorder"
|
||||
|
Loading…
Reference in New Issue
Block a user