Download service now has a listener for the badge and fab icon
This commit is contained in:
parent
e23973cc9c
commit
733dc3765e
@ -1,6 +1,5 @@
|
|||||||
package eu.kanade.tachiyomi.data.download
|
package eu.kanade.tachiyomi.data.download
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.app.Service
|
import android.app.Service
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
@ -17,7 +16,6 @@ import com.jakewharton.rxrelay.BehaviorRelay
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
|
||||||
import eu.kanade.tachiyomi.util.lang.plusAssign
|
import eu.kanade.tachiyomi.util.lang.plusAssign
|
||||||
import eu.kanade.tachiyomi.util.system.connectivityManager
|
import eu.kanade.tachiyomi.util.system.connectivityManager
|
||||||
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
import eu.kanade.tachiyomi.util.system.isServiceRunning
|
||||||
@ -42,13 +40,29 @@ class DownloadService : Service() {
|
|||||||
*/
|
*/
|
||||||
val runningRelay: BehaviorRelay<Boolean> = BehaviorRelay.create(false)
|
val runningRelay: BehaviorRelay<Boolean> = BehaviorRelay.create(false)
|
||||||
|
|
||||||
|
private val listeners = mutableSetOf<DownloadServiceListener>()
|
||||||
|
|
||||||
|
fun addListener(listener: DownloadServiceListener) {
|
||||||
|
listeners.add(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun removeListener(listener: DownloadServiceListener) {
|
||||||
|
listeners.remove(listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun callListeners() {
|
||||||
|
val downloadManager: DownloadManager by injectLazy()
|
||||||
|
listeners.forEach {
|
||||||
|
it.downloadStatusChanged(downloadManager.hasQueue())
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Starts this service.
|
* Starts this service.
|
||||||
*
|
*
|
||||||
* @param context the application context.
|
* @param context the application context.
|
||||||
*/
|
*/
|
||||||
fun start(context: Context) {
|
fun start(context: Context) {
|
||||||
MainActivity.setDownloadBadge(true)
|
callListeners()
|
||||||
val intent = Intent(context, DownloadService::class.java)
|
val intent = Intent(context, DownloadService::class.java)
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||||
context.startService(intent)
|
context.startService(intent)
|
||||||
@ -63,7 +77,7 @@ class DownloadService : Service() {
|
|||||||
* @param context the application context.
|
* @param context the application context.
|
||||||
*/
|
*/
|
||||||
fun stop(context: Context) {
|
fun stop(context: Context) {
|
||||||
MainActivity.setDownloadBadge(false)
|
callListeners()
|
||||||
context.stopService(Intent(context, DownloadService::class.java))
|
context.stopService(Intent(context, DownloadService::class.java))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,3 +223,7 @@ class DownloadService : Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface DownloadServiceListener {
|
||||||
|
fun downloadStatusChanged(downloading: Boolean)
|
||||||
|
}
|
||||||
|
@ -91,7 +91,7 @@ class Downloader(
|
|||||||
launchNow {
|
launchNow {
|
||||||
val chapters = async { store.restore() }
|
val chapters = async { store.restore() }
|
||||||
queue.addAll(chapters.await())
|
queue.addAll(chapters.await())
|
||||||
MainActivity.setDownloadBadge(queue.isNotEmpty())
|
DownloadService.callListeners()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,8 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.database.models.Category
|
import eu.kanade.tachiyomi.data.database.models.Category
|
||||||
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
import eu.kanade.tachiyomi.data.database.models.LibraryManga
|
||||||
import eu.kanade.tachiyomi.data.database.models.Manga
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadServiceListener
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
@ -74,7 +76,8 @@ class LibraryController(
|
|||||||
SecondaryDrawerController,
|
SecondaryDrawerController,
|
||||||
ActionMode.Callback,
|
ActionMode.Callback,
|
||||||
ChangeMangaCategoriesDialog.Listener,
|
ChangeMangaCategoriesDialog.Listener,
|
||||||
MigrationInterface {
|
MigrationInterface,
|
||||||
|
DownloadServiceListener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Position of the active category.
|
* Position of the active category.
|
||||||
@ -226,6 +229,8 @@ class LibraryController(
|
|||||||
fab.setOnClickListener {
|
fab.setOnClickListener {
|
||||||
router.pushController(DownloadController().withFadeTransaction())
|
router.pushController(DownloadController().withFadeTransaction())
|
||||||
}
|
}
|
||||||
|
fab.scaleX = 0f
|
||||||
|
fab.scaleY = 0f
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enableReorderItems(category: Category) {
|
fun enableReorderItems(category: Category) {
|
||||||
@ -259,11 +264,13 @@ class LibraryController(
|
|||||||
if (type.isEnter) {
|
if (type.isEnter) {
|
||||||
activity?.tabs?.setupWithViewPager(library_pager)
|
activity?.tabs?.setupWithViewPager(library_pager)
|
||||||
presenter.subscribeLibrary()
|
presenter.subscribeLibrary()
|
||||||
|
DownloadService.addListener(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
adapter?.onDestroy()
|
adapter?.onDestroy()
|
||||||
|
DownloadService.removeListener(this)
|
||||||
adapter = null
|
adapter = null
|
||||||
actionMode = null
|
actionMode = null
|
||||||
tabsVisibilitySubscription?.unsubscribe()
|
tabsVisibilitySubscription?.unsubscribe()
|
||||||
@ -271,6 +278,12 @@ class LibraryController(
|
|||||||
super.onDestroyView(view)
|
super.onDestroyView(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun downloadStatusChanged(downloading: Boolean) {
|
||||||
|
val scale = if (downloading) 1f else 0f
|
||||||
|
fab.animate().scaleX(scale).scaleY(scale).setDuration(200).start()
|
||||||
|
fab.isClickable = downloading
|
||||||
|
fab.isFocusable = downloading
|
||||||
|
}
|
||||||
override fun onDetach(view: View) {
|
override fun onDetach(view: View) {
|
||||||
destroyActionModeIfNeeded()
|
destroyActionModeIfNeeded()
|
||||||
snack?.dismiss()
|
snack?.dismiss()
|
||||||
|
@ -33,6 +33,8 @@ import com.google.android.material.snackbar.Snackbar
|
|||||||
import eu.kanade.tachiyomi.Migrations
|
import eu.kanade.tachiyomi.Migrations
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadService
|
||||||
|
import eu.kanade.tachiyomi.data.download.DownloadServiceListener
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
@ -75,7 +77,7 @@ import uy.kohesive.injekt.injectLazy
|
|||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
|
||||||
open class MainActivity : BaseActivity() {
|
open class MainActivity : BaseActivity(), DownloadServiceListener {
|
||||||
|
|
||||||
protected lateinit var router: Router
|
protected lateinit var router: Router
|
||||||
|
|
||||||
@ -198,7 +200,7 @@ open class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
val content: ViewGroup = findViewById(R.id.main_content)
|
val content: ViewGroup = findViewById(R.id.main_content)
|
||||||
bottomNav = preferences.useBottonNav().getOrDefault()
|
bottomNav = preferences.useBottonNav().getOrDefault()
|
||||||
bottomNavView = navigationView
|
DownloadService.addListener(this)
|
||||||
content.fitsSystemWindows = !bottomNav
|
content.fitsSystemWindows = !bottomNav
|
||||||
if (!bottomNav) {
|
if (!bottomNav) {
|
||||||
container.systemUiVisibility =
|
container.systemUiVisibility =
|
||||||
@ -378,8 +380,7 @@ open class MainActivity : BaseActivity() {
|
|||||||
super.onResume()
|
super.onResume()
|
||||||
bottomNav = preferences.useBottonNav().getOrDefault()
|
bottomNav = preferences.useBottonNav().getOrDefault()
|
||||||
getExtensionUpdates()
|
getExtensionUpdates()
|
||||||
bottomNavView = navigationView
|
DownloadService.callListeners()
|
||||||
setDownloadBadge(Injekt.get<DownloadManager>().hasQueue())
|
|
||||||
val useBiometrics = preferences.useBiometrics().getOrDefault()
|
val useBiometrics = preferences.useBiometrics().getOrDefault()
|
||||||
if (useBiometrics && BiometricManager.from(this)
|
if (useBiometrics && BiometricManager.from(this)
|
||||||
.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
|
||||||
@ -394,11 +395,6 @@ open class MainActivity : BaseActivity() {
|
|||||||
preferences.useBiometrics().set(false)
|
preferences.useBiometrics().set(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
|
||||||
super.onPause()
|
|
||||||
bottomNavView = null
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getExtensionUpdates() {
|
private fun getExtensionUpdates() {
|
||||||
if (Date().time >= preferences.lastExtCheck().getOrDefault() +
|
if (Date().time >= preferences.lastExtCheck().getOrDefault() +
|
||||||
TimeUnit.HOURS.toMillis(1)) {
|
TimeUnit.HOURS.toMillis(1)) {
|
||||||
@ -469,7 +465,7 @@ open class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
bottomNavView = null
|
DownloadService.removeListener(this)
|
||||||
nav_view?.setNavigationItemSelectedListener(null)
|
nav_view?.setNavigationItemSelectedListener(null)
|
||||||
toolbar?.setNavigationOnClickListener(null)
|
toolbar?.setNavigationOnClickListener(null)
|
||||||
}
|
}
|
||||||
@ -642,6 +638,21 @@ open class MainActivity : BaseActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun downloadStatusChanged(downloading: Boolean) {
|
||||||
|
if (!bottomNav) return
|
||||||
|
val downloadManager = Injekt.get<DownloadManager>()
|
||||||
|
val hasQueue = downloading || downloadManager.hasQueue()
|
||||||
|
if (hasQueue) {
|
||||||
|
val badge = navigationView?.getOrCreateBadge(R.id.nav_drawer_library)
|
||||||
|
?: return
|
||||||
|
badge.clearNumber()
|
||||||
|
badge.backgroundColor = getResourceColor(R.attr.badgeColor)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
navigationView?.removeBadge(R.id.nav_drawer_library)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
// Shortcut actions
|
// Shortcut actions
|
||||||
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
|
const val SHORTCUT_LIBRARY = "eu.kanade.tachiyomi.SHOW_LIBRARY"
|
||||||
@ -662,24 +673,6 @@ open class MainActivity : BaseActivity() {
|
|||||||
|
|
||||||
var bottomNav = false
|
var bottomNav = false
|
||||||
internal set
|
internal set
|
||||||
|
|
||||||
internal var bottomNavView:BottomNavigationView? = null
|
|
||||||
|
|
||||||
fun setDownloadBadge(downloading: Boolean) {
|
|
||||||
if (!bottomNav) return
|
|
||||||
val downloadManager = Injekt.get<DownloadManager>()
|
|
||||||
val hasQueue = downloading || downloadManager.hasQueue()
|
|
||||||
if (hasQueue) {
|
|
||||||
val badge = bottomNavView?.getOrCreateBadge(R.id.nav_drawer_library)
|
|
||||||
?: return
|
|
||||||
badge.clearNumber()
|
|
||||||
badge.backgroundColor = bottomNavView?.context?.getResourceColor(R.attr
|
|
||||||
.badgeColor) ?: Color.BLACK
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
bottomNavView?.removeBadge(R.id.nav_drawer_library)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,6 @@ class SearchActivity: MainActivity() {
|
|||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
bottomNav = false
|
bottomNav = false
|
||||||
bottomNavView = null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun handleIntentAction(intent: Intent): Boolean {
|
override fun handleIntentAction(intent: Intent): Boolean {
|
||||||
|
@ -28,14 +28,10 @@
|
|||||||
|
|
||||||
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
<com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
android:id="@+id/fab"
|
android:id="@+id/fab"
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_anchor="@id/bottom_sheet"
|
app:layout_anchor="@id/bottom_sheet"
|
||||||
|
style="@style/Theme.Widget.FABFixed"
|
||||||
app:layout_anchorGravity="end|top"
|
app:layout_anchorGravity="end|top"
|
||||||
android:backgroundTint="?attr/colorAccent"
|
android:layout_gravity="center"
|
||||||
android:tint="@color/md_white_1000"
|
|
||||||
app:tint="@color/md_white_1000"
|
|
||||||
android:layout_margin="24dp"
|
|
||||||
app:srcCompat="@drawable/ic_file_download_white_24dp"/>
|
app:srcCompat="@drawable/ic_file_download_white_24dp"/>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
Loading…
x
Reference in New Issue
Block a user