Merge pull request #117 from hingbong/master

功能添加: 选择默认字体时, 可选择字体默认字体(非衬线), 系统衬线字体, 系统等宽字体
pull/118/head
kunfei 5 years ago committed by GitHub
commit 651c5f36cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 6
      app/src/main/java/io/legado/app/help/AppConfig.kt
  3. 7
      app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt
  4. 18
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  5. 5
      app/src/main/res/values/arrays.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -38,4 +38,5 @@ object PreferKey {
const val bodyIndent = "textIndent" const val bodyIndent = "textIndent"
const val shareLayout = "shareLayout" const val shareLayout = "shareLayout"
const val readStyleSelect = "readStyleSelect" const val readStyleSelect = "readStyleSelect"
const val systemTypefaces = "system_typefaces"
} }

@ -86,4 +86,10 @@ object AppConfig {
set(value) { set(value) {
App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value) App.INSTANCE.putPrefInt(PreferKey.chineseConverterType, value)
} }
var systemTypefaces: Int
get() = App.INSTANCE.getPrefInt(PreferKey.systemTypefaces)
set(value) {
App.INSTANCE.putPrefInt(PreferKey.systemTypefaces, value)
}
} }

@ -8,6 +8,7 @@ import android.text.TextUtils
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.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp import io.legado.app.help.BookHelp
import io.legado.app.help.ReadBookConfig import io.legado.app.help.ReadBookConfig
import io.legado.app.ui.book.read.page.entities.TextChapter import io.legado.app.ui.book.read.page.entities.TextChapter
@ -308,7 +309,11 @@ object ChapterProvider {
if (!TextUtils.isEmpty(fontPath)) { if (!TextUtils.isEmpty(fontPath)) {
Typeface.createFromFile(fontPath) Typeface.createFromFile(fontPath)
} else { } else {
Typeface.SANS_SERIF when (AppConfig.systemTypefaces) {
1 -> Typeface.SERIF
2 -> Typeface.MONOSPACE
else -> Typeface.SANS_SERIF
}
} }
} catch (e: Exception) { } catch (e: Exception) {
App.INSTANCE.removePref(PreferKey.readBookFont) App.INSTANCE.removePref(PreferKey.readBookFont)

@ -16,7 +16,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.BaseDialogFragment import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.EventBus
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig
import io.legado.app.help.permission.Permissions import io.legado.app.help.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.permission.PermissionsCompat
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
@ -89,9 +91,13 @@ class FontSelectDialog : BaseDialogFragment(),
R.id.menu_default -> { R.id.menu_default -> {
val cb = (parentFragment as? CallBack) ?: (activity as? CallBack) val cb = (parentFragment as? CallBack) ?: (activity as? CallBack)
cb?.let { cb?.let {
if (it.curFontPath != "") { val requireContext = requireContext()
it.selectFile("") requireContext.alert(titleResource = R.string.system_typeface) {
items(requireContext.resources.getStringArray(R.array.system_typefaces).toList()) { _, i ->
AppConfig.systemTypefaces = i
onDefaultFontChange(it)
} }
}.show()
} }
dismiss() dismiss()
} }
@ -255,6 +261,14 @@ class FontSelectDialog : BaseDialogFragment(),
} }
} }
private fun onDefaultFontChange(callBack: CallBack){
if (curFilePath() == "") {
postEvent(EventBus.UP_CONFIG, true)
} else {
callBack.selectFile("")
}
}
interface CallBack { interface CallBack {
fun selectFile(path: String) fun selectFile(path: String)
val curFontPath: String val curFontPath: String

@ -152,4 +152,9 @@
<item>简体转繁体</item> <item>简体转繁体</item>
</string-array> </string-array>
<string-array name="system_typefaces">
<item>系统默认字体</item>
<item>系统衬线字体</item>
<item>系统等宽等宽</item>
</string-array>
</resources> </resources>

@ -627,4 +627,5 @@
<string name="reduce"></string> <string name="reduce"></string>
<string name="plus"></string> <string name="plus"></string>
<string name="other_aloud_setting">其它朗读设置</string> <string name="other_aloud_setting">其它朗读设置</string>
<string name="system_typeface">系统内置字体样式</string>
</resources> </resources>

Loading…
Cancel
Save