feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 8b69dbfb34
commit 5608c283ec
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 4
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  3. 2
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupSelectDialog.kt
  5. 4
      app/src/main/java/io/legado/app/ui/book/group/GroupViewModel.kt
  6. 3
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt

@ -32,4 +32,5 @@ object PreferKey {
const val webDavPassword = "web_dav_password" const val webDavPassword = "web_dav_password"
const val changeSourceLoadToc = "changeSourceLoadToc" const val changeSourceLoadToc = "changeSourceLoadToc"
const val chineseConverterType = "chineseConverterType" const val chineseConverterType = "chineseConverterType"
const val launcherIcon = "launcherIcon"
} }

@ -13,8 +13,8 @@ interface BookGroupDao {
@Query("SELECT * FROM book_groups ORDER BY `order`") @Query("SELECT * FROM book_groups ORDER BY `order`")
fun liveDataAll(): LiveData<List<BookGroup>> fun liveDataAll(): LiveData<List<BookGroup>>
@get:Query("SELECT count(groupId) FROM book_groups") @get:Query("SELECT sum(groupId) FROM book_groups")
val idsCount: Int val idsSum: Int
@get:Query("SELECT MAX(`order`) FROM book_groups") @get:Query("SELECT MAX(`order`) FROM book_groups")
val maxOrder: Int val maxOrder: Int

@ -10,6 +10,7 @@ import com.jayway.jsonpath.ParseContext
import io.legado.app.App import io.legado.app.App
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
@ -106,6 +107,7 @@ object Restore {
edit.commit() edit.commit()
} }
} }
LauncherIconHelp.changeIcon(App.INSTANCE.getPrefString(PreferKey.launcherIcon))
} }
private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? { private inline fun <reified T> fileToListT(path: String, fileName: String): List<T>? {

@ -162,7 +162,7 @@ class GroupSelectDialog : DialogFragment(), Toolbar.OnMenuItemClickListener {
override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: BookGroup, payloads: MutableList<Any>) {
holder.itemView.apply { holder.itemView.apply {
cb_group.text = item.groupName cb_group.text = item.groupName
cb_group.isChecked = (groupId or item.groupId) > 0 cb_group.isChecked = (groupId and item.groupId) > 0
cb_group.setOnCheckedChangeListener { buttonView, isChecked -> cb_group.setOnCheckedChangeListener { buttonView, isChecked ->
if (buttonView.isPressed) { if (buttonView.isPressed) {
groupId = if (isChecked) { groupId = if (isChecked) {

@ -10,8 +10,8 @@ class GroupViewModel(application: Application) : BaseViewModel(application) {
fun addGroup(groupName: String) { fun addGroup(groupName: String) {
execute { execute {
var id = 1 var id = 1
val idsCount = App.db.bookGroupDao().idsCount val idsSum = App.db.bookGroupDao().idsSum
while (id and idsCount != 0) { while (id and idsSum != 0) {
id *= 2 id *= 2
} }
val bookGroup = BookGroup( val bookGroup = BookGroup(

@ -9,6 +9,7 @@ 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.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -47,7 +48,7 @@ class ThemeConfigFragment : PreferenceFragmentCompat(), SharedPreferences.OnShar
override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) {
sharedPreferences ?: return sharedPreferences ?: return
when (key) { when (key) {
"launcherIcon" -> LauncherIconHelp.changeIcon(getPrefString(key)) PreferKey.launcherIcon -> LauncherIconHelp.changeIcon(getPrefString(key))
"transparentStatusBar" -> { "transparentStatusBar" -> {
recreateActivities() recreateActivities()
} }

Loading…
Cancel
Save