pull/32/head
Administrator 5 years ago
parent fa543ccaf8
commit 39bd21ecff
  1. 2
      app/src/main/java/io/legado/app/App.kt
  2. 6
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  3. 5
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  4. 24
      app/src/main/java/io/legado/app/utils/EventBusKt.kt

@ -51,7 +51,7 @@ class App : Application() {
.autoClear(false) .autoClear(false)
} }
fun initNightTheme() { fun initNightTheme() {//对整个应用生效,不要手动调用recreate
if (getPrefBoolean("isNightTheme")) { if (getPrefBoolean("isNightTheme")) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES) AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
} else { } else {

@ -7,8 +7,6 @@ import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import com.jaredrummler.android.colorpicker.ColorPreferenceCompat
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.constant.Bus import io.legado.app.constant.Bus
@ -106,8 +104,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
.putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800)) .putInt("colorBackgroundNight", App.INSTANCE.getCompatColor(R.color.md_grey_800))
.apply() .apply()
App.INSTANCE.upThemeStore() App.INSTANCE.upThemeStore()
LiveEventBus.get().with(Bus.RECREATE).post("")
Handler().postDelayed({ activity?.recreate() }, 100)
} }
.setNegativeButton(R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.show().upTint() .show().upTint()
@ -138,8 +134,6 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
private fun upTheme(isNightTheme: Boolean) { private fun upTheme(isNightTheme: Boolean) {
if (App.INSTANCE.getPrefBoolean("isNightTheme") == isNightTheme) { if (App.INSTANCE.getPrefBoolean("isNightTheme") == isNightTheme) {
App.INSTANCE.upThemeStore() App.INSTANCE.upThemeStore()
LiveEventBus.get().with(Bus.RECREATE).post("")
Handler().postDelayed({ activity?.recreate() }, 100)
} }
} }

@ -5,7 +5,6 @@ import android.view.MenuItem
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.Observer
import androidx.viewpager.widget.ViewPager import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView import com.google.android.material.bottomnavigation.BottomNavigationView
import io.legado.app.App import io.legado.app.App
@ -112,8 +111,8 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
} }
override fun observeLiveBus() { override fun observeLiveBus() {
observeEvent<String>(Bus.RECREATE, Observer { observeEvent<String>(Bus.RECREATE) {
recreate() recreate()
}) }
} }
} }

@ -13,18 +13,26 @@ inline fun <reified EVENT> postEvent(tag: String, event: EVENT) {
return LiveEventBus.get().with(tag, EVENT::class.java).post(event) return LiveEventBus.get().with(tag, EVENT::class.java).post(event)
} }
inline fun <reified EVENT> AppCompatActivity.observeEvent(tag: String, observer: Observer<EVENT>) { inline fun <reified EVENT> AppCompatActivity.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observe(this, observer) return eventObservable<EVENT>(tag).observe(this, Observer {
observer(it)
})
} }
inline fun <reified EVENT> AppCompatActivity.observeEventSticky(tag: String, observer: Observer<EVENT>) { inline fun <reified EVENT> AppCompatActivity.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observeSticky(this, observer) return eventObservable<EVENT>(tag).observeSticky(this, Observer {
observer(it)
})
} }
inline fun <reified EVENT> Fragment.observeEvent(tag: String, observer: Observer<EVENT>) { inline fun <reified EVENT> Fragment.observeEvent(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observe(this, observer) return eventObservable<EVENT>(tag).observe(this, Observer {
observer(it)
})
} }
inline fun <reified EVENT> Fragment.observeEventSticky(tag: String, observer: Observer<EVENT>) { inline fun <reified EVENT> Fragment.observeEventSticky(tag: String, crossinline observer: (EVENT) -> Unit) {
return eventObservable<EVENT>(tag).observeSticky(this, observer) return eventObservable<EVENT>(tag).observeSticky(this, Observer {
observer(it)
})
} }
Loading…
Cancel
Save