Просмотр исходного кода

增加章节进度条 (#4826)

* 修复当前屏幕可见图未设置滤镜

* ...

* 增加章节进度条
lhjgege 1 год назад
Родитель
Сommit
0d8bbbfe60

+ 27 - 0
app/src/main/java/io/legado/app/model/ReadManga.kt

@@ -67,6 +67,7 @@ object ReadManga : CoroutineScope by MainScope() {
     var rateLimiter = ConcurrentRateLimiter(null)
     val mangaContents get() = buildContentList()
     val hasNextChapter get() = durChapterIndex < simulatedChapterSize - 1
+    val mSeekParPos = mutableMapOf<Int, MutableMap<Int, Int>>()
 
     fun resetData(book: Book) {
         ReadManga.book = book
@@ -583,6 +584,32 @@ object ReadManga : CoroutineScope by MainScope() {
         return MangaChapter(chapter, contentList, imageCount)
     }
 
+    fun recordMangaPosition(dataList: MutableList<Any>) {
+        Coroutine.async {
+            var globalPosition = 0
+            val mangaList = mutableListOf<MangaContent>()
+            dataList.forEach {
+                if (it is MangaContent) {
+                    mangaList.add(it)
+                }
+            }
+            dataList.groupBy { if (it is MangaContent) it.mChapterIndex else (it as ReaderLoading).mChapterIndex }
+                .forEach { (chapterIndex, items) ->
+                    val itemMap = mutableMapOf<Int, Int>()
+                    for (i in items.indices) {
+                        val item = items[i]
+                        if (item is MangaContent) {
+                            itemMap[item.index] = globalPosition++
+                        } else {
+                            globalPosition++
+                        }
+                    }
+                    mSeekParPos[chapterIndex] = itemMap
+                }
+        }
+    }
+
+
     interface Callback {
         fun upContent()
         fun loadFail(msg: String)

+ 16 - 0
app/src/main/java/io/legado/app/ui/book/manga/ReadMangaActivity.kt

@@ -227,6 +227,7 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
                             ReadManga.durChapterPos = content.index
                             ReadManga.curPageChanged()
                         }
+                        binding.mangaMenu.upSeekBar(content.index, content.imageCount)
                         upInfoBar(
                             content.mChapterIndex,
                             content.chapterSize,
@@ -277,6 +278,8 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
             val curFinish = data.curFinish
             val nextFinish = data.nextFinish
             mAdapter.submitList(list) {
+                binding.mangaMenu.upSeekBar(ReadManga.durChapterPos, ReadManga.durChapterImageCount)
+                ReadManga.recordMangaPosition(mAdapter.getCurrentList())
                 if (loadingViewVisible && curFinish) {
                     binding.infobar.isVisible = true
                     upInfoBar(
@@ -564,6 +567,12 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
         toggleSystemBar(menuIsVisible)
     }
 
+    override fun moveToTargetIndex(isNext: Boolean) {
+        var targetIndex =
+            if (isNext) ReadManga.durChapterIndex + 1 else ReadManga.durChapterIndex - 1
+        viewModel.openChapter(if (isNext) targetIndex else targetIndex, 0)
+    }
+
     override fun dispatchKeyEvent(event: KeyEvent): Boolean {
         val keyCode = event.keyCode
         val action = event.action
@@ -746,4 +755,11 @@ class ReadMangaActivity : VMBaseActivity<ActivityMangaBinding, ReadMangaViewMode
         // 强制刷新屏幕
         window.decorView.postInvalidate()
     }
+
+    override fun seekValue(pos: Int) {
+        val mangaIndex = ReadManga.mSeekParPos[ReadManga.durChapterIndex]
+        if (mangaIndex != null && mangaIndex[pos] != null) {
+            binding.mRecyclerManga.scrollToPosition(mangaIndex[pos]!!)
+        }
+    }
 }

+ 31 - 0
app/src/main/java/io/legado/app/ui/book/read/MangaMenu.kt

@@ -8,6 +8,7 @@ import android.util.AttributeSet
 import android.view.LayoutInflater
 import android.view.animation.Animation
 import android.widget.FrameLayout
+import android.widget.SeekBar
 import androidx.core.view.isGone
 import androidx.core.view.isVisible
 import io.legado.app.R
@@ -22,6 +23,7 @@ import io.legado.app.lib.theme.primaryColor
 import io.legado.app.lib.theme.primaryTextColor
 import io.legado.app.model.ReadManga
 import io.legado.app.ui.browser.WebViewActivity
+import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
 import io.legado.app.utils.ColorUtils
 import io.legado.app.utils.ConstraintModify
 import io.legado.app.utils.activity
@@ -81,6 +83,7 @@ class MangaMenu @JvmOverloads constructor(
         override fun onAnimationEnd(animation: Animation) {
             this@MangaMenu.invisible()
             binding.titleBar.invisible()
+            binding.bottomMenu.invisible()
             isMenuOutAnimating = false
             canShowMenu = false
             callBack.upSystemUiVisibility(false)
@@ -134,6 +137,9 @@ class MangaMenu @JvmOverloads constructor(
         brightnessBackground.setColor(ColorUtils.adjustAlpha(bgColor, 0.5f))
         if (AppConfig.isEInkMode) {
             titleBar.setBackgroundResource(R.drawable.bg_eink_border_bottom)
+            bottomMenu.setBackgroundResource(R.drawable.bg_eink_border_top)
+        } else {
+            bottomMenu.setBackgroundColor(bgColor)
         }
         if (AppConfig.showReadTitleBarAddition) {
             titleBarAddition.visible()
@@ -173,6 +179,7 @@ class MangaMenu @JvmOverloads constructor(
         if (this.isVisible) {
             if (anim) {
                 binding.titleBar.startAnimation(menuTopOut)
+                binding.bottomMenu.startAnimation(menuBottomOut)
             } else {
                 menuOutListener.onAnimationStart(menuBottomOut)
                 menuOutListener.onAnimationEnd(menuBottomOut)
@@ -183,8 +190,10 @@ class MangaMenu @JvmOverloads constructor(
     fun runMenuIn(anim: Boolean = !AppConfig.isEInkMode) {
         this.visible()
         binding.titleBar.visible()
+        binding.bottomMenu.visible()
         if (anim) {
             binding.titleBar.startAnimation(menuTopIn)
+            binding.bottomMenu.startAnimation(menuBottomIn)
         } else {
             menuInListener.onAnimationStart(menuBottomIn)
             menuInListener.onAnimationEnd(menuBottomIn)
@@ -225,11 +234,33 @@ class MangaMenu @JvmOverloads constructor(
         tvChapterName.setOnLongClickListener(chapterViewLongClickListener)
         tvChapterUrl.setOnClickListener(chapterViewClickListener)
         tvChapterUrl.setOnLongClickListener(chapterViewLongClickListener)
+
+        tvNext.setOnClickListener {
+            callBack.moveToTargetIndex(true)
+        }
+        tvPre.setOnClickListener {
+            callBack.moveToTargetIndex(false)
+        }
+
+        seekReadPage.setOnSeekBarChangeListener(object : SeekBarChangeListener {
+            override fun onStopTrackingTouch(seekBar: SeekBar) {
+                callBack.seekValue(seekBar.progress)
+            }
+        })
+    }
+
+    fun upSeekBar(value: Int, count: Int) {
+        binding.seekReadPage.apply {
+            max = count.minus(1)
+            progress = value
+        }
     }
 
     interface CallBack {
         fun openBookInfoActivity()
         fun upSystemUiVisibility(menuIsVisible: Boolean)
+        fun moveToTargetIndex(isNext: Boolean)
+        fun seekValue(pos: Int)
     }
 
 }

+ 56 - 0
app/src/main/res/layout/view_manga_menu.xml

@@ -73,4 +73,60 @@
 
     </io.legado.app.ui.widget.TitleBar>
 
+    <LinearLayout
+        android:id="@+id/bottom_menu"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:background="@color/background_menu"
+        android:importantForAccessibility="no"
+        android:orientation="vertical"
+        app:layout_constraintBottom_toBottomOf="parent">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginLeft="20dp"
+            android:layout_marginTop="10dp"
+            android:layout_marginRight="20dp"
+            android:layout_marginBottom="10dp"
+            android:importantForAccessibility="no"
+            android:orientation="horizontal">
+
+            <TextView
+                android:id="@+id/tv_pre"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="10dp"
+                android:layout_marginEnd="10dp"
+                android:background="?android:attr/selectableItemBackgroundBorderless"
+                android:paddingTop="10dp"
+                android:paddingBottom="10dp"
+                android:text="@string/previous_chapter"
+                android:textColor="@color/primaryText"
+                android:textSize="14sp"
+                tools:ignore="TouchTargetSizeCheck" />
+
+            <io.legado.app.lib.theme.view.ThemeSeekBar
+                android:id="@+id/seek_read_page"
+                android:layout_width="0dp"
+                android:layout_height="25dp"
+                android:layout_gravity="center_vertical"
+                android:layout_weight="1" />
+
+            <TextView
+                android:id="@+id/tv_next"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:layout_marginStart="10dp"
+                android:layout_marginEnd="10dp"
+                android:background="?android:attr/selectableItemBackgroundBorderless"
+                android:paddingTop="10dp"
+                android:paddingBottom="10dp"
+                android:text="@string/next_chapter"
+                android:textColor="@color/primaryText"
+                android:textSize="14sp"
+                tools:ignore="TouchTargetSizeCheck" />
+        </LinearLayout>
+    </LinearLayout>
+
 </androidx.constraintlayout.widget.ConstraintLayout>