pull/32/head
GKF 6 years ago
parent de0e04176c
commit 59f74e05d8
  1. 6
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 23
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 8
      app/src/main/java/io/legado/app/ui/main/myconfig/PreferenceFragment.kt
  4. 5
      app/src/main/java/io/legado/app/utils/GsonExtensions.kt
  5. 4
      app/src/main/res/xml/pref_main.xml

@ -0,0 +1,6 @@
package io.legado.app.data.entities
interface BaseBook {
var variableMap: HashMap<String, String>?
fun putVariable(key: String, value: String)
}

@ -1,10 +1,15 @@
package io.legado.app.data.entities package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import android.text.TextUtils.isEmpty
import androidx.room.Entity import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import com.google.gson.Gson
import io.legado.app.constant.AppConst.NOT_AVAILABLE import io.legado.app.constant.AppConst.NOT_AVAILABLE
import io.legado.app.utils.fromJson
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@ -40,7 +45,10 @@ data class Book(
var order: Int = 0, // 手动排序 var order: Int = 0, // 手动排序
var useReplaceRule: Boolean = true, // 正文使用净化替换规则 var useReplaceRule: Boolean = true, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable { ) : Parcelable, BaseBook {
@IgnoredOnParcel
@Ignore
override var variableMap: HashMap<String, String>? = null
fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0) fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0)
@ -52,4 +60,17 @@ data class Book(
fun getDisplayDescription() = customDescription ?: description fun getDisplayDescription() = customDescription ?: description
private fun initVariableMap() {
if (variableMap == null) {
variableMap = if (isEmpty(variable)) {
HashMap()
} else {
Gson().fromJson<HashMap<String, String>>(variable!!)
}
}
}
override fun putVariable(key: String, value: String) {
initVariableMap()
}
} }

@ -6,6 +6,7 @@ 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.ui.about.AboutActivity
import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigActivity
import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.config.ConfigViewModel
import org.jetbrains.anko.startActivity import org.jetbrains.anko.startActivity
@ -39,19 +40,20 @@ class PreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnShare
when (preference.key) { when (preference.key) {
"setting" -> { "setting" -> {
requireContext().startActivity<ConfigActivity>( requireContext().startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_CONFIG) Pair("configType", ConfigViewModel.TYPE_CONFIG)
) )
} }
"web_dav_setting" -> { "web_dav_setting" -> {
requireContext().startActivity<ConfigActivity>( requireContext().startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG) Pair("configType", ConfigViewModel.TYPE_WEB_DAV_CONFIG)
) )
} }
"theme_setting" -> { "theme_setting" -> {
requireContext().startActivity<ConfigActivity>( requireContext().startActivity<ConfigActivity>(
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG) Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
) )
} }
"about" -> requireContext().startActivity<AboutActivity>()
} }
} }
return super.onPreferenceTreeClick(preference) return super.onPreferenceTreeClick(preference)

@ -0,0 +1,5 @@
package io.legado.app.utils
import com.google.gson.Gson
inline fun <reified T> Gson.fromJson(json: String) = fromJson(json, T::class.java)

@ -5,14 +5,12 @@
<io.legado.app.lib.theme.prefs.ATESwitchPreference <io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="isNightTheme" android:key="isNightTheme"
android:summary="开启/关闭暗色主题"
android:title="暗色主题" android:title="暗色主题"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference <io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false" android:defaultValue="false"
android:key="webService" android:key="webService"
android:summary="开启/关闭Web阅读和写源"
android:title="Web服务" android:title="Web服务"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
@ -43,7 +41,7 @@
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false"> <io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false">
<androidx.preference.Preference <androidx.preference.Preference
android:key="about" android:key="donate"
android:summary="您的支持是我更新的动力" android:summary="您的支持是我更新的动力"
android:title="@string/donate" android:title="@string/donate"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />

Loading…
Cancel
Save