|
|
@ -1,12 +1,14 @@ |
|
|
|
package io.legado.app.base |
|
|
|
package io.legado.app.base |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.graphics.Color |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.Menu |
|
|
|
import android.view.Menu |
|
|
|
import android.view.MenuItem |
|
|
|
import android.view.MenuItem |
|
|
|
|
|
|
|
import android.view.View |
|
|
|
|
|
|
|
import android.view.WindowManager |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.app.AppCompatActivity |
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
import androidx.appcompat.view.menu.MenuBuilder |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.appcompat.view.menu.MenuItemImpl |
|
|
|
import androidx.core.content.ContextCompat |
|
|
|
|
|
|
|
import androidx.core.view.forEach |
|
|
|
import androidx.core.view.forEach |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
import androidx.lifecycle.ViewModel |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
@ -14,6 +16,8 @@ import io.legado.app.lib.theme.ColorUtils |
|
|
|
import io.legado.app.lib.theme.DrawableUtils |
|
|
|
import io.legado.app.lib.theme.DrawableUtils |
|
|
|
import io.legado.app.lib.theme.ThemeStore |
|
|
|
import io.legado.app.lib.theme.ThemeStore |
|
|
|
import io.legado.app.lib.theme.getPrimaryTextColor |
|
|
|
import io.legado.app.lib.theme.getPrimaryTextColor |
|
|
|
|
|
|
|
import io.legado.app.utils.getCompatColor |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
|
|
|
|
|
|
@ -23,6 +27,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
initTheme() |
|
|
|
initTheme() |
|
|
|
|
|
|
|
setupSystemBar() |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
setContentView(layoutID) |
|
|
|
setContentView(layoutID) |
|
|
|
onViewModelCreated(viewModel, savedInstanceState) |
|
|
|
onViewModelCreated(viewModel, savedInstanceState) |
|
|
@ -37,7 +42,7 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
} |
|
|
|
} |
|
|
|
val bool = onCompatCreateOptionsMenu(it) |
|
|
|
val bool = onCompatCreateOptionsMenu(it) |
|
|
|
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) |
|
|
|
val primaryTextColor = getPrimaryTextColor(ColorUtils.isColorLight(ThemeStore.primaryColor(this))) |
|
|
|
val defaultTextColor = ContextCompat.getColor(this, R.color.tv_text_default) |
|
|
|
val defaultTextColor = getCompatColor(R.color.tv_text_default) |
|
|
|
menu.forEach { item -> |
|
|
|
menu.forEach { item -> |
|
|
|
(item as MenuItemImpl).let { impl -> |
|
|
|
(item as MenuItemImpl).let { impl -> |
|
|
|
//overflow:展开的item |
|
|
|
//overflow:展开的item |
|
|
@ -77,4 +82,11 @@ abstract class BaseActivity<VM : ViewModel> : AppCompatActivity() { |
|
|
|
setTheme(R.style.AppTheme_Dark) |
|
|
|
setTheme(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 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |