浏览代码

Move queue start/pause to FAB

arkon 4 年之前
父节点
当前提交
fc7a040509

+ 28 - 7
app/src/main/java/eu/kanade/tachiyomi/ui/download/DownloadController.kt

@@ -15,6 +15,9 @@ import eu.kanade.tachiyomi.source.model.Page
 import eu.kanade.tachiyomi.ui.base.controller.NucleusController
 import java.util.HashMap
 import java.util.concurrent.TimeUnit
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.onEach
+import reactivecircus.flowbinding.android.view.clicks
 import rx.Observable
 import rx.Subscription
 import rx.android.schedulers.AndroidSchedulers
@@ -74,6 +77,21 @@ class DownloadController :
         binding.recycler.layoutManager = LinearLayoutManager(view.context)
         binding.recycler.setHasFixedSize(true)
 
+        binding.fab.clicks()
+            .onEach {
+                val context = applicationContext ?: return@onEach
+
+                if (isRunning) {
+                    DownloadService.stop(context)
+                    presenter.pauseDownloads()
+                } else {
+                    DownloadService.start(context)
+                }
+
+                setInformationView()
+            }
+            .launchIn(scope)
+
         // Subscribe to changes
         DownloadService.runningRelay
             .observeOn(AndroidSchedulers.mainThread())
@@ -102,8 +120,6 @@ class DownloadController :
     }
 
     override fun onPrepareOptionsMenu(menu: Menu) {
-        menu.findItem(R.id.start_queue).isVisible = !isRunning && !presenter.downloadQueue.isEmpty()
-        menu.findItem(R.id.pause_queue).isVisible = isRunning
         menu.findItem(R.id.clear_queue).isVisible = !presenter.downloadQueue.isEmpty()
         menu.findItem(R.id.reorder).isVisible = !presenter.downloadQueue.isEmpty()
     }
@@ -111,11 +127,6 @@ class DownloadController :
     override fun onOptionsItemSelected(item: MenuItem): Boolean {
         val context = applicationContext ?: 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()
@@ -253,8 +264,18 @@ class DownloadController :
     private fun setInformationView() {
         if (presenter.downloadQueue.isEmpty()) {
             binding.emptyView.show(R.string.information_no_downloads)
+            binding.fab.hide()
         } else {
             binding.emptyView.hide()
+            binding.fab.show()
+
+            binding.fab.setImageResource(
+                if (isRunning) {
+                    R.drawable.ic_pause_24dp
+                } else {
+                    R.drawable.ic_play_arrow_24dp
+                }
+            )
         }
     }
 

+ 10 - 0
app/src/main/res/layout/download_controller.xml

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/frame_container"
     android:layout_width="match_parent"
@@ -9,8 +10,17 @@
         android:id="@+id/recycler"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
+        android:clipToPadding="false"
+        android:paddingBottom="@dimen/fab_list_padding"
         tools:listitem="@layout/download_item" />
 
+    <com.google.android.material.floatingactionbutton.FloatingActionButton
+        android:id="@+id/fab"
+        style="@style/Theme.Widget.FAB"
+        android:visibility="gone"
+        app:layout_anchor="@id/recycler"
+        app:srcCompat="@drawable/ic_pause_24dp" />
+
     <eu.kanade.tachiyomi.widget.EmptyView
         android:id="@+id/empty_view"
         android:layout_width="wrap_content"

+ 0 - 14
app/src/main/res/menu/download_queue.xml

@@ -2,20 +2,6 @@
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
 
-    <item
-        android:id="@+id/start_queue"
-        android:icon="@drawable/ic_play_arrow_24dp"
-        android:title="@string/action_start"
-        app:iconTint="?attr/colorOnPrimary"
-        app:showAsAction="ifRoom" />
-
-    <item
-        android:id="@+id/pause_queue"
-        android:icon="@drawable/ic_pause_24dp"
-        android:title="@string/action_pause"
-        app:iconTint="?attr/colorOnPrimary"
-        app:showAsAction="ifRoom" />
-
     <item
         android:id="@+id/reorder"
         android:title="@string/action_reorganize_by"

+ 0 - 1
app/src/main/res/values/strings.xml

@@ -67,7 +67,6 @@
     <string name="action_show_downloaded">Downloaded</string>
     <string name="action_next_unread">Next unread</string>
     <string name="action_view_chapters">View chapters</string>
-    <string name="action_start">Start</string>
     <string name="action_stop">Stop</string>
     <string name="action_pause">Pause</string>
     <string name="action_close">Close</string>