diff --git a/app/src/main/java/io/legado/app/constant/PageAnim.kt b/app/src/main/java/io/legado/app/constant/PageAnim.kt new file mode 100644 index 000000000..ac98ef023 --- /dev/null +++ b/app/src/main/java/io/legado/app/constant/PageAnim.kt @@ -0,0 +1,22 @@ +package io.legado.app.constant + +import androidx.annotation.IntDef + +object PageAnim { + + const val coverPageAnim = 0 + + const val slidePageAnim = 1 + + const val simulationPageAnim = 2 + + const val scrollPageAnim = 3 + + const val noAnim = 4 + + @Target(AnnotationTarget.VALUE_PARAMETER) + @Retention(AnnotationRetention.SOURCE) + @IntDef(coverPageAnim, slidePageAnim, simulationPageAnim, scrollPageAnim, noAnim) + annotation class Anim + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index 02afb4f1a..4446d36eb 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -4,6 +4,7 @@ import android.os.Parcelable import androidx.room.* import io.legado.app.constant.AppPattern import io.legado.app.constant.BookType +import io.legado.app.constant.PageAnim import io.legado.app.data.appDb import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig @@ -207,7 +208,7 @@ data class Book( fun getPageAnim(): Int { var pageAnim = config.pageAnim - ?: if (type == BookType.image) 3 else ReadBookConfig.pageAnim + ?: if (type == BookType.image) PageAnim.scrollPageAnim else ReadBookConfig.pageAnim if (pageAnim < 0) { pageAnim = ReadBookConfig.pageAnim } diff --git a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt index b2e166bb7..796a6866b 100644 --- a/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/config/ReadBookConfig.kt @@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable import androidx.annotation.Keep import io.legado.app.R import io.legado.app.constant.AppLog +import io.legado.app.constant.PageAnim import io.legado.app.constant.PreferKey import io.legado.app.help.DefaultData import io.legado.app.help.coroutine.Coroutine @@ -173,7 +174,7 @@ object ReadBookConfig { var pageAnim: Int get() = config.curPageAnim() - set(value) { + set(@PageAnim.Anim value) { config.setCurPageAnim(value) } @@ -515,7 +516,7 @@ object ReadBookConfig { } } - fun setCurPageAnim(anim: Int) { + fun setCurPageAnim(@PageAnim.Anim anim: Int) { when { AppConfig.isEInkMode -> pageAnimEInk = anim else -> pageAnim = anim diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt index 7d29bbfdc..7610d17ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ReadView.kt @@ -12,6 +12,7 @@ import android.view.MotionEvent import android.view.ViewConfiguration import android.view.WindowInsets import android.widget.FrameLayout +import io.legado.app.constant.PageAnim import io.legado.app.help.config.AppConfig import io.legado.app.help.config.ReadBookConfig import io.legado.app.lib.theme.accentColor @@ -127,7 +128,7 @@ class ReadView(context: Context, attrs: AttributeSet) : super.dispatchDraw(canvas) pageDelegate?.onDraw(canvas) if (!isInEditMode && callBack.isAutoPage && !isScroll) { - // TODO 自动翻页 + // 自动翻页 nextPage.screenshot()?.let { val bottom = callBack.autoPageProgress autoPageRect.set(0, 0, width, bottom) @@ -481,16 +482,16 @@ class ReadView(context: Context, attrs: AttributeSet) : isScroll = ReadBook.pageAnim() == 3 ChapterProvider.upLayout() when (ReadBook.pageAnim()) { - 0 -> if (pageDelegate !is CoverPageDelegate) { + PageAnim.coverPageAnim -> if (pageDelegate !is CoverPageDelegate) { pageDelegate = CoverPageDelegate(this) } - 1 -> if (pageDelegate !is SlidePageDelegate) { + PageAnim.slidePageAnim -> if (pageDelegate !is SlidePageDelegate) { pageDelegate = SlidePageDelegate(this) } - 2 -> if (pageDelegate !is SimulationPageDelegate) { + PageAnim.simulationPageAnim -> if (pageDelegate !is SimulationPageDelegate) { pageDelegate = SimulationPageDelegate(this) } - 3 -> if (pageDelegate !is ScrollPageDelegate) { + PageAnim.scrollPageAnim -> if (pageDelegate !is ScrollPageDelegate) { pageDelegate = ScrollPageDelegate(this) } else -> if (pageDelegate !is NoAnimPageDelegate) {