From 12504cd1944ed5b1a3ae7d77e94d518cf1e06c2f Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 26 Aug 2019 20:24:24 +0800 Subject: [PATCH] up --- .../legado/app/ui/readbook/config/ReadStyleDialog.kt | 6 ++++++ .../java/io/legado/app/ui/widget/page/PageView.kt | 11 ++++++++++- .../app/ui/widget/page/delegate/PageDelegate.kt | 9 ++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt index 5ef3c30a4..08603ddf6 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadStyleDialog.kt @@ -15,9 +15,11 @@ import io.legado.app.help.ReadBookConfig import io.legado.app.lib.theme.accentColor import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.readbook.Help +import io.legado.app.ui.readbook.ReadBookActivity import io.legado.app.utils.getPrefInt import io.legado.app.utils.postEvent import io.legado.app.utils.putPrefInt +import kotlinx.android.synthetic.main.activity_read_book.* import kotlinx.android.synthetic.main.dialog_read_book_style.* import org.jetbrains.anko.sdk27.listeners.onCheckedChange import org.jetbrains.anko.sdk27.listeners.onClick @@ -70,6 +72,10 @@ class ReadStyleDialog : DialogFragment() { for (i in 0 until rg_page_anim.childCount) { if (checkedId == rg_page_anim[i].id) { requireContext().putPrefInt("pageAnim", i) + val activity = activity + if (activity is ReadBookActivity) { + activity.page_view.upPageAnim() + } break } } diff --git a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt index 95d37a5da..f10eeda81 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/PageView.kt @@ -7,8 +7,10 @@ import android.util.AttributeSet import android.view.MotionEvent import android.widget.FrameLayout import io.legado.app.help.ReadBookConfig +import io.legado.app.ui.widget.page.delegate.CoverPageDelegate import io.legado.app.ui.widget.page.delegate.PageDelegate import io.legado.app.ui.widget.page.delegate.SlidePageDelegate +import io.legado.app.utils.getPrefInt class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs), PageDelegate.PageInterface { @@ -30,7 +32,7 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att upBg() setWillNotDraw(false) - pageDelegate = SlidePageDelegate(this) + upPageAnim() setPageFactory(TextPageFactory.create(object : DataSource { override fun pageIndex(): Int { @@ -138,6 +140,13 @@ class PageView(context: Context, attrs: AttributeSet) : FrameLayout(context, att upContent() } + fun upPageAnim() { + pageDelegate = when (context.getPrefInt("pageAnim")) { + 1 -> SlidePageDelegate(this) + else -> CoverPageDelegate(this) + } + } + fun upContent() { pageFactory?.let { prevPage?.setContent(it.previousPage()) diff --git a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt index 1313b44b5..229bfcb48 100644 --- a/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/widget/page/delegate/PageDelegate.kt @@ -13,7 +13,10 @@ import io.legado.app.utils.screenshot import kotlin.math.abs abstract class PageDelegate(protected val pageView: PageView) { - val centerRectF = RectF() + val centerRectF = RectF( + pageView.width * 0.33f, pageView.height * 0.33f, + pageView.width * 0.66f, pageView.height * 0.66f + ) //起始点 protected var startX: Float = 0.toFloat() protected var startY: Float = 0.toFloat() @@ -97,8 +100,8 @@ abstract class PageDelegate(protected val pageView: PageView) { viewHeight = height invalidate() centerRectF.set( - width / 3f, height / 3f, - width * 2f / 3, height * 2f / 3 + width * 0.33f, height * 0.33f, + width * 0.66f, height * 0.66f ) }