pull/32/head
Awesome 6 years ago
parent f43d8483e1
commit e42adff0be
  1. 21
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 12
      app/src/main/java/io/legado/app/utils/AnkoExtensions.kt
  4. 12
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt
  5. 13
      app/src/main/res/layout/fragment_bookshelf.xml

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

@ -11,8 +11,8 @@ class BookshelfFragment : Fragment(R.layout.fragment_bookshelf) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e("TAG", "BookshelfFragment")
}
}
}

@ -1,6 +1,12 @@
package io.legado.app.utils
import android.app.Activity
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import android.view.View
import android.view.WindowManager
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
@ -51,3 +57,9 @@ fun Fragment.longToast(text: CharSequence) = requireActivity().longToast(text)
fun Fragment.dip(value: Int): Int = requireActivity().dip(value)
fun Fragment.dip(value: Float): Int = requireActivity().dip(value)
fun Fragment.getCompatColor(@ColorRes id: Int): Int = requireContext().getCompatColor(id)
fun Fragment.getCompatDrawable(@DrawableRes id: Int): Drawable? = requireContext().getCompatDrawable(id)
fun Fragment.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = requireContext().getCompatColorStateList(id)

@ -1,6 +1,11 @@
package io.legado.app.utils
import android.content.Context
import android.content.res.ColorStateList
import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import org.jetbrains.anko.connectivityManager
import org.jetbrains.anko.defaultSharedPreferences
@ -41,6 +46,13 @@ fun Context.putPrefStringSet(key: String, value: MutableSet<String>) =
fun Context.removePref(key: String) =
defaultSharedPreferences.edit { remove(key) }
fun Context.getCompatColor(@ColorRes id: Int): Int = ContextCompat.getColor(this, id)
fun Context.getCompatDrawable(@DrawableRes id: Int): Drawable? = ContextCompat.getDrawable(this, id)
fun Context.getCompatColorStateList(@ColorRes id: Int): ColorStateList? = ContextCompat.getColorStateList(this, id)
fun Context.getStatusBarHeight(): Int {
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
return resources.getDimensionPixelSize(resourceId)

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<io.legado.app.ui.widget.TitleBar
android:id="@+id/title_bar"
@ -13,4 +14,4 @@
app:layout_constraintTop_toTopOf="parent"
app:title="@string/bookshelf"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save