From ed96e3addd0e9e25415c11c9c52268a689b048c7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 19:04:52 +0800 Subject: [PATCH 01/44] =?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/info/BookInfoActivity.kt | 3 +-- .../java/io/legado/app/ui/widget/TitleBar.kt | 6 +++++ .../res/layout-land/activity_book_info.xml | 26 +++++++++---------- .../main/res/layout/activity_book_info.xml | 7 ++--- 4 files changed, 21 insertions(+), 21 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 bd9b3700f..4ea22d61c 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 @@ -57,8 +57,7 @@ class BookInfoActivity : get() = getViewModel(BookInfoViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - setSupportActionBar(toolbar) - supportActionBar?.setDisplayHomeAsUpEnabled(true) + title_bar.transparent() viewModel.bookData.observe(this, Observer { showBook(it) }) viewModel.chapterListData.observe(this, Observer { upLoading(false, it) }) viewModel.initData(intent) 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 663bb55a8..94d3b7be6 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 @@ -2,6 +2,7 @@ package io.legado.app.ui.widget import android.content.Context import android.content.res.ColorStateList +import android.graphics.Color import android.util.AttributeSet import android.view.Menu import android.view.View @@ -186,6 +187,11 @@ class TitleBar(context: Context, attrs: AttributeSet?) : AppBarLayout(context, a toolbar.setSubtitleTextAppearance(context, resId) } + fun transparent() { + elevation = 0f + backgroundColor = Color.TRANSPARENT + } + private fun attachToActivity() { if (attachToActivity) { activity?.let { diff --git a/app/src/main/res/layout-land/activity_book_info.xml b/app/src/main/res/layout-land/activity_book_info.xml index 27e0bec0d..1dc7d789c 100644 --- a/app/src/main/res/layout-land/activity_book_info.xml +++ b/app/src/main/res/layout-land/activity_book_info.xml @@ -14,13 +14,10 @@ android:contentDescription="@string/bg_image" app:layout_constraintTop_toTopOf="parent" /> - @@ -81,7 +78,8 @@ android:paddingLeft="10dp" android:paddingTop="8dp" android:paddingRight="16dp" - android:paddingBottom="3dp"> + android:paddingBottom="3dp" + tools:ignore="RtlHardcoded"> + android:scrollbars="vertical" + tools:ignore="NestedWeights"> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" /> @@ -290,7 +288,7 @@ android:text="@string/group_s" android:textColor="@color/tv_text_summary" android:textSize="13sp" - tools:ignore="NestedWeights" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" /> + tools:ignore="NestedWeights,RtlHardcoded,RtlSymmetry" /> + android:background="@color/background" /> - From 41e1afb05cae47755b431b917bb3058555d03ebb Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 19:09:23 +0800 Subject: [PATCH 02/44] =?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/drawable/ic_help.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/drawable/ic_help.xml b/app/src/main/res/drawable/ic_help.xml index d5ecd8235..32838437b 100644 --- a/app/src/main/res/drawable/ic_help.xml +++ b/app/src/main/res/drawable/ic_help.xml @@ -1,6 +1,6 @@ Date: Fri, 20 Mar 2020 19:17:12 +0800 Subject: [PATCH 03/44] =?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/audio/AudioPlayActivity.kt | 5 ++--- app/src/main/res/layout/activity_audio_play.xml | 11 ++++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt index bece64c93..3c960093b 100644 --- a/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/audio/AudioPlayActivity.kt @@ -46,9 +46,8 @@ class AudioPlayActivity : private var adjustProgress = false override fun onActivityCreated(savedInstanceState: Bundle?) { - setSupportActionBar(toolbar) - supportActionBar?.setDisplayHomeAsUpEnabled(true) - AudioPlay.titleData.observe(this, Observer { toolbar.title = it }) + title_bar.transparent() + AudioPlay.titleData.observe(this, Observer { title_bar.title = it }) AudioPlay.coverData.observe(this, Observer { upCover(it) }) viewModel.initData(intent) initView() diff --git a/app/src/main/res/layout/activity_audio_play.xml b/app/src/main/res/layout/activity_audio_play.xml index 7869b3b1c..71a7edfe8 100644 --- a/app/src/main/res/layout/activity_audio_play.xml +++ b/app/src/main/res/layout/activity_audio_play.xml @@ -21,13 +21,10 @@ android:layout_height="match_parent" android:background="#50000000" /> - + app:layout_constraintTop_toBottomOf="@+id/title_bar" /> Date: Fri, 20 Mar 2020 19:50:39 +0800 Subject: [PATCH 04/44] =?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/storage/Backup.kt | 48 +++++++++---------- .../book/source/manage/BookSourceViewModel.kt | 5 +- .../legado/app/ui/config/BackupRestoreUi.kt | 22 ++++----- .../ui/replacerule/ReplaceRuleViewModel.kt | 5 +- .../rss/source/manage/RssSourceViewModel.kt | 5 +- 5 files changed, 38 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/storage/Backup.kt b/app/src/main/java/io/legado/app/help/storage/Backup.kt index 32bc2b765..60d86d6a3 100644 --- a/app/src/main/java/io/legado/app/help/storage/Backup.kt +++ b/app/src/main/java/io/legado/app/help/storage/Backup.kt @@ -21,14 +21,6 @@ object Backup { FileUtils.getDirFile(App.INSTANCE.filesDir, "backup").absolutePath } - val legadoPath by lazy { - FileUtils.getSdCardPath() + File.separator + "YueDu3.0" - } - - val exportPath by lazy { - legadoPath + File.separator + "Export" - } - val backupFileNames by lazy { arrayOf( "bookshelf.json", "bookGroup.json", "bookSource.json", "rssSource.json", @@ -42,16 +34,13 @@ object Backup { return } Coroutine.async { - val backupPath = context.getPrefString(PreferKey.backupPath) - if (backupPath.isNullOrEmpty()) { - backup(context) - } else { - backup(context, backupPath) + context.getPrefString(PreferKey.backupPath)?.let { + backup(context, it, true) } } } - suspend fun backup(context: Context, path: String = legadoPath) { + suspend fun backup(context: Context, path: String, isAuto: Boolean = false) { context.putPrefLong(PreferKey.lastBackup, System.currentTimeMillis()) withContext(IO) { synchronized(this@Backup) { @@ -81,9 +70,9 @@ object Backup { } WebDavHelp.backUpWebDav(backupPath) if (path.isContentPath()) { - copyBackup(context, Uri.parse(path)) + copyBackup(context, Uri.parse(path), isAuto) } else { - copyBackup(File(path)) + copyBackup(File(path), isAuto) } } } @@ -97,28 +86,39 @@ object Backup { } @Throws(java.lang.Exception::class) - private fun copyBackup(context: Context, uri: Uri) { - + private fun copyBackup(context: Context, uri: Uri, isAuto: Boolean) { DocumentFile.fromTreeUri(context, uri)?.let { treeDoc -> for (fileName in backupFileNames) { val file = File(backupPath + File.separator + fileName) if (file.exists()) { - treeDoc.findFile(fileName)?.delete() - treeDoc.createFile("", fileName) - ?.writeBytes(context, file.readBytes()) + if (isAuto) { + treeDoc.findFile("auto")?.findFile(fileName)?.delete() + DocumentUtils.createFileIfNotExist( + treeDoc, + fileName, + subDirs = *arrayOf("auto") + )?.writeBytes(context, file.readBytes()) + } else { + treeDoc.findFile(fileName)?.delete() + treeDoc.createFile("", fileName) + ?.writeBytes(context, file.readBytes()) + } } } } } @Throws(java.lang.Exception::class) - private fun copyBackup(rootFile: File) { + private fun copyBackup(rootFile: File, isAuto: Boolean) { for (fileName in backupFileNames) { val file = File(backupPath + File.separator + fileName) if (file.exists()) { file.copyTo( - FileUtils.createFileIfNotExist(rootFile, fileName), - true + if (isAuto) { + FileUtils.createFileIfNotExist(rootFile, fileName, "auto") + } else { + FileUtils.createFileIfNotExist(rootFile, fileName) + }, true ) } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt index d44efd3ad..c84497536 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt @@ -8,7 +8,6 @@ import io.legado.app.App import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.BookSource import io.legado.app.help.http.HttpHelper -import io.legado.app.help.storage.Backup import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.Restore.jsonPath import io.legado.app.utils.* @@ -96,7 +95,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) FileUtils.createFileIfNotExist(file, "exportBookSource.json") .writeText(json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${file.absolutePath}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } @@ -109,7 +108,7 @@ class BookSourceViewModel(application: Application) : BaseViewModel(application) doc.createFile("", "exportBookSource.json") ?.writeText(context, json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${doc.uri.path}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } diff --git a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt index 409638a4c..c849ae1de 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt @@ -48,30 +48,24 @@ object BackupRestoreUi { selectBackupFolder(fragment, backupSelectRequestCode) } } else { - backupUsePermission(fragment, requestCode = backupSelectRequestCode) + backupUsePermission(fragment, backupPath) } } } private fun backupUsePermission( fragment: Fragment, - path: String = Backup.legadoPath, - requestCode: Int = selectFolderRequestCode + path: String ) { PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) .onGranted { - when (requestCode) { - selectFolderRequestCode -> AppConfig.backupPath = Backup.legadoPath - else -> { - Coroutine.async { - AppConfig.backupPath = path - Backup.backup(fragment.requireContext(), path) - }.onSuccess { - fragment.toast(R.string.backup_success) - } - } + Coroutine.async { + AppConfig.backupPath = path + Backup.backup(fragment.requireContext(), path) + }.onSuccess { + fragment.toast(R.string.backup_success) } } .request() @@ -107,7 +101,7 @@ object BackupRestoreUi { } } - private fun restoreUsePermission(fragment: Fragment, path: String = Backup.legadoPath) { + private fun restoreUsePermission(fragment: Fragment, path: String) { PermissionsCompat.Builder(fragment) .addPermissions(*Permissions.Group.STORAGE) .rationale(R.string.tip_perm_request_storage) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index a63d7ea38..7187c6b88 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -8,7 +8,6 @@ import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.http.HttpHelper -import io.legado.app.help.storage.Backup import io.legado.app.help.storage.ImportOldData import io.legado.app.utils.* import org.jetbrains.anko.toast @@ -93,7 +92,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application FileUtils.createFileIfNotExist(file, "exportReplaceRule.json") .writeText(json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${file.absolutePath}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } @@ -106,7 +105,7 @@ class ReplaceRuleViewModel(application: Application) : BaseViewModel(application doc.createFile("", "exportReplaceRule.json") ?.writeText(context, json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${doc.uri.path}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt index 82bad9584..300d7468c 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceViewModel.kt @@ -9,7 +9,6 @@ import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.RssSource import io.legado.app.help.http.HttpHelper -import io.legado.app.help.storage.Backup import io.legado.app.help.storage.Restore.jsonPath import io.legado.app.utils.* import org.jetbrains.anko.toast @@ -74,7 +73,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) FileUtils.createFileIfNotExist(file, "exportRssSource.json") .writeText(json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${file.absolutePath}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } @@ -87,7 +86,7 @@ class RssSourceViewModel(application: Application) : BaseViewModel(application) doc.createFile("", "exportRssSource.json") ?.writeText(context, json) }.onSuccess { - context.toast("成功导出至\n${Backup.exportPath}") + context.toast("成功导出至\n${doc.uri.path}") }.onError { context.toast("导出失败\n${it.localizedMessage}") } From 19ce729b2f5a606f95a8d4acdbb8faf3668786ab Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 20:00:03 +0800 Subject: [PATCH 05/44] =?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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index cb38140fe..cff4f10ba 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 请关注[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来 +**2020/03/20** +* 自动备份文件和手动备份文件分开存储 + **2020/03/19** * 美化界面我的 by yangyxd * 优化搜索 From 8297cdb6d41a7df9b8da0ff1211632a1abf9d7e8 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 20:41:03 +0800 Subject: [PATCH 06/44] =?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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index cff4f10ba..7da858d27 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -4,7 +4,7 @@ * 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来 **2020/03/20** -* 自动备份文件和手动备份文件分开存储 +* 自动备份文件和手动备份文件分开 **2020/03/19** * 美化界面我的 by yangyxd From bc0a3abf56197ed1414e19f239971225cc745bb2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 20:58:12 +0800 Subject: [PATCH 07/44] =?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/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index f2d9e96cf..7dadb803b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -136,12 +136,12 @@ dependencies { implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version" //room - def room_version = '2.2.4' + def room_version = '2.2.5' implementation "androidx.room:room-runtime:$room_version" kapt "androidx.room:room-compiler:$room_version" //paging - implementation 'androidx.paging:paging-runtime:2.1.1' + implementation 'androidx.paging:paging-runtime:2.1.2' //anko def anko_version = '0.10.8' From c06be92a26050295ef48d63a23bbfcb6220fd98d Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 21:20:55 +0800 Subject: [PATCH 08/44] =?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/data/entities/RssStar.kt | 14 ++++++++++++- .../legado/app/ui/rss/read/ReadRssActivity.kt | 2 +- .../app/ui/rss/read/ReadRssViewModel.kt | 20 +++++++++---------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/RssStar.kt b/app/src/main/java/io/legado/app/data/entities/RssStar.kt index 5199b586d..1d0c266f8 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssStar.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssStar.kt @@ -16,4 +16,16 @@ data class RssStar( var description: String? = null, var content: String? = null, var image: String? = null -) \ No newline at end of file +) { + fun toRssArticle(): RssArticle { + return RssArticle( + origin = origin, + title = title, + link = link, + pubDate = pubDate, + description = description, + content = content, + image = image + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index 9aa30235b..73c55961b 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -193,7 +193,7 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r } override fun upStarMenu() { - if (viewModel.star) { + if (viewModel.rssStar != null) { starMenuItem?.setIcon(R.drawable.ic_star) starMenuItem?.setTitle(R.string.in_favorites) } else { diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index fd721e09b..cf8cafeef 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -15,6 +15,7 @@ import io.legado.app.base.BaseViewModel import io.legado.app.constant.AppConst import io.legado.app.data.entities.RssArticle import io.legado.app.data.entities.RssSource +import io.legado.app.data.entities.RssStar import io.legado.app.help.http.HttpHelper import io.legado.app.model.Rss import io.legado.app.model.analyzeRule.AnalyzeUrl @@ -34,7 +35,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), var rssArticle: RssArticle? = null val contentLiveData = MutableLiveData() val urlLiveData = MutableLiveData() - var star = false + var rssStar: RssStar? = null var textToSpeech: TextToSpeech? = null private var ttsInitFinish = false private var ttsTextList = arrayListOf() @@ -45,8 +46,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), val link = intent.getStringExtra("link") if (origin != null && link != null) { rssSource = App.db.rssSourceDao().getByKey(origin) - star = App.db.rssStarDao().get(origin, link) != null - rssArticle = App.db.rssArticleDao().get(origin, link) + rssStar = App.db.rssStarDao().get(origin, link) + rssArticle = rssStar?.toRssArticle() ?: App.db.rssArticleDao().get(origin, link) rssArticle?.let { rssArticle -> if (!rssArticle.description.isNullOrBlank()) { contentLiveData.postValue(rssArticle.description) @@ -86,13 +87,12 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), fun favorite() { execute { - rssArticle?.let { - if (star) { - App.db.rssStarDao().delete(it.origin, it.link) - } else { - App.db.rssStarDao().insert(it.toStar()) - } - star = !star + rssStar?.let { + App.db.rssStarDao().delete(it.origin, it.link) + rssStar = null + } ?: rssArticle?.toStar()?.let { + App.db.rssStarDao().insert(it) + rssStar = it } }.onSuccess { callBack?.upStarMenu() From a35708f7c6132c1201a8a8103528cec00b678fbe Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 21:21:44 +0800 Subject: [PATCH 09/44] =?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 7da858d27..eb04b0e7a 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -5,6 +5,7 @@ **2020/03/20** * 自动备份文件和手动备份文件分开 +* 修复一些rss收藏取消不了的bug **2020/03/19** * 美化界面我的 by yangyxd From 5bcba9e1cf978b69d41e9683475bfb688d489ed3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 21:27:19 +0800 Subject: [PATCH 10/44] =?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/model/webBook/BookContent.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt index 568615aa1..873b6b3a9 100644 --- a/app/src/main/java/io/legado/app/model/webBook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webBook/BookContent.kt @@ -2,6 +2,7 @@ package io.legado.app.model.webBook import io.legado.app.App import io.legado.app.R +import io.legado.app.constant.BookType import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookSource @@ -39,7 +40,12 @@ object BookContent { var contentData = analyzeContent( book, baseUrl, body, contentRule, bookChapter, bookSource ) - content.append(contentData.content.replace(bookChapter.title, "")).append("\n") + if (bookSource.bookSourceType == BookType.default) { + content.append(contentData.content.replace(bookChapter.title, "")).append("\n") + } else { + content.append(contentData.content).append("\n") + } + if (contentData.nextUrl.size == 1) { var nextUrl = contentData.nextUrl[0] val nextChapterUrl = if (!nextChapterUrlF.isNullOrEmpty()) From 325bf9adb3646d7b453d34c7315d563441b675d7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 22:09:45 +0800 Subject: [PATCH 11/44] =?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/model/Rss.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index b3622b40b..b4a4b5153 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -21,7 +21,10 @@ object Rss { context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - val analyzeUrl = AnalyzeUrl(pageUrl ?: rssSource.sourceUrl) + val analyzeUrl = AnalyzeUrl( + pageUrl ?: rssSource.sourceUrl, + headerMapF = rssSource.getHeaderMap() + ) val body = analyzeUrl.getResponseAwait(rssSource.sourceUrl).body RssParserByRule.parseXML(body, rssSource) } From b02b7ffa0e6682bfa916d89848c5b180b20cc742 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 22:17:51 +0800 Subject: [PATCH 12/44] =?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/model/Debug.kt | 6 +++--- app/src/main/java/io/legado/app/model/Rss.kt | 7 +++++-- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 13 ++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 2acd8ac9e..51ae12afd 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -67,7 +67,7 @@ object Debug { if (ruleContent.isNullOrEmpty()) { log(debugSource, "⇒内容规则为空,默认获取整个网页", state = 1000) } else { - rssContentDebug(it.articles[0], ruleContent) + rssContentDebug(it.articles[0], ruleContent, rssSource) } } else { log(debugSource, "⇒存在描述规则,不解析内容页") @@ -80,9 +80,9 @@ object Debug { } } - private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String) { + private fun rssContentDebug(rssArticle: RssArticle, ruleContent: String, rssSource: RssSource) { log(debugSource, "︾开始解析内容页") - Rss.getContent(rssArticle, ruleContent) + Rss.getContent(rssArticle, ruleContent, rssSource) .onSuccess { log(debugSource, it) log(debugSource, "︽内容页解析完成", state = 1000) diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index b4a4b5153..24dadade0 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -33,12 +33,15 @@ object Rss { fun getContent( rssArticle: RssArticle, ruleContent: String, + rssSource: RssSource?, scope: CoroutineScope = Coroutine.DEFAULT, context: CoroutineContext = Dispatchers.IO ): Coroutine { return Coroutine.async(scope, context) { - val body = AnalyzeUrl(rssArticle.link, baseUrl = rssArticle.origin) - .getResponseAwait(rssArticle.origin) + val body = AnalyzeUrl( + rssArticle.link, baseUrl = rssArticle.origin, + headerMapF = rssSource?.getHeaderMap() + ).getResponseAwait(rssArticle.origin) .body val analyzeRule = AnalyzeRule() analyzeRule.setContent( diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index cf8cafeef..f5b84642f 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -23,6 +23,7 @@ import io.legado.app.utils.DocumentUtils import io.legado.app.utils.FileUtils import io.legado.app.utils.isContentPath import io.legado.app.utils.writeBytes +import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.launch import java.io.File import java.util.* @@ -79,9 +80,15 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } private fun loadContent(rssArticle: RssArticle, ruleContent: String) { - Rss.getContent(rssArticle, ruleContent, this) - .onSuccess { - contentLiveData.postValue(it) + Rss.getContent(rssArticle, ruleContent, rssSource, this) + .onSuccess(IO) { body -> + rssArticle.description = body + App.db.rssArticleDao().insert(rssArticle) + rssStar?.let { + it.description = body + App.db.rssStarDao().insert(it) + } + contentLiveData.postValue(body) } } From 806caa71439d3a00ab04714a2779f3db56ea2747 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 20 Mar 2020 22:19:00 +0800 Subject: [PATCH 13/44] =?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 eb04b0e7a..14e08cf02 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -6,6 +6,7 @@ **2020/03/20** * 自动备份文件和手动备份文件分开 * 修复一些rss收藏取消不了的bug +* 修复rss请求头无效bug **2020/03/19** * 美化界面我的 by yangyxd From 5660af2da59c81f5b8c0a62498e2fe231821b68e Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 21 Mar 2020 17:39:21 +0800 Subject: [PATCH 14/44] =?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/ui/book/info/BookInfoActivity.kt | 3 +++ 1 file changed, 3 insertions(+) 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 4ea22d61c..e0b6f275a 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 @@ -230,6 +230,9 @@ class BookInfoActivity : tv_author.onClick { startActivity(Pair("key", viewModel.bookData.value?.author)) } + tv_name.onClick { + startActivity(Pair("key", viewModel.bookData.value?.name)) + } } @SuppressLint("InflateParams") From 5778ae41d726832f6ca4e9bbd21408d907059085 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 21 Mar 2020 17:40:31 +0800 Subject: [PATCH 15/44] =?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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 14e08cf02..d767bdc71 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 请关注[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来 +**2020/03/21** +* 详情页点击书名搜索 + **2020/03/20** * 自动备份文件和手动备份文件分开 * 修复一些rss收藏取消不了的bug From 7004b47898e5533b4f9c887bd06241f24b4af281 Mon Sep 17 00:00:00 2001 From: wqfantexi Date: Sat, 21 Mar 2020 20:31:03 +0800 Subject: [PATCH 16/44] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 12 +++- .../book/source/manage/BookSourceActivity.kt | 10 +++- .../legado/app/ui/config/FileAssociation.kt | 37 ++++++++++++ .../app/ui/config/FileAssociationViewModel.kt | 60 +++++++++++++++++++ .../app/ui/replacerule/ReplaceRuleActivity.kt | 11 +++- .../ui/replacerule/ReplaceRuleViewModel.kt | 17 +++++- .../ui/rss/source/manage/RssSourceActivity.kt | 11 +++- .../res/layout/activity_file_association.xml | 9 +++ 8 files changed, 159 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/config/FileAssociation.kt create mode 100644 app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt create mode 100644 app/src/main/res/layout/activity_file_association.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9d778fbb3..71fa00c62 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -244,7 +244,17 @@ - + + + + + + + + + + + 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 385088640..d3cb63af3 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 @@ -104,8 +104,14 @@ class BookSourceActivity : VMBaseActivity(R.layout.activity when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() - viewModel.importSource(url) { msg -> - title_bar.snackbar(msg) + if (url.startsWith("http", false)){ + viewModel.importSource(url) { msg -> + title_bar.snackbar(msg) + } + } + else{ + viewModel.importSourceFromFilePath(url){msg -> + title_bar.snackbar(msg)} } } else -> { diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt new file mode 100644 index 000000000..0b2a3c749 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt @@ -0,0 +1,37 @@ +package io.legado.app.ui.config + +import android.content.Intent +import android.os.Bundle +import io.legado.app.R +import io.legado.app.base.VMBaseActivity +import io.legado.app.ui.main.MainActivity +import io.legado.app.utils.getViewModel + + +class FileAssociation : VMBaseActivity(R.layout.activity_file_association) { + override val viewModel: FileAssociationViewModel + get() = getViewModel(FileAssociationViewModel::class.java) + + override fun onActivityCreated(savedInstanceState: Bundle?) { + if (null != intent.data){ + val newIntent = viewModel.dispatchIndent(intent.data!!) + if (newIntent != null){ + this.startActivityForResult(newIntent, 100) + }else{ + gotoMainActivity() + } + } + } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + + //返回后直接跳转到主页面 + gotoMainActivity() + } + + private fun gotoMainActivity(){ + val mIntent = Intent() + mIntent.setClass(this, MainActivity::class.java) + startActivity(mIntent) + } +} diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt new file mode 100644 index 000000000..4a09b4325 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -0,0 +1,60 @@ +package io.legado.app.ui.config + +import android.app.Application +import android.content.Intent +import android.net.Uri +import android.text.TextUtils +import io.legado.app.base.BaseViewModel +import io.legado.app.model.localBook.LocalBook +import io.legado.app.utils.isJsonArray +import io.legado.app.utils.isJsonObject +import org.jetbrains.anko.toast +import java.io.File + +class FileAssociationViewModel(application: Application) : BaseViewModel(application) { + fun dispatchIndent(uri:Uri):Intent?{ + var url = ""; + //如果是普通的url,需要根据返回的内容判断是什么 + if(uri.scheme == "file" || uri.scheme == "content"){ + val file = File(uri.path.toString()) + var scheme = "" + if (file.exists()) { + val content = file.readText() + if (content.isJsonObject() || content.isJsonArray()){ + //暂时根据文件内容判断属于什么 + if (content.contains("bookSourceUrl")){ + scheme = "booksource" + }else if (content.contains("sourceUrl")){ + scheme = "rsssource" + }else if (content.contains("pattern")){ + scheme = "replace" + } + } + if (TextUtils.isEmpty(scheme)){ + execute{ + LocalBook.importFile(uri.path.toString()) + toast("添加本地文件成功${uri.path}") + } + + return null + } + } + else{ + toast("文件不存在") + return null + } + + url = "yuedu://${scheme}/importonline?src=${uri.path}" + } + else if (uri.scheme == "yuedu"){ + url = uri.toString() + } + else{ + url = "yuedu://booksource/importonline?src=${uri.path}" + } + val data = Uri.parse(url) + val newIndent = Intent(Intent.ACTION_VIEW) + newIndent.data = data; + return newIndent + } +} \ No newline at end of file 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 fd0a591b6..1f9057e35 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 @@ -81,8 +81,15 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() - viewModel.importSource(url) { msg -> - title_bar.snackbar(msg) + if (url.startsWith("http", false)){ + viewModel.importSource(url) { msg -> + title_bar.snackbar(msg) + } + } + else{ + viewModel.importSourceFromFilePath(url) { msg -> + title_bar.snackbar(msg) + } } } else -> { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt index a63d7ea38..8f0e848f0 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleViewModel.kt @@ -11,11 +11,26 @@ import io.legado.app.help.http.HttpHelper import io.legado.app.help.storage.Backup import io.legado.app.help.storage.ImportOldData import io.legado.app.utils.* +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext import org.jetbrains.anko.toast import java.io.File class ReplaceRuleViewModel(application: Application) : BaseViewModel(application) { - + fun importSourceFromFilePath(path: String, finally: (msg: String) -> Unit) { + execute { + val file = File(path) + if (file.exists()) { + importSource(file.readText(), finally) + } else { + withContext(Dispatchers.Main) { + finally("打开文件出错") + } + } + }.onError { + finally(it.localizedMessage ?: "打开文件出错") + } + } fun importSource(text: String, showMsg: (msg: String) -> Unit) { execute { if (text.isAbsUrl()) { diff --git a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt index fb54d0cae..1f7503e47 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt @@ -117,8 +117,15 @@ class RssSourceActivity : VMBaseActivity(R.layout.activity_r when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> Snackbar.make(title_bar, R.string.importing, Snackbar.LENGTH_INDEFINITE).show() - viewModel.importSource(url) { msg -> - title_bar.snackbar(msg) + if (url.startsWith("http", false)){ + viewModel.importSource(url) { msg -> + title_bar.snackbar(msg) + } + } + else{ + viewModel.importSourceFromFilePath(url) { msg -> + title_bar.snackbar(msg) + } } } else -> { diff --git a/app/src/main/res/layout/activity_file_association.xml b/app/src/main/res/layout/activity_file_association.xml new file mode 100644 index 000000000..5c147517b --- /dev/null +++ b/app/src/main/res/layout/activity_file_association.xml @@ -0,0 +1,9 @@ + + + + From a98ed055f63e9d683acbea1370f62e1f073b3049 Mon Sep 17 00:00:00 2001 From: wqfantexi Date: Sat, 21 Mar 2020 21:16:28 +0800 Subject: [PATCH 17/44] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=AD=A6=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/ui/config/FileAssociationViewModel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index 4a09b4325..810c885f6 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -13,7 +13,7 @@ import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { fun dispatchIndent(uri:Uri):Intent?{ - var url = ""; + val url:String //如果是普通的url,需要根据返回的内容判断是什么 if(uri.scheme == "file" || uri.scheme == "content"){ val file = File(uri.path.toString()) From 9a0d5f3975a4618b954ed6ce1658ef9f39a8e2d1 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:15:04 +0800 Subject: [PATCH 18/44] =?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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index d767bdc71..37586e6fa 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 请关注[开源阅读]()支持我,同时关注合作公众号[小说拾遗](),阅读公众号小编。 * 弄了个企业公众号[开源阅读](),后面弄好后会把原来的[开源阅读软件]()迁移过来 +**2020/03/21** +* 添加文件关联 by wqfantexi + **2020/03/21** * 详情页点击书名搜索 From 7f5d9435ca372931d7a2c348e8d4dc62c3eddb80 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:16:06 +0800 Subject: [PATCH 19/44] =?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/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b408eb6b9..ef44bed69 100644 --- a/app/src/main/java/io/legado/app/ui/README.md +++ b/app/src/main/java/io/legado/app/ui/README.md @@ -6,7 +6,7 @@ * book\info 书籍信息查看 * book\read 书籍阅读界面 * book\search 搜索书籍界面 -* book\source 搜索书源界面 +* book\source 书源界面 * book\changeCover 封面换源界面 * book\changeSource 换源界面 * book\chapterList 目录界面 From 77c3263ddbec38a2d2a7bd2e5a4585bd390e8056 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:19:58 +0800 Subject: [PATCH 20/44] =?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 --- .../legado/app/ui/config/FileAssociation.kt | 14 ++++++++------ .../app/ui/config/FileAssociationViewModel.kt | 19 +++++++++++-------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt index 0b2a3c749..9e459a226 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt @@ -8,20 +8,22 @@ import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel -class FileAssociation : VMBaseActivity(R.layout.activity_file_association) { +class FileAssociation : + VMBaseActivity(R.layout.activity_file_association) { override val viewModel: FileAssociationViewModel get() = getViewModel(FileAssociationViewModel::class.java) override fun onActivityCreated(savedInstanceState: Bundle?) { - if (null != intent.data){ - val newIntent = viewModel.dispatchIndent(intent.data!!) - if (newIntent != null){ + intent.data?.let { data -> + val newIntent = viewModel.dispatchIndent(data) + if (newIntent != null) { this.startActivityForResult(newIntent, 100) - }else{ + } else { gotoMainActivity() } } } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) @@ -29,7 +31,7 @@ class FileAssociation : VMBaseActivity(R.layout.activi gotoMainActivity() } - private fun gotoMainActivity(){ + private fun gotoMainActivity() { val mIntent = Intent() mIntent.setClass(this, MainActivity::class.java) startActivity(mIntent) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index 810c885f6..11705c537 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -8,7 +8,6 @@ import io.legado.app.base.BaseViewModel import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonObject -import org.jetbrains.anko.toast import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { @@ -22,12 +21,16 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica val content = file.readText() if (content.isJsonObject() || content.isJsonArray()){ //暂时根据文件内容判断属于什么 - if (content.contains("bookSourceUrl")){ - scheme = "booksource" - }else if (content.contains("sourceUrl")){ - scheme = "rsssource" - }else if (content.contains("pattern")){ - scheme = "replace" + when { + content.contains("bookSourceUrl") -> { + scheme = "booksource" + } + content.contains("sourceUrl") -> { + scheme = "rsssource" + } + content.contains("pattern") -> { + scheme = "replace" + } } } if (TextUtils.isEmpty(scheme)){ @@ -54,7 +57,7 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica } val data = Uri.parse(url) val newIndent = Intent(Intent.ACTION_VIEW) - newIndent.data = data; + newIndent.data = data return newIndent } } \ No newline at end of file From 00c757582f7051683e9d825243f722df5cd5e3c3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:40:44 +0800 Subject: [PATCH 21/44] =?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/config/FileAssociationViewModel.kt | 76 +++++++++---------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index 11705c537..bed99c025 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -11,53 +11,49 @@ import io.legado.app.utils.isJsonObject import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { - fun dispatchIndent(uri:Uri):Intent?{ - val url:String - //如果是普通的url,需要根据返回的内容判断是什么 - if(uri.scheme == "file" || uri.scheme == "content"){ - val file = File(uri.path.toString()) - var scheme = "" - if (file.exists()) { - val content = file.readText() - if (content.isJsonObject() || content.isJsonArray()){ - //暂时根据文件内容判断属于什么 - when { - content.contains("bookSourceUrl") -> { - scheme = "booksource" - } - content.contains("sourceUrl") -> { - scheme = "rsssource" - } - content.contains("pattern") -> { - scheme = "replace" - } + fun dispatchIndent(uri: Uri): Intent? { + val url: String + //如果是普通的url,需要根据返回的内容判断是什么 + if (uri.scheme == "file" || uri.scheme == "content") { + val file = File(uri.path.toString()) + var scheme = "" + if (file.exists()) { + val content = file.readText() + if (content.isJsonObject() || content.isJsonArray()) { + //暂时根据文件内容判断属于什么 + when { + content.contains("bookSourceUrl") -> { + scheme = "booksource" } - } - if (TextUtils.isEmpty(scheme)){ - execute{ - LocalBook.importFile(uri.path.toString()) - toast("添加本地文件成功${uri.path}") + content.contains("sourceUrl") -> { + scheme = "rsssource" + } + content.contains("pattern") -> { + scheme = "replace" } - - return null } } - else{ - toast("文件不存在") + if (TextUtils.isEmpty(scheme)) { + execute { + LocalBook.importFile(uri.path.toString()) + toast("添加本地文件成功${uri.path}") + } return null } - - url = "yuedu://${scheme}/importonline?src=${uri.path}" - } - else if (uri.scheme == "yuedu"){ - url = uri.toString() + } else { + toast("文件不存在") + return null } - else{ - url = "yuedu://booksource/importonline?src=${uri.path}" - } - val data = Uri.parse(url) - val newIndent = Intent(Intent.ACTION_VIEW) + + url = "yuedu://${scheme}/importonline?src=${uri.path}" + } else if (uri.scheme == "yuedu") { + url = uri.toString() + } else { + url = "yuedu://booksource/importonline?src=${uri.path}" + } + val data = Uri.parse(url) + val newIndent = Intent(Intent.ACTION_VIEW) newIndent.data = data - return newIndent + return newIndent } } \ No newline at end of file From 08f59704636d2bb0ecb1f07dcd1b8225b367912d Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 10:56:45 +0800 Subject: [PATCH 22/44] =?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/config/FileAssociationViewModel.kt | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt index bed99c025..80db1af37 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationViewModel.kt @@ -4,10 +4,12 @@ import android.app.Application import android.content.Intent import android.net.Uri import android.text.TextUtils +import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel import io.legado.app.model.localBook.LocalBook import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonObject +import io.legado.app.utils.readText import java.io.File class FileAssociationViewModel(application: Application) : BaseViewModel(application) { @@ -15,10 +17,18 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica val url: String //如果是普通的url,需要根据返回的内容判断是什么 if (uri.scheme == "file" || uri.scheme == "content") { - val file = File(uri.path.toString()) + val content = if (uri.scheme == "file") { + val file = File(uri.path.toString()) + if (file.exists()) { + file.readText() + } else { + null + } + } else { + DocumentFile.fromSingleUri(context, uri)?.readText(context) + } var scheme = "" - if (file.exists()) { - val content = file.readText() + if (content != null) { if (content.isJsonObject() || content.isJsonArray()) { //暂时根据文件内容判断属于什么 when { From df408c67115d79d666c4ddd38fbf2d0820dca332 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 11:49:34 +0800 Subject: [PATCH 23/44] =?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/AndroidManifest.xml | 4 +++- .../config/{FileAssociation.kt => FileAssociationActivity.kt} | 2 +- app/src/main/res/layout/activity_file_association.xml | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) rename app/src/main/java/io/legado/app/ui/config/{FileAssociation.kt => FileAssociationActivity.kt} (97%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a8ae915ff..cfb6793b8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -287,7 +287,9 @@ - + diff --git a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt b/app/src/main/java/io/legado/app/ui/config/FileAssociationActivity.kt similarity index 97% rename from app/src/main/java/io/legado/app/ui/config/FileAssociation.kt rename to app/src/main/java/io/legado/app/ui/config/FileAssociationActivity.kt index 9e459a226..80390c639 100644 --- a/app/src/main/java/io/legado/app/ui/config/FileAssociation.kt +++ b/app/src/main/java/io/legado/app/ui/config/FileAssociationActivity.kt @@ -8,7 +8,7 @@ import io.legado.app.ui.main.MainActivity import io.legado.app.utils.getViewModel -class FileAssociation : +class FileAssociationActivity : VMBaseActivity(R.layout.activity_file_association) { override val viewModel: FileAssociationViewModel get() = getViewModel(FileAssociationViewModel::class.java) diff --git a/app/src/main/res/layout/activity_file_association.xml b/app/src/main/res/layout/activity_file_association.xml index 5c147517b..2a7adee89 100644 --- a/app/src/main/res/layout/activity_file_association.xml +++ b/app/src/main/res/layout/activity_file_association.xml @@ -1,9 +1,8 @@ + tools:context="io.legado.app.ui.config.FileAssociationActivity"> From a43b730ed4b2a1684c2053c34f347ce7fb62c72f Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 12:46:29 +0800 Subject: [PATCH 24/44] =?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/utils/EncodingDetect.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/java/io/legado/app/utils/EncodingDetect.java b/app/src/main/java/io/legado/app/utils/EncodingDetect.java index 29174b88e..b5bd4cf66 100644 --- a/app/src/main/java/io/legado/app/utils/EncodingDetect.java +++ b/app/src/main/java/io/legado/app/utils/EncodingDetect.java @@ -66,7 +66,7 @@ public class EncodingDetect { } public static String getEncode(@NonNull byte[] bytes) { - int len = bytes.length > 2000 ? 2000 : bytes.length; + int len = Math.min(bytes.length, 2000); byte[] cBytes = new byte[len]; System.arraycopy(bytes, 0, cBytes, 0, len); BytesEncodingDetect bytesEncodingDetect = new BytesEncodingDetect(); @@ -1010,14 +1010,8 @@ class BytesEncodingDetect extends Encoding { column = rawtext[i + 1] + 256; if (column < 0x9f) { adjust = 1; - if (column > 0x7f) { - column -= 0x20; - } else { - column -= 0x19; - } } else { adjust = 0; - column -= 0x7e; } if (row < 0xa0) { row = ((row - 0x70) << 1) - adjust; From 44183959c5f6132f4b287c339fae528f37ab57ba Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 12:56:23 +0800 Subject: [PATCH 25/44] =?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-night/colors.xml | 2 +- app/src/main/res/values/colors.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/values-night/colors.xml b/app/src/main/res/values-night/colors.xml index 8ac7aa66a..eb9189f7a 100644 --- a/app/src/main/res/values-night/colors.xml +++ b/app/src/main/res/values-night/colors.xml @@ -7,7 +7,7 @@ @color/md_grey_900 @color/md_grey_850 @color/md_grey_800 - #10303030 + #10ffffff #69000000 diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 0fe64b7ca..91906845e 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -16,7 +16,7 @@ @color/md_grey_50 @color/md_grey_100 @color/md_grey_200 - @color/md_grey_50 + #10000000 #00000000 #10000000 From fd00bf2509d42d5d1f1667dc60bdb4e928e8a392 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 22 Mar 2020 13:11:41 +0800 Subject: [PATCH 26/44] =?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 | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index 37586e6fa..5e5d52454 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -269,14 +269,7 @@ - 调试正文页>>输入正文页URL,如:`--https://www.zhaishuyuan.com/chapter/30394/20940996` * 修改订阅中自动添加style的情景 - 订阅源的内容规则中存在` - ``` + 订阅源的内容规则中存在`