修改setEdgeEffectColor,适配ViewPager

pull/32/head
Administrator 5 years ago
parent 52c0d67489
commit 16b4932a01
  1. 4
      app/src/main/java/io/legado/app/base/BaseActivity.kt
  2. 38
      app/src/main/java/io/legado/app/lib/theme/ATH.kt
  3. 2
      app/src/main/java/io/legado/app/ui/about/AboutActivity.kt
  4. 2
      app/src/main/java/io/legado/app/ui/about/DonateActivity.kt
  5. 2
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt
  6. 2
      app/src/main/java/io/legado/app/ui/bookinfo/BookInfoEditActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt
  8. 2
      app/src/main/java/io/legado/app/ui/booksource/BookSourceActivity.kt
  9. 2
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  10. 6
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  11. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  12. 2
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookFragment.kt
  13. 8
      app/src/main/java/io/legado/app/ui/main/my/PreferenceFragment.kt
  14. 5
      app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt
  15. 2
      app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt
  16. 2
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  17. 2
      app/src/main/java/io/legado/app/ui/search/SearchActivity.kt
  18. 2
      app/src/main/java/io/legado/app/ui/sourcedebug/SourceDebugActivity.kt
  19. 2
      app/src/main/java/io/legado/app/ui/sourceedit/SourceEditActivity.kt
  20. 2
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt
  21. 3
      app/src/main/res/layout/fragment_bookshelf.xml

@ -30,7 +30,7 @@ abstract class BaseActivity<VM : ViewModel>(private val fullScreen: Boolean = tr
setupSystemBar() setupSystemBar()
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
setContentView(layoutID) setContentView(layoutID)
onViewModelCreated(viewModel, savedInstanceState) onActivityCreated(viewModel, savedInstanceState)
observeLiveBus() observeLiveBus()
} }
@ -39,7 +39,7 @@ abstract class BaseActivity<VM : ViewModel>(private val fullScreen: Boolean = tr
cancel() cancel()
} }
abstract fun onViewModelCreated(viewModel: VM, savedInstanceState: Bundle?) abstract fun onActivityCreated(viewModel: VM, savedInstanceState: Bundle?)
final override fun onCreateOptionsMenu(menu: Menu?): Boolean { final override fun onCreateOptionsMenu(menu: Menu?): Boolean {
return menu?.let { return menu?.let {

@ -11,6 +11,7 @@ import android.widget.EdgeEffect
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager.widget.ViewPager
import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefBoolean
@ -28,7 +29,10 @@ object ATH {
} }
fun setStatusbarColorAuto(activity: Activity) { fun setStatusbarColorAuto(activity: Activity) {
setStatusbarColor(activity, ThemeStore.statusBarColor(activity, activity.getPrefBoolean("transparentStatusBar"))) setStatusbarColor(
activity,
ThemeStore.statusBarColor(activity, activity.getPrefBoolean("transparentStatusBar"))
)
} }
fun setStatusbarColor(activity: Activity, color: Int) { fun setStatusbarColor(activity: Activity, color: Int) {
@ -116,8 +120,8 @@ object ATH {
return dialog return dialog
} }
fun setEdgeEffectColor(view: RecyclerView, color: Int) { fun setEdgeEffectColor(view: RecyclerView?, @ColorInt color: Int) {
view.edgeEffectFactory = object : RecyclerView.EdgeEffectFactory() { view?.edgeEffectFactory = object : RecyclerView.EdgeEffectFactory() {
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect { override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
val edgeEffect = super.createEdgeEffect(view, direction) val edgeEffect = super.createEdgeEffect(view, direction)
edgeEffect.color = color edgeEffect.color = color
@ -125,4 +129,32 @@ object ATH {
} }
} }
} }
fun setEdgeEffectColor(viewPager: ViewPager?, @ColorInt color: Int) {
try {
val clazz = ViewPager::class.java
for (name in arrayOf("mLeftEdge", "mRightEdge")) {
val field = clazz.getDeclaredField(name)
field.isAccessible = true
val edge = field.get(viewPager)
(edge as EdgeEffect).color = color
}
} catch (ignored: Exception) {
}
}
fun applyEdgeEffectColor(view: View?) {
when (view) {
is RecyclerView -> view.edgeEffectFactory = DEFAULT_EFFECT_FACTORY
is ViewPager -> setEdgeEffectColor(view, ThemeStore.primaryColor(view.context))
}
}
private val DEFAULT_EFFECT_FACTORY = object : RecyclerView.EdgeEffectFactory() {
override fun createEdgeEffect(view: RecyclerView, direction: Int): EdgeEffect {
val edgeEffect = super.createEdgeEffect(view, direction)
edgeEffect.color = ThemeStore.primaryColor(view.context)
return edgeEffect
}
}
} }

@ -17,7 +17,7 @@ class AboutActivity : BaseActivity<AndroidViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_about get() = R.layout.activity_about
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
val fTag = "aboutFragment" val fTag = "aboutFragment"
var aboutFragment = supportFragmentManager.findFragmentByTag(fTag) var aboutFragment = supportFragmentManager.findFragmentByTag(fTag)
if (aboutFragment == null) aboutFragment = AboutFragment() if (aboutFragment == null) aboutFragment = AboutFragment()

@ -30,7 +30,7 @@ class DonateActivity : BaseActivity<AndroidViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_donate get() = R.layout.activity_donate
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
vw_zfb_tz.setOnClickListener { aliDonate(this) } vw_zfb_tz.setOnClickListener { aliDonate(this) }
cv_wx_gzh.setOnClickListener { cv_wx_gzh.setOnClickListener {

@ -11,7 +11,7 @@ class BookInfoActivity : BaseActivity<BookInfoViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_book_info get() = R.layout.activity_book_info
override fun onViewModelCreated(viewModel: BookInfoViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: BookInfoViewModel, savedInstanceState: Bundle?) {
} }

@ -11,7 +11,7 @@ class BookInfoEditActivity : BaseActivity<BookInfoViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_book_info_edit get() = R.layout.activity_book_info_edit
override fun onViewModelCreated(viewModel: BookInfoViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: BookInfoViewModel, savedInstanceState: Bundle?) {
} }

@ -24,7 +24,7 @@ class BookshelfActivity : BaseActivity<BookshelfViewModel>() {
private lateinit var bookshelfAdapter: BookshelfAdapter private lateinit var bookshelfAdapter: BookshelfAdapter
private var bookshelfLiveData: LiveData<PagedList<Book>>? = null private var bookshelfLiveData: LiveData<PagedList<Book>>? = null
override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) {
if (viewModel.bookGroup == null) { if (viewModel.bookGroup == null) {
viewModel.bookGroup = intent.getParcelableExtra("data") viewModel.bookGroup = intent.getParcelableExtra("data")
} }

@ -37,7 +37,7 @@ class BookSourceActivity : BaseActivity<BookshelfViewModel>(), BookSourceAdapter
private lateinit var adapter: BookSourceAdapter private lateinit var adapter: BookSourceAdapter
private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null private var bookSourceLiveDate: LiveData<PagedList<BookSource>>? = null
override fun onViewModelCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: BookshelfViewModel, savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
initRecyclerView() initRecyclerView()
initDataObserve() initDataObserve()

@ -13,7 +13,7 @@ class ConfigActivity : BaseActivity<ConfigViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_config get() = R.layout.activity_config
override fun onViewModelCreated(viewModel: ConfigViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: ConfigViewModel, savedInstanceState: Bundle?) {
intent.getIntExtra("configType", -1).let { intent.getIntExtra("configType", -1).let {
if (it != -1) viewModel.configType = it if (it != -1) viewModel.configType = it
} }

@ -14,6 +14,7 @@ import io.legado.app.base.BaseActivity
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.Selector import io.legado.app.lib.theme.Selector
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.main.bookshelf.BookshelfFragment import io.legado.app.ui.main.bookshelf.BookshelfFragment
@ -35,10 +36,11 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_main get() = R.layout.activity_main
override fun onViewModelCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: MainViewModel, savedInstanceState: Bundle?) {
ATH.applyEdgeEffectColor(view_pager_main)
bottom_navigation_view.setBackgroundColor(ThemeStore.backgroundColor(this)) bottom_navigation_view.setBackgroundColor(ThemeStore.backgroundColor(this))
val colorStateList = Selector.colorBuild() val colorStateList = Selector.colorBuild()
.setDefaultColor(bottom_navigation_view.context.getCompatColor(R.color.btn_bg_press_tp)) .setDefaultColor(getCompatColor(R.color.btn_bg_press_tp))
.setSelectedColor(ThemeStore.primaryColor(bottom_navigation_view.context)).create() .setSelectedColor(ThemeStore.primaryColor(bottom_navigation_view.context)).create()
bottom_navigation_view.itemIconTintList = colorStateList bottom_navigation_view.itemIconTintList = colorStateList
bottom_navigation_view.itemTextColor = colorStateList bottom_navigation_view.itemTextColor = colorStateList

@ -17,11 +17,13 @@ import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.bookshelf.BookshelfActivity import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.ui.search.SearchActivity import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.disableAutoFill import io.legado.app.utils.disableAutoFill
import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.fragment_find_book.*
import kotlinx.android.synthetic.main.view_title_bar.* import kotlinx.android.synthetic.main.view_title_bar.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -58,6 +60,7 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf), SearchView.
} }
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_bookshelf)
refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context)) refresh_layout.setColorSchemeColors(ThemeStore.accentColor(refresh_layout.context))
refresh_layout.setOnRefreshListener { refresh_layout.setOnRefreshListener {
refresh_layout.isRefreshing = false refresh_layout.isRefreshing = false

@ -33,7 +33,7 @@ class FindBookFragment : BaseFragment(R.layout.fragment_find_book) {
} }
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.setEdgeEffectColor(rv_find, ThemeStore.primaryColor(rv_find.context)) ATH.applyEdgeEffectColor(rv_find)
rv_find.layoutManager = FlexboxLayoutManager(context) rv_find.layoutManager = FlexboxLayoutManager(context)
adapter = FindBookAdapter() adapter = FindBookAdapter()
rv_find.adapter = adapter rv_find.adapter = adapter

@ -2,10 +2,13 @@ package io.legado.app.ui.main.my
import android.content.SharedPreferences import android.content.SharedPreferences
import android.os.Bundle import android.os.Bundle
import android.view.View
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore
import io.legado.app.ui.about.AboutActivity import io.legado.app.ui.about.AboutActivity
import io.legado.app.ui.about.DonateActivity import io.legado.app.ui.about.DonateActivity
import io.legado.app.ui.booksource.BookSourceActivity import io.legado.app.ui.booksource.BookSourceActivity
@ -20,6 +23,11 @@ class PreferenceFragment : PreferenceFragmentCompat(),
addPreferencesFromResource(R.xml.pref_main) addPreferencesFromResource(R.xml.pref_main)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ATH.applyEdgeEffectColor(listView)
}
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this)

@ -4,6 +4,9 @@ import android.os.Bundle
import android.view.View import android.view.View
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseFragment import io.legado.app.base.BaseFragment
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.fragment_rss.*
class RssFragment : BaseFragment(R.layout.fragment_rss) { class RssFragment : BaseFragment(R.layout.fragment_rss) {
@ -12,6 +15,6 @@ class RssFragment : BaseFragment(R.layout.fragment_rss) {
} }
private fun initRecyclerView() { private fun initRecyclerView() {
ATH.applyEdgeEffectColor(recycler_view)
} }
} }

@ -26,7 +26,7 @@ class QrCodeActivity : BaseActivity<AndroidViewModel>(), QRCodeView.Delegate {
private val requestQrImage = 202 private val requestQrImage = 202
private var flashlightIsOpen: Boolean = false private var flashlightIsOpen: Boolean = false
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
setSupportActionBar(toolbar) setSupportActionBar(toolbar)
zxingview.setDelegate(this) zxingview.setDelegate(this)
fab_flashlight.setOnClickListener { fab_flashlight.setOnClickListener {

@ -31,7 +31,7 @@ class ReplaceRuleActivity : BaseActivity<ReplaceRuleViewModel>() {
private var rulesLiveData: LiveData<PagedList<ReplaceRule>>? = null private var rulesLiveData: LiveData<PagedList<ReplaceRule>>? = null
private var allEnabled = false private var allEnabled = false
override fun onViewModelCreated(viewModel: ReplaceRuleViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: ReplaceRuleViewModel, savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initDataObservers() initDataObservers()
initSwipeToDelete() initSwipeToDelete()

@ -15,7 +15,7 @@ class SearchActivity : BaseActivity<SearchViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_search get() = R.layout.activity_search
override fun onViewModelCreated(viewModel: SearchViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: SearchViewModel, savedInstanceState: Bundle?) {
initSearchView() initSearchView()
viewModel.search() viewModel.search()
} }

@ -30,7 +30,7 @@ class SourceDebugActivity : BaseActivity<AndroidViewModel>(), SourceDebug.Callba
private lateinit var adapter: SourceDebugAdapter private lateinit var adapter: SourceDebugAdapter
private var bookSource: BookSource? = null private var bookSource: BookSource? = null
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
launch(IO) { launch(IO) {
intent.getStringExtra("key")?.let { intent.getStringExtra("key")?.let {
bookSource = App.db.bookSourceDao().findByKey(it) bookSource = App.db.bookSourceDao().findByKey(it)

@ -42,7 +42,7 @@ class SourceEditActivity : BaseActivity<SourceEditViewModel>(false), KeyboardToo
private var mSoftKeyboardTool: PopupWindow? = null private var mSoftKeyboardTool: PopupWindow? = null
private var mIsSoftKeyBoardShowing = false private var mIsSoftKeyBoardShowing = false
override fun onViewModelCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: SourceEditViewModel, savedInstanceState: Bundle?) {
initView() initView()
viewModel.sourceLiveData.observe(this, Observer { viewModel.sourceLiveData.observe(this, Observer {
upRecyclerView(it) upRecyclerView(it)

@ -18,7 +18,7 @@ class WelcomeActivity : BaseActivity<AndroidViewModel>() {
override val layoutID: Int override val layoutID: Int
get() = R.layout.activity_welcome get() = R.layout.activity_welcome
override fun onViewModelCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) { override fun onActivityCreated(viewModel: AndroidViewModel, savedInstanceState: Bundle?) {
iv_bg.setColorFilter(ThemeStore.accentColor(this)) iv_bg.setColorFilter(ThemeStore.accentColor(this))
val welAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(800) val welAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(800)
welAnimator.startDelay = 100 welAnimator.startDelay = 100

@ -15,7 +15,8 @@
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_book_group" android:id="@+id/rv_book_group"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:overScrollMode="never"/>
<TextView <TextView
android:id="@+id/tv_recent_reading" android:id="@+id/tv_recent_reading"

Loading…
Cancel
Save