diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt
index ff6198af2..07f22f159 100644
--- a/app/src/main/java/io/legado/app/constant/PreferKey.kt
+++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt
@@ -31,5 +31,5 @@ object PreferKey {
const val webDavAccount = "web_dav_account"
const val webDavPassword = "web_dav_password"
const val changeSourceLoadToc = "changeSourceLoadToc"
- const val isChineseConverterEnable = "isChineseConverterEnable"
+ const val chineseConverterType = "chineseConverterType"
}
\ No newline at end of file
diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt
index c1d779be3..a7d70efa8 100644
--- a/app/src/main/java/io/legado/app/help/AppConfig.kt
+++ b/app/src/main/java/io/legado/app/help/AppConfig.kt
@@ -78,6 +78,9 @@ object AppConfig {
val clickAllNext: Boolean get() = App.INSTANCE.getPrefBoolean(PreferKey.clickAllNext, false)
- val isChineseConverterEnable: String?
- get() = App.INSTANCE.getPrefString(PreferKey.isChineseConverterEnable)
+ var chineseConverterType: Int
+ get() = App.INSTANCE.getPrefInt(PreferKey.chineseConverterType)
+ set(value) {
+ App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value)
+ }
}
diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt
index 98e421e85..03308a2f9 100644
--- a/app/src/main/java/io/legado/app/help/BookHelp.kt
+++ b/app/src/main/java/io/legado/app/help/BookHelp.kt
@@ -2,6 +2,7 @@ package io.legado.app.help
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
+import com.github.houbb.opencc4j.util.ZhConverterUtil
import io.legado.app.App
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
@@ -275,6 +276,10 @@ object BookHelp {
}
}
}
+ when (AppConfig.chineseConverterType) {
+ 2 -> c = ZhConverterUtil.toTraditional(c)
+ 1 -> c = ZhConverterUtil.toSimple(c)
+ }
val indent = App.INSTANCE.getPrefInt("textIndent", 2)
return c.replace("\\s*\\n+\\s*".toRegex(), "\n" + " ".repeat(indent))
}
diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
index 35bc34787..ecb7df170 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/config/MoreConfigDialog.kt
@@ -95,7 +95,6 @@ class MoreConfigDialog : DialogFragment() {
PreferKey.hideStatusBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.hideNavigationBar -> postEvent(EventBus.UP_CONFIG, true)
PreferKey.keepLight -> postEvent(PreferKey.keepLight, true)
- PreferKey.isChineseConverterEnable -> postEvent(EventBus.UP_CONFIG, true)
}
}
diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
index 10d3d3433..110eac0e5 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/config/ReadStyleDialog.kt
@@ -78,6 +78,9 @@ class ReadStyleDialog : DialogFragment(), FontSelectDialog.CallBack {
}
private fun initOnClick() {
+ chinese_converter.onChanged {
+ postEvent(EventBus.UP_CONFIG, true)
+ }
tv_text_bold.onClick {
with(ReadBookConfig.getConfig()) {
textBold = !textBold
diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
index f53b1550d..cc9e9e666 100644
--- a/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
+++ b/app/src/main/java/io/legado/app/ui/book/read/page/ContentView.kt
@@ -9,11 +9,9 @@ import android.view.Gravity
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView
-import com.github.houbb.opencc4j.util.ZhConverterUtil
import io.legado.app.R
import io.legado.app.constant.AppConst.TIME_FORMAT
import io.legado.app.constant.PreferKey
-import io.legado.app.help.AppConfig
import io.legado.app.help.ReadBookConfig
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.view_book_page.view.*
@@ -113,13 +111,7 @@ class ContentView : FrameLayout {
fun setContent(textPage: TextPage?) {
if (textPage != null) {
content_text_view.gravity = Gravity.START
- content_text_view.text = if ("0" != AppConfig.isChineseConverterEnable) {
- if ("1" == AppConfig.isChineseConverterEnable)
- ZhConverterUtil.toTraditional(textPage.text.toString())
- else ZhConverterUtil.toSimple(textPage.text.toString())
- } else {
- textPage.text
- }
+ content_text_view.text = textPage.text
tv_bottom_left.text = textPage.title
pageSize = textPage.pageSize
setPageIndex(textPage.index)
diff --git a/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt b/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt
new file mode 100644
index 000000000..c88407b3a
--- /dev/null
+++ b/app/src/main/java/io/legado/app/ui/widget/ChineseConverter.kt
@@ -0,0 +1,70 @@
+package io.legado.app.ui.widget
+
+import android.content.Context
+import android.text.Spannable
+import android.text.SpannableString
+import android.text.style.ForegroundColorSpan
+import android.util.AttributeSet
+import androidx.appcompat.widget.AppCompatTextView
+import io.legado.app.App
+import io.legado.app.R
+import io.legado.app.help.AppConfig
+import io.legado.app.lib.dialogs.alert
+import io.legado.app.lib.theme.Selector
+import io.legado.app.lib.theme.ThemeStore
+import io.legado.app.lib.theme.accentColor
+import io.legado.app.utils.dp
+import io.legado.app.utils.getCompatColor
+import org.jetbrains.anko.sdk27.listeners.onClick
+
+class ChineseConverter(context: Context, attrs: AttributeSet?) : AppCompatTextView(context, attrs) {
+
+ private val spannableString = SpannableString("简/繁")
+ private val enabledSpan = ForegroundColorSpan(App.INSTANCE.accentColor)
+ private var onChanged: (() -> Unit)? = null
+
+ init {
+ background = Selector.shapeBuild()
+ .setCornerRadius(1.dp)
+ .setStrokeWidth(1.dp)
+ .setDisabledStrokeColor(context.getCompatColor(R.color.md_grey_500))
+ .setDefaultStrokeColor(ThemeStore.textColorSecondary(context))
+ .setSelectedStrokeColor(ThemeStore.accentColor(context))
+ .setPressedBgColor(context.getCompatColor(R.color.transparent30))
+ .create()
+ setTextColor(
+ Selector.colorBuild()
+ .setDefaultColor(ThemeStore.textColorSecondary(context))
+ .setSelectedColor(ThemeStore.accentColor(context))
+ .setDisabledColor(context.getCompatColor(R.color.md_grey_500))
+ .create()
+ )
+ upUi(AppConfig.chineseConverterType)
+ onClick {
+ selectType()
+ }
+ }
+
+ private fun upUi(type: Int) {
+ spannableString.removeSpan(enabledSpan)
+ when (type) {
+ 1 -> spannableString.setSpan(enabledSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
+ 2 -> spannableString.setSpan(enabledSpan, 2, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE)
+ }
+ text = spannableString
+ }
+
+ private fun selectType() {
+ context.alert(titleResource = R.string.chinese_converter) {
+ items(context.resources.getStringArray(R.array.chinese_mode).toList()) { _, i ->
+ AppConfig.chineseConverterType = i
+ upUi(i)
+ onChanged?.invoke()
+ }
+ }.show()
+ }
+
+ fun onChanged(unit: () -> Unit) {
+ onChanged = unit
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/dialog_read_book_style.xml b/app/src/main/res/layout/dialog_read_book_style.xml
index d246417c6..362a153d3 100644
--- a/app/src/main/res/layout/dialog_read_book_style.xml
+++ b/app/src/main/res/layout/dialog_read_book_style.xml
@@ -65,6 +65,20 @@
android:gravity="center"
android:textSize="14sp"
app:layout_constraintLeft_toRightOf="@+id/tv_text_indent"
+ app:layout_constraintRight_toLeftOf="@id/chinese_converter"
+ app:layout_constraintTop_toTopOf="parent" />
+
+
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 37f196921..ec780c8b6 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -144,13 +144,8 @@
- 关闭
- - 简体转繁体
- 繁体转简体
+ - 简体转繁体
-
- - 0
- - 1
- - 2
-
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 388769252..b77cb7e75 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -605,5 +605,5 @@
长按文字在操作菜单中显示阅读·搜索
文字操作显示搜索
记录日志
- 中文简繁体转换
+ 中文简繁体转换
diff --git a/app/src/main/res/xml/pref_config_read.xml b/app/src/main/res/xml/pref_config_read.xml
index e8f76305e..5aae899c8 100644
--- a/app/src/main/res/xml/pref_config_read.xml
+++ b/app/src/main/res/xml/pref_config_read.xml
@@ -28,14 +28,6 @@
android:key="volumeKeyPage"
app:iconSpaceReserved="false" />
-
-