From 6da350aee69e1f66b2c22c8d21f87a9207e93f89 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 20 Mar 2020 22:53:24 -0400 Subject: [PATCH] Minor extension update cleanup, default to on --- .../java/eu/kanade/tachiyomi/Migrations.kt | 4 ++ .../tachiyomi/data/backup/BackupCreatorJob.kt | 2 +- .../data/library/LibraryUpdateJob.kt | 2 +- .../data/notification/NotificationReceiver.kt | 18 +++---- .../data/preference/PreferencesHelper.kt | 2 +- .../tachiyomi/data/updater/UpdaterJob.kt | 2 +- .../tachiyomi/extension/ExtensionManager.kt | 12 +++-- .../tachiyomi/extension/ExtensionUpdateJob.kt | 49 ++++++++++--------- .../extension/api/ExtensionGithubApi.kt | 15 ++++-- .../ui/extension/ExtensionController.kt | 7 ++- .../kanade/tachiyomi/ui/main/MainActivity.kt | 44 ++++++++--------- .../tachiyomi/ui/more/MoreController.kt | 9 +++- .../util/preference/PreferenceDSL.kt | 6 +-- .../widget/preference/BadgePreference.kt | 37 ++++++++++++++ .../widget/preference/ExtensionPreference.kt | 37 -------------- .../drawable/round_textview_background.xml | 10 ++-- ...ference_update_text.xml => pref_badge.xml} | 15 ++---- app/src/main/res/menu/extension_main.xml | 4 +- app/src/main/res/values/strings.xml | 4 +- 19 files changed, 146 insertions(+), 133 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/BadgePreference.kt delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt rename app/src/main/res/layout/{preference_update_text.xml => pref_badge.xml} (61%) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index ad664d8074..d0e9b823c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -5,6 +5,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateJob import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.data.updater.UpdaterJob +import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import java.io.File object Migrations { @@ -27,6 +28,9 @@ object Migrations { if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) { UpdaterJob.setupTask(context) } + if (preferences.automaticExtUpdates().getOrDefault()) { + ExtensionUpdateJob.setupTask(context) + } return false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt index 512c3fb691..01905e02a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreatorJob.kt @@ -26,7 +26,7 @@ class BackupCreatorJob(private val context: Context, workerParams: WorkerParamet } companion object { - const val TAG = "BackupCreator" + private const val TAG = "BackupCreator" fun setupTask(context: Context, prefInterval: Int? = null) { val preferences = Injekt.get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 869d8f20f0..8cbe006d9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -23,7 +23,7 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet } companion object { - const val TAG = "LibraryUpdate" + private const val TAG = "LibraryUpdate" fun setupTask(context: Context, prefInterval: Int? = null) { val preferences = Injekt.get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index 8a6b7b98e4..ba6c91786b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -410,11 +410,9 @@ class NotificationReceiver : BroadcastReceiver() { internal fun markAsReadPendingBroadcast( context: Context, manga: Manga, - chapters: - Array, + chapters: Array, groupId: Int - ): - PendingIntent { + ): PendingIntent { val newIntent = Intent(context, NotificationReceiver::class.java).apply { action = ACTION_MARK_AS_READ putExtra(EXTRA_CHAPTER_URL, chapters.map { it.url }.toTypedArray()) @@ -442,14 +440,14 @@ class NotificationReceiver : BroadcastReceiver() { * Returns [PendingIntent] that opens the extensions controller. * * @param context context of application + * @return [PendingIntent] */ internal fun openExtensionsPendingActivity(context: Context): PendingIntent { - val newIntent = - Intent(context, MainActivity::class.java).setAction(MainActivity.SHORTCUT_EXTENSIONS) - .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - return PendingIntent.getActivity( - context, 0, newIntent, PendingIntent.FLAG_UPDATE_CURRENT - ) + val intent = Intent(context, MainActivity::class.java).apply { + action = MainActivity.SHORTCUT_EXTENSIONS + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + } + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 9782fe52a5..cb92b86a39 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -190,7 +190,7 @@ class PreferencesHelper(val context: Context) { fun automaticUpdates() = prefs.getBoolean(Keys.automaticUpdates, true) - fun automaticExtUpdates() = rxPrefs.getBoolean(Keys.automaticExtUpdates, false) + fun automaticExtUpdates() = rxPrefs.getBoolean(Keys.automaticExtUpdates, true) fun extensionUpdatesCount() = rxPrefs.getInteger("ext_updates_count", 0) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt index deb37f2bde..c98387b291 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/UpdaterJob.kt @@ -55,7 +55,7 @@ class UpdaterJob(private val context: Context, workerParams: WorkerParameters) : } companion object { - const val TAG = "UpdateChecker" + private const val TAG = "UpdateChecker" fun setupTask(context: Context) { val constraints = Constraints.Builder() diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index dd41d986c9..cdd56e7242 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -187,7 +187,7 @@ class ExtensionManager( if (changed) { installedExtensions = mutInstalledExtensions } - preferences.extensionUpdatesCount().set(installedExtensions.count { it.hasUpdate }) + updatePendingUpdatesCount() } /** @@ -318,12 +318,12 @@ class ExtensionManager( override fun onExtensionInstalled(extension: Extension.Installed) { registerNewExtension(extension.withUpdateCheck()) - preferences.extensionUpdatesCount().set(installedExtensions.count { it.hasUpdate }) + updatePendingUpdatesCount() } override fun onExtensionUpdated(extension: Extension.Installed) { registerUpdatedExtension(extension.withUpdateCheck()) - preferences.extensionUpdatesCount().set(installedExtensions.count { it.hasUpdate }) + updatePendingUpdatesCount() } override fun onExtensionUntrusted(extension: Extension.Untrusted) { @@ -332,7 +332,7 @@ class ExtensionManager( override fun onPackageUninstalled(pkgName: String) { unregisterExtension(pkgName) - preferences.extensionUpdatesCount().set(installedExtensions.count { it.hasUpdate }) + updatePendingUpdatesCount() } } @@ -346,4 +346,8 @@ class ExtensionManager( } return this } + + private fun updatePendingUpdatesCount() { + preferences.extensionUpdatesCount().set(installedExtensions.count { it.hasUpdate }) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 01866d8483..4c21ccf3eb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -31,36 +31,37 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam } catch (e: Exception) { return@coroutineScope Result.failure() } + if (pendingUpdates.isNotEmpty()) { - val names = pendingUpdates.map { it.name } - NotificationManagerCompat.from(context).apply { - notify(Notifications.ID_UPDATES_TO_EXTS, - context.notification(Notifications.CHANNEL_UPDATES_TO_EXTS) { - setContentTitle( - context.resources.getQuantityString( - R.plurals.update_check_notification_ext_updates, - names.size, - names.size - ) - ) - val extNames = names.joinToString(", ") - setContentText(extNames) - setStyle(NotificationCompat.BigTextStyle().bigText(extNames)) - setSmallIcon(R.drawable.ic_extension_24dp) - setContentIntent( - NotificationReceiver.openExtensionsPendingActivity( - context - ) - ) - setAutoCancel(true) - }) - } + createUpdateNotification(pendingUpdates.map { it.name }) } + Result.success() } + private fun createUpdateNotification(names: List) { + NotificationManagerCompat.from(context).apply { + notify(Notifications.ID_UPDATES_TO_EXTS, + context.notification(Notifications.CHANNEL_UPDATES_TO_EXTS) { + setContentTitle( + context.resources.getQuantityString( + R.plurals.update_check_notification_ext_updates, + names.size, + names.size + ) + ) + val extNames = names.joinToString(", ") + setContentText(extNames) + setStyle(NotificationCompat.BigTextStyle().bigText(extNames)) + setSmallIcon(R.drawable.ic_extension_24dp) + setContentIntent(NotificationReceiver.openExtensionsPendingActivity(context)) + setAutoCancel(true) + }) + } + } + companion object { - const val TAG = "ExtensionUpdate" + private const val TAG = "ExtensionUpdate" fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { val preferences = Injekt.get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index 1223f24218..cf8d448f5c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -7,12 +7,14 @@ import com.github.salomonbrys.kotson.int import com.github.salomonbrys.kotson.string import com.google.gson.Gson import com.google.gson.JsonArray +import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.extension.util.ExtensionLoader import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.network.await +import java.util.Date import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.Response @@ -21,6 +23,7 @@ import uy.kohesive.injekt.injectLazy internal class ExtensionGithubApi { private val network: NetworkHelper by injectLazy() + private val preferences: PreferencesHelper by injectLazy() private val gson: Gson by injectLazy() @@ -33,23 +36,29 @@ internal class ExtensionGithubApi { } suspend fun checkForUpdates(context: Context): List { + val call = GET(EXT_URL) + return withContext(Dispatchers.IO) { - val call = GET(EXT_URL) val response = network.client.newCall(call).await() + preferences.lastExtCheck().set(Date().time) + if (response.isSuccessful) { val extensions = parseResponse(response) - val extensionsWithUpdate = mutableListOf() val installedExtensions = ExtensionLoader.loadExtensions(context) .filterIsInstance() .map { it.extension } + + val extensionsWithUpdate = mutableListOf() for (installedExt in installedExtensions) { val pkgName = installedExt.pkgName val availableExt = extensions.find { it.pkgName == pkgName } ?: continue val hasUpdate = availableExt.versionCode > installedExt.versionCode - if (hasUpdate) extensionsWithUpdate.add(installedExt) + if (hasUpdate) { + extensionsWithUpdate.add(installedExt) + } } extensionsWithUpdate diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt index ad216e20b0..4bac6bf9b5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt @@ -36,6 +36,8 @@ open class ExtensionController : NucleusController(), FlexibleAdapter.OnItemLongClickListener, ExtensionTrustDialog.Listener { + private val preferences: PreferencesHelper = Injekt.get() + /** * Adapter containing the list of manga from the catalogue. */ @@ -92,7 +94,6 @@ open class ExtensionController : NucleusController(), } R.id.action_auto_check -> { item.isChecked = !item.isChecked - val preferences: PreferencesHelper = Injekt.get() preferences.automaticExtUpdates().set(item.isChecked) ExtensionUpdateJob.setupTask(activity!!, item.isChecked) } @@ -150,9 +151,7 @@ open class ExtensionController : NucleusController(), // Fixes problem with the overflow icon showing up in lieu of search searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) - val autoItem = menu.findItem(R.id.action_auto_check) - val preferences: PreferencesHelper = Injekt.get() - autoItem.isChecked = preferences.automaticExtUpdates().getOrDefault() + menu.findItem(R.id.action_auto_check).isChecked = preferences.automaticExtUpdates().getOrDefault() } override fun onItemClick(view: View, position: Int): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index aed87bafb8..c91d98d72c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -13,7 +13,6 @@ import com.bluelinelabs.conductor.RouterTransaction import eu.kanade.tachiyomi.Migrations import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver -import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.ui.base.activity.BaseActivity @@ -39,7 +38,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import timber.log.Timber -import uy.kohesive.injekt.injectLazy class MainActivity : BaseActivity() { @@ -152,33 +150,33 @@ class MainActivity : BaseActivity() { } } - private fun setExtensionsBadge() { - val updates = preferences.extensionUpdatesCount().getOrDefault() - if (updates > 0) { - val badge = bottom_nav.getOrCreateBadge(R.id.nav_more) - badge.number = updates - } else { - bottom_nav.removeBadge(R.id.nav_more) - } - } - override fun onResume() { super.onResume() getExtensionUpdates() } + private fun setExtensionsBadge() { + val updates = preferences.extensionUpdatesCount().getOrDefault() + if (updates > 0) { + bottom_nav.getOrCreateBadge(R.id.nav_more).number = updates + } else { + bottom_nav.removeBadge(R.id.nav_more) + } + } + private fun getExtensionUpdates() { - if (Date().time >= preferences.lastExtCheck().getOrDefault() + - TimeUnit.HOURS.toMillis(2)) { - GlobalScope.launch(Dispatchers.IO) { - val preferences: PreferencesHelper by injectLazy() - try { - val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity) - preferences.extensionUpdatesCount().set(pendingUpdates.size) - preferences.lastExtCheck().set(Date().time) - } catch (e: java.lang.Exception) { - Timber.e(e) - } + // Limit checks to once every 2 hours at most + val now = Date().time + if (now < preferences.lastExtCheck().getOrDefault() + TimeUnit.HOURS.toMillis(2)) { + return + } + + GlobalScope.launch(Dispatchers.IO) { + try { + val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity) + preferences.extensionUpdatesCount().set(pendingUpdates.size) + } catch (e: Exception) { + Timber.e(e) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 17403a071b..7c3cefb5a2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -2,6 +2,8 @@ package eu.kanade.tachiyomi.ui.more import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.download.DownloadController @@ -9,7 +11,7 @@ import eu.kanade.tachiyomi.ui.extension.ExtensionController import eu.kanade.tachiyomi.ui.migration.MigrationController import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsMainController -import eu.kanade.tachiyomi.util.preference.extensionPreference +import eu.kanade.tachiyomi.util.preference.badgePreference import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.iconTint import eu.kanade.tachiyomi.util.preference.onClick @@ -18,6 +20,8 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.titleRes import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser +import uy.kohesive.injekt.Injekt +import uy.kohesive.injekt.api.get class MoreController : SettingsController(), RootController { @@ -26,10 +30,11 @@ class MoreController : SettingsController(), RootController { val tintColor = context.getResourceColor(R.attr.colorAccent) - extensionPreference { + badgePreference { titleRes = R.string.label_extensions iconRes = R.drawable.ic_extension_24dp iconTint = tintColor + setBadge(Injekt.get().extensionUpdatesCount().getOrDefault()) onClick { router.pushController(ExtensionController().withFadeTransaction()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt index f9b7a62e99..4cb24e0648 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceDSL.kt @@ -13,7 +13,7 @@ import androidx.preference.PreferenceManager import androidx.preference.PreferenceScreen import androidx.preference.SwitchPreferenceCompat import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat -import eu.kanade.tachiyomi.widget.preference.ExtensionPreference +import eu.kanade.tachiyomi.widget.preference.BadgePreference import eu.kanade.tachiyomi.widget.preference.IntListPreference import eu.kanade.tachiyomi.widget.preference.SwitchPreferenceCategory @@ -57,8 +57,8 @@ inline fun PreferenceGroup.multiSelectListPreference(block: (@DSL MultiSelectLis return initThenAdd(MultiSelectListPreference(context), block).also(::initDialog) } -inline fun PreferenceGroup.extensionPreference(block: (@DSL Preference).() -> Unit): ExtensionPreference { - return initThenAdd(ExtensionPreference(context), block) +inline fun PreferenceGroup.badgePreference(block: (@DSL BadgePreference).() -> Unit): BadgePreference { + return initThenAdd(BadgePreference(context), block) } inline fun PreferenceScreen.preferenceCategory(block: (@DSL PreferenceCategory).() -> Unit): PreferenceCategory { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/BadgePreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/BadgePreference.kt new file mode 100644 index 0000000000..b0a97ab1aa --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/BadgePreference.kt @@ -0,0 +1,37 @@ +package eu.kanade.tachiyomi.widget.preference + +import android.content.Context +import android.util.AttributeSet +import androidx.preference.Preference +import androidx.preference.PreferenceViewHolder +import eu.kanade.tachiyomi.R +import eu.kanade.tachiyomi.util.view.gone +import eu.kanade.tachiyomi.util.view.visible +import kotlinx.android.synthetic.main.pref_badge.view.badge + +class BadgePreference @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) : + Preference(context, attrs) { + + private var badgeNumber: Int = 0 + + init { + widgetLayoutResource = R.layout.pref_badge + } + + override fun onBindViewHolder(holder: PreferenceViewHolder) { + super.onBindViewHolder(holder) + + if (badgeNumber > 0) { + holder.itemView.badge.text = badgeNumber.toString() + holder.itemView.badge.visible() + } else { + holder.itemView.badge.text = null + holder.itemView.badge.gone() + } + } + + fun setBadge(number: Int) { + this.badgeNumber = number + notifyChanged() + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt deleted file mode 100644 index 4602b72cc3..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/preference/ExtensionPreference.kt +++ /dev/null @@ -1,37 +0,0 @@ -package eu.kanade.tachiyomi.widget.preference - -import android.content.Context -import android.util.AttributeSet -import androidx.preference.Preference -import androidx.preference.PreferenceViewHolder -import eu.kanade.tachiyomi.R -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 ExtensionPreference @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().extensionUpdatesCount().getOrDefault() - if (updates > 0) { - extUpdateText.text = updates.toString() - extUpdateText.visible() - } else { - extUpdateText.text = null - extUpdateText.gone() - } - } -} diff --git a/app/src/main/res/drawable/round_textview_background.xml b/app/src/main/res/drawable/round_textview_background.xml index deb60b367e..fb61cf1ed5 100644 --- a/app/src/main/res/drawable/round_textview_background.xml +++ b/app/src/main/res/drawable/round_textview_background.xml @@ -1,9 +1,9 @@ - + - - \ No newline at end of file + android:width="25dp" + android:height="25dp" /> + + diff --git a/app/src/main/res/layout/preference_update_text.xml b/app/src/main/res/layout/pref_badge.xml similarity index 61% rename from app/src/main/res/layout/preference_update_text.xml rename to app/src/main/res/layout/pref_badge.xml index 3baa6286ef..471c1caba3 100644 --- a/app/src/main/res/layout/preference_update_text.xml +++ b/app/src/main/res/layout/pref_badge.xml @@ -1,17 +1,12 @@ \ No newline at end of file + tools:text="3" /> diff --git a/app/src/main/res/menu/extension_main.xml b/app/src/main/res/menu/extension_main.xml index f0b98861eb..f71533988a 100644 --- a/app/src/main/res/menu/extension_main.xml +++ b/app/src/main/res/menu/extension_main.xml @@ -18,8 +18,8 @@ + android:title="@string/pref_enable_automatic_extension_updates" + app:showAsAction="never" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1e2848b35..e11016cc17 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -211,7 +211,7 @@ Version: %1$s Language: %1$s No preferences to edit for this extension - Auto-check for updates + Check for extension updates Fullscreen @@ -601,6 +601,6 @@ Library Downloader Chapter updates - Extension Updates + Extension updates