Download queue option moved to download settings

Also popup menus now us mat menus
This commit is contained in:
Jay 2020-02-05 00:32:50 -08:00
parent 98972e76c9
commit fa5b85e3b2
23 changed files with 152 additions and 41 deletions

View File

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.data.download
import android.app.Activity
import android.app.Notification
import android.app.Service
import android.content.Context
@ -16,6 +17,7 @@ import com.jakewharton.rxrelay.BehaviorRelay
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.notification.Notifications
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.system.connectivityManager
import eu.kanade.tachiyomi.util.system.isServiceRunning
@ -46,6 +48,7 @@ class DownloadService : Service() {
* @param context the application context.
*/
fun start(context: Context) {
MainActivity.setDownloadBadge(true)
val intent = Intent(context, DownloadService::class.java)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
context.startService(intent)
@ -60,6 +63,7 @@ class DownloadService : Service() {
* @param context the application context.
*/
fun stop(context: Context) {
MainActivity.setDownloadBadge(false)
context.stopService(Intent(context, DownloadService::class.java))
}
@ -124,7 +128,7 @@ class DownloadService : Service() {
* Not used.
*/
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
return Service.START_NOT_STICKY
return START_NOT_STICKY
}
/**

View File

@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.online.HttpSource
import eu.kanade.tachiyomi.source.online.fetchAllImageUrlsFromPageList
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.util.lang.RetryWithDelay
import eu.kanade.tachiyomi.util.lang.plusAssign
import eu.kanade.tachiyomi.util.storage.DiskUtil
@ -90,6 +91,7 @@ class Downloader(
launchNow {
val chapters = async { store.restore() }
queue.addAll(chapters.await())
MainActivity.setDownloadBadge(queue.isNotEmpty())
}
}

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.download
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.widget.PopupMenu
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.ui.library
import android.app.DownloadManager
import android.content.Context
import android.content.res.Configuration
import android.graphics.Color
@ -42,7 +41,6 @@ import eu.kanade.tachiyomi.ui.base.controller.SecondaryDrawerController
import eu.kanade.tachiyomi.ui.base.controller.TabbedController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.category.CategoryController
import eu.kanade.tachiyomi.ui.download.DownloadController
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.migration.MigrationController
@ -438,8 +436,6 @@ class LibraryController(
val searchView = searchItem.actionView as SearchView
searchView.queryHint = resources?.getString(R.string.search_hint)
menu.findItem(R.id.action_downloads).isVisible = MainActivity.bottomNav &&
presenter.hasPendingDownloads()
searchItem.collapseActionView()
if (query.isNotEmpty()) {
searchItem.expandActionView()
@ -486,9 +482,6 @@ class LibraryController(
R.id.action_edit_categories -> {
router.pushController(CategoryController().withFadeTransaction())
}
R.id.action_downloads -> {
router.pushController(DownloadController().withFadeTransaction())
}
R.id.action_source_migration -> {
router.pushController(MigrationController().withFadeTransaction())
}

View File

@ -101,8 +101,6 @@ class LibraryPresenter(
subscribeLibrary()
}
fun hasPendingDownloads() = downloadManager.hasQueue()
/**
* Subscribes to library if needed.
*/

View File

@ -27,9 +27,11 @@ import com.bluelinelabs.conductor.Router
import com.bluelinelabs.conductor.RouterTransaction
import com.bluelinelabs.conductor.changehandler.FadeChangeHandler
import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.snackbar.Snackbar
import eu.kanade.tachiyomi.Migrations
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
@ -48,10 +50,11 @@ import eu.kanade.tachiyomi.ui.library.LibraryController
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.ui.recent_updates.RecentChaptersController
import eu.kanade.tachiyomi.ui.recently_read.RecentlyReadController
import eu.kanade.tachiyomi.ui.setting.SettingsDownloadController
import eu.kanade.tachiyomi.ui.setting.SettingsMainController
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.launchUI
import eu.kanade.tachiyomi.util.view.doOnApplyWindowInsets
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.marginBottom
import eu.kanade.tachiyomi.util.view.marginTop
@ -59,13 +62,14 @@ import eu.kanade.tachiyomi.util.view.updateLayoutParams
import eu.kanade.tachiyomi.util.view.updatePadding
import eu.kanade.tachiyomi.util.view.updatePaddingRelative
import eu.kanade.tachiyomi.util.view.visible
import eu.kanade.tachiyomi.util.system.openInBrowser
import kotlinx.android.synthetic.main.main_activity.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import timber.log.Timber
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.util.Date
import java.util.concurrent.TimeUnit
@ -146,9 +150,7 @@ open class MainActivity : BaseActivity() {
R.id.nav_drawer_recently_read -> setRoot(RecentlyReadController(), id)
R.id.nav_drawer_catalogues -> setRoot(CatalogueController(), id)
R.id.nav_drawer_extensions -> setRoot(ExtensionController(), id)
R.id.nav_drawer_downloads -> {
router.pushController(DownloadController().withFadeTransaction())
}
R.id.nav_drawer_downloads -> setRoot(DownloadController(), id)
R.id.nav_drawer_settings -> setRoot(SettingsMainController(), id)
}
//navigationView.selectedItemId = id
@ -197,6 +199,7 @@ open class MainActivity : BaseActivity() {
val content: ViewGroup = findViewById(R.id.main_content)
bottomNav = preferences.useBottonNav().getOrDefault()
bottomNavView = navigationView
content.fitsSystemWindows = !bottomNav
if (!bottomNav) {
container.systemUiVisibility =
@ -365,7 +368,7 @@ open class MainActivity : BaseActivity() {
extUpdateText.visible()
val badge = navigationView.getOrCreateBadge(R.id.nav_drawer_settings)
badge.number = updates
badge.backgroundColor = getResourceColor(R.attr.colorAccent)
badge.backgroundColor = getResourceColor(R.attr.badgeColor)
badge.badgeTextColor = Color.WHITE
}
else {
@ -379,6 +382,8 @@ open class MainActivity : BaseActivity() {
super.onResume()
bottomNav = preferences.useBottonNav().getOrDefault()
getExtensionUpdates()
bottomNavView = navigationView
setDownloadBadge(Injekt.get<DownloadManager>().hasQueue())
val useBiometrics = preferences.useBiometrics().getOrDefault()
if (useBiometrics && BiometricManager.from(this)
.canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) {
@ -393,6 +398,10 @@ open class MainActivity : BaseActivity() {
preferences.useBiometrics().set(false)
}
override fun onPause() {
super.onPause()
bottomNavView = null
}
private fun getExtensionUpdates() {
if (Date().time >= preferences.lastExtCheck().getOrDefault() +
@ -464,6 +473,7 @@ open class MainActivity : BaseActivity() {
override fun onDestroy() {
super.onDestroy()
bottomNavView = null
nav_view?.setNavigationItemSelectedListener(null)
toolbar?.setNavigationOnClickListener(null)
}
@ -529,22 +539,28 @@ open class MainActivity : BaseActivity() {
}
}
R.id.nav_drawer_downloads -> {
if (router.backstack.isEmpty()) {
setRoot(LibraryController(), R.id.nav_drawer_library)
router.pushController(RouterTransaction.with(DownloadController())
.pushChangeHandler(SimpleSwapChangeHandler())
.popChangeHandler(FadeChangeHandler()))
if (router.backstackSize > 1) {
router.popToRoot()
}
if (bottomNav) {
navigationView.selectedItemId = R.id.nav_drawer_settings
val newBackstack = listOf(
RouterTransaction.with(SettingsMainController()),
RouterTransaction.with(SettingsDownloadController()),
RouterTransaction.with(DownloadController()))
router.setBackstack(newBackstack, FadeChangeHandler())
}
else {
router.pushController(DownloadController().withFadeTransaction())
nav_view.setCheckedItem(R.id.nav_drawer_settings)
setRoot(DownloadController(), id)
}
}
R.id.nav_drawer_settings -> {
setRoot(SettingsMainController(), id)
}
R.id.nav_drawer_help -> {
openInBrowser(URL_HELP)
}
}
}
}
@ -650,6 +666,33 @@ open class MainActivity : BaseActivity() {
var bottomNav = false
internal set
internal var bottomNavView:BottomNavigationView? = null
fun setDownloadBadge(downloading: Boolean) {
if (!bottomNav) return
val badge = bottomNavView?.getOrCreateBadge(R.id.nav_drawer_settings) ?: return
val downloadManager = Injekt.get<DownloadManager>()
val hasQueue = downloading || downloadManager.hasQueue()
if (hasQueue) {
badge.clearNumber()
badge.backgroundColor = bottomNavView?.context?.getResourceColor(R.attr
.badgeColor) ?: Color.BLACK
}
else
{
val updates = Injekt.get<PreferencesHelper>().extensionUpdatesCount().getOrDefault()
if (updates > 0) {
badge.number = updates
badge.backgroundColor = bottomNavView?.context?.getResourceColor(R.attr
.badgeColor) ?: Color.BLACK
badge.badgeTextColor = Color.WHITE
}
else {
bottomNavView?.removeBadge(R.id.nav_drawer_settings)
}
}
}
}
}

View File

@ -182,6 +182,7 @@ class SearchActivity: MainActivity() {
override fun onResume() {
super.onResume()
bottomNav = false
bottomNavView = null
}
override fun handleIntentAction(intent: Intent): Boolean {

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.manga.chapter
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.widget.PopupMenu
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.download.model.Download

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.migration.manga.process
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.widget.PopupMenu
import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.ui.recent_updates
import android.view.View
import android.widget.PopupMenu
import androidx.appcompat.widget.PopupMenu
import com.bumptech.glide.load.engine.DiskCacheStrategy
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.model.Download

View File

@ -9,6 +9,7 @@ import com.afollestad.materialdialogs.list.listItems
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.widget.preference.DownloadQueuePreference
import eu.kanade.tachiyomi.widget.preference.ExtensionPreference
import eu.kanade.tachiyomi.widget.preference.IntListMatPreference
import eu.kanade.tachiyomi.widget.preference.IntListPreference
@ -34,6 +35,12 @@ inline fun PreferenceGroup.extensionPreference(block: (@DSL Preference).() -> Un
return initThenAdd(ExtensionPreference(context), block)
}
inline fun PreferenceGroup.downloadQueuePreference(block: (@DSL Preference).() -> Unit):
DownloadQueuePreference {
return initThenAdd(DownloadQueuePreference(context), block)
}
inline fun PreferenceGroup.switchPreference(block: (@DSL SwitchPreferenceCompat).() -> Unit): SwitchPreferenceCompat {
return initThenAdd(SwitchPreferenceCompat(context), block)
}

View File

@ -11,12 +11,15 @@ import androidx.core.content.ContextCompat
import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.list.listItemsSingleChoice
import com.bluelinelabs.conductor.RouterTransaction
import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.download.DownloadController
import eu.kanade.tachiyomi.util.system.getFilePicker
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@ -31,6 +34,13 @@ class SettingsDownloadController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.pref_category_downloads
downloadQueuePreference {
titleRes = R.string.label_download_queue
onClick {
router.pushController(DownloadController().withFadeTransaction())
}
}
preference {
key = Keys.downloadsDirectory
titleRes = R.string.pref_download_directory

View File

@ -49,7 +49,7 @@ class SettingsMainController : SettingsController() {
titleRes = R.string.pref_category_reader
onClick { navigateTo(SettingsReaderController()) }
}
preference {
downloadQueuePreference {
iconRes = R.drawable.ic_file_download_black_24dp
iconTint = tintColor
titleRes = R.string.pref_category_downloads

View File

@ -0,0 +1,45 @@
package eu.kanade.tachiyomi.widget.preference
import android.content.Context
import androidx.preference.Preference
import androidx.preference.PreferenceViewHolder
import android.util.AttributeSet
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.data.preference.getOrDefault
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible
import kotlinx.android.synthetic.main.preference_update_text.view.*
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
class DownloadQueuePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
Preference(context, attrs) {
init {
widgetLayoutResource = R.layout.preference_update_text
}
override fun onBindViewHolder(holder: PreferenceViewHolder) {
super.onBindViewHolder(holder)
val extUpdateText = holder.itemView.textView
val updates = Injekt.get<DownloadManager>().queue.size
if (updates > 0) {
extUpdateText.text = context.resources.getQuantityString(R.plurals
.downloads_pending, updates, updates)
extUpdateText.visible()
}
else {
extUpdateText.text = null
extUpdateText.gone()
}
}
public override fun notifyChanged() {
super.notifyChanged()
}
}

View File

@ -51,7 +51,7 @@ class LoginCheckBoxPreference @JvmOverloads constructor(
}
// Make method public
override public fun notifyChanged() {
public override fun notifyChanged() {
super.notifyChanged()
}

View File

@ -17,12 +17,6 @@
android:title="@string/action_filter"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_downloads"
android:icon="@drawable/ic_file_download_white_24dp"
android:title="@string/label_download_queue"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_edit_categories"
android:title="@string/action_edit_categories"

View File

@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<group android:checkableBehavior="single"
android:id="@+id/menu_top">
<item
android:checked="true"
android:id="@+id/nav_drawer_library"
@ -24,6 +25,9 @@
android:icon="@drawable/ic_extension_black_24dp"
app:actionLayout="@layout/menu_counter"
android:title="@string/label_extensions"/>
</group>
<group android:checkableBehavior="single"
android:id="@+id/menu_bottom">
<item
android:id="@+id/nav_drawer_downloads"
android:icon="@drawable/ic_file_download_black_24dp"

View File

@ -15,6 +15,7 @@
<color name="purePrimary">#212121</color>
<color name="splashBackground">#212121</color>
<color name="actionModeShadow">@color/md_white_1000_38</color>
<color name="badgeColor">#3399FF</color>
<color name="textColorPrimary">@color/md_white_1000</color>
<color name="textColorSecondary">@color/md_white_1000_70</color>

View File

@ -16,6 +16,7 @@
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Tachiyomi">
<item name="colorPrimary">#54759E</item>
<item name="colorPrimaryDark">#54759E</item>
<item name="badgeColor">@color/material_red_accent_700</item>
</style>
<!--==============-->

View File

@ -31,4 +31,5 @@
<attr name="icon_color" format="reference|integer"/>
<attr name="snackbar_background" format="reference|integer"/>
<attr name="snackbar_text" format="reference|integer"/>
<attr name="badgeColor" format="reference|integer"/>
</resources>

View File

@ -31,6 +31,7 @@
<color name="textColorHintInverse">@color/md_white_1000_50</color>
<color name="divider">@color/md_black_1000_12</color>
<color name="oldNavBarBackground">#B3FFFFFF</color>
<color name="badgeColor">@color/material_red_accent_700</color>
<color name="preference_fallback_accent_color">@color/colorAccent</color>
<color name="darkPrimaryColor">#212121</color>

View File

@ -20,13 +20,17 @@
<string name="label_selected">Selected: %1$d</string>
<string name="label_migration">Source migration</string>
<string name="label_extensions">Extensions</string>
<string name="label_extension_info">Extension info</string>
<string name="label_help">Help</string>
<string name="unlock_library">Unlock to access Library</string>
<plurals name="extensions_updates_available">
<item quantity="one">Update available</item>
<item quantity="other">%d updates available</item>
</plurals>
<string name="label_extension_info">Extension info</string>
<string name="label_help">Help</string>
<string name="unlock_library">Unlock to access Library</string>
<plurals name="downloads_pending">
<item quantity="one">1 in queue</item>
<item quantity="other">%d in queue</item>
</plurals>
<!-- Actions -->
<string name="action_filter">Filter</string>

View File

@ -45,6 +45,7 @@
<item name="snackbar_background">@color/snackbarBackground</item>
<item name="snackbar_text">@color/textColorPrimaryInverse</item>
<item name="actionBarTintColor">@color/md_white_1000</item>
<item name="badgeColor">@color/badgeColor</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:navigationBarColor">#B3000000</item>
@ -66,6 +67,7 @@
<item name="actionBarTheme">@style/ThemeOverlay.AppCompat.DayNight.ActionBar</item>
<item name="tabBarIconColor">@color/colorPrimary</item>
<item name="tabBarIconInactive">@color/colorPrimaryInactive</item>
<item name="badgeColor">@color/colorAccent</item>
</style>
<style name="Theme.Tachiyomi.DarkBlue" parent="Theme.Tachiyomi"/>
<style name="Theme.Tachiyomi.Amoled" parent="Theme.Tachiyomi"/>