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. 2
      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
import android.os.Parcelable
import android.text.TextUtils.isEmpty
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index
import androidx.room.PrimaryKey
import com.google.gson.Gson
import io.legado.app.constant.AppConst.NOT_AVAILABLE
import io.legado.app.utils.fromJson
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
@Parcelize
@ -40,7 +45,10 @@ data class Book(
var order: Int = 0, // 手动排序
var useReplaceRule: Boolean = true, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable {
) : Parcelable, BaseBook {
@IgnoredOnParcel
@Ignore
override var variableMap: HashMap<String, String>? = null
fun getUnreadChapterNum() = Math.max(totalChapterNum - durChapterIndex - 1, 0)
@ -52,4 +60,17 @@ data class Book(
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 io.legado.app.App
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.ConfigViewModel
import org.jetbrains.anko.startActivity
@ -52,6 +53,7 @@ class PreferenceFragment : PreferenceFragmentCompat(), SharedPreferences.OnShare
Pair("configType", ConfigViewModel.TYPE_THEME_CONFIG)
)
}
"about" -> requireContext().startActivity<AboutActivity>()
}
}
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
android:defaultValue="false"
android:key="isNightTheme"
android:summary="开启/关闭暗色主题"
android:title="暗色主题"
app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:key="webService"
android:summary="开启/关闭Web阅读和写源"
android:title="Web服务"
app:iconSpaceReserved="false" />
@ -43,7 +41,7 @@
<io.legado.app.lib.theme.prefs.ATEPreferenceCategory app:iconSpaceReserved="false">
<androidx.preference.Preference
android:key="about"
android:key="donate"
android:summary="您的支持是我更新的动力"
android:title="@string/donate"
app:iconSpaceReserved="false" />

Loading…
Cancel
Save