From 939b7a77793ef6f7605e16ed95ac2b7ce4e73b73 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 08:35:25 +0800 Subject: [PATCH 01/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../read/page/delegate/CoverPageDelegate.kt | 20 +++++------ .../page/delegate/HorizontalPageDelegate.kt | 35 +++++++++++++++++++ .../page/delegate/SimulationPageDelegate.kt | 30 ---------------- .../read/page/delegate/SlidePageDelegate.kt | 25 ++++++------- 4 files changed, 54 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt index 2f4b2c404..c973fc87c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/CoverPageDelegate.kt @@ -1,11 +1,12 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas +import android.graphics.Matrix import android.graphics.drawable.GradientDrawable import io.legado.app.ui.book.read.page.PageView class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { - + private val bitmapMatrix = Matrix() private val shadowDrawableR: GradientDrawable init { @@ -16,13 +17,6 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { shadowDrawableR.gradientType = GradientDrawable.LINEAR_GRADIENT } - override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { - curPage.x = 0.toFloat() - prevPage.x = -viewWidth.toFloat() - nextPage.x = 0.toFloat() - super.setStartPoint(x, y, invalidate) - } - override fun onDraw(canvas: Canvas) { val offsetX = touchX - startX @@ -33,10 +27,14 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth if (!isRunning) return if (mDirection == Direction.PREV) { - prevPage.translationX = offsetX - viewWidth + bitmapMatrix.setTranslate(distanceX, 0.toFloat()) + curBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) } + prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } addShadow(distanceX.toInt(), canvas) } else if (mDirection == Direction.NEXT) { - curPage.translationX = offsetX + bitmapMatrix.setTranslate(distanceX - viewWidth, 0.toFloat()) + nextBitmap?.let { canvas.drawBitmap(it, 0f, 0f, null) } + curBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } addShadow(distanceX.toInt(), canvas) } } @@ -52,8 +50,6 @@ class CoverPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { } override fun onAnimStop() { - curPage.x = 0.toFloat() - prevPage.x = -viewWidth.toFloat() if (!isCancel) { pageView.fillPage(mDirection) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index a95d01e2a..0a6180200 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -1,11 +1,36 @@ package io.legado.app.ui.book.read.page.delegate +import android.graphics.Bitmap import android.view.MotionEvent import io.legado.app.ui.book.read.page.PageView +import io.legado.app.utils.screenshot import kotlin.math.abs abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageView) { + protected var curBitmap: Bitmap? = null + protected var prevBitmap: Bitmap? = null + protected var nextBitmap: Bitmap? = null + + override fun setDirection(direction: Direction) { + super.setDirection(direction) + setBitmap() + } + + private fun setBitmap() { + when (mDirection) { + Direction.PREV -> { + prevBitmap = prevPage.screenshot() + curBitmap = curPage.screenshot() + } + Direction.NEXT -> { + nextBitmap = nextPage.screenshot() + curBitmap = curPage.screenshot() + } + else -> Unit + } + } + override fun onTouch(event: MotionEvent) { when (event.action) { MotionEvent.ACTION_DOWN -> { @@ -69,4 +94,14 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie onAnimStart() } + override fun onDestroy() { + super.onDestroy() + prevBitmap?.recycle() + prevBitmap = null + curBitmap?.recycle() + curBitmap = null + nextBitmap?.recycle() + nextBitmap = null + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index b337a17a1..3b97ede32 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -4,7 +4,6 @@ import android.graphics.* import android.graphics.drawable.GradientDrawable import android.os.Build import io.legado.app.ui.book.read.page.PageView -import io.legado.app.utils.screenshot import kotlin.math.* @Suppress("DEPRECATION") @@ -73,10 +72,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi private val mPaint: Paint = Paint().apply { style = Paint.Style.FILL } - private var curBitmap: Bitmap? = null - private var prevBitmap: Bitmap? = null - private var nextBitmap: Bitmap? = null - init { //设置颜色数组 val color = intArrayOf(0x333333, -0x4fcccccd) @@ -118,16 +113,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mMaxLength = hypot(viewWidth.toDouble(), viewHeight.toDouble()).toFloat() } - override fun onDestroy() { - super.onDestroy() - prevBitmap?.recycle() - prevBitmap = null - curBitmap?.recycle() - curBitmap = null - nextBitmap?.recycle() - nextBitmap = null - } - override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { super.setStartPoint(x, y, invalidate) calcCornerXY(x, y) @@ -152,7 +137,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi override fun setDirection(direction: Direction) { super.setDirection(direction) - setBitmap() when (direction) { Direction.PREV -> //上一页滑动不出现对角 @@ -169,20 +153,6 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } } - private fun setBitmap() { - when (mDirection) { - Direction.PREV -> { - prevBitmap = prevPage.screenshot() - curBitmap = curPage.screenshot() - } - Direction.NEXT -> { - nextBitmap = nextPage.screenshot() - curBitmap = curPage.screenshot() - } - else -> Unit - } - } - override fun onAnimStart() { var dx: Float val dy: Float diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt index 850c6b4ea..197b65c39 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SlidePageDelegate.kt @@ -1,16 +1,12 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.Canvas +import android.graphics.Matrix import io.legado.app.ui.book.read.page.PageView class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { - override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { - curPage.x = 0f - prevPage.x = -viewWidth.toFloat() - nextPage.x = viewWidth.toFloat() - super.setStartPoint(x, y, invalidate) - } + private val bitmapMatrix = Matrix() override fun onAnimStart() { val distanceX: Float @@ -41,21 +37,22 @@ class SlidePageDelegate(pageView: PageView) : HorizontalPageDelegate(pageView) { if ((mDirection == Direction.NEXT && offsetX > 0) || (mDirection == Direction.PREV && offsetX < 0) ) return - + val distanceX = if (offsetX > 0) offsetX - viewWidth else offsetX + viewWidth if (!isRunning) return if (mDirection == Direction.PREV) { - curPage.translationX = offsetX - prevPage.translationX = offsetX - viewWidth + bitmapMatrix.setTranslate(distanceX + viewWidth, 0.toFloat()) + curBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } + bitmapMatrix.setTranslate(distanceX, 0.toFloat()) + prevBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } } else if (mDirection == Direction.NEXT) { - curPage.translationX = offsetX - nextPage.translationX = offsetX + viewWidth + bitmapMatrix.setTranslate(distanceX, 0.toFloat()) + nextBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } + bitmapMatrix.setTranslate(distanceX - viewWidth, 0.toFloat()) + curBitmap?.let { canvas.drawBitmap(it, bitmapMatrix, null) } } } override fun onAnimStop() { - curPage.x = 0f - prevPage.x = -viewWidth.toFloat() - nextPage.x = viewWidth.toFloat() if (!isCancel) { pageView.fillPage(mDirection) } From d578e0e95835acfa801ae4e8342e340784cd24aa Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 10:19:52 +0800 Subject: [PATCH 02/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 48 ++++++++----------- .../ui/book/read/page/entities/TextPage.kt | 4 +- 2 files changed, 23 insertions(+), 29 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 430db0e53..f101308bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -28,7 +28,7 @@ object ChapterProvider { var visibleHeight = 0 var visibleRight = 0 var visibleBottom = 0 - private var lineSpacingExtra = 0f + private var lineSpacingExtra = 0 private var paragraphSpacing = 0 var typeface: Typeface = Typeface.SANS_SERIF var titlePaint = TextPaint() @@ -51,7 +51,7 @@ object ChapterProvider { val pageLengths = arrayListOf() val stringBuilder = StringBuilder() var surplusText = content - var durY = 0 + var durY = 0f textPages.add(TextPage()) while (surplusText.isNotEmpty()) { if (textPages.first().textLines.isEmpty()) { @@ -107,40 +107,37 @@ object ChapterProvider { */ private fun joinTitle( title: String, - y: Int, + y: Float, textPages: ArrayList, pageLines: ArrayList, pageLengths: ArrayList, stringBuilder: StringBuilder - ): Int { + ): Float { var durY = y val layout = StaticLayout( title, titlePaint, visibleWidth, - Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingExtra, true + Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true ) for (lineIndex in 0 until layout.lineCount) { textPages.last().height = durY val textLine = TextLine(isTitle = true) - if (durY + layout.getLineBaseline(lineIndex) - layout.getLineTop(lineIndex) - + contentPaint.fontMetrics.descent < visibleHeight + if (durY + titlePaint.textSize < visibleHeight ) { textPages.last().textLines.add(textLine) - durY = durY + layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) + durY += titlePaint.textSize + lineSpacingExtra } else { textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) //新页面 - durY = layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) + durY = titlePaint.textSize + lineSpacingExtra textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() - textLine.lineBase = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() - textLine.lineBottom = textLine.lineBase + contentPaint.fontMetrics.descent + textLine.lineTop = paddingTop + durY - titlePaint.textSize + textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent + textLine.lineBottom = paddingTop + durY val words = title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -165,40 +162,37 @@ object ChapterProvider { */ private fun joinBody( text: String, - y: Int, + y: Float, textPages: ArrayList, pageLines: ArrayList, pageLengths: ArrayList, stringBuilder: StringBuilder - ): Int { + ): Float { var durY = y val layout = StaticLayout( text, contentPaint, visibleWidth, - Layout.Alignment.ALIGN_NORMAL, 1f, lineSpacingExtra, true + Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true ) for (lineIndex in 0 until layout.lineCount) { textPages.last().height = durY val textLine = TextLine() - if (durY + layout.getLineBaseline(lineIndex) - layout.getLineTop(lineIndex) - + contentPaint.fontMetrics.descent < visibleHeight + if (durY + contentPaint.textSize < visibleHeight ) { textPages.last().textLines.add(textLine) - durY = durY + layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) + durY += contentPaint.textSize + lineSpacingExtra } else { textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) //新页面 - durY = layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex) + durY = contentPaint.textSize + lineSpacingExtra textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineTop(lineIndex))).toFloat() - textLine.lineBase = (paddingTop + durY - - (layout.getLineBottom(lineIndex) - layout.getLineBaseline(lineIndex))).toFloat() - textLine.lineBottom = textLine.lineBase + contentPaint.fontMetrics.descent + textLine.lineTop = paddingTop + durY - titlePaint.textSize + textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent + textLine.lineBottom = paddingTop + durY val words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) @@ -346,7 +340,7 @@ object ChapterProvider { val bold = if (ReadBookConfig.textBold) Typeface.BOLD else Typeface.NORMAL contentPaint.typeface = Typeface.create(typeface, bold) //间距 - lineSpacingExtra = ReadBookConfig.lineSpacingExtra.dp.toFloat() + lineSpacingExtra = ReadBookConfig.lineSpacingExtra.dp paragraphSpacing = ReadBookConfig.paragraphSpacing.dp titlePaint.textSize = (ReadBookConfig.textSize + 2).dp.toFloat() contentPaint.textSize = ReadBookConfig.textSize.dp.toFloat() diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt index 4e6089ddd..e8782b6c3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/entities/TextPage.kt @@ -14,7 +14,7 @@ data class TextPage( var pageSize: Int = 0, var chapterSize: Int = 0, var chapterIndex: Int = 0, - var height: Int = 0 + var height: Float = 0f ) { @Suppress("DEPRECATION") @@ -46,7 +46,7 @@ data class TextPage( } textLines.add(textLine) } - height = ChapterProvider.visibleHeight + height = ChapterProvider.visibleHeight.toFloat() } return this } From eecd276b4adc2f3a395728047c9b8e45276a1fe0 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 10:29:01 +0800 Subject: [PATCH 03/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/model/localBook/LocalBook.kt | 17 +++++++++-------- .../app/ui/book/info/BookInfoViewModel.kt | 4 ++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index c58410cd7..9a893b8a3 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -30,15 +30,16 @@ object LocalBook { } fun deleteBook(book: Book, deleteOriginal: Boolean) { - if (book.isTxt()) { - val bookFile = - FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName, subDirs = *arrayOf()) - bookFile.delete() - } + kotlin.runCatching { + if (book.isTxt()) { + val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName) + bookFile.delete() + } - if (deleteOriginal) { - val uri = Uri.parse(book.bookUrl) - DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() + if (deleteOriginal) { + val uri = Uri.parse(book.bookUrl) + DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() + } } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 0364696a6..485d704ce 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -202,12 +202,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { execute { bookData.value?.let { + App.db.bookDao().delete(it) + inBookshelf = false if (it.isLocalBook()) { LocalBook.deleteBook(it, deleteOriginal) } - App.db.bookDao().delete(it) } - inBookshelf = false }.onSuccess { success?.invoke() } From 69dba6c8416bda48a7c72bef1bf9bb14c8cc5016 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 10:45:56 +0800 Subject: [PATCH 04/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/info/BookInfoActivity.kt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 782b538ee..d20cf203b 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -21,8 +21,6 @@ import io.legado.app.help.BlurTransformation import io.legado.app.help.ImageLoader import io.legado.app.help.IntentDataHelp import io.legado.app.lib.dialogs.alert -import io.legado.app.lib.dialogs.noButton -import io.legado.app.lib.dialogs.okButton import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.ui.book.changesource.ChangeSourceDialog @@ -232,17 +230,17 @@ class BookInfoActivity : titleResource = R.string.sure, messageResource = R.string.sure_delete_book_file ) { - okButton { + positiveButton(R.string.yes) { viewModel.delBook(true) { finish() } } - noButton { + negativeButton(R.string.no) { viewModel.delBook(false) { finish() } } - } + }.show() } else { viewModel.delBook { upTvBookshelf() From ef660675e6d8b5643bc7fb30b65add485bdf3812 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 10:49:45 +0800 Subject: [PATCH 05/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 630769a92..58a2b01af 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,6 +2,10 @@ * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 请关注[开源阅读软件]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 +**2020/03/03** +* 修复bug +* 优化排版,确保段距为0时每行在相同的位置 + **2020/03/02** * 添加书源登录 * 替换规则实时生效 From e7795b4e76a56be3a79ea699e9636a679afb5a0a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 11:15:04 +0800 Subject: [PATCH 06/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index f101308bf..88ac4ed28 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -121,21 +121,21 @@ object ChapterProvider { for (lineIndex in 0 until layout.lineCount) { textPages.last().height = durY val textLine = TextLine(isTitle = true) - if (durY + titlePaint.textSize < visibleHeight + if (durY + titlePaint.textHeight < visibleHeight ) { textPages.last().textLines.add(textLine) - durY += titlePaint.textSize + lineSpacingExtra + durY += titlePaint.textHeight + lineSpacingExtra } else { textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) //新页面 - durY = titlePaint.textSize + lineSpacingExtra + durY = titlePaint.textHeight + lineSpacingExtra textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = paddingTop + durY - titlePaint.textSize + textLine.lineTop = paddingTop + durY - titlePaint.textHeight textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent textLine.lineBottom = paddingTop + durY val words = @@ -176,21 +176,21 @@ object ChapterProvider { for (lineIndex in 0 until layout.lineCount) { textPages.last().height = durY val textLine = TextLine() - if (durY + contentPaint.textSize < visibleHeight + if (durY + contentPaint.textHeight < visibleHeight ) { textPages.last().textLines.add(textLine) - durY += contentPaint.textSize + lineSpacingExtra + durY += contentPaint.textHeight + lineSpacingExtra } else { textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) //新页面 - durY = contentPaint.textSize + lineSpacingExtra + durY = contentPaint.textHeight + lineSpacingExtra textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = paddingTop + durY - titlePaint.textSize + textLine.lineTop = paddingTop + durY - titlePaint.textHeight textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent textLine.lineBottom = paddingTop + durY val words = @@ -360,4 +360,8 @@ object ChapterProvider { visibleBottom = paddingTop + visibleHeight } + val TextPaint.textHeight: Float + get() { + return this.fontMetrics.descent - fontMetrics.ascent - fontMetrics.leading + } } \ No newline at end of file From 2ee88c5f97efde420c745bebce3c3124bd0d79ee Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 11:48:36 +0800 Subject: [PATCH 07/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3c92dae8f..68f3af591 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -614,7 +614,7 @@ 长按选择文本 页眉 正文 - 页角 + 页脚 文本选择结束位置 文本选择开始位置 共用布局 From 9d3e6b4e9363b6bc4e18b45569f157d0e9974b53 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 12:36:41 +0800 Subject: [PATCH 08/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 102 ++++++------------ 1 file changed, 30 insertions(+), 72 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 88ac4ed28..6d16bf50f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -60,7 +60,15 @@ object ChapterProvider { if (end > 0) { val title = surplusText.substring(0, end) surplusText = surplusText.substring(end + 1) - durY = joinTitle(title, durY, textPages, pageLines, pageLengths, stringBuilder) + durY = setTypeText( + title, + durY, + textPages, + pageLines, + pageLengths, + stringBuilder, + true + ) } } else { //正文 @@ -73,7 +81,8 @@ object ChapterProvider { text = surplusText surplusText = "" } - durY = joinBody(text, durY, textPages, pageLines, pageLengths, stringBuilder) + durY = + setTypeText(text, durY, textPages, pageLines, pageLengths, stringBuilder, false) } } textPages.last().height = durY + 20.dp @@ -103,110 +112,59 @@ object ChapterProvider { } /** - * 标题 + * 排版文字 */ - private fun joinTitle( - title: String, - y: Float, - textPages: ArrayList, - pageLines: ArrayList, - pageLengths: ArrayList, - stringBuilder: StringBuilder - ): Float { - var durY = y - val layout = StaticLayout( - title, titlePaint, visibleWidth, - Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true - ) - for (lineIndex in 0 until layout.lineCount) { - textPages.last().height = durY - val textLine = TextLine(isTitle = true) - if (durY + titlePaint.textHeight < visibleHeight - ) { - textPages.last().textLines.add(textLine) - durY += titlePaint.textHeight + lineSpacingExtra - } else { - textPages.last().text = stringBuilder.toString() - stringBuilder.clear() - pageLines.add(textPages.last().textLines.size) - pageLengths.add(textPages.last().text.length) - //新页面 - durY = titlePaint.textHeight + lineSpacingExtra - textPages.add(TextPage()) - textPages.last().textLines.add(textLine) - } - textLine.lineTop = paddingTop + durY - titlePaint.textHeight - textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent - textLine.lineBottom = paddingTop + durY - val words = - title.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) - stringBuilder.append(words) - textLine.text = words - val desiredWidth = layout.getLineWidth(lineIndex) - if (lineIndex != layout.lineCount - 1) { - addCharsToLineMiddle(textLine, words, titlePaint, desiredWidth, 0f) - } else { - //最后一行 - val x = if (ReadBookConfig.titleCenter) - (visibleWidth - layout.getLineWidth(lineIndex)) / 2 - else 0f - addCharsToLineLast(textLine, words, stringBuilder, titlePaint, x) - } - } - durY += paragraphSpacing - return durY - } - - /** - * 正文 - */ - private fun joinBody( + private fun setTypeText( text: String, y: Float, textPages: ArrayList, pageLines: ArrayList, pageLengths: ArrayList, - stringBuilder: StringBuilder + stringBuilder: StringBuilder, + isTitle: Boolean ): Float { var durY = y + val textPaint = if (isTitle) titlePaint else contentPaint val layout = StaticLayout( - text, contentPaint, visibleWidth, + text, textPaint, visibleWidth, Layout.Alignment.ALIGN_NORMAL, 0f, 0f, true ) for (lineIndex in 0 until layout.lineCount) { textPages.last().height = durY - val textLine = TextLine() - if (durY + contentPaint.textHeight < visibleHeight - ) { + val textLine = TextLine(isTitle = isTitle) + if (durY + textPaint.textHeight < visibleHeight) { textPages.last().textLines.add(textLine) - durY += contentPaint.textHeight + lineSpacingExtra + durY += textPaint.textHeight + lineSpacingExtra } else { textPages.last().text = stringBuilder.toString() stringBuilder.clear() pageLines.add(textPages.last().textLines.size) pageLengths.add(textPages.last().text.length) //新页面 - durY = contentPaint.textHeight + lineSpacingExtra + durY = textPaint.textHeight + lineSpacingExtra textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = paddingTop + durY - titlePaint.textHeight - textLine.lineBase = paddingTop + durY - titlePaint.fontMetrics.descent + textLine.lineTop = paddingTop + durY - textPaint.textHeight + textLine.lineBase = paddingTop + durY - textPaint.fontMetrics.descent textLine.lineBottom = paddingTop + durY val words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) textLine.text = words val desiredWidth = layout.getLineWidth(lineIndex) - if (lineIndex == 0 && layout.lineCount > 1) { + if (lineIndex == 0 && layout.lineCount > 1 && !isTitle) { //第一行 - addCharsToLineFirst(textLine, words, contentPaint, desiredWidth) + addCharsToLineFirst(textLine, words, textPaint, desiredWidth) } else if (lineIndex == layout.lineCount - 1) { //最后一行 - addCharsToLineLast(textLine, words, stringBuilder, contentPaint, 0f) + val x = if (isTitle && ReadBookConfig.titleCenter) + (visibleWidth - layout.getLineWidth(lineIndex)) / 2 + else 0f + addCharsToLineLast(textLine, words, stringBuilder, textPaint, x) } else { //中间行 - addCharsToLineMiddle(textLine, words, contentPaint, desiredWidth, 0f) + addCharsToLineMiddle(textLine, words, textPaint, desiredWidth, 0f) } } durY += paragraphSpacing From d3e4352b5c0966351ea203821496fd9226a168bb Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 13:32:18 +0800 Subject: [PATCH 09/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/ChapterProvider.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 6d16bf50f..706c3d603 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -61,13 +61,7 @@ object ChapterProvider { val title = surplusText.substring(0, end) surplusText = surplusText.substring(end + 1) durY = setTypeText( - title, - durY, - textPages, - pageLines, - pageLengths, - stringBuilder, - true + title, durY, textPages, pageLines, pageLengths, stringBuilder, true ) } } else { @@ -145,9 +139,9 @@ object ChapterProvider { textPages.add(TextPage()) textPages.last().textLines.add(textLine) } - textLine.lineTop = paddingTop + durY - textPaint.textHeight - textLine.lineBase = paddingTop + durY - textPaint.fontMetrics.descent - textLine.lineBottom = paddingTop + durY + textLine.lineBottom = paddingTop + durY - lineSpacingExtra + textLine.lineBase = textLine.lineBottom - textPaint.fontMetrics.descent + textLine.lineTop = textLine.lineBottom - textPaint.textHeight val words = text.substring(layout.getLineStart(lineIndex), layout.getLineEnd(lineIndex)) stringBuilder.append(words) From 1854b0050a0a744e51e007920837332631d8f661 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 13:33:00 +0800 Subject: [PATCH 10/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 58a2b01af..5796de3ac 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/03/03** * 修复bug * 优化排版,确保段距为0时每行在相同的位置 +* 修复底部遮挡 **2020/03/02** * 添加书源登录 From 1298747e45db1e28b4e507fdf5c5585a66876d2d Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 13:47:49 +0800 Subject: [PATCH 11/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/book/read/page/ChapterProvider.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt index 706c3d603..bc9dfc6e1 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/ChapterProvider.kt @@ -312,8 +312,8 @@ object ChapterProvider { visibleBottom = paddingTop + visibleHeight } - val TextPaint.textHeight: Float + private val TextPaint.textHeight: Float get() { - return this.fontMetrics.descent - fontMetrics.ascent - fontMetrics.leading + return this.fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading } } \ No newline at end of file From 7d178ebc8bb40ac4a8f83189305f1b3976d687dd Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 16:15:27 +0800 Subject: [PATCH 12/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/book/read/page/delegate/HorizontalPageDelegate.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt index 0a6180200..74583bae0 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/HorizontalPageDelegate.kt @@ -20,11 +20,15 @@ abstract class HorizontalPageDelegate(pageView: PageView) : PageDelegate(pageVie private fun setBitmap() { when (mDirection) { Direction.PREV -> { + prevBitmap?.recycle() prevBitmap = prevPage.screenshot() + curBitmap?.recycle() curBitmap = curPage.screenshot() } Direction.NEXT -> { + nextBitmap?.recycle() nextBitmap = nextPage.screenshot() + curBitmap?.recycle() curBitmap = curPage.screenshot() } else -> Unit From ae924bee8198cd5ede50aeb91c458efbbec3476f Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 19:21:44 +0800 Subject: [PATCH 13/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/SimulationPageDelegate.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 3b97ede32..f59b0f646 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -114,20 +114,20 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } override fun setStartPoint(x: Float, y: Float, invalidate: Boolean) { - super.setStartPoint(x, y, invalidate) + super.setStartPoint(x, y, false) calcCornerXY(x, y) } override fun setTouchPoint(x: Float, y: Float, invalidate: Boolean) { super.setTouchPoint(x, y, false) //触摸y中间位置吧y变成屏幕高度 - if ((startY > viewHeight / 3.0 && startY < viewHeight * 2 / 3.0) + if ((startY > viewHeight / 3 && startY < viewHeight * 2 / 3) || mDirection == Direction.PREV ) { touchY = viewHeight.toFloat() } - if (startY > viewHeight / 3.0 && startY < viewHeight / 2.0 + if (startY > viewHeight / 3 && startY < viewHeight / 2 && mDirection == Direction.NEXT ) { touchY = 1f @@ -140,13 +140,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi when (direction) { Direction.PREV -> //上一页滑动不出现对角 - if (startX > viewWidth / 2.0) { + if (startX > viewWidth / 2) { calcCornerXY(startX, viewHeight.toFloat()) } else { calcCornerXY(viewWidth - startX, viewHeight.toFloat()) } Direction.NEXT -> - if (viewWidth / 2.0 > startX) { + if (viewWidth / 2 > startX) { calcCornerXY(viewWidth - startX, startY) } else -> Unit @@ -193,6 +193,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi } override fun onDraw(canvas: Canvas) { + if (!isRunning) return when (mDirection) { Direction.NEXT -> { calcPoints() @@ -455,8 +456,8 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi * 计算拖拽点对应的拖拽脚 */ private fun calcCornerXY(x: Float, y: Float) { - mCornerX = if (x <= viewWidth / 2.0) 0 else viewWidth - mCornerY = if (y <= viewHeight / 2.0) 0 else viewHeight + mCornerX = if (x <= viewWidth / 2) 0 else viewWidth + mCornerY = if (y <= viewHeight / 2) 0 else viewHeight mIsRtOrLb = (mCornerX == 0 && mCornerY == viewHeight) || (mCornerY == 0 && mCornerX == viewWidth) } @@ -513,7 +514,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mBezierStart2.x = mCornerX.toFloat() mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2 - mTouchToCornerDis = hypot(mTouchX - mCornerX, touchY - mCornerY) + mTouchToCornerDis = hypot(mTouchX - mCornerX, mTouchY - mCornerY) mBezierEnd1 = getCross(PointF(mTouchX, mTouchY), mBezierControl1, mBezierStart1, mBezierStart2) From af7f21dc5cb6c404c533fe8dd95bff33e24b38b8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 19:50:15 +0800 Subject: [PATCH 14/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../page/delegate/SimulationPageDelegate.kt | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index f59b0f646..c5e7d40a4 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -468,21 +468,23 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mMiddleX = (mTouchX + mCornerX) / 2 mMiddleY = (mTouchY + mCornerY) / 2 - mBezierControl1.x = mMiddleX - (mCornerY - mMiddleY) * (mCornerY - mMiddleY) / (mCornerX - mMiddleX) mBezierControl1.y = mCornerY.toFloat() - mBezierControl2.x = mCornerX.toFloat() - mBezierControl2.y = if ((mCornerY - mMiddleY).toInt() == 0) { - mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f + + val f4 = mCornerY - mMiddleY + if (f4 == 0f) { + mBezierControl2.y = mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f + } else { - mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) + mBezierControl2.y = + mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } - mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 mBezierStart1.y = mCornerY.toFloat() - //固定左边上下两个点 + + // 固定左边上下两个点 if (mTouchX > 0 && mTouchX < viewWidth) { if (mBezierStart1.x < 0 || mBezierStart1.x > viewWidth) { if (mBezierStart1.x < 0) @@ -491,6 +493,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi val f1 = abs(mCornerX - mTouchX) val f2 = viewWidth * f1 / mBezierStart1.x mTouchX = abs(mCornerX - f2) + val f3 = abs(mCornerX - mTouchX) * abs(mCornerY - mTouchY) / f1 mTouchY = abs(mCornerY - f3) @@ -502,10 +505,14 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mBezierControl1.y = mCornerY.toFloat() mBezierControl2.x = mCornerX.toFloat() - mBezierControl2.y = if ((mCornerY - mMiddleY).toInt() == 0) { - mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f + + val f5 = mCornerY - mMiddleY + if (f5 == 0f) { + mBezierControl2.y = + mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / 0.1f } else { - mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) + mBezierControl2.y = + mMiddleY - (mCornerX - mMiddleX) * (mCornerX - mMiddleX) / (mCornerY - mMiddleY) } mBezierStart1.x = mBezierControl1.x - (mCornerX - mBezierControl1.x) / 2 @@ -514,12 +521,19 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mBezierStart2.x = mCornerX.toFloat() mBezierStart2.y = mBezierControl2.y - (mCornerY - mBezierControl2.y) / 2 - mTouchToCornerDis = hypot(mTouchX - mCornerX, mTouchY - mCornerY) + mTouchToCornerDis = hypot( + (mTouchX - mCornerX).toDouble(), + (mTouchY - mCornerY).toDouble() + ).toFloat() - mBezierEnd1 = - getCross(PointF(mTouchX, mTouchY), mBezierControl1, mBezierStart1, mBezierStart2) - mBezierEnd2 = - getCross(PointF(mTouchX, mTouchY), mBezierControl2, mBezierStart1, mBezierStart2) + mBezierEnd1 = getCross( + PointF(mTouchX, mTouchY), mBezierControl1, mBezierStart1, + mBezierStart2 + ) + mBezierEnd2 = getCross( + PointF(mTouchX, mTouchY), mBezierControl2, mBezierStart1, + mBezierStart2 + ) mBezierVertex1.x = (mBezierStart1.x + 2 * mBezierControl1.x + mBezierEnd1.x) / 4 mBezierVertex1.y = (2 * mBezierControl1.y + mBezierStart1.y + mBezierEnd1.y) / 4 From 0f97c19cd4bec05a6d3196e834ffdc77e45fc79a Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 20:27:56 +0800 Subject: [PATCH 15/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/help/ReadBookConfig.kt | 8 +++++ .../page/delegate/SimulationPageDelegate.kt | 2 ++ .../java/io/legado/app/utils/BitmapUtils.kt | 33 ++++++++++++++++--- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index a3a6de521..0801f88dd 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -27,6 +27,7 @@ object ReadBookConfig { val durConfig get() = getConfig(styleSelect) private val shareConfig get() = getConfig(5) var bg: Drawable? = null + var bgMeanColor: Int = 0 init { upConfig() @@ -68,6 +69,13 @@ object ReadBookConfig { val width = dm.widthPixels val height = dm.heightPixels bg = durConfig.bgDrawable(width, height) + bg?.let { + if (it is BitmapDrawable) { + bgMeanColor = BitmapUtils.getMeanColor(it.bitmap) + } else if (it is ColorDrawable) { + bgMeanColor = it.color + } + } } fun save() { diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index c5e7d40a4..616a41614 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -3,6 +3,7 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.* import android.graphics.drawable.GradientDrawable import android.os.Build +import io.legado.app.help.ReadBookConfig import io.legado.app.ui.book.read.page.PageView import kotlin.math.* @@ -268,6 +269,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mMatrix.setValues(mMatrixArray) mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y) mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y) + canvas.drawColor(ReadBookConfig.bgMeanColor) canvas.drawBitmap(bitmap, mMatrix, mPaint) mPaint.colorFilter = null canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y) diff --git a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt index 371be8122..138a0c063 100644 --- a/app/src/main/java/io/legado/app/utils/BitmapUtils.kt +++ b/app/src/main/java/io/legado/app/utils/BitmapUtils.kt @@ -5,6 +5,7 @@ import android.graphics.Bitmap import android.graphics.Bitmap.Config import android.graphics.BitmapFactory import android.graphics.Canvas +import android.graphics.Color import android.renderscript.Allocation import android.renderscript.Element import android.renderscript.RenderScript @@ -12,10 +13,7 @@ import android.renderscript.ScriptIntrinsicBlur import android.view.View import io.legado.app.App import java.io.IOException -import kotlin.math.ceil -import kotlin.math.floor -import kotlin.math.min -import kotlin.math.sqrt +import kotlin.math.* @Suppress("unused", "WeakerAccess") @@ -257,4 +255,31 @@ object BitmapUtils { return blurredBitmap } + fun getMeanColor(bitmap: Bitmap): Int { + val width: Int = bitmap.width + val height: Int = bitmap.height + var pixel: Int + var pixelSumRed = 0 + var pixelSumBlue = 0 + var pixelSumGreen = 0 + for (i in 0..99) { + for (j in 70..99) { + pixel = bitmap.getPixel( + (i * width / 100.toFloat()).roundToInt(), + (j * height / 100.toFloat()).roundToInt() + ) + pixelSumRed += Color.red(pixel) + pixelSumGreen += Color.green(pixel) + pixelSumBlue += Color.blue(pixel) + } + } + val averagePixelRed = pixelSumRed / 3000 + val averagePixelBlue = pixelSumBlue / 3000 + val averagePixelGreen = pixelSumGreen / 3000 + return Color.rgb( + averagePixelRed + 3, + averagePixelGreen + 3, averagePixelBlue + 3 + ) + } + } From 0429b71e7741bdd46ec134333e27545e5b28ac14 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 20:30:03 +0800 Subject: [PATCH 16/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 5796de3ac..1d968faec 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ * 修复bug * 优化排版,确保段距为0时每行在相同的位置 * 修复底部遮挡 +* 修复仿真翻页动画 **2020/03/02** * 添加书源登录 From 7993725caa3327502ef3566279545dd54cde7ac4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 20:45:28 +0800 Subject: [PATCH 17/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/read/page/delegate/SimulationPageDelegate.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index 616a41614..ba5dfba96 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -1,6 +1,8 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.* +import android.graphics.drawable.BitmapDrawable +import android.graphics.drawable.ColorDrawable import android.graphics.drawable.GradientDrawable import android.os.Build import io.legado.app.help.ReadBookConfig @@ -269,7 +271,13 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mMatrix.setValues(mMatrixArray) mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y) mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y) - canvas.drawColor(ReadBookConfig.bgMeanColor) + ReadBookConfig.bg?.let { + if (it is BitmapDrawable) { + canvas.drawBitmap(it.bitmap, 0f, 0f, mPaint) + } else if (it is ColorDrawable) { + canvas.drawColor(it.color) + } + } canvas.drawBitmap(bitmap, mMatrix, mPaint) mPaint.colorFilter = null canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y) From e117e54894dcb32c06fb62d68e3c5093e1cf96be Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 21:58:59 +0800 Subject: [PATCH 18/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/data/dao/BookDao.kt | 7 ++++ .../legado/app/data/entities/BookProgress.kt | 7 ++++ .../app/help/storage/SyncBookProgress.kt | 41 +++++++++++++++++++ .../io/legado/app/help/storage/WebDavHelp.kt | 8 ++-- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/data/entities/BookProgress.kt create mode 100644 app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index b0c07339c..5ba798703 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData import androidx.room.* import io.legado.app.constant.BookType import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookProgress @Dao interface BookDao { @@ -67,4 +68,10 @@ interface BookDao { @Query("update books set `group` = :newGroupId where `group` = :oldGroupId") fun upGroup(oldGroupId: Int, newGroupId: Int) + + @get:Query("select bookUrl, durChapterIndex, durChapterPos from books") + val allBookProgress: List + + @Query("update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos where bookUrl = :bookUrl") + fun upBookProgress(bookUrl: String, durChapterIndex: Int, durChapterPos: Int) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt new file mode 100644 index 000000000..ed2d8abdd --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt @@ -0,0 +1,7 @@ +package io.legado.app.data.entities + +data class BookProgress( + val bookUrl: String, + val durChapterIndex: Int, + var durChapterPos: Int +) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt new file mode 100644 index 000000000..76ff8cb1f --- /dev/null +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -0,0 +1,41 @@ +package io.legado.app.help.storage + +import io.legado.app.App +import io.legado.app.data.entities.BookProgress +import io.legado.app.lib.webdav.WebDav +import io.legado.app.utils.FileUtils +import io.legado.app.utils.GSON +import io.legado.app.utils.fromJsonArray + +object SyncBookProgress { + private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") + private val webDavUrl = WebDavHelp.getWebDavUrl() + "legado/bookProgress.json" + + fun uploadBookProgress() { + val value = App.db.bookDao().allBookProgress + if (value.isNotEmpty()) { + val json = GSON.toJson(value) + file.writeText(json) + if (WebDavHelp.initWebDav()) { + WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() + WebDav(webDavUrl).upload(file.absolutePath) + } + } + } + + + fun downloadBookProgress() { + WebDav(webDavUrl).downloadTo(file.absolutePath, true) + if (file.exists()) { + val json = file.readText() + GSON.fromJsonArray(json)?.forEach { + App.db.bookDao().upBookProgress( + it.bookUrl, + it.durChapterIndex, + it.durChapterPos + ) + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index a1386f9f7..0b4b97aab 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -25,7 +25,7 @@ object WebDavHelp { private const val defaultWebDavUrl = "https://dav.jianguoyun.com/dav/" private val zipFilePath = "${FileUtils.getCachePath()}${File.separator}backup.zip" - private fun getWebDavUrl(): String { + fun getWebDavUrl(): String { var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl) if (url.isNullOrEmpty()) { url = defaultWebDavUrl @@ -34,7 +34,7 @@ object WebDavHelp { return url } - private fun initWebDav(): Boolean { + fun initWebDav(): Boolean { val account = App.INSTANCE.getPrefString(PreferKey.webDavAccount) val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword) if (!account.isNullOrBlank() && !password.isNullOrBlank()) { @@ -82,8 +82,8 @@ object WebDavHelp { private fun restoreWebDav(name: String, success: () -> Unit) { Coroutine.async { getWebDavUrl().let { - val file = WebDav(it + "legado/" + name) - file.downloadTo(zipFilePath, true) + val webDav = WebDav(it + "legado/" + name) + webDav.downloadTo(zipFilePath, true) @Suppress("BlockingMethodInNonBlockingContext") ZipUtils.unzipFile(zipFilePath, Backup.backupPath) Restore.restore(Backup.backupPath) From df14e99bf3cdac4621dbd1e6ab143aff67011595 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 22:05:57 +0800 Subject: [PATCH 19/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookDao.kt | 16 +++++++++++++--- .../io/legado/app/data/entities/BookProgress.kt | 3 ++- .../legado/app/help/storage/SyncBookProgress.kt | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 5ba798703..69fa4a5f9 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -69,9 +69,19 @@ interface BookDao { @Query("update books set `group` = :newGroupId where `group` = :oldGroupId") fun upGroup(oldGroupId: Int, newGroupId: Int) - @get:Query("select bookUrl, durChapterIndex, durChapterPos from books") + @get:Query("select bookUrl, durChapterIndex, durChapterPos, durChapterTime from books") val allBookProgress: List - @Query("update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos where bookUrl = :bookUrl") - fun upBookProgress(bookUrl: String, durChapterIndex: Int, durChapterPos: Int) + @Query( + """ + update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos + where bookUrl = :bookUrl and durChapterTime < :durChapterTime + """ + ) + fun upBookProgress( + bookUrl: String, + durChapterIndex: Int, + durChapterPos: Int, + durChapterTime: Int + ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt index ed2d8abdd..df9c80464 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt @@ -3,5 +3,6 @@ package io.legado.app.data.entities data class BookProgress( val bookUrl: String, val durChapterIndex: Int, - var durChapterPos: Int + var durChapterPos: Int, + var durChapterTime: Int ) \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index 76ff8cb1f..b01a11f0e 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -32,7 +32,8 @@ object SyncBookProgress { App.db.bookDao().upBookProgress( it.bookUrl, it.durChapterIndex, - it.durChapterPos + it.durChapterPos, + it.durChapterTime ) } } From 3b653cebbf5832ec0588dd7fccbaa41d2498f847 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 22:11:55 +0800 Subject: [PATCH 20/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/help/storage/SyncBookProgress.kt | 40 +++++++++++-------- .../java/io/legado/app/lib/webdav/WebDav.kt | 1 - 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index b01a11f0e..ee8bba384 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -2,39 +2,45 @@ package io.legado.app.help.storage import io.legado.app.App import io.legado.app.data.entities.BookProgress +import io.legado.app.help.coroutine.Coroutine import io.legado.app.lib.webdav.WebDav import io.legado.app.utils.FileUtils import io.legado.app.utils.GSON import io.legado.app.utils.fromJsonArray +@Suppress("BlockingMethodInNonBlockingContext") object SyncBookProgress { private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") private val webDavUrl = WebDavHelp.getWebDavUrl() + "legado/bookProgress.json" fun uploadBookProgress() { - val value = App.db.bookDao().allBookProgress - if (value.isNotEmpty()) { - val json = GSON.toJson(value) - file.writeText(json) - if (WebDavHelp.initWebDav()) { - WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() - WebDav(webDavUrl).upload(file.absolutePath) + Coroutine.async { + val value = App.db.bookDao().allBookProgress + if (value.isNotEmpty()) { + val json = GSON.toJson(value) + file.writeText(json) + if (WebDavHelp.initWebDav()) { + WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() + WebDav(webDavUrl).upload(file.absolutePath) + } } } } fun downloadBookProgress() { - WebDav(webDavUrl).downloadTo(file.absolutePath, true) - if (file.exists()) { - val json = file.readText() - GSON.fromJsonArray(json)?.forEach { - App.db.bookDao().upBookProgress( - it.bookUrl, - it.durChapterIndex, - it.durChapterPos, - it.durChapterTime - ) + Coroutine.async { + WebDav(webDavUrl).downloadTo(file.absolutePath, true) + if (file.exists()) { + val json = file.readText() + GSON.fromJsonArray(json)?.forEach { + App.db.bookDao().upBookProgress( + it.bookUrl, + it.durChapterIndex, + it.durChapterPos, + it.durChapterTime + ) + } } } } diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index 32b79ce79..47aa59344 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -202,7 +202,6 @@ constructor(urlStr: String) { * 上传文件 */ @Throws(IOException::class) - @JvmOverloads fun upload(localPath: String, contentType: String? = null): Boolean { val file = File(localPath) if (!file.exists()) return false From 610c18e7db69a7052aba125087de8c1be8d45eac Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 22:14:13 +0800 Subject: [PATCH 21/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/ui/main/MainActivity.kt | 2 ++ app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt index 8b4705ae0..298ccb294 100644 --- a/app/src/main/java/io/legado/app/ui/main/MainActivity.kt +++ b/app/src/main/java/io/legado/app/ui/main/MainActivity.kt @@ -16,6 +16,7 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.storage.Backup +import io.legado.app.help.storage.SyncBookProgress import io.legado.app.lib.theme.ATH import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud @@ -128,6 +129,7 @@ class MainActivity : VMBaseActivity(R.layout.activity_main), override fun finish() { if (!BuildConfig.DEBUG) { + SyncBookProgress.uploadBookProgress() Backup.autoBack(this) } super.finish() diff --git a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt index 7e535f009..5c84aa679 100644 --- a/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt +++ b/app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt @@ -8,6 +8,7 @@ import io.legado.app.R import io.legado.app.base.BaseActivity import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine +import io.legado.app.help.storage.SyncBookProgress import io.legado.app.lib.theme.accentColor import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainActivity @@ -41,6 +42,7 @@ open class WelcomeActivity : BaseActivity(R.layout.activity_welcome) { else -> null } } + SyncBookProgress.downloadBookProgress() root_view.postDelayed({ startMainActivity() }, 300) } From 656fe45efb0459f440e9c9181d7b3d9a4674d4e1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 22:16:16 +0800 Subject: [PATCH 22/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/read/page/delegate/SimulationPageDelegate.kt | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt index ba5dfba96..616a41614 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/delegate/SimulationPageDelegate.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.book.read.page.delegate import android.graphics.* -import android.graphics.drawable.BitmapDrawable -import android.graphics.drawable.ColorDrawable import android.graphics.drawable.GradientDrawable import android.os.Build import io.legado.app.help.ReadBookConfig @@ -271,13 +269,7 @@ class SimulationPageDelegate(pageView: PageView) : HorizontalPageDelegate(pageVi mMatrix.setValues(mMatrixArray) mMatrix.preTranslate(-mBezierControl1.x, -mBezierControl1.y) mMatrix.postTranslate(mBezierControl1.x, mBezierControl1.y) - ReadBookConfig.bg?.let { - if (it is BitmapDrawable) { - canvas.drawBitmap(it.bitmap, 0f, 0f, mPaint) - } else if (it is ColorDrawable) { - canvas.drawColor(it.color) - } - } + canvas.drawColor(ReadBookConfig.bgMeanColor) canvas.drawBitmap(bitmap, mMatrix, mPaint) mPaint.colorFilter = null canvas.rotate(mDegrees, mBezierStart1.x, mBezierStart1.y) From 4f200ec3bb1a8160764a1024f699097770fbb251 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 3 Mar 2020 22:35:21 +0800 Subject: [PATCH 23/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/help/storage/SyncBookProgress.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index ee8bba384..b95344144 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -30,16 +30,18 @@ object SyncBookProgress { fun downloadBookProgress() { Coroutine.async { - WebDav(webDavUrl).downloadTo(file.absolutePath, true) - if (file.exists()) { - val json = file.readText() - GSON.fromJsonArray(json)?.forEach { - App.db.bookDao().upBookProgress( - it.bookUrl, - it.durChapterIndex, - it.durChapterPos, - it.durChapterTime - ) + if (WebDavHelp.initWebDav()) { + WebDav(webDavUrl).downloadTo(file.absolutePath, true) + if (file.exists()) { + val json = file.readText() + GSON.fromJsonArray(json)?.forEach { + App.db.bookDao().upBookProgress( + it.bookUrl, + it.durChapterIndex, + it.durChapterPos, + it.durChapterTime + ) + } } } } From fe8420f4a26c1558786f38228ba95f490888c247 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:07:43 +0800 Subject: [PATCH 24/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 7 ++++--- .../main/java/io/legado/app/data/entities/BookProgress.kt | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 69fa4a5f9..f15da01b6 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -69,12 +69,12 @@ interface BookDao { @Query("update books set `group` = :newGroupId where `group` = :oldGroupId") fun upGroup(oldGroupId: Int, newGroupId: Int) - @get:Query("select bookUrl, durChapterIndex, durChapterPos, durChapterTime from books") + @get:Query("select bookUrl, durChapterIndex, durChapterPos, durChapterTime, durChapterTitle from books") val allBookProgress: List @Query( """ - update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos + update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos, durChapterTitle = :durChapterTitle where bookUrl = :bookUrl and durChapterTime < :durChapterTime """ ) @@ -82,6 +82,7 @@ interface BookDao { bookUrl: String, durChapterIndex: Int, durChapterPos: Int, - durChapterTime: Int + durChapterTime: Int, + durChapterTitle: String? ) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt index df9c80464..cd5d46daa 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt @@ -3,6 +3,7 @@ package io.legado.app.data.entities data class BookProgress( val bookUrl: String, val durChapterIndex: Int, - var durChapterPos: Int, - var durChapterTime: Int + val durChapterPos: Int, + val durChapterTime: Int, + val durChapterTitle: String? ) \ No newline at end of file From d1b6060d5847b81d4b7819d748046d1a37bf08c5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:15:45 +0800 Subject: [PATCH 25/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/storage/SyncBookProgress.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index b95344144..7966205fe 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -27,7 +27,6 @@ object SyncBookProgress { } } - fun downloadBookProgress() { Coroutine.async { if (WebDavHelp.initWebDav()) { @@ -39,7 +38,8 @@ object SyncBookProgress { it.bookUrl, it.durChapterIndex, it.durChapterPos, - it.durChapterTime + it.durChapterTime, + it.durChapterTitle ) } } From 1b469f8e4af5aafbd05898c215793bb3df4918de Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:18:46 +0800 Subject: [PATCH 26/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/entities/BookProgress.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt index cd5d46daa..c0d693284 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookProgress.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookProgress.kt @@ -4,6 +4,6 @@ data class BookProgress( val bookUrl: String, val durChapterIndex: Int, val durChapterPos: Int, - val durChapterTime: Int, + val durChapterTime: Long, val durChapterTitle: String? ) \ No newline at end of file From b6726c813e1e9117c3067808df40c11baf6b1b59 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:19:52 +0800 Subject: [PATCH 27/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index f15da01b6..22d5932e0 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -82,7 +82,7 @@ interface BookDao { bookUrl: String, durChapterIndex: Int, durChapterPos: Int, - durChapterTime: Int, + durChapterTime: Long, durChapterTitle: String? ) } \ No newline at end of file From e8844d93002bd0ae390043243420a03fea1117c5 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:28:53 +0800 Subject: [PATCH 28/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookDao.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 22d5932e0..f25d76be5 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -74,7 +74,9 @@ interface BookDao { @Query( """ - update books set durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos, durChapterTitle = :durChapterTitle + update books set + durChapterIndex = :durChapterIndex, durChapterPos = :durChapterPos, + durChapterTime = :durChapterTime, durChapterTitle = :durChapterTitle where bookUrl = :bookUrl and durChapterTime < :durChapterTime """ ) From 5c0e8ddbb5ab44b75f13a208b5630b9c0a6bab69 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 08:31:13 +0800 Subject: [PATCH 29/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 1d968faec..b8633fd1f 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -2,11 +2,14 @@ * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 请关注[开源阅读软件]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 +**2020/03/04** +* 修复仿真翻页动画 +* 添加阅读记录同步,正常退出进入软件时同步阅读记录 + **2020/03/03** * 修复bug * 优化排版,确保段距为0时每行在相同的位置 * 修复底部遮挡 -* 修复仿真翻页动画 **2020/03/02** * 添加书源登录 From 1b0dc675a955d9a82ecb0841ced8506bd9568e25 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 09:05:49 +0800 Subject: [PATCH 30/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 1 + .../app/help/storage/SyncBookProgress.kt | 3 +-- .../io/legado/app/help/storage/WebDavHelp.kt | 25 +++++++++++-------- app/src/main/res/xml/pref_config_backup.xml | 7 ++++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 72d8c6b15..b427f687b 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -32,6 +32,7 @@ object PreferKey { const val webDavUrl = "web_dav_url" const val webDavAccount = "web_dav_account" const val webDavPassword = "web_dav_password" + const val webDavCreateDir = "webDavCreateDir" const val changeSourceLoadToc = "changeSourceLoadToc" const val chineseConverterType = "chineseConverterType" const val launcherIcon = "launcherIcon" diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index 7966205fe..8f2bbaf47 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -11,7 +11,7 @@ import io.legado.app.utils.fromJsonArray @Suppress("BlockingMethodInNonBlockingContext") object SyncBookProgress { private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") - private val webDavUrl = WebDavHelp.getWebDavUrl() + "legado/bookProgress.json" + private val webDavUrl = "${WebDavHelp.rootWebDavUrl}bookProgress.json" fun uploadBookProgress() { Coroutine.async { @@ -20,7 +20,6 @@ object SyncBookProgress { val json = GSON.toJson(value) file.writeText(json) if (WebDavHelp.initWebDav()) { - WebDav(WebDavHelp.getWebDavUrl() + "legado").makeAsDir() WebDav(webDavUrl).upload(file.absolutePath) } } diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index 0b4b97aab..fc14289c5 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -10,6 +10,7 @@ import io.legado.app.lib.webdav.WebDav import io.legado.app.lib.webdav.http.HttpAuth import io.legado.app.utils.FileUtils import io.legado.app.utils.ZipUtils +import io.legado.app.utils.getPrefBoolean import io.legado.app.utils.getPrefString import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -25,12 +26,16 @@ object WebDavHelp { private const val defaultWebDavUrl = "https://dav.jianguoyun.com/dav/" private val zipFilePath = "${FileUtils.getCachePath()}${File.separator}backup.zip" - fun getWebDavUrl(): String { + val rootWebDavUrl: String + get() { var url = App.INSTANCE.getPrefString(PreferKey.webDavUrl) if (url.isNullOrEmpty()) { url = defaultWebDavUrl } - if (!url.endsWith("/")) url += "/" + if (!url.endsWith("/")) url = "${url}/" + if (App.INSTANCE.getPrefBoolean(PreferKey.webDavCreateDir, true)) { + url = "${url}legado/" + } return url } @@ -39,17 +44,18 @@ object WebDavHelp { val password = App.INSTANCE.getPrefString(PreferKey.webDavPassword) if (!account.isNullOrBlank() && !password.isNullOrBlank()) { HttpAuth.auth = HttpAuth.Auth(account, password) + WebDav(rootWebDavUrl).makeAsDir() return true } return false } private fun getWebDavFileNames(): ArrayList { - val url = getWebDavUrl() + val url = rootWebDavUrl val names = arrayListOf() if (initWebDav()) { try { - var files = WebDav(url + "legado/").listFiles() + var files = WebDav(url).listFiles() files = files.reversed() for (index: Int in 0 until min(10, files.size)) { files[index].displayName?.let { @@ -81,8 +87,8 @@ object WebDavHelp { private fun restoreWebDav(name: String, success: () -> Unit) { Coroutine.async { - getWebDavUrl().let { - val webDav = WebDav(it + "legado/" + name) + rootWebDavUrl.let { + val webDav = WebDav(it + name) webDav.downloadTo(zipFilePath, true) @Suppress("BlockingMethodInNonBlockingContext") ZipUtils.unzipFile(zipFilePath, Backup.backupPath) @@ -102,10 +108,9 @@ object WebDavHelp { } FileUtils.deleteFile(zipFilePath) if (ZipUtils.zipFiles(paths, zipFilePath)) { - WebDav(getWebDavUrl() + "legado").makeAsDir() - val putUrl = getWebDavUrl() + "legado/backup" + - SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) - .format(Date(System.currentTimeMillis())) + ".zip" + val backupDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) + .format(Date(System.currentTimeMillis())) + val putUrl = "${rootWebDavUrl}backup${backupDate}.zip" WebDav(putUrl).upload(zipFilePath) } } diff --git a/app/src/main/res/xml/pref_config_backup.xml b/app/src/main/res/xml/pref_config_backup.xml index 3f99cfef2..b2442aa09 100644 --- a/app/src/main/res/xml/pref_config_backup.xml +++ b/app/src/main/res/xml/pref_config_backup.xml @@ -24,6 +24,13 @@ android:summary="@string/web_dav_pw_s" app:iconSpaceReserved="false" /> + + From 1fde27020872b252e9030fc08354d67e4cdff9c9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 4 Mar 2020 09:09:47 +0800 Subject: [PATCH 31/31] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/storage/SyncBookProgress.kt | 5 +++-- .../java/io/legado/app/help/storage/WebDavHelp.kt | 14 +++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt index 8f2bbaf47..ddb4d6ef5 100644 --- a/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt +++ b/app/src/main/java/io/legado/app/help/storage/SyncBookProgress.kt @@ -10,8 +10,9 @@ import io.legado.app.utils.fromJsonArray @Suppress("BlockingMethodInNonBlockingContext") object SyncBookProgress { - private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, "bookProgress.json") - private val webDavUrl = "${WebDavHelp.rootWebDavUrl}bookProgress.json" + const val fileName = "bookProgress.json" + private val file = FileUtils.createFileIfNotExist(App.INSTANCE.cacheDir, fileName) + private val webDavUrl = "${WebDavHelp.rootWebDavUrl}$fileName" fun uploadBookProgress() { Coroutine.async { diff --git a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt index fc14289c5..50857893d 100644 --- a/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt +++ b/app/src/main/java/io/legado/app/help/storage/WebDavHelp.kt @@ -88,11 +88,15 @@ object WebDavHelp { private fun restoreWebDav(name: String, success: () -> Unit) { Coroutine.async { rootWebDavUrl.let { - val webDav = WebDav(it + name) - webDav.downloadTo(zipFilePath, true) - @Suppress("BlockingMethodInNonBlockingContext") - ZipUtils.unzipFile(zipFilePath, Backup.backupPath) - Restore.restore(Backup.backupPath) + if (name == SyncBookProgress.fileName) { + SyncBookProgress.downloadBookProgress() + } else { + val webDav = WebDav(it + name) + webDav.downloadTo(zipFilePath, true) + @Suppress("BlockingMethodInNonBlockingContext") + ZipUtils.unzipFile(zipFilePath, Backup.backupPath) + Restore.restore(Backup.backupPath) + } } }.onSuccess { success.invoke()