From 02f0d1a041d80f8939c905774385f1fef619d961 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 11:16:23 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=A8=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B=E8=B0=83=E7=94=A8ReaderProvider=E5=87=BA=E7=8E=B0Curs?= =?UTF-8?q?orIndexOutOfBoundsException=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/api/ReaderProvider.kt | 66 +------------------ 1 file changed, 2 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/io/legado/app/api/ReaderProvider.kt b/app/src/main/java/io/legado/app/api/ReaderProvider.kt index 23c74aa98..b45d2f5c0 100644 --- a/app/src/main/java/io/legado/app/api/ReaderProvider.kt +++ b/app/src/main/java/io/legado/app/api/ReaderProvider.kt @@ -4,12 +4,11 @@ package io.legado.app.api import android.content.ContentProvider -import android.content.ContentResolver import android.content.ContentValues import android.content.UriMatcher -import android.database.* +import android.database.Cursor +import android.database.MatrixCursor import android.net.Uri -import android.os.Bundle import com.google.gson.Gson import io.legado.app.api.controller.BookshelfController import io.legado.app.api.controller.SourceController @@ -121,66 +120,5 @@ class ReaderProvider : ContentProvider() { addRow(arrayOf(mData)) } - override fun getCount() = 1 - - override fun getColumnIndex(s: String) = 0 - - @Throws(IllegalArgumentException::class) - override fun getColumnIndexOrThrow(s: String): Int { - throw UnsupportedOperationException("Not yet implemented") - } - - override fun getColumnName(i: Int) = null as String? - - override fun getColumnNames() = arrayOf() - - override fun getColumnCount() = 0 - - override fun getBlob(i: Int) = ByteArray(0) - - override fun getString(i: Int) = mData - - override fun copyStringToBuffer( - i: Int, - charArrayBuffer: CharArrayBuffer - ) { - } - - override fun getShort(i: Int) = 0.toShort() - - - override fun getInt(i: Int) = 0 - - override fun getLong(i: Int) = 0L - - override fun getFloat(i: Int) = 0F - - override fun getDouble(i: Int) = 0.toDouble() - - override fun getType(i: Int) = 0 - - override fun isNull(i: Int) = false - - override fun deactivate() {} - override fun requery() = false - - override fun close() {} - override fun isClosed() = false - - override fun registerContentObserver(contentObserver: ContentObserver) {} - override fun unregisterContentObserver(contentObserver: ContentObserver) {} - override fun registerDataSetObserver(dataSetObserver: DataSetObserver) {} - override fun unregisterDataSetObserver(dataSetObserver: DataSetObserver) {} - override fun setNotificationUri(contentResolver: ContentResolver, uri: Uri) {} - - override fun getNotificationUri() = null as Uri? - - override fun getWantsAllOnMoveCalls() = false - - override fun setExtras(bundle: Bundle) {} - override fun getExtras() = null as Bundle? - - override fun respond(bundle: Bundle) = null as Bundle? - } } \ No newline at end of file From afbb08a38887e5d5cf580769197956906cd01a67 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 13:27:34 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E6=9B=B4=E6=96=B0android=20studio=20?= =?UTF-8?q?=E5=88=B0=204.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 4 ++-- build.gradle | 5 ++--- gradle/wrapper/gradle-wrapper.properties | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 476e545bc..be8813009 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-kapt' apply plugin: 'de.timfreiheit.resourceplaceholders' -apply plugin: 'io.fabric' +apply plugin: 'com.google.firebase.crashlytics' androidExtensions { experimental = true @@ -128,7 +128,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.3.2' implementation 'androidx.appcompat:appcompat:1.2.0' implementation 'androidx.media:media:1.2.0' - implementation 'androidx.preference:preference:1.1.1' + implementation 'androidx.preference:preference-ktx:1.1.1' implementation 'androidx.constraintlayout:constraintlayout:2.0.2' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' diff --git a/build.gradle b/build.gradle index 92c6e5f3e..cad3c6349 100644 --- a/build.gradle +++ b/build.gradle @@ -8,15 +8,14 @@ buildscript { maven { url 'https://maven.aliyun.com/nexus/content/groups/public/' } maven { url 'https://s3.amazonaws.com/fabric-artifacts/public' } maven { url 'https://maven.aliyun.com/repository/gradle-plugin' } - maven { url 'https://maven.fabric.io/public' } maven { url 'https://plugins.gradle.org/m2/' } } dependencies { - classpath 'com.android.tools.build:gradle:4.0.2' + classpath 'com.android.tools.build:gradle:4.1.0' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'de.timfreiheit.resourceplaceholders:placeholders:0.3' classpath 'com.google.gms:google-services:4.3.4' - classpath 'io.fabric.tools:gradle:1.31.2' + classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0' } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c1e56316f..806be7b26 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Sat May 30 10:00:31 CST 2020 +#Tue Oct 13 11:35:54 CST 2020 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip From 2ad15245eac760c603c49ad360e6ebbb08b841f5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 13:55:17 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E6=9B=B4=E6=96=B0android=20studio=20?= =?UTF-8?q?=E5=88=B0=204.1?= 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 c7875c262..c0d83e4cb 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -1,7 +1,10 @@ # 更新日志 * 关注公众号 **[开源阅读]()** 菜单•软件下载 提前享受新版本。 * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 -- 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 + +**2020/10/13** +* 更新android studio 到 4.1 **2020/10/12** * 优化预下载,防止同时下载太多卡顿 From e9ad7fc3aa1f81bbc4ee363fe42833b4024f7c95 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 17:19:17 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E6=9B=B4=E6=96=B0android=20studio=20?= =?UTF-8?q?=E5=88=B0=204.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/book/read/config/BgTextConfigDialog.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index b8d71b515..4b56b9aff 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -333,7 +333,10 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { val bgName = FileUtils.getName(config.bgStr()) val bgPath = FileUtils.getPath(requireContext().externalFilesDir, "bg", bgName) if (!FileUtils.exist(bgPath)) { - FileUtils.getFile(configDir, bgName).copyTo(File(bgPath)) + val bgFile = FileUtils.getFile(configDir, bgName) + if (bgFile.exists()) { + bgFile.copyTo(File(bgPath)) + } } } ReadBookConfig.durConfig = config From b4f0379eea11bda2ec8f592412ce3f0b8445d5b5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 20:00:38 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/README.md | 2 +- app/src/main/java/io/legado/app/base/README.md | 2 +- app/src/main/java/io/legado/app/data/README.md | 2 +- app/src/main/java/io/legado/app/help/README.md | 2 +- app/src/main/java/io/legado/app/lib/README.md | 2 +- app/src/main/java/io/legado/app/model/README.md | 2 +- app/src/main/java/io/legado/app/service/README.md | 2 +- app/src/main/java/io/legado/app/ui/README.md | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/README.md b/app/src/main/java/io/legado/app/README.md index b23d4196d..a05f70415 100644 --- a/app/src/main/java/io/legado/app/README.md +++ b/app/src/main/java/io/legado/app/README.md @@ -1,4 +1,4 @@ -## 文件结构介绍 +# 文件结构介绍 * base 基类 * constant 常量 diff --git a/app/src/main/java/io/legado/app/base/README.md b/app/src/main/java/io/legado/app/base/README.md index d28e27909..ba3d001f1 100644 --- a/app/src/main/java/io/legado/app/base/README.md +++ b/app/src/main/java/io/legado/app/base/README.md @@ -1 +1 @@ -## 基类 \ No newline at end of file +# 基类 \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/README.md b/app/src/main/java/io/legado/app/data/README.md index 9b5f490b7..a9354610f 100644 --- a/app/src/main/java/io/legado/app/data/README.md +++ b/app/src/main/java/io/legado/app/data/README.md @@ -1,4 +1,4 @@ -## 存储数据用 +# 存储数据用 * dao 数据操作 * entities 数据模型 * \Book 书籍信息 diff --git a/app/src/main/java/io/legado/app/help/README.md b/app/src/main/java/io/legado/app/help/README.md index a614de113..9bf5306f7 100644 --- a/app/src/main/java/io/legado/app/help/README.md +++ b/app/src/main/java/io/legado/app/help/README.md @@ -1 +1 @@ -## 放置一些帮助类 \ No newline at end of file +# 放置一些帮助类 \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/README.md b/app/src/main/java/io/legado/app/lib/README.md index 1089be064..b6375d25c 100644 --- a/app/src/main/java/io/legado/app/lib/README.md +++ b/app/src/main/java/io/legado/app/lib/README.md @@ -1,4 +1,4 @@ -## 放置一些copy过来的库 +# 放置一些copy过来的库 * dialogs 弹出框 * theme 主题 * webDav 网络存储 \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/README.md b/app/src/main/java/io/legado/app/model/README.md index d791c861e..150cfb8bd 100644 --- a/app/src/main/java/io/legado/app/model/README.md +++ b/app/src/main/java/io/legado/app/model/README.md @@ -1,4 +1,4 @@ -## 放置一些模块类 +# 放置一些模块类 * analyzeRule 书源规则解析 * localBook 本地书籍解析 * rss 订阅规则解析 diff --git a/app/src/main/java/io/legado/app/service/README.md b/app/src/main/java/io/legado/app/service/README.md index 64c4ca44c..2d40d9375 100644 --- a/app/src/main/java/io/legado/app/service/README.md +++ b/app/src/main/java/io/legado/app/service/README.md @@ -1,4 +1,4 @@ -## android服务 +# android服务 * AudioPlayService 音频播放服务 * CheckSourceService 书源检测服务 * DownloadService 缓存服务 diff --git a/app/src/main/java/io/legado/app/ui/README.md b/app/src/main/java/io/legado/app/ui/README.md index 102071a0c..059ce3ff0 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -1,4 +1,4 @@ -## 放置与界面有关的类 +# 放置与界面有关的类 * about 关于界面 * association 导入书源界面 From af2887322988ba51fa8500eb036c597d171daa6a Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 20:01:21 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/help.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/help.md b/app/src/main/assets/help.md index a6e6ecf0b..2b2afc64b 100644 --- a/app/src/main/assets/help.md +++ b/app/src/main/assets/help.md @@ -1,4 +1,4 @@ -## 常见问题 +# 常见问题 1.为什么第一次安装好之后什么东西都没有? * 因为阅读只是一个转码工具,不提供内容,第一次安装app,需要自己手动导入书源,可以从公众号[开源阅读]()、QQ群、酷安评论里获取由书友制作分享的书源。 From 5ad0960e086d3fc5ed240499af2396ca2be8305e Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 20:23:39 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E4=B9=A6=E6=9E=B6=E6=95=B4=E7=90=86?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=BB=91=E5=8A=A8=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/assets/updateLog.md | 1 + .../ui/book/arrange/ArrangeBookActivity.kt | 7 +++++ .../app/ui/book/arrange/ArrangeBookAdapter.kt | 28 +++++++++++++++++++ .../book/source/manage/BookSourceActivity.kt | 1 - 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index c0d83e4cb..d756e531b 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/10/13** * 更新android studio 到 4.1 +* 书架整理增加滑动选择 **2020/10/12** * 优化预下载,防止同时下载太多卡顿 diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt index 76ac7c89a..d2fedc183 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.ui.book.group.GroupManageDialog import io.legado.app.ui.book.group.GroupSelectDialog import io.legado.app.ui.widget.SelectActionBar +import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import io.legado.app.ui.widget.recycler.VerticalDivider import io.legado.app.utils.applyTint @@ -71,6 +72,12 @@ class ArrangeBookActivity : VMBaseActivity(R.layout.activi val itemTouchCallback = ItemTouchCallback() itemTouchCallback.onItemTouchCallbackListener = adapter itemTouchCallback.isCanDrag = getPrefInt(PreferKey.bookshelfSort) == 3 + val dragSelectTouchHelper: DragSelectTouchHelper = + DragSelectTouchHelper(adapter.initDragSelectTouchHelperCallback()).setSlideArea(16, 50) + dragSelectTouchHelper.attachToRecyclerView(recycler_view) + // When this page is opened, it is in selection mode + dragSelectTouchHelper.activeSlideSelect() + // Note: need judge selection first, so add ItemTouchHelper after it. ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) select_action_bar.setMainActionText(R.string.move_to_group) select_action_bar.inflateMenu(R.menu.arrange_book_sel) diff --git a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt index 762e18d1d..62c28e766 100644 --- a/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/arrange/ArrangeBookAdapter.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.book.arrange import android.content.Context import android.view.View +import androidx.core.os.bundleOf import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.adapter.ItemViewHolder @@ -9,6 +10,7 @@ import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookGroup import io.legado.app.lib.theme.backgroundColor +import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback import kotlinx.android.synthetic.main.item_arrange_book.view.* import org.jetbrains.anko.backgroundColor @@ -154,6 +156,32 @@ class ArrangeBookAdapter(context: Context, val callBack: CallBack) : isMoved = false } + fun initDragSelectTouchHelperCallback(): DragSelectTouchHelper.Callback { + return object : DragSelectTouchHelper.AdvanceCallback(Mode.ToggleAndReverse) { + override fun currentSelectedId(): MutableSet { + return selectedBooks + } + + override fun getItemId(position: Int): Book { + return getItem(position)!! + } + + override fun updateSelectState(position: Int, isSelected: Boolean): Boolean { + getItem(position)?.let { + if (isSelected) { + selectedBooks.add(it) + } else { + selectedBooks.remove(it) + } + notifyItemChanged(position, bundleOf(Pair("selected", null))) + callBack.upSelectCount() + return true + } + return false + } + } + } + interface CallBack { val groupList: List fun upSelectCount() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 221d6142b..d974431cd 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -174,7 +174,6 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity dragSelectTouchHelper.attachToRecyclerView(recycler_view) // When this page is opened, it is in selection mode dragSelectTouchHelper.activeSlideSelect() - // Note: need judge selection first, so add ItemTouchHelper after it. ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) } From 49195110d6a7cdc69c8c11e549bd1d6122995b05 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 21:14:14 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt | 3 ++- app/src/main/res/layout/activity_replace_rule.xml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 1f65877f8..f41cba885 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -43,7 +43,8 @@ import org.jetbrains.anko.toast import java.io.File -class ReplaceRuleActivity : VMBaseActivity(R.layout.activity_replace_rule), +class ReplaceRuleActivity : + VMBaseActivity(R.layout.activity_replace_rule, false), SearchView.OnQueryTextListener, PopupMenu.OnMenuItemClickListener, FileChooserDialog.CallBack, diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index dbcc248a5..9dec7eab0 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -1,7 +1,7 @@ Date: Tue, 13 Oct 2020 22:13:07 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/replacerule/ReplaceRuleActivity.kt | 6 ++++-- .../io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt | 6 ++++-- app/src/main/res/layout/activity_replace_rule.xml | 1 - app/src/main/res/layout/dialog_replace_edit.xml | 2 +- app/src/main/res/values/styles.xml | 7 +++---- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index f41cba885..6e0ae230d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -42,9 +42,11 @@ import org.jetbrains.anko.startActivity import org.jetbrains.anko.toast import java.io.File - +/** + * 替换规则管理 + */ class ReplaceRuleActivity : - VMBaseActivity(R.layout.activity_replace_rule, false), + VMBaseActivity(R.layout.activity_replace_rule), SearchView.OnQueryTextListener, PopupMenu.OnMenuItemClickListener, FileChooserDialog.CallBack, diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt index 4bbfb44be..fd922296b 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt @@ -23,6 +23,9 @@ import io.legado.app.utils.toast import kotlinx.android.synthetic.main.dialog_replace_edit.* import org.jetbrains.anko.sdk27.listeners.onFocusChange +/** + * 编辑替换规则 + */ class ReplaceEditDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener, KeyboardToolPop.CallBack { @@ -92,8 +95,7 @@ class ReplaceEditDialog : BaseDialogFragment(), val rule = getReplaceRule() if (!rule.isValid()){ toast(R.string.replace_rule_invalid) - } - else{ + } else{ viewModel.save(rule) { callBack?.onReplaceRuleSave() dismiss() diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index 9dec7eab0..926273704 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -12,7 +12,6 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:contentLayout="@layout/view_search" - app:fitStatusBar="false" app:title="@string/replace_purify" /> + android:layout_height="wrap_content"> - //**************************************************************System - Style******************************************************************************// + //**********System Style******************// - //**************************************************************Widget - Style******************************************************************************// + //*******************Widget Style**********************************// + From b8ee7151f826c6a626381c0958cb5541f4fb3fe5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 22:24:22 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/dialog_replace_edit.xml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/res/layout/dialog_replace_edit.xml b/app/src/main/res/layout/dialog_replace_edit.xml index dbdeb7158..362180e8b 100644 --- a/app/src/main/res/layout/dialog_replace_edit.xml +++ b/app/src/main/res/layout/dialog_replace_edit.xml @@ -1,19 +1,19 @@ + android:layout_height="match_parent" + android:orientation="vertical"> + app:title="@string/replace_rule_edit" + app:titleTextAppearance="@style/ToolbarTitle" /> + android:layout_height="wrap_content" + android:maxLines="6" /> + android:layout_height="wrap_content" + android:maxLines="6" /> + android:layout_height="wrap_content" + android:maxLines="6" /> From a59ecb190a07dee2e842c1e3691d72af25dd4213 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 22:33:44 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/dialog_replace_edit.xml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/src/main/res/layout/dialog_replace_edit.xml b/app/src/main/res/layout/dialog_replace_edit.xml index 362180e8b..91af590fe 100644 --- a/app/src/main/res/layout/dialog_replace_edit.xml +++ b/app/src/main/res/layout/dialog_replace_edit.xml @@ -59,8 +59,7 @@ + android:layout_height="wrap_content" /> + android:layout_height="wrap_content" /> + android:layout_height="wrap_content" /> From a2712e904eca7f4af4c4b4d3e1e79cecbd2892c3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 13 Oct 2020 23:38:34 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9B=BF=E6=8D=A2?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 10 +- .../java/io/legado/app/constant/EventBus.kt | 1 + .../legado/app/ui/audio/AudioPlayActivity.kt | 2 +- .../app/ui/book/info/BookInfoActivity.kt | 2 +- .../app/ui/book/read/ReadBookActivity.kt | 16 +- .../{chapterlist => toc}/BookmarkAdapter.kt | 2 +- .../{chapterlist => toc}/BookmarkFragment.kt | 2 +- .../ChapterListActivity.kt | 2 +- .../ChapterListAdapter.kt | 2 +- .../ChapterListFragment.kt | 2 +- .../ChapterListViewModel.kt | 2 +- .../io/legado/app/ui/main/my/MyFragment.kt | 2 +- .../{replacerule => replace}/DiffCallBack.kt | 2 +- .../GroupManageDialog.kt | 2 +- .../ReplaceRuleActivity.kt | 8 +- .../ReplaceRuleAdapter.kt | 2 +- .../ReplaceRuleViewModel.kt | 2 +- .../ui/replace/edit/ReplaceEditActivity.kt | 166 ++++++++++++++++++ .../edit/ReplaceEditViewModel.kt | 14 +- .../ui/replacerule/edit/ReplaceEditDialog.kt | 158 ----------------- ...ace_edit.xml => activity_replace_edit.xml} | 14 +- .../main/res/layout/activity_replace_rule.xml | 2 +- 22 files changed, 216 insertions(+), 199 deletions(-) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/BookmarkAdapter.kt (98%) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/BookmarkFragment.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/ChapterListActivity.kt (98%) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/ChapterListAdapter.kt (98%) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/ChapterListFragment.kt (99%) rename app/src/main/java/io/legado/app/ui/book/{chapterlist => toc}/ChapterListViewModel.kt (95%) rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/DiffCallBack.kt (97%) rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/GroupManageDialog.kt (99%) rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/ReplaceRuleActivity.kt (98%) rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/ReplaceRuleAdapter.kt (99%) rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/ReplaceRuleViewModel.kt (99%) create mode 100644 app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt rename app/src/main/java/io/legado/app/ui/{replacerule => replace}/edit/ReplaceEditViewModel.kt (77%) delete mode 100644 app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt rename app/src/main/res/layout/{dialog_replace_edit.xml => activity_replace_edit.xml} (91%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d67e2db53..8a50fc718 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -181,6 +181,12 @@ android:configChanges="locale|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize|stateHidden" /> + + @@ -220,7 +226,7 @@ android:launchMode="singleTop" /> (R.layout.activity_boo ReadBook.CallBack, AutoReadDialog.CallBack, TocRegexDialog.CallBack, - ReplaceEditDialog.CallBack, ColorPickerDialogListener { private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 @@ -487,8 +486,8 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ReadBook.bookSource?.bookSourceUrl?.let { scopes.add(it) } - ReplaceEditDialog.show( - supportFragmentManager, + ReplaceEditActivity.show( + this, pattern = selectedText, scope = scopes.joinToString(";") ) @@ -696,7 +695,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo /** * 替换规则变化 */ - override fun onReplaceRuleSave() { + private fun onReplaceRuleSave() { Coroutine.async { BookHelp.upReplaceRules() ReadBook.loadContent(resetPageOffset = false) @@ -918,6 +917,9 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(PreferKey.showBrightnessView) { read_menu.upBrightnessState() } + observeEvent(EventBus.REPLACE_RULE_SAVE) { + onReplaceRuleSave() + } } private fun upScreenTimeOut() { diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt index e9c7384ea..64f004aed 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.view.LayoutInflater import android.view.View diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt rename to app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt index b24d438e8..0f507640c 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/BookmarkFragment.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.annotation.SuppressLint import android.app.Activity diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListActivity.kt rename to app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt index 58f19a6b4..b595bacbe 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.os.Bundle import android.view.Menu diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListAdapter.kt rename to app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt index 5d4b3621b..9a994f7ca 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.content.Context import android.view.View diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt rename to app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt index d4339bb23..679b53238 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListFragment.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.annotation.SuppressLint import android.app.Activity.RESULT_OK diff --git a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt similarity index 95% rename from app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListViewModel.kt rename to app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt index 7671facc9..2fed31e10 100644 --- a/app/src/main/java/io/legado/app/ui/book/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/toc/ChapterListViewModel.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.book.chapterlist +package io.legado.app.ui.book.toc import android.app.Application diff --git a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt index 8ceb76b48..20b36c065 100644 --- a/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/my/MyFragment.kt @@ -24,7 +24,7 @@ import io.legado.app.ui.config.BackupRestoreUi import io.legado.app.ui.config.ConfigActivity import io.legado.app.ui.config.ConfigViewModel import io.legado.app.ui.filechooser.FileChooserDialog -import io.legado.app.ui.replacerule.ReplaceRuleActivity +import io.legado.app.ui.replace.ReplaceRuleActivity import io.legado.app.ui.widget.dialog.TextDialog import io.legado.app.ui.widget.prefs.NameListPreference import io.legado.app.ui.widget.prefs.PreferenceCategory diff --git a/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/replace/DiffCallBack.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt rename to app/src/main/java/io/legado/app/ui/replace/DiffCallBack.kt index 62fe0cec3..0a5200116 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/DiffCallBack.kt +++ b/app/src/main/java/io/legado/app/ui/replace/DiffCallBack.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.replacerule +package io.legado.app.ui.replace import android.os.Bundle import androidx.recyclerview.widget.DiffUtil diff --git a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt rename to app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt index bf9cb5409..b18c15fc1 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/GroupManageDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replace/GroupManageDialog.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.replacerule +package io.legado.app.ui.replace import android.annotation.SuppressLint import android.content.Context diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt similarity index 98% rename from app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt rename to app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt index 6e0ae230d..302c59b6d 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.replacerule +package io.legado.app.ui.replace import android.annotation.SuppressLint import android.app.Activity @@ -28,7 +28,7 @@ import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.association.ImportReplaceRuleActivity import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FilePicker -import io.legado.app.ui.replacerule.edit.ReplaceEditDialog +import io.legado.app.ui.replace.edit.ReplaceEditActivity import io.legado.app.ui.widget.SelectActionBar import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback @@ -169,7 +169,7 @@ class ReplaceRuleActivity : override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_add_replace_rule -> - ReplaceEditDialog().show(supportFragmentManager, "replaceNew") + ReplaceEditActivity.show(this) R.id.menu_group_manage -> GroupManageDialog().show(supportFragmentManager, "groupManage") @@ -306,7 +306,7 @@ class ReplaceRuleActivity : override fun edit(rule: ReplaceRule) { setResult(Activity.RESULT_OK) - ReplaceEditDialog.show(supportFragmentManager, rule.id) + ReplaceEditActivity.show(this, rule.id) } override fun toTop(rule: ReplaceRule) { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt rename to app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt index bcb29e87d..14c42568a 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleAdapter.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.replacerule +package io.legado.app.ui.replace import android.content.Context import android.os.Bundle diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt similarity index 99% rename from app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt rename to app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt index afbbcdcf6..a14647c82 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/ReplaceRuleViewModel.kt @@ -1,4 +1,4 @@ -package io.legado.app.ui.replacerule +package io.legado.app.ui.replace import android.app.Application import android.text.TextUtils diff --git a/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt new file mode 100644 index 000000000..90e1fcaa0 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt @@ -0,0 +1,166 @@ +package io.legado.app.ui.replace.edit + +import android.content.Context +import android.content.Intent +import android.graphics.Rect +import android.os.Bundle +import android.view.Gravity +import android.view.Menu +import android.view.MenuItem +import android.view.ViewTreeObserver +import android.widget.EditText +import android.widget.PopupWindow +import io.legado.app.R +import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.AppConst +import io.legado.app.constant.EventBus +import io.legado.app.data.entities.ReplaceRule +import io.legado.app.ui.widget.KeyboardToolPop +import io.legado.app.utils.getViewModel +import io.legado.app.utils.postEvent +import kotlinx.android.synthetic.main.activity_replace_edit.* +import org.jetbrains.anko.displayMetrics +import org.jetbrains.anko.toast +import kotlin.math.abs + +/** + * 编辑替换规则 + */ +class ReplaceEditActivity : + VMBaseActivity(R.layout.activity_replace_edit, false), + ViewTreeObserver.OnGlobalLayoutListener, + KeyboardToolPop.CallBack { + + companion object { + + fun show( + context: Context, + id: Long = -1, + pattern: String? = null, + isRegex: Boolean = false, + scope: String? = null + ) { + val intent = Intent(context, ReplaceEditActivity::class.java) + intent.putExtra("id", id) + intent.putExtra("pattern", pattern) + intent.putExtra("isRegex", isRegex) + intent.putExtra("scope", scope) + context.startActivity(intent) + } + } + + override val viewModel: ReplaceEditViewModel + get() = getViewModel(ReplaceEditViewModel::class.java) + + private var mSoftKeyboardTool: PopupWindow? = null + private var mIsSoftKeyBoardShowing = false + + override fun onActivityCreated(savedInstanceState: Bundle?) { + mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this) + window.decorView.viewTreeObserver.addOnGlobalLayoutListener(this) + viewModel.replaceRuleData.observe(this, { + upReplaceView(it) + }) + viewModel.initData(intent) + } + + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.replace_edit, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_save -> { + val rule = getReplaceRule() + if (!rule.isValid()) { + toast(R.string.replace_rule_invalid) + } else { + viewModel.save(rule) { + postEvent(EventBus.REPLACE_RULE_SAVE, "") + finish() + } + } + } + } + return true + } + + private fun upReplaceView(replaceRule: ReplaceRule) { + et_name.setText(replaceRule.name) + et_group.setText(replaceRule.group) + et_replace_rule.setText(replaceRule.pattern) + cb_use_regex.isChecked = replaceRule.isRegex + et_replace_to.setText(replaceRule.replacement) + et_scope.setText(replaceRule.scope) + } + + private fun getReplaceRule(): ReplaceRule { + val replaceRule: ReplaceRule = viewModel.replaceRuleData.value ?: ReplaceRule() + replaceRule.name = et_name.text.toString() + replaceRule.group = et_group.text.toString() + replaceRule.pattern = et_replace_rule.text.toString() + replaceRule.isRegex = cb_use_regex.isChecked + replaceRule.replacement = et_replace_to.text.toString() + replaceRule.scope = et_scope.text.toString() + return replaceRule + } + + private fun insertText(text: String) { + if (text.isBlank()) return + val view = window?.decorView?.findFocus() + if (view is EditText) { + val start = view.selectionStart + val end = view.selectionEnd + val edit = view.editableText//获取EditText的文字 + if (start < 0 || start >= edit.length) { + edit.append(text) + } else { + edit.replace(start, end, text)//光标所在位置插入文字 + } + } + } + + override fun sendText(text: String) { + if (text == AppConst.keyboardToolChars[0]) { + val view = window?.decorView?.findFocus() + view?.clearFocus() + } else { + insertText(text) + } + } + + private fun showKeyboardTopPopupWindow() { + mSoftKeyboardTool?.let { + if (it.isShowing) return + if (!isFinishing) { + it.showAtLocation(ll_content, Gravity.BOTTOM, 0, 0) + } + } + } + + private fun closePopupWindow() { + mSoftKeyboardTool?.dismiss() + } + + override fun onGlobalLayout() { + val rect = Rect() + // 获取当前页面窗口的显示范围 + window.decorView.getWindowVisibleDisplayFrame(rect) + val screenHeight = this.displayMetrics.heightPixels + val keyboardHeight = screenHeight - rect.bottom // 输入法的高度 + val preShowing = mIsSoftKeyBoardShowing + if (abs(keyboardHeight) > screenHeight / 5) { + mIsSoftKeyBoardShowing = true // 超过屏幕五分之一则表示弹出了输入法 + root_view.setPadding(0, 0, 0, 100) + showKeyboardTopPopupWindow() + } else { + mIsSoftKeyBoardShowing = false + root_view.setPadding(0, 0, 0, 0) + if (preShowing) { + closePopupWindow() + } + } + } + +} diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt similarity index 77% rename from app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt rename to app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt index 1308b64ec..12df23446 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt @@ -1,7 +1,7 @@ -package io.legado.app.ui.replacerule.edit +package io.legado.app.ui.replace.edit import android.app.Application -import android.os.Bundle +import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -11,18 +11,18 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application val replaceRuleData = MutableLiveData() - fun initData(bundle: Bundle) { + fun initData(intent: Intent) { execute { replaceRuleData.value ?: let { - val id = bundle.getLong("id") + val id = intent.getLongExtra("id", -1) if (id > 0) { App.db.replaceRuleDao().findById(id)?.let { replaceRuleData.postValue(it) } } else { - val pattern = bundle.getString("pattern") ?: "" - val isRegex = bundle.getBoolean("isRegex") - val scope = bundle.getString("scope") + val pattern = intent.getStringExtra("pattern") ?: "" + val isRegex = intent.getBooleanExtra("isRegex", false) + val scope = intent.getStringExtra("scope") val rule = ReplaceRule( name = pattern, pattern = pattern, diff --git a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt deleted file mode 100644 index fd922296b..000000000 --- a/app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt +++ /dev/null @@ -1,158 +0,0 @@ -package io.legado.app.ui.replacerule.edit - -import android.os.Bundle -import android.view.LayoutInflater -import android.view.MenuItem -import android.view.View -import android.view.ViewGroup -import android.view.ViewGroup.LayoutParams.MATCH_PARENT -import android.view.ViewGroup.LayoutParams.WRAP_CONTENT -import android.widget.EditText -import android.widget.PopupWindow -import androidx.appcompat.widget.Toolbar -import androidx.fragment.app.FragmentManager -import io.legado.app.R -import io.legado.app.base.BaseDialogFragment -import io.legado.app.constant.AppConst -import io.legado.app.data.entities.ReplaceRule -import io.legado.app.lib.theme.primaryColor -import io.legado.app.ui.widget.KeyboardToolPop -import io.legado.app.utils.applyTint -import io.legado.app.utils.getViewModel -import io.legado.app.utils.toast -import kotlinx.android.synthetic.main.dialog_replace_edit.* -import org.jetbrains.anko.sdk27.listeners.onFocusChange - -/** - * 编辑替换规则 - */ -class ReplaceEditDialog : BaseDialogFragment(), - Toolbar.OnMenuItemClickListener, - KeyboardToolPop.CallBack { - - companion object { - - fun show( - fragmentManager: FragmentManager, - id: Long = -1, - pattern: String? = null, - isRegex: Boolean = false, - scope: String? = null - ) { - val dialog = ReplaceEditDialog() - val bundle = Bundle() - bundle.putLong("id", id) - bundle.putString("pattern", pattern) - bundle.putBoolean("isRegex", isRegex) - bundle.putString("scope", scope) - dialog.arguments = bundle - dialog.show(fragmentManager, this::class.simpleName) - } - } - - private lateinit var viewModel: ReplaceEditViewModel - private lateinit var mSoftKeyboardTool: PopupWindow - - override fun onStart() { - super.onStart() - dialog?.window?.setLayout(MATCH_PARENT, WRAP_CONTENT) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View? { - viewModel = getViewModel(ReplaceEditViewModel::class.java) - return inflater.inflate(R.layout.dialog_replace_edit, container) - } - - override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { - tool_bar.setBackgroundColor(primaryColor) - mSoftKeyboardTool = KeyboardToolPop(requireContext(), AppConst.keyboardToolChars, this) - tool_bar.inflateMenu(R.menu.replace_edit) - tool_bar.menu.applyTint(requireContext()) - tool_bar.setOnMenuItemClickListener(this) - viewModel.replaceRuleData.observe(viewLifecycleOwner, { - upReplaceView(it) - }) - arguments?.let { - viewModel.initData(it) - } - et_replace_rule.onFocusChange { v, hasFocus -> - if (hasFocus) { - mSoftKeyboardTool.width = v.width - mSoftKeyboardTool.showAsDropDown(v) - } else { - mSoftKeyboardTool.dismiss() - } - } - } - - override fun onMenuItemClick(item: MenuItem?): Boolean { - when (item?.itemId) { - R.id.menu_save -> { - val rule = getReplaceRule() - if (!rule.isValid()){ - toast(R.string.replace_rule_invalid) - } else{ - viewModel.save(rule) { - callBack?.onReplaceRuleSave() - dismiss() - } - } - } - } - return true - } - - private fun upReplaceView(replaceRule: ReplaceRule) { - et_name.setText(replaceRule.name) - et_group.setText(replaceRule.group) - et_replace_rule.setText(replaceRule.pattern) - cb_use_regex.isChecked = replaceRule.isRegex - et_replace_to.setText(replaceRule.replacement) - et_scope.setText(replaceRule.scope) - } - - private fun getReplaceRule(): ReplaceRule { - val replaceRule: ReplaceRule = viewModel.replaceRuleData.value ?: ReplaceRule() - replaceRule.name = et_name.text.toString() - replaceRule.group = et_group.text.toString() - replaceRule.pattern = et_replace_rule.text.toString() - replaceRule.isRegex = cb_use_regex.isChecked - replaceRule.replacement = et_replace_to.text.toString() - replaceRule.scope = et_scope.text.toString() - return replaceRule - } - - val callBack get() = activity as? CallBack - - private fun insertText(text: String) { - if (text.isBlank()) return - val view = dialog?.window?.decorView?.findFocus() - if (view is EditText) { - val start = view.selectionStart - val end = view.selectionEnd - val edit = view.editableText//获取EditText的文字 - if (start < 0 || start >= edit.length) { - edit.append(text) - } else { - edit.replace(start, end, text)//光标所在位置插入文字 - } - } - } - - override fun sendText(text: String) { - if (text == AppConst.keyboardToolChars[0]) { - val view = dialog?.window?.decorView?.findFocus() - view?.clearFocus() - } else { - insertText(text) - } - } - - interface CallBack { - fun onReplaceRuleSave() - } -} diff --git a/app/src/main/res/layout/dialog_replace_edit.xml b/app/src/main/res/layout/activity_replace_edit.xml similarity index 91% rename from app/src/main/res/layout/dialog_replace_edit.xml rename to app/src/main/res/layout/activity_replace_edit.xml index 91af590fe..c6b80619d 100644 --- a/app/src/main/res/layout/dialog_replace_edit.xml +++ b/app/src/main/res/layout/activity_replace_edit.xml @@ -1,19 +1,19 @@ - + app:contentInsetStartWithNavigation="0dp" + app:displayHomeAsUp="true" + app:fitStatusBar="false" + app:title="@string/replace_rule_edit" /> + tools:context=".ui.replace.ReplaceRuleActivity"> Date: Tue, 13 Oct 2020 23:44:08 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/res/layout/activity_chapter_list.xml | 23 ++++++++++--------- .../main/res/layout/activity_replace_rule.xml | 1 + 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/layout/activity_chapter_list.xml b/app/src/main/res/layout/activity_chapter_list.xml index 159f77324..c78973583 100644 --- a/app/src/main/res/layout/activity_chapter_list.xml +++ b/app/src/main/res/layout/activity_chapter_list.xml @@ -1,19 +1,20 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:id="@+id/title_bar" + android:layout_width="match_parent" + android:layout_height="wrap_content" + app:contentInsetStartWithNavigation="0dp" + app:contentLayout="@layout/view_tab_layout" /> + android:id="@+id/view_pager" + android:layout_width="match_parent" + android:layout_height="match_parent" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index 6ddd9b0fd..8b918b280 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -11,6 +11,7 @@ android:id="@+id/title_bar" android:layout_width="match_parent" android:layout_height="wrap_content" + app:contentInsetStartWithNavigation="0dp" app:contentLayout="@layout/view_search" app:title="@string/replace_purify" /> From 7d3b88a3902ec40b1eac324aa99d329ae67ad324 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 17:14:29 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/res/layout/item_bookshelf_grid.xml | 4 ++-- app/src/main/res/layout/item_bookshelf_list_add.xml | 8 -------- 2 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 app/src/main/res/layout/item_bookshelf_list_add.xml diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 114c3c58e..23aa8a37c 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -6,7 +6,8 @@ android:layout_height="wrap_content" android:paddingTop="2dp" android:paddingRight="10dp" - android:paddingLeft="10dp"> + android:paddingLeft="10dp" + android:paddingBottom="4dp"> - \ No newline at end of file From 20603acef69702fbd997c40883350352de5ef78d Mon Sep 17 00:00:00 2001 From: fisher Date: Wed, 14 Oct 2020 18:10:28 +0800 Subject: [PATCH 15/24] numeric type : dot is available --- app/src/main/assets/txtTocRule.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/txtTocRule.json b/app/src/main/assets/txtTocRule.json index 4469235a2..58e9e8644 100644 --- a/app/src/main/assets/txtTocRule.json +++ b/app/src/main/assets/txtTocRule.json @@ -31,7 +31,7 @@ "id": -5, "enable": false, "name": "数字(纯数字标题)", - "rule": "(?<=[ \\s])\\d+[  \\t]{0,4}$", + "rule": "(?<=[ \\s])\\d+\\.?[  \\t]{0,4}$", "serialNumber": 4 }, { From 796eb7b62776121a952987c0c5180c6a46452ae3 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 18:32:44 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/book/read/config/BgTextConfigDialog.kt | 2 +- .../main/res/layout/item_bookshelf_grid.xml | 51 +++++++------------ app/src/main/res/layout/view_no_book.xml | 6 +++ 3 files changed, 25 insertions(+), 34 deletions(-) create mode 100644 app/src/main/res/layout/view_no_book.xml diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt index 4b56b9aff..ab4f80c73 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt @@ -177,7 +177,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FileChooserDialog.CallBack { postEvent(EventBus.UP_CONFIG, true) dismiss() } else { - toast("数量以是最少,不能删除.") + toast("数量已是最少,不能删除.") } } } diff --git a/app/src/main/res/layout/item_bookshelf_grid.xml b/app/src/main/res/layout/item_bookshelf_grid.xml index 23aa8a37c..73c9b616a 100644 --- a/app/src/main/res/layout/item_bookshelf_grid.xml +++ b/app/src/main/res/layout/item_bookshelf_grid.xml @@ -4,46 +4,30 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingTop="2dp" - android:paddingRight="10dp" - android:paddingLeft="10dp" + android:paddingTop="8dp" + android:paddingRight="8dp" + android:paddingLeft="8dp" android:paddingBottom="4dp"> - - - - - + tools:ignore="UnusedAttribute" /> \ No newline at end of file diff --git a/app/src/main/res/layout/view_no_book.xml b/app/src/main/res/layout/view_no_book.xml new file mode 100644 index 000000000..77d9ef65f --- /dev/null +++ b/app/src/main/res/layout/view_no_book.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file From dbe566310fc1bb0801a220458837aaef3ea53618 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 19:01:24 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= 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 d756e531b..0670f92a0 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,10 @@ * 关注合作公众号 **[小说拾遗]()** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2020/10/14** +* 优化替换规则编辑界面 +* 修复网格书架间距变大bug + **2020/10/13** * 更新android studio 到 4.1 * 书架整理增加滑动选择 From 9223f807dd206fc1d52353292e43c0d527a9d1de Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 19:48:51 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/books/BooksFragment.kt | 9 ++++++- app/src/main/res/layout/fragment_books.xml | 25 +++++++++++++------ app/src/main/res/layout/view_empty.xml | 22 ++++++++++++++++ app/src/main/res/layout/view_no_book.xml | 6 ----- app/src/main/res/values-zh-rHK/strings.xml | 2 +- app/src/main/res/values-zh-rTW/strings.xml | 2 +- app/src/main/res/values-zh/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- 8 files changed, 52 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/layout/view_empty.xml delete mode 100644 app/src/main/res/layout/view_no_book.xml diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index c0004de15..9482e32fe 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -2,6 +2,7 @@ package io.legado.app.ui.main.bookshelf.books import android.os.Bundle import android.view.View +import androidx.core.view.isGone import androidx.lifecycle.LiveData import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.GridLayoutManager @@ -23,8 +24,12 @@ import io.legado.app.ui.audio.AudioPlayActivity import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.main.MainViewModel -import io.legado.app.utils.* +import io.legado.app.utils.getPrefInt +import io.legado.app.utils.getViewModelOfActivity +import io.legado.app.utils.observeEvent +import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_books.* +import kotlinx.android.synthetic.main.view_empty.* import org.jetbrains.anko.startActivity import kotlin.math.max @@ -55,6 +60,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), position = it.getInt("position", 0) groupId = it.getLong("groupId", -1) } + tv_empty_msg.setText(R.string.bookshelf_empty) initRecyclerView() upRecyclerData() } @@ -104,6 +110,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, { list -> + vw_empty.isGone = list.isNotEmpty() val books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime } 2 -> list.sortedBy { it.name } diff --git a/app/src/main/res/layout/fragment_books.xml b/app/src/main/res/layout/fragment_books.xml index 30f8ce74c..76a26a844 100644 --- a/app/src/main/res/layout/fragment_books.xml +++ b/app/src/main/res/layout/fragment_books.xml @@ -1,12 +1,23 @@ - + android:layout_height="match_parent" + xmlns:tools="http://schemas.android.com/tools"> - + android:layout_height="match_parent"> + + + + + + + + - \ No newline at end of file diff --git a/app/src/main/res/layout/view_empty.xml b/app/src/main/res/layout/view_empty.xml new file mode 100644 index 000000000..96eb611dd --- /dev/null +++ b/app/src/main/res/layout/view_empty.xml @@ -0,0 +1,22 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/view_no_book.xml b/app/src/main/res/layout/view_no_book.xml deleted file mode 100644 index 77d9ef65f..000000000 --- a/app/src/main/res/layout/view_no_book.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 7fb96aa3c..45d5d54bf 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -45,7 +45,7 @@ 最近閲讀 最後閲讀 更新日誌 - 書架還空着,快去添加吧! + 書架還空著,先去搜索書籍或從發現裏添加吧!\n如果初次使用請先關註公眾號[開源閱讀]獲取書源! 搜尋 下載 列表 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 2cfe6ff7a..8996f0491 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -45,7 +45,7 @@ 最近閱讀 最後閱讀 更新日誌 - 書架還空著,先去添加吧! + 書架還空著,先去搜索書籍或從發現裏添加吧!\n如果初次使用請先關註公眾號[開源閱讀]獲取書源! 搜尋 下載 列表 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index d9a62c811..3c473b05e 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -47,7 +47,7 @@ 最近阅读 最后阅读 更新日志 - 书架还空着,先去添加吧! + 书架还空着,先去搜索书籍或从发现里添加吧!\n如果初次使用请先关注公众号[开源阅读]获取书源! 搜索 下载 列表 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9186d4e20..ed78926eb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -48,7 +48,7 @@ Recent reading Last reading What\'s new - Still empty,please add it first. + The bookshelf is still empty. Search for books or add them from discovery! \n if you use it for the first time, please pay attention to the public account [开源阅读] to get the book source! Search Download List From cabcbb2512a05d000d996c8b7e9f682097329abb Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 20:30:48 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/books/BooksFragment.kt | 3 +-- .../app/ui/main/explore/ExploreFragment.kt | 3 +++ .../java/io/legado/app/ui/widget/TitleBar.kt | 27 ++++++++++--------- app/src/main/res/layout/fragment_books.xml | 10 ++++++- .../main/res/layout/fragment_find_book.xml | 23 +++++++++++++--- app/src/main/res/layout/item_find_book.xml | 3 ++- app/src/main/res/layout/view_empty.xml | 22 --------------- 7 files changed, 49 insertions(+), 42 deletions(-) delete mode 100644 app/src/main/res/layout/view_empty.xml diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 9482e32fe..216d6420c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -29,7 +29,6 @@ import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.observeEvent import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_books.* -import kotlinx.android.synthetic.main.view_empty.* import org.jetbrains.anko.startActivity import kotlin.math.max @@ -110,7 +109,7 @@ class BooksFragment : BaseFragment(R.layout.fragment_books), else -> App.db.bookDao().observeByGroup(groupId) } bookshelfLiveData?.observe(this, { list -> - vw_empty.isGone = list.isNotEmpty() + tv_empty_msg.isGone = list.isNotEmpty() val books = when (getPrefInt(PreferKey.bookshelfSort)) { 1 -> list.sortedByDescending { it.latestChapterTime } 2 -> list.sortedBy { it.name } diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index bceb905d1..610516a64 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -6,6 +6,7 @@ import android.view.MenuItem import android.view.SubMenu import android.view.View import androidx.appcompat.widget.SearchView +import androidx.core.view.isGone import androidx.lifecycle.LiveData import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.LinearLayoutManager @@ -43,6 +44,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) + tv_empty_msg.text = "当前没有发现源,关注公众号[开源阅读]添加带发现的书源!" initSearchView() initRecyclerView() initGroupData() @@ -111,6 +113,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ App.db.bookSourceDao().liveExplore("%$key%") } liveExplore?.observe(viewLifecycleOwner, { + tv_empty_msg.isGone = it.isNotEmpty() val diffResult = DiffUtil .calculateDiff(ExploreDiffCallBack(ArrayList(adapter.getItems()), it)) adapter.setItems(it) diff --git a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt index 39e1cd441..2143b4e48 100644 --- a/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/TitleBar.kt @@ -138,23 +138,24 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a } } - if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) { - topPadding = context.statusBarHeight - } + if (!isInEditMode) { + if (a.getBoolean(R.styleable.TitleBar_fitStatusBar, true)) { + topPadding = context.statusBarHeight + } - if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) { - bottomPadding = context.navigationBarHeight - } + if (a.getBoolean(R.styleable.TitleBar_fitNavigationBar, false)) { + bottomPadding = context.navigationBarHeight + } - backgroundColor = context.primaryColor + backgroundColor = context.primaryColor - stateListAnimator = null - elevation = if (AppConfig.elevation < 0) { - context.elevation - } else { - AppConfig.elevation.toFloat() + stateListAnimator = null + elevation = if (AppConfig.elevation < 0) { + context.elevation + } else { + AppConfig.elevation.toFloat() + } } - a.recycle() } diff --git a/app/src/main/res/layout/fragment_books.xml b/app/src/main/res/layout/fragment_books.xml index 76a26a844..9ad51b407 100644 --- a/app/src/main/res/layout/fragment_books.xml +++ b/app/src/main/res/layout/fragment_books.xml @@ -17,7 +17,15 @@ - + diff --git a/app/src/main/res/layout/fragment_find_book.xml b/app/src/main/res/layout/fragment_find_book.xml index 8609db403..826d713ad 100644 --- a/app/src/main/res/layout/fragment_find_book.xml +++ b/app/src/main/res/layout/fragment_find_book.xml @@ -1,6 +1,7 @@ - @@ -17,6 +18,22 @@ + android:layout_height="0dp" + app:layout_constraintTop_toBottomOf="@+id/title_bar" + app:layout_constraintBottom_toBottomOf="parent" + tools:listitem="@layout/item_find_book" /> - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_find_book.xml b/app/src/main/res/layout/item_find_book.xml index 5ee810333..61ce006c7 100644 --- a/app/src/main/res/layout/item_find_book.xml +++ b/app/src/main/res/layout/item_find_book.xml @@ -24,7 +24,8 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" - android:textColor="@color/primaryText" /> + android:textColor="@color/primaryText" + tools:text="起点中文" /> - - - - - \ No newline at end of file From b67bb916efd4974aa2bc8c35005b2fc81435d5e8 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 20:43:50 +0800 Subject: [PATCH 20/24] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/main/bookshelf/books/BooksFragment.kt | 4 ++- .../app/ui/main/explore/ExploreFragment.kt | 6 ++-- .../io/legado/app/ui/main/rss/RssFragment.kt | 8 +++-- app/src/main/res/layout/fragment_rss.xml | 30 +++++++++++++++---- app/src/main/res/layout/item_rss.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 9 files changed, 48 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt index 216d6420c..eec10578c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt @@ -32,7 +32,9 @@ import kotlinx.android.synthetic.main.fragment_books.* import org.jetbrains.anko.startActivity import kotlin.math.max - +/** + * 书架界面 + */ class BooksFragment : BaseFragment(R.layout.fragment_books), BaseBooksAdapter.CallBack { diff --git a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt index 610516a64..e1fb1c814 100644 --- a/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/explore/ExploreFragment.kt @@ -29,7 +29,9 @@ import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_title_bar.* import java.text.Collator - +/** + * 发现界面 + */ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_book), ExploreAdapter.CallBack { override val viewModel: ExploreViewModel @@ -44,7 +46,7 @@ class ExploreFragment : VMBaseFragment(R.layout.fragment_find_ override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) - tv_empty_msg.text = "当前没有发现源,关注公众号[开源阅读]添加带发现的书源!" + tv_empty_msg.setText(R.string.explore_empty) initSearchView() initRecyclerView() initGroupData() diff --git a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt index 82ccf867f..34e9f0dc5 100644 --- a/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/rss/RssFragment.kt @@ -4,7 +4,7 @@ import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View -import androidx.recyclerview.widget.GridLayoutManager +import androidx.core.view.isGone import io.legado.app.App import io.legado.app.R import io.legado.app.base.VMBaseFragment @@ -22,6 +22,9 @@ import io.legado.app.utils.startActivity import kotlinx.android.synthetic.main.fragment_rss.* import kotlinx.android.synthetic.main.view_title_bar.* +/** + * 订阅界面 + */ class RssFragment : VMBaseFragment(R.layout.fragment_rss), RssAdapter.CallBack { @@ -31,6 +34,7 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) + tv_empty_msg.setText(R.string.rss_source_empty) initRecyclerView() initData() } @@ -50,12 +54,12 @@ class RssFragment : VMBaseFragment(R.layout.fragment_rss), private fun initRecyclerView() { ATH.applyEdgeEffectColor(recycler_view) adapter = RssAdapter(requireContext(), this) - recycler_view.layoutManager = GridLayoutManager(requireContext(), 4) recycler_view.adapter = adapter } private fun initData() { App.db.rssSourceDao().liveEnabled().observe(viewLifecycleOwner, { + tv_empty_msg.isGone = it.isNotEmpty() if (it.isEmpty()) { getViewModelOfActivity(MainViewModel::class.java).initRss() } diff --git a/app/src/main/res/layout/fragment_rss.xml b/app/src/main/res/layout/fragment_rss.xml index f1469fbd7..6d4bfdeeb 100644 --- a/app/src/main/res/layout/fragment_rss.xml +++ b/app/src/main/res/layout/fragment_rss.xml @@ -1,20 +1,40 @@ - + android:layout_height="match_parent" + android:orientation="vertical"> + android:layout_height="0dp" + app:layout_constraintTop_toBottomOf="@id/title_bar" + app:layout_constraintBottom_toBottomOf="parent" + app:layoutManager="androidx.recyclerview.widget.GridLayoutManager" + app:spanCount="4" + tools:listitem="@layout/item_rss" /> - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_rss.xml b/app/src/main/res/layout/item_rss.xml index f3765bf58..3911221d6 100644 --- a/app/src/main/res/layout/item_rss.xml +++ b/app/src/main/res/layout/item_rss.xml @@ -1,6 +1,7 @@ @@ -24,6 +25,7 @@ android:gravity="top|center_horizontal" android:lines="2" android:ellipsize="end" + tools:text="RSS" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toBottomOf="@+id/iv_icon" /> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 45d5d54bf..b107331c7 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -767,5 +767,7 @@ 分享選中書源 時間排序 全文搜索 + 关注公众号[开源阅读]获取订阅源! + 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 8996f0491..f6ba89777 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -767,5 +767,7 @@ 分享選中書源 時間排序 全文搜尋 + 关注公众号[开源阅读]获取订阅源! + 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 3c473b05e..743147864 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -770,5 +770,7 @@ 切换默认主题 时间排序 全文搜索 + 关注公众号[开源阅读]获取订阅源! + 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ed78926eb..ad9af3df7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -773,5 +773,7 @@ Share selected sources Sort by update time Search content + 关注公众号[开源阅读]获取订阅源! + 当前没有发现源,关注公众号[开源阅读]添加带发现的书源! From d42d738d676627b562b3b7ed3d5de874b6c4cb43 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 21:13:09 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/BookHelp.kt | 5 ++--- .../java/io/legado/app/model/localBook/AnalyzeTxtFile.kt | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/BookHelp.kt b/app/src/main/java/io/legado/app/help/BookHelp.kt index 36a193fa0..ae992e696 100644 --- a/app/src/main/java/io/legado/app/help/BookHelp.kt +++ b/app/src/main/java/io/legado/app/help/BookHelp.kt @@ -322,11 +322,10 @@ object BookHelp { } val contents = arrayListOf() c.split("\n").forEach { - val str = it.replace("^\\s+".toRegex(), "") - .replace("\r", "") + val str = it.replace("^[\\n\\s\\r]+".toRegex(), "") if (contents.isEmpty()) { contents.add(title) - if (str != title && it.isNotEmpty()) { + if (str != title && str.isNotEmpty()) { contents.add("${ReadBookConfig.paragraphIndent}$str") } } else if (str.isNotEmpty()) { diff --git a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt index b7f1b015e..6dfa74594 100644 --- a/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt +++ b/app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt @@ -261,6 +261,8 @@ class AnalyzeTxtFile { bookStream.seek(bookChapter.start!!) bookStream.read(content) return String(content, book.fileCharset()) + .substringAfter(bookChapter.title) + .replace("^[\\n\\s]+".toRegex(), "  ") } private fun getBookFile(book: Book): File { From 0493a3f81a1f3ca6df805cfccd1620877e270b22 Mon Sep 17 00:00:00 2001 From: gedoor Date: Wed, 14 Oct 2020 21:19:05 +0800 Subject: [PATCH 22/24] update log --- app/src/main/assets/updateLog.md | 639 +------------------------------ 1 file changed, 21 insertions(+), 618 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 0670f92a0..a182e7c52 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/10/14** * 优化替换规则编辑界面 * 修复网格书架间距变大bug +* 其它一些优化,bug修复 **2020/10/13** * 更新android studio 到 4.1 @@ -115,16 +116,7 @@ getTxtInFolder(unzipPath: String): String **2020/09/02** * 搜索url支持put,get,js里使用java.put,java.get -* 对于搜索重定向的源,可以使用此方法获得重定向后的url -``` - -var url='https://www.yooread.net/e/search/index.php,'+JSON.stringify({ -"method":"POST", -"body":"show=title&tempid=1&keyboard="+key -}); -String(java.connect(url).raw().request().url()) - -``` + * 正文合并后替换规则支持所有规则写法,包括js **2020/09/01** @@ -134,11 +126,15 @@ String(java.connect(url).raw().request().url()) * 字体跟随背景,每个背景对应一个字体 * 优化图片下载 -**2020/08/29** -* 修复一个null引起的崩溃bug -* 修复我的界面滚动时图标消失的bug -* 修复从详情页目录打开章节内容不对的bug -* 书源选择增加滑动选择, 选择框区域滑动时进行选择 by [Mupceet](https://github.com/Mupceet) +**功能介绍** +* 书源调试 + - 调试搜索>>输入关键字,如:`系统` + - 调试发现>>输入发现URL,如:`月票榜::https://www.qidian.com/rank/yuepiao?page={{page}}` + - 调试详情页>>输入详情页URL,如:`https://m.qidian.com/book/1015609210` + - 调试目录页>>输入目录页URL,如:`++https://www.zhaishuyuan.com/read/30394` + - 调试正文页>>输入正文页URL,如:`--https://www.zhaishuyuan.com/chapter/30394/20940996` +* 修改订阅中自动添加style的情景 + 订阅源的内容规则中存在`