feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 6129c814ca
commit 84155570df
  1. 4
      app/src/main/java/io/legado/app/lib/theme/ATHUtils.kt
  2. 14
      app/src/main/java/io/legado/app/ui/book/read/page/delegate/PageDelegate.kt
  3. 1
      app/src/main/res/values/strings.xml
  4. 6
      app/src/main/res/xml/pref_config_read.xml

@ -8,10 +8,6 @@ import androidx.annotation.AttrRes
*/ */
object ATHUtils { object ATHUtils {
fun isWindowBackgroundDark(context: Context): Boolean {
return !ColorUtils.isColorLight(resolveColor(context, android.R.attr.windowBackground))
}
@JvmOverloads @JvmOverloads
fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int { fun resolveColor(context: Context, @AttrRes attr: Int, fallback: Int = 0): Int {
val a = context.theme.obtainStyledAttributes(intArrayOf(attr)) val a = context.theme.obtainStyledAttributes(intArrayOf(attr))

@ -45,7 +45,7 @@ abstract class PageDelegate(protected val pageView: PageView) {
protected var atTop: Boolean = false protected var atTop: Boolean = false
protected var atBottom: Boolean = false protected var atBottom: Boolean = false
private var snackbar: Snackbar? = null private var snackBar: Snackbar? = null
private val scroller: Scroller by lazy { private val scroller: Scroller by lazy {
Scroller( Scroller(
@ -291,10 +291,10 @@ abstract class PageDelegate(protected val pageView: PageView) {
direction = Direction.PREV direction = Direction.PREV
val hasPrev = pageView.pageFactory?.hasPrev() == true val hasPrev = pageView.pageFactory?.hasPrev() == true
if (!hasPrev) { if (!hasPrev) {
snackbar ?: let { snackBar ?: let {
snackbar = pageView.snackbar("没有上一页") snackBar = pageView.snackbar("没有上一页")
} }
snackbar?.let { snackBar?.let {
if (!it.isShown) { if (!it.isShown) {
it.setText("没有上一页") it.setText("没有上一页")
it.show() it.show()
@ -309,10 +309,10 @@ abstract class PageDelegate(protected val pageView: PageView) {
direction = Direction.NEXT direction = Direction.NEXT
val hasNext = pageView.pageFactory?.hasNext() == true val hasNext = pageView.pageFactory?.hasNext() == true
if (!hasNext) { if (!hasNext) {
snackbar ?: let { snackBar ?: let {
snackbar = pageView.snackbar("没有下一页") snackBar = pageView.snackbar("没有下一页")
} }
snackbar?.let { snackBar?.let {
if (!it.isShown) { if (!it.isShown) {
it.setText("没有下一页") it.setText("没有下一页")
it.show() it.show()

@ -609,4 +609,5 @@
<string name="chage_icon_error">图标为矢量图标,Android8.0以前不支持</string> <string name="chage_icon_error">图标为矢量图标,Android8.0以前不支持</string>
<string name="aloud_config">朗读设置</string> <string name="aloud_config">朗读设置</string>
<string name="main_activity">主界面</string> <string name="main_activity">主界面</string>
<string name="selectText">选择文本</string>
</resources> </resources>

@ -40,6 +40,12 @@
android:key="volumeKeyPageOnPlay" android:key="volumeKeyPageOnPlay"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="true"
android:title="@string/selectText"
android:key="selectText"
app:iconSpaceReserved="false" />
<Preference <Preference
android:key="customPageKey" android:key="customPageKey"
android:title="@string/custom_page_key" android:title="@string/custom_page_key"

Loading…
Cancel
Save