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:
Jays2Kings 2021-05-08 15:55:27 -04:00
parent a6ff4f7518
commit b95009052f
4 changed files with 35 additions and 27 deletions

View File

@ -6,6 +6,7 @@ import android.util.AttributeSet
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.LinearLayout import android.widget.LinearLayout
import androidx.core.view.isVisible
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.DownloadService import eu.kanade.tachiyomi.data.download.DownloadService
@ -85,6 +86,14 @@ class DownloadBottomSheet @JvmOverloads constructor(
sheetBehavior?.collapse() sheetBehavior?.collapse()
} }
} }
binding.downloadFab.setOnClickListener {
if (!isRunning) {
DownloadService.start(context)
} else {
DownloadService.stop(context)
presenter.pauseDownloads()
}
}
update() update()
setInformationView() setInformationView()
if (!controller.hasQueue()) { if (!controller.hasQueue()) {
@ -96,6 +105,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
fun update() { fun update() {
presenter.getItems() presenter.getItems()
onQueueStatusChange(!presenter.downloadManager.isPaused()) onQueueStatusChange(!presenter.downloadManager.isPaused())
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
} }
private fun updateDLTitle() { private fun updateDLTitle() {
@ -115,6 +125,7 @@ class DownloadBottomSheet @JvmOverloads constructor(
private fun onQueueStatusChange(running: Boolean) { private fun onQueueStatusChange(running: Boolean) {
val oldRunning = isRunning val oldRunning = isRunning
isRunning = running isRunning = running
binding.downloadFab.isVisible = presenter.downloadQueue.isNotEmpty()
if (oldRunning != running) { if (oldRunning != running) {
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
@ -180,11 +191,8 @@ class DownloadBottomSheet @JvmOverloads constructor(
} }
fun prepareMenu(menu: Menu) { fun prepareMenu(menu: Menu) {
// Set start button visibility. binding.downloadFab.text = context.getString(if (isRunning) R.string.pause else R.string.resume)
menu.findItem(R.id.start_queue)?.isVisible = !isRunning && !presenter.downloadQueue.isEmpty() binding.downloadFab.setIconResource(if (isRunning) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp)
// Set pause button visibility.
menu.findItem(R.id.pause_queue)?.isVisible = isRunning && !presenter.downloadQueue.isEmpty()
// Set clear button visibility. // Set clear button visibility.
menu.findItem(R.id.clear_queue)?.isVisible = !presenter.downloadQueue.isEmpty() menu.findItem(R.id.clear_queue)?.isVisible = !presenter.downloadQueue.isEmpty()
@ -196,11 +204,6 @@ class DownloadBottomSheet @JvmOverloads constructor(
fun onOptionsItemSelected(item: MenuItem): Boolean { fun onOptionsItemSelected(item: MenuItem): Boolean {
val context = activity ?: return false val context = activity ?: return false
when (item.itemId) { when (item.itemId) {
R.id.start_queue -> DownloadService.start(context)
R.id.pause_queue -> {
DownloadService.stop(context)
presenter.pauseDownloads()
}
R.id.clear_queue -> { R.id.clear_queue -> {
DownloadService.stop(context) DownloadService.stop(context)
presenter.clearQueue() presenter.clearQueue()

View File

@ -162,9 +162,6 @@ class RecentsController(bundle: Bundle? = null) :
binding.recycler.updatePaddingRelative( binding.recycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0 bottom = activityBinding?.bottomNav?.height ?: 0
) )
binding.downloadBottomSheet.dlRecycler.updatePaddingRelative(
bottom = activityBinding?.bottomNav?.height ?: 0
)
binding.recentsEmptyView.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.recentsEmptyView.updateLayoutParams<ViewGroup.MarginLayoutParams> {
topMargin = headerHeight topMargin = headerHeight
bottomMargin = activityBinding?.bottomNav?.height ?: 0 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) { if (state == BottomSheetBehavior.STATE_HIDDEN || state == BottomSheetBehavior.STATE_COLLAPSED) {
binding.shadow2.alpha = binding.shadow2.alpha =
if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f if (state == BottomSheetBehavior.STATE_COLLAPSED) 0.25f else 0f
@ -353,6 +357,13 @@ class RecentsController(bundle: Bundle? = null) :
binding.downloadBottomSheet.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> { binding.downloadBottomSheet.fastScroller.updateLayoutParams<ViewGroup.MarginLayoutParams> {
bottomMargin = -pad.toInt() 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) { fun setRefreshing(refresh: Boolean) {

View File

@ -56,7 +56,7 @@
tools:text="Downloads" /> tools:text="Downloads" />
</LinearLayout> </LinearLayout>
<FrameLayout <androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/recycler_layout" android:id="@+id/recycler_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -81,5 +81,11 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
app:fastScrollerBubbleEnabled="true" /> 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> </eu.kanade.tachiyomi.ui.download.DownloadBottomSheet>

View File

@ -2,18 +2,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> 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 <item
android:id="@+id/reorder" android:id="@+id/reorder"
android:title="@string/reorder" android:title="@string/reorder"