|
|
|
@ -1,19 +1,22 @@ |
|
|
|
|
package io.legado.app.base |
|
|
|
|
|
|
|
|
|
import android.graphics.Color |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.Menu |
|
|
|
|
import android.view.MenuItem |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.WindowManager |
|
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
import androidx.core.view.forEach |
|
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.lib.theme.ColorUtils |
|
|
|
|
import io.legado.app.lib.theme.DrawableUtils |
|
|
|
|
import io.legado.app.lib.theme.ThemeStore |
|
|
|
|
import io.legado.app.lib.theme.getPrimaryTextColor |
|
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
|
|
|
|
@ -24,6 +27,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
initTheme() |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
setupSystemBar() |
|
|
|
|
setContentView(layoutID) |
|
|
|
|
onViewModelCreated(viewModel, savedInstanceState) |
|
|
|
|
} |
|
|
|
@ -37,7 +41,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
} |
|
|
|
|
val bool = onCompatCreateOptionsMenu(it) |
|
|
|
|
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) |
|
|
|
|
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default) |
|
|
|
|
val defaultTextColor = getCompatColor(io.legado.app.R.color.tv_text_default) |
|
|
|
|
menu.forEach { item -> |
|
|
|
|
(item as MenuItemImpl).let { impl -> |
|
|
|
|
//overflow:展开的item |
|
|
|
@ -72,9 +76,16 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
|
|
|
|
|
protected fun initTheme() { |
|
|
|
|
if (ColorUtils.isColorLight(ThemeStore.primaryColor(this))) { |
|
|
|
|
setTheme(R.style.AppTheme_Light) |
|
|
|
|
setTheme(io.legado.app.R.style.AppTheme_Light) |
|
|
|
|
} else { |
|
|
|
|
setTheme(R.style.AppTheme_Dark) |
|
|
|
|
setTheme(io.legado.app.R.style.AppTheme_Dark) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected fun setupSystemBar() { |
|
|
|
|
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS or WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION) |
|
|
|
|
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
|
|
|
|
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS) |
|
|
|
|
window.statusBarColor = Color.TRANSPARENT |
|
|
|
|
} |
|
|
|
|
} |