|
@@ -4,7 +4,6 @@ import android.app.SearchManager
|
|
|
import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.view.ViewGroup
|
|
|
-import androidx.core.view.GravityCompat
|
|
|
import com.bluelinelabs.conductor.Conductor
|
|
|
import com.bluelinelabs.conductor.Controller
|
|
|
import com.bluelinelabs.conductor.ControllerChangeHandler
|
|
@@ -14,12 +13,12 @@ import eu.kanade.tachiyomi.Migrations
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
|
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|
|
+import eu.kanade.tachiyomi.databinding.MainActivityBinding
|
|
|
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
|
|
|
import eu.kanade.tachiyomi.ui.base.controller.RootController
|
|
|
-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.catalogue.CatalogueController
|
|
@@ -33,7 +32,6 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController
|
|
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController
|
|
|
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
|
|
@@ -43,8 +41,6 @@ class MainActivity : BaseActivity() {
|
|
|
|
|
|
private lateinit var router: Router
|
|
|
|
|
|
- private var secondaryDrawer: ViewGroup? = null
|
|
|
-
|
|
|
private val startScreenId by lazy {
|
|
|
when (preferences.startScreen()) {
|
|
|
2 -> R.id.nav_history
|
|
@@ -58,6 +54,8 @@ class MainActivity : BaseActivity() {
|
|
|
|
|
|
private var isHandlingShortcut: Boolean = false
|
|
|
|
|
|
+ private lateinit var binding: MainActivityBinding
|
|
|
+
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
@@ -67,15 +65,16 @@ class MainActivity : BaseActivity() {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- setContentView(R.layout.main_activity)
|
|
|
+ binding = MainActivityBinding.inflate(layoutInflater)
|
|
|
+ setContentView(binding.root)
|
|
|
|
|
|
- setSupportActionBar(toolbar)
|
|
|
+ setSupportActionBar(binding.toolbar)
|
|
|
|
|
|
- tabAnimator = ViewHeightAnimator(tabs)
|
|
|
- bottomNavAnimator = ViewHeightAnimator(bottom_nav)
|
|
|
+ tabAnimator = ViewHeightAnimator(binding.tabs)
|
|
|
+ bottomNavAnimator = ViewHeightAnimator(binding.bottomNav)
|
|
|
|
|
|
// Set behavior of bottom nav
|
|
|
- bottom_nav.setOnNavigationItemSelectedListener { item ->
|
|
|
+ binding.bottomNav.setOnNavigationItemSelectedListener { item ->
|
|
|
val id = item.itemId
|
|
|
|
|
|
val currentRoot = router.backstack.firstOrNull()
|
|
@@ -104,16 +103,12 @@ class MainActivity : BaseActivity() {
|
|
|
if (!router.hasRootController()) {
|
|
|
// Set start screen
|
|
|
if (!handleIntentAction(intent)) {
|
|
|
- setSelectedDrawerItem(startScreenId)
|
|
|
+ setSelectedNavItem(startScreenId)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- toolbar.setNavigationOnClickListener {
|
|
|
- if (router.backstackSize == 1) {
|
|
|
- drawer.openDrawer(GravityCompat.START)
|
|
|
- } else {
|
|
|
- onBackPressed()
|
|
|
- }
|
|
|
+ binding.toolbar.setNavigationOnClickListener {
|
|
|
+ onBackPressed()
|
|
|
}
|
|
|
|
|
|
router.addChangeListener(object : ControllerChangeHandler.ControllerChangeListener {
|
|
@@ -165,9 +160,9 @@ class MainActivity : BaseActivity() {
|
|
|
private fun setExtensionsBadge() {
|
|
|
val updates = preferences.extensionUpdatesCount().getOrDefault()
|
|
|
if (updates > 0) {
|
|
|
- bottom_nav.getOrCreateBadge(R.id.nav_more).number = updates
|
|
|
+ binding.bottomNav.getOrCreateBadge(R.id.nav_more).number = updates
|
|
|
} else {
|
|
|
- bottom_nav.removeBadge(R.id.nav_more)
|
|
|
+ binding.bottomNav.removeBadge(R.id.nav_more)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -197,15 +192,15 @@ class MainActivity : BaseActivity() {
|
|
|
isHandlingShortcut = true
|
|
|
|
|
|
when (intent.action) {
|
|
|
- SHORTCUT_LIBRARY -> setSelectedDrawerItem(R.id.nav_library)
|
|
|
- SHORTCUT_RECENTLY_UPDATED -> setSelectedDrawerItem(R.id.nav_updates)
|
|
|
- SHORTCUT_RECENTLY_READ -> setSelectedDrawerItem(R.id.nav_history)
|
|
|
- SHORTCUT_CATALOGUES -> setSelectedDrawerItem(R.id.nav_sources)
|
|
|
+ SHORTCUT_LIBRARY -> setSelectedNavItem(R.id.nav_library)
|
|
|
+ SHORTCUT_RECENTLY_UPDATED -> setSelectedNavItem(R.id.nav_updates)
|
|
|
+ SHORTCUT_RECENTLY_READ -> setSelectedNavItem(R.id.nav_history)
|
|
|
+ SHORTCUT_CATALOGUES -> setSelectedNavItem(R.id.nav_sources)
|
|
|
SHORTCUT_EXTENSIONS -> {
|
|
|
if (router.backstackSize > 1) {
|
|
|
router.popToRoot()
|
|
|
}
|
|
|
- setSelectedDrawerItem(R.id.nav_more)
|
|
|
+ setSelectedNavItem(R.id.nav_more)
|
|
|
router.pushController(ExtensionController().withFadeTransaction())
|
|
|
}
|
|
|
SHORTCUT_MANGA -> {
|
|
@@ -213,14 +208,14 @@ class MainActivity : BaseActivity() {
|
|
|
if (router.backstackSize > 1) {
|
|
|
router.popToRoot()
|
|
|
}
|
|
|
- setSelectedDrawerItem(R.id.nav_library)
|
|
|
+ setSelectedNavItem(R.id.nav_library)
|
|
|
router.pushController(RouterTransaction.with(MangaController(extras)))
|
|
|
}
|
|
|
SHORTCUT_DOWNLOADS -> {
|
|
|
if (router.backstackSize > 1) {
|
|
|
router.popToRoot()
|
|
|
}
|
|
|
- setSelectedDrawerItem(R.id.nav_more)
|
|
|
+ setSelectedNavItem(R.id.nav_more)
|
|
|
router.pushController(RouterTransaction.with(DownloadController()))
|
|
|
}
|
|
|
Intent.ACTION_SEARCH, "com.google.android.gms.actions.SEARCH_ACTION" -> {
|
|
@@ -258,24 +253,22 @@ class MainActivity : BaseActivity() {
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
|
- bottom_nav?.setOnNavigationItemSelectedListener(null)
|
|
|
- toolbar?.setNavigationOnClickListener(null)
|
|
|
+ binding.bottomNav.setOnNavigationItemSelectedListener(null)
|
|
|
+ binding.toolbar.setNavigationOnClickListener(null)
|
|
|
}
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
val backstackSize = router.backstackSize
|
|
|
- if (drawer.isDrawerOpen(GravityCompat.START) || drawer.isDrawerOpen(GravityCompat.END)) {
|
|
|
- drawer.closeDrawers()
|
|
|
- } else if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) {
|
|
|
- setSelectedDrawerItem(startScreenId)
|
|
|
+ if (backstackSize == 1 && router.getControllerWithTag("$startScreenId") == null) {
|
|
|
+ setSelectedNavItem(startScreenId)
|
|
|
} else if (backstackSize == 1 || !router.handleBack()) {
|
|
|
super.onBackPressed()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private fun setSelectedDrawerItem(itemId: Int) {
|
|
|
+ private fun setSelectedNavItem(itemId: Int) {
|
|
|
if (!isFinishing) {
|
|
|
- bottom_nav.selectedItemId = itemId
|
|
|
+ binding.bottomNav.selectedItemId = itemId
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -298,31 +291,20 @@ class MainActivity : BaseActivity() {
|
|
|
}
|
|
|
|
|
|
if (from is TabbedController) {
|
|
|
- from.cleanupTabs(tabs)
|
|
|
+ from.cleanupTabs(binding.tabs)
|
|
|
}
|
|
|
if (to is TabbedController) {
|
|
|
tabAnimator.expand()
|
|
|
- to.configureTabs(tabs)
|
|
|
+ to.configureTabs(binding.tabs)
|
|
|
} else {
|
|
|
tabAnimator.collapse()
|
|
|
- tabs.setupWithViewPager(null)
|
|
|
- }
|
|
|
-
|
|
|
- if (from is SecondaryDrawerController) {
|
|
|
- if (secondaryDrawer != null) {
|
|
|
- from.cleanupSecondaryDrawer(drawer)
|
|
|
- drawer.removeView(secondaryDrawer)
|
|
|
- secondaryDrawer = null
|
|
|
- }
|
|
|
- }
|
|
|
- if (to is SecondaryDrawerController) {
|
|
|
- secondaryDrawer = to.createSecondaryDrawer(drawer)?.also { drawer.addView(it) }
|
|
|
+ binding.tabs.setupWithViewPager(null)
|
|
|
}
|
|
|
|
|
|
if (to is NoToolbarElevationController) {
|
|
|
- appbar.disableElevation()
|
|
|
+ binding.appbar.disableElevation()
|
|
|
} else {
|
|
|
- appbar.enableElevation()
|
|
|
+ binding.appbar.enableElevation()
|
|
|
}
|
|
|
}
|
|
|
|