Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Mar 4, 2024
1 parent 561cb5e commit 752999b
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
<!-- 配置界面 -->
<activity
android:name=".ui.config.ConfigActivity"
android:launchMode="singleTask" />
android:launchMode="standard" />
<!-- 搜索界面 -->
<activity
android:name=".ui.book.search.SearchActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import io.legado.app.R
import io.legado.app.constant.AppLog
import io.legado.app.constant.AppPattern
import io.legado.app.data.entities.HttpTTS
import io.legado.app.exception.ConcurrentException
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.config.AppConfig
import io.legado.app.help.coroutine.Coroutine
Expand Down Expand Up @@ -194,7 +193,6 @@ class HttpReadAloudService : BaseReadAloudService(),
} catch (e: Exception) {
when (e) {
is CancellationException -> throw e
is ConcurrentException -> delay(e.waitTime.toLong())
is ScriptException, is WrappedException -> {
AppLog.put("js错误\n${e.localizedMessage}", e, true)
e.printOnDebug()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ContentTextView(context: Context, attrs: AttributeSet?) : View(context, at

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
if (!isMainView) return
ChapterProvider.upViewSize(w, h)
textPage.format()
}
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/java/io/legado/app/ui/config/ConfigActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,4 @@ class ConfigActivity : VMBaseActivity<ActivityConfigBinding, ConfigViewModel>()
}
}

override fun finish() {
if (supportFragmentManager.findFragmentByTag(ConfigTag.COVER_CONFIG) != null
|| supportFragmentManager.findFragmentByTag(ConfigTag.WELCOME_CONFIG) != null
) {
replaceFragment<ThemeConfigFragment>(ConfigTag.THEME_CONFIG)
} else {
super.finish()
}
}

}
41 changes: 36 additions & 5 deletions app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,23 @@ import io.legado.app.lib.prefs.fragment.PreferenceFragment
import io.legado.app.lib.theme.primaryColor
import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.*
import io.legado.app.utils.ColorUtils
import io.legado.app.utils.FileUtils
import io.legado.app.utils.MD5Utils
import io.legado.app.utils.SelectImageContract
import io.legado.app.utils.applyTint
import io.legado.app.utils.externalFiles
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.inputStream
import io.legado.app.utils.postEvent
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.putPrefString
import io.legado.app.utils.readUri
import io.legado.app.utils.removePref
import io.legado.app.utils.setEdgeEffectColor
import io.legado.app.utils.startActivity
import io.legado.app.utils.toastOnUi
import splitties.init.appCtx
import java.io.FileOutputStream

Expand All @@ -47,6 +63,7 @@ class ThemeConfigFragment : PreferenceFragment(),
requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false)
}

requestCodeBgDark -> setBgFromUri(uri, PreferKey.bgImageN) {
upTheme(true)
}
Expand Down Expand Up @@ -130,12 +147,14 @@ class ThemeConfigFragment : PreferenceFragment(),
PreferKey.cBBackground -> {
upTheme(false)
}

PreferKey.cNPrimary,
PreferKey.cNAccent,
PreferKey.cNBackground,
PreferKey.cNBBackground -> {
upTheme(true)
}

PreferKey.bgImage,
PreferKey.bgImageN -> {
upPreferenceSummary(key, getPrefString(key))
Expand All @@ -160,6 +179,7 @@ class ThemeConfigFragment : PreferenceFragment(),
AppConfig.elevation = it
recreateActivities()
}

PreferKey.fontScale -> NumberPickerDialog(requireContext())
.setTitle(getString(R.string.font_scale))
.setMaxValue(16)
Expand All @@ -173,15 +193,20 @@ class ThemeConfigFragment : PreferenceFragment(),
putPrefInt(PreferKey.fontScale, it)
recreateActivities()
}

PreferKey.bgImage -> selectBgAction(false)
PreferKey.bgImageN -> selectBgAction(true)
"themeList" -> ThemeListDialog().show(childFragmentManager, "themeList")
"saveDayTheme",
"saveNightTheme" -> alertSaveTheme(key)
"coverConfig" -> (activity as? ConfigActivity)
?.replaceFragment<CoverConfigFragment>(ConfigTag.COVER_CONFIG)
"welcomeStyle" -> (activity as? ConfigActivity)
?.replaceFragment<WelcomeConfigFragment>(ConfigTag.WELCOME_CONFIG)

"coverConfig" -> startActivity<ConfigActivity> {
putExtra("configTag", ConfigTag.COVER_CONFIG)
}

"welcomeStyle" -> startActivity<ConfigActivity> {
putExtra("configTag", ConfigTag.WELCOME_CONFIG)
}
}
return super.onPreferenceTreeClick(preference)
}
Expand All @@ -199,6 +224,7 @@ class ThemeConfigFragment : PreferenceFragment(),
"saveDayTheme" -> {
ThemeConfig.saveDayTheme(requireContext(), themeName)
}

"saveNightTheme" -> {
ThemeConfig.saveNightTheme(requireContext(), themeName)
}
Expand All @@ -224,13 +250,15 @@ class ThemeConfigFragment : PreferenceFragment(),
0 -> alertImageBlurring(blurringKey) {
upTheme(isNight)
}

1 -> {
if (isNight) {
selectImage.launch(requestCodeBgDark)
} else {
selectImage.launch(requestCodeBgLight)
}
}

2 -> {
removePref(bgKey)
upTheme(isNight)
Expand Down Expand Up @@ -285,16 +313,19 @@ class ThemeConfigFragment : PreferenceFragment(),
when (preferenceKey) {
PreferKey.barElevation -> preference.summary =
getString(R.string.bar_elevation_s, value)

PreferKey.fontScale -> {
val fontScale = AppContextWrapper.getFontScale(requireContext())
preference.summary = getString(R.string.font_scale_summary, fontScale)
}

PreferKey.bgImage,
PreferKey.bgImageN -> preference.summary = if (value.isNullOrBlank()) {
getString(R.string.select_image)
} else {
value
}

else -> preference.summary = value
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class CanvasRecorderImpl : BaseCanvasRecorder() {
override val height get() = bitmap?.height ?: -1

private fun init(width: Int, height: Int) {
if (width <= 0 || height <= 0) {
return
}
if (bitmap == null) {
bitmap = BitmapPool.obtain(width, height)
}
Expand All @@ -34,13 +37,13 @@ class CanvasRecorderImpl : BaseCanvasRecorder() {

override fun beginRecording(width: Int, height: Int): Canvas {
init(width, height)
bitmap!!.eraseColor(Color.TRANSPARENT)
canvas = canvasPool.obtain().apply { setBitmap(bitmap!!) }
bitmap?.eraseColor(Color.TRANSPARENT)
canvas = canvasPool.obtain().apply { setBitmap(bitmap) }
return canvas!!
}

override fun endRecording() {
bitmap!!.prepareToDraw()
bitmap?.prepareToDraw()
super.endRecording()
canvasPool.recycle(canvas!!)
canvas = null
Expand Down

0 comments on commit 752999b

Please sign in to comment.