|
@@ -7,13 +7,18 @@ import android.view.MenuItem
|
|
|
import android.view.View
|
|
|
import android.view.ViewGroup
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
+import androidx.recyclerview.widget.RecyclerView
|
|
|
+import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.download.DownloadService
|
|
|
import eu.kanade.tachiyomi.data.download.model.Download
|
|
|
import eu.kanade.tachiyomi.databinding.DownloadControllerBinding
|
|
|
import eu.kanade.tachiyomi.source.model.Page
|
|
|
+import eu.kanade.tachiyomi.ui.base.controller.FabController
|
|
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
|
|
-import eu.kanade.tachiyomi.ui.main.offsetAppbarHeight
|
|
|
+import eu.kanade.tachiyomi.util.view.gone
|
|
|
+import eu.kanade.tachiyomi.util.view.shrinkOnScroll
|
|
|
+import eu.kanade.tachiyomi.util.view.visible
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
import kotlinx.coroutines.flow.launchIn
|
|
|
import kotlinx.coroutines.flow.onEach
|
|
@@ -28,6 +33,7 @@ import rx.android.schedulers.AndroidSchedulers
|
|
|
*/
|
|
|
class DownloadController :
|
|
|
NucleusController<DownloadControllerBinding, DownloadPresenter>(),
|
|
|
+ FabController,
|
|
|
DownloadAdapter.DownloadItemListener {
|
|
|
|
|
|
/**
|
|
@@ -35,6 +41,9 @@ class DownloadController :
|
|
|
*/
|
|
|
private var adapter: DownloadAdapter? = null
|
|
|
|
|
|
+ private var actionFab: ExtendedFloatingActionButton? = null
|
|
|
+ private var actionFabScrollListener: RecyclerView.OnScrollListener? = null
|
|
|
+
|
|
|
/**
|
|
|
* Map of subscriptions for active downloads.
|
|
|
*/
|
|
@@ -78,7 +87,25 @@ class DownloadController :
|
|
|
binding.recycler.layoutManager = LinearLayoutManager(view.context)
|
|
|
binding.recycler.setHasFixedSize(true)
|
|
|
|
|
|
- binding.fab.clicks()
|
|
|
+ actionFabScrollListener = actionFab?.shrinkOnScroll(binding.recycler)
|
|
|
+
|
|
|
+ // Subscribe to changes
|
|
|
+ DownloadService.runningRelay
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribeUntilDestroy { onQueueStatusChange(it) }
|
|
|
+
|
|
|
+ presenter.getDownloadStatusObservable()
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribeUntilDestroy { onStatusChange(it) }
|
|
|
+
|
|
|
+ presenter.getDownloadProgressObservable()
|
|
|
+ .observeOn(AndroidSchedulers.mainThread())
|
|
|
+ .subscribeUntilDestroy { onUpdateDownloadedPages(it) }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun configureFab(fab: ExtendedFloatingActionButton) {
|
|
|
+ actionFab = fab
|
|
|
+ fab.clicks()
|
|
|
.onEach {
|
|
|
val context = applicationContext ?: return@onEach
|
|
|
|
|
@@ -92,21 +119,11 @@ class DownloadController :
|
|
|
setInformationView()
|
|
|
}
|
|
|
.launchIn(scope)
|
|
|
+ }
|
|
|
|
|
|
- binding.fab.offsetAppbarHeight(activity!!)
|
|
|
-
|
|
|
- // Subscribe to changes
|
|
|
- DownloadService.runningRelay
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribeUntilDestroy { onQueueStatusChange(it) }
|
|
|
-
|
|
|
- presenter.getDownloadStatusObservable()
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribeUntilDestroy { onStatusChange(it) }
|
|
|
-
|
|
|
- presenter.getDownloadProgressObservable()
|
|
|
- .observeOn(AndroidSchedulers.mainThread())
|
|
|
- .subscribeUntilDestroy { onUpdateDownloadedPages(it) }
|
|
|
+ override fun cleanupFab(fab: ExtendedFloatingActionButton) {
|
|
|
+ actionFabScrollListener?.let { binding.recycler.removeOnScrollListener(it) }
|
|
|
+ actionFab = null
|
|
|
}
|
|
|
|
|
|
override fun onDestroyView(view: View) {
|
|
@@ -267,18 +284,28 @@ class DownloadController :
|
|
|
private fun setInformationView() {
|
|
|
if (presenter.downloadQueue.isEmpty()) {
|
|
|
binding.emptyView.show(R.string.information_no_downloads)
|
|
|
- binding.fab.hide()
|
|
|
+ actionFab?.gone()
|
|
|
} else {
|
|
|
binding.emptyView.hide()
|
|
|
- binding.fab.show()
|
|
|
-
|
|
|
- binding.fab.setImageResource(
|
|
|
- if (isRunning) {
|
|
|
- R.drawable.ic_pause_24dp
|
|
|
- } else {
|
|
|
- R.drawable.ic_play_arrow_24dp
|
|
|
- }
|
|
|
- )
|
|
|
+ actionFab?.apply {
|
|
|
+ visible()
|
|
|
+
|
|
|
+ setText(
|
|
|
+ if (isRunning) {
|
|
|
+ R.string.action_pause
|
|
|
+ } else {
|
|
|
+ R.string.action_resume
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+ setIconResource(
|
|
|
+ if (isRunning) {
|
|
|
+ R.drawable.ic_pause_24dp
|
|
|
+ } else {
|
|
|
+ R.drawable.ic_play_arrow_24dp
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|