pull/32/head
gedoor 6 years ago
parent 3fb20d551c
commit 95a3ded538
  1. 6
      app/build.gradle
  2. 6
      app/src/main/java/io/legado/app/App.kt
  3. 2
      app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
  4. 6
      app/src/main/java/io/legado/app/ui/config/ConfigViewModel.kt
  5. 3
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  6. 9
      app/src/main/java/io/legado/app/ui/main/MainActivity.kt
  7. 2
      app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt

@ -103,6 +103,9 @@ dependencies {
implementation "org.jetbrains.anko:anko-sdk27:$anko_version"
implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version"
//liveEventBus
implementation 'com.jeremyliao:live-event-bus-x:1.4.4'
//
def coroutines_version = '1.2.1'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
@ -117,7 +120,7 @@ dependencies {
// implementation 'com.jayway.jsonpath:json-path:2.4.0'
//Retrofit
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.0'//
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
//Glide
@ -125,4 +128,5 @@ dependencies {
//
implementation 'com.jaredrummler:colorpicker:1.1.0'
}

@ -8,6 +8,7 @@ import android.content.pm.PackageManager
import android.os.Build
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AppCompatDelegate
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.constant.AppConst.channelIdDownload
import io.legado.app.constant.AppConst.channelIdReadAloud
import io.legado.app.constant.AppConst.channelIdWeb
@ -44,6 +45,11 @@ class App : Application() {
if (!ThemeStore.isConfigured(this, versionCode)) upThemeStore()
initNightTheme()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannelId()
LiveEventBus.get()
.config()
.supportBroadcast(this)
.lifecycleObserverAlwaysActive(true)
.autoClear(false)
}
fun initNightTheme() {

@ -32,7 +32,7 @@ class ConfigActivity : BaseActivity<ConfigViewModel>() {
.replace(R.id.configFrameLayout, ThemeConfigFragment())
.commit()
}
ConfigViewModel.TYPE_WEBDAV_CONFIG -> {
ConfigViewModel.TYPE_WEB_DAV_CONFIG -> {
title_bar.title = "WebDav设置"
supportFragmentManager.beginTransaction()
.replace(R.id.configFrameLayout, WebDavConfigFragment())

@ -5,9 +5,9 @@ import androidx.lifecycle.AndroidViewModel
class ConfigViewModel(application: Application) : AndroidViewModel(application) {
companion object {
val TYPE_CONFIG = 0
val TYPE_THEME_CONFIG = 1
val TYPE_WEBDAV_CONFIG = 2
const val TYPE_CONFIG = 0
const val TYPE_THEME_CONFIG = 1
const val TYPE_WEB_DAV_CONFIG = 2
}
var configType: Int = TYPE_CONFIG

@ -6,6 +6,7 @@ import android.os.Handler
import android.os.Looper
import androidx.appcompat.app.AlertDialog
import androidx.preference.PreferenceFragmentCompat
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.App
import io.legado.app.R
import io.legado.app.lib.theme.ColorUtils
@ -84,6 +85,8 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
private fun upTheme(isNightTheme: Boolean) {
if (App.INSTANCE.getPrefBoolean("isNightTheme", false) == isNightTheme) {
App.INSTANCE.upThemeStore()
LiveEventBus.get().with("recreate").post("recreate")
Handler().postDelayed({activity?.recreate()}, 300)
}
}

@ -6,8 +6,10 @@ import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.lifecycle.Observer
import androidx.viewpager.widget.ViewPager
import com.google.android.material.bottomnavigation.BottomNavigationView
import com.jeremyliao.liveeventbus.LiveEventBus
import io.legado.app.R
import io.legado.app.base.BaseActivity
import io.legado.app.help.permission.Permissions
@ -34,6 +36,7 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
view_pager_main.adapter = TabFragmentPageAdapter(supportFragmentManager)
view_pager_main.addOnPageChangeListener(this)
bottom_navigation_view.setOnNavigationItemSelectedListener(this)
observeLiveBus()
}
override fun onNavigationItemSelected(item: MenuItem): Boolean {
@ -84,4 +87,10 @@ class MainActivity : BaseActivity<MainViewModel>(), BottomNavigationView.OnNavig
}
}
private fun observeLiveBus() {
LiveEventBus.get().with("recreate", String::class.java)
.observe(this, Observer {
recreate()
})
}
}

@ -44,7 +44,7 @@ class PreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnShare
}
"web_dav_setting" -> {
requireContext().startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_WEBDAV_CONFIG)
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
)
}
"theme_setting" -> {

Loading…
Cancel
Save