Remove activity mixin class

This commit is contained in:
inorichi 2017-05-24 14:00:26 +02:00
parent 73d1a1a05e
commit c7686323b7
6 changed files with 21 additions and 123 deletions

View file

@ -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<PreferencesHelper>().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
}

View file

@ -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()
}
}

View file

@ -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<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
override var resumed = false
abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>() {
init {
@Suppress("LeakingThis")
LocaleHelper.updateConfiguration(this)
}
override fun getActivity() = this
override fun onResume() {
super.onResume()
resumed = true
}
override fun onPause() {
resumed = false
super.onPause()
}
}

View file

@ -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

View file

@ -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()
}
}

View file

@ -99,7 +99,11 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
return
}
setupToolbar(toolbar)
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener {
onBackPressed()
}
initializeSettings()
initializeBottomMenu()
@ -131,6 +135,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
}
override fun onDestroy() {
toolbar.setNavigationOnClickListener(null)
subscriptions.unsubscribe()
viewer = null
super.onDestroy()
@ -256,7 +261,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
// 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<ReaderPresenter>() {
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) {