diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt deleted file mode 100644 index 947f32d18..000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt +++ /dev/null @@ -1,84 +0,0 @@ -package eu.kanade.tachiyomi.ui.base.activity - -import android.Manifest -import android.content.pm.PackageManager -import android.os.Build -import android.support.v4.app.ActivityCompat -import android.support.v4.content.ContextCompat -import android.support.v7.app.ActionBar -import android.support.v7.app.AppCompatActivity -import android.support.v7.widget.Toolbar -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get - -interface ActivityMixin { - - var resumed: Boolean - - fun setupToolbar(toolbar: Toolbar, backNavigation: Boolean = true) { - setSupportActionBar(toolbar) - getSupportActionBar()?.setDisplayHomeAsUpEnabled(true) - if (backNavigation) { - toolbar.setNavigationOnClickListener { - if (resumed) { - onBackPressed() - } - } - } - } - - fun setAppTheme() { - setTheme(when (Injekt.get().theme()) { - 2 -> R.style.Theme_Tachiyomi_Dark - 3 -> R.style.Theme_Tachiyomi_Amoled - else -> R.style.Theme_Tachiyomi - }) - } - - fun setToolbarTitle(title: String) { - getSupportActionBar()?.title = title - } - - fun setToolbarTitle(titleResource: Int) { - getSupportActionBar()?.title = getString(titleResource) - } - - fun setToolbarSubtitle(title: String) { - getSupportActionBar()?.subtitle = title - } - - fun setToolbarSubtitle(titleResource: Int) { - getSupportActionBar()?.subtitle = getString(titleResource) - } - - /** - * Requests read and write permissions on Android M and higher. - */ - fun requestPermissionsOnMarshmallow() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - if (ContextCompat.checkSelfPermission(getActivity(), - Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { - - ActivityCompat.requestPermissions(getActivity(), - arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE), - 1) - - } - } - } - - fun getActivity(): AppCompatActivity - - fun onBackPressed() - - fun getSupportActionBar(): ActionBar? - - fun setSupportActionBar(toolbar: Toolbar?) - - fun setTheme(resource: Int) - - fun getString(resource: Int): String - -} \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 38a4568d0..2b9745ea1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -3,24 +3,11 @@ package eu.kanade.tachiyomi.ui.base.activity import android.support.v7.app.AppCompatActivity import eu.kanade.tachiyomi.util.LocaleHelper -abstract class BaseActivity : AppCompatActivity(), ActivityMixin { - - override var resumed = false +abstract class BaseActivity : AppCompatActivity() { init { + @Suppress("LeakingThis") LocaleHelper.updateConfiguration(this) } - override fun getActivity() = this - - override fun onResume() { - super.onResume() - resumed = true - } - - override fun onPause() { - resumed = false - super.onPause() - } - } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 7cae74bdd..560fb01c8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -4,24 +4,11 @@ import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.util.LocaleHelper import nucleus.view.NucleusAppCompatActivity -abstract class BaseRxActivity

> : NucleusAppCompatActivity

(), ActivityMixin { - - override var resumed = false +abstract class BaseRxActivity

> : NucleusAppCompatActivity

() { init { + @Suppress("LeakingThis") LocaleHelper.updateConfiguration(this) } - override fun getActivity() = this - - override fun onResume() { - super.onResume() - resumed = true - } - - override fun onPause() { - resumed = false - super.onPause() - } - } 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 8f1e435b0..d4b3da4b6 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 @@ -42,7 +42,6 @@ class MainActivity : BaseActivity() { private val startScreenId by lazy { when (preferences.startScreen()) { - 1 -> R.id.nav_drawer_library 2 -> R.id.nav_drawer_recently_read 3 -> R.id.nav_drawer_recent_updates else -> R.id.nav_drawer_library @@ -52,7 +51,11 @@ class MainActivity : BaseActivity() { lateinit var tabAnimator: TabsAnimator override fun onCreate(savedInstanceState: Bundle?) { - setAppTheme() + setTheme(when (preferences.theme()) { + 2 -> R.style.Theme_Tachiyomi_Dark + 3 -> R.style.Theme_Tachiyomi_Amoled + else -> R.style.Theme_Tachiyomi + }) super.onCreate(savedInstanceState) // Do not let the launcher create a new activity http://stackoverflow.com/questions/16283079 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt index 67195b882..304d32f2d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/TabsAnimator.kt @@ -21,9 +21,9 @@ class TabsAnimator(val tabs: TabLayout) { * Animation used to expand and collapse the tab layout. */ private val animation by lazy { - ObjectAnimator.ofInt(this, "height", tabsHeight).also { - it.duration = 300L - it.interpolator = DecelerateInterpolator() + ObjectAnimator.ofInt(this, "height", tabsHeight).apply { + duration = 300L + interpolator = DecelerateInterpolator() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 11b27c623..b9c16184d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -99,7 +99,11 @@ class ReaderActivity : BaseRxActivity() { return } - setupToolbar(toolbar) + setSupportActionBar(toolbar) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + toolbar.setNavigationOnClickListener { + onBackPressed() + } initializeSettings() initializeBottomMenu() @@ -131,6 +135,7 @@ class ReaderActivity : BaseRxActivity() { } override fun onDestroy() { + toolbar.setNavigationOnClickListener(null) subscriptions.unsubscribe() viewer = null super.onDestroy() @@ -256,7 +261,7 @@ class ReaderActivity : BaseRxActivity() { // Invert the seekbar for the right to left reader page_seekbar.rotation = 180f } - setToolbarTitle(manga.title) + supportActionBar?.title = manga.title please_wait.visibility = View.VISIBLE please_wait.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fade_in_long)) } @@ -288,10 +293,10 @@ class ReaderActivity : BaseRxActivity() { page_seekbar.max = numPages - 1 page_seekbar.progress = currentPage - setToolbarSubtitle(if (chapter.isRecognizedNumber) + supportActionBar?.subtitle = if (chapter.isRecognizedNumber) getString(R.string.chapter_subtitle, decimalFormat.format(chapter.chapter_number.toDouble())) else - chapter.name) + chapter.name } fun onAppendChapter(chapter: ReaderChapter) {