|
@@ -13,6 +13,9 @@ 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
|
|
|
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
|
|
import eu.kanade.tachiyomi.ui.base.controller.NoToolbarElevationController
|
|
@@ -23,16 +26,20 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
|
|
import eu.kanade.tachiyomi.ui.catalogue.CatalogueController
|
|
|
import eu.kanade.tachiyomi.ui.catalogue.global_search.CatalogueSearchController
|
|
|
import eu.kanade.tachiyomi.ui.download.DownloadController
|
|
|
+import eu.kanade.tachiyomi.ui.extension.ExtensionController
|
|
|
import eu.kanade.tachiyomi.ui.library.LibraryController
|
|
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
|
|
import eu.kanade.tachiyomi.ui.more.MoreController
|
|
|
import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
|
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
|
|
-import kotlinx.android.synthetic.main.main_activity.appbar
|
|
|
-import kotlinx.android.synthetic.main.main_activity.bottom_nav
|
|
|
-import kotlinx.android.synthetic.main.main_activity.drawer
|
|
|
-import kotlinx.android.synthetic.main.main_activity.tabs
|
|
|
-import kotlinx.android.synthetic.main.main_activity.toolbar
|
|
|
+import java.util.Date
|
|
|
+import java.util.concurrent.TimeUnit
|
|
|
+import kotlinx.android.synthetic.main.main_activity.*
|
|
|
+import kotlinx.coroutines.Dispatchers
|
|
|
+import kotlinx.coroutines.GlobalScope
|
|
|
+import kotlinx.coroutines.launch
|
|
|
+import timber.log.Timber
|
|
|
+import uy.kohesive.injekt.injectLazy
|
|
|
|
|
|
class MainActivity : BaseActivity() {
|
|
|
|
|
@@ -133,6 +140,10 @@ class MainActivity : BaseActivity() {
|
|
|
ChangelogDialogController().showDialog(router)
|
|
|
}
|
|
|
}
|
|
|
+ preferences.extensionUpdatesCount().asObservable().subscribe {
|
|
|
+ setExtensionsBadge()
|
|
|
+ }
|
|
|
+ setExtensionsBadge()
|
|
|
}
|
|
|
|
|
|
override fun onNewIntent(intent: Intent) {
|
|
@@ -141,6 +152,37 @@ 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 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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun handleIntentAction(intent: Intent): Boolean {
|
|
|
val notificationId = intent.getIntExtra("notificationId", -1)
|
|
|
if (notificationId > -1) {
|
|
@@ -152,6 +194,10 @@ class MainActivity : BaseActivity() {
|
|
|
SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_updates)
|
|
|
SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_history)
|
|
|
SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_catalogues)
|
|
|
+ SHORTCUT_EXTENSIONS -> {
|
|
|
+ setSelectedDrawerItem(R.id.nav_more)
|
|
|
+ router.pushController(ExtensionController().withFadeTransaction())
|
|
|
+ }
|
|
|
SHORTCUT_MANGA -> {
|
|
|
val extras = intent.extras ?: return false
|
|
|
setSelectedDrawerItem(R.id.nav_library)
|
|
@@ -267,6 +313,7 @@ class MainActivity : BaseActivity() {
|
|
|
const val SHORTCUT_CATALOGUES = "eu.kanade.tachiyomi.SHOW_CATALOGUES"
|
|
|
const val SHORTCUT_DOWNLOADS = "eu.kanade.tachiyomi.SHOW_DOWNLOADS"
|
|
|
const val SHORTCUT_MANGA = "eu.kanade.tachiyomi.SHOW_MANGA"
|
|
|
+ const val SHORTCUT_EXTENSIONS = "eu.kanade.tachiyomi.EXTENSIONS"
|
|
|
|
|
|
const val INTENT_SEARCH = "eu.kanade.tachiyomi.SEARCH"
|
|
|
const val INTENT_SEARCH_QUERY = "query"
|