From 67713281190cf2081d96aa9f32d8810dbc275d27 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 26 Mar 2021 22:51:52 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epublib/build.gradle | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/epublib/build.gradle b/epublib/build.gradle index 176ef0013..cdded11c1 100644 --- a/epublib/build.gradle +++ b/epublib/build.gradle @@ -21,6 +21,8 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } + android { + } } compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 @@ -30,11 +32,4 @@ android { dependencies { - //因为安卓自带的XmlPullParserFactory - //me.ag2s.epublib.epub.EpubProcessorSupport - //修改createXmlSerializer方法可使用kxml2 - // https://mvnrepository.com/artifact/kxml2/kxml2 - //implementation 'kxml2:kxml2:2.3.0' - //去除了slf4j依赖 - //implementation 'org.slf4j:-android:1.7.25' } \ No newline at end of file From 6fbcce8af231420d1d0bc068becc6cc980f34b67 Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 26 Mar 2021 22:52:54 +0800 Subject: [PATCH 2/7] =?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 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/assets/updateLog.md b/app/src/main/assets/updateLog.md index cb8557c7b..9f3784cbf 100644 --- a/app/src/main/assets/updateLog.md +++ b/app/src/main/assets/updateLog.md @@ -3,6 +3,9 @@ * 关注合作公众号 **[小说拾遗]** 获取好看的小说。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 +**2021/03/26** +* 优化epubLib by ag2s20150909 + **2021/03/23** * 修复繁简转换“勐”“十”问题。使用了剥离HanLP简繁代码的民间库。APK减少6M左右 * js添加一个并发访问的方法 java.ajaxAll(urlList: Array) 返回 Array From 4ff399b4bb3785a759f509c1bc2ce9867905dbe5 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 00:42:11 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 35 ++++++++++- .../association/FileAssociationViewModel.kt | 59 ++++++++++++------- .../association/ImportBookSourceActivity.kt | 10 +--- .../association/ImportBookSourceViewModel.kt | 33 +---------- 4 files changed, 74 insertions(+), 63 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 85914dd9d..8e07090d0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -367,16 +367,47 @@ android:name=".ui.association.FileAssociationActivity" android:launchMode="singleTop" android:theme="@style/AppTheme.Transparent"> + + + - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt index a230b4450..4885e8ffc 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt @@ -6,6 +6,7 @@ import android.net.Uri import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import io.legado.app.base.BaseViewModel +import io.legado.app.help.IntentDataHelp import io.legado.app.model.localBook.LocalBook import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.utils.isJsonArray @@ -23,7 +24,6 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica execute { //如果是普通的url,需要根据返回的内容判断是什么 if (uri.scheme == "file" || uri.scheme == "content") { - var scheme = "" val content = if (uri.scheme == "file") { File(uri.path.toString()).readText() } else { @@ -34,36 +34,51 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica //暂时根据文件内容判断属于什么 when { content.contains("bookSourceUrl") -> { - scheme = "booksource" + successLiveData.postValue( + Intent( + context, + ImportBookSourceActivity::class.java + ).apply { + val dataKey = IntentDataHelp.putData(content) + putExtra("dataKey", dataKey) + } + ) + return@execute } content.contains("sourceUrl") -> { - scheme = "rsssource" + successLiveData.postValue( + Intent( + context, + ImportRssSourceActivity::class.java + ).apply { + val dataKey = IntentDataHelp.putData(content) + putExtra("dataKey", dataKey) + } + ) + return@execute } content.contains("pattern") -> { - scheme = "replace" + successLiveData.postValue( + Intent( + context, + ImportReplaceRuleActivity::class.java + ).apply { + val dataKey = IntentDataHelp.putData(content) + putExtra("dataKey", dataKey) + } + ) + return@execute } } } - if (scheme.isEmpty()) { - val book = if (uri.scheme == "content") { - LocalBook.importFile(uri) - } else { - LocalBook.importFile(uri) - } - val intent = Intent(context, ReadBookActivity::class.java) - intent.putExtra("bookUrl", book.bookUrl) - successLiveData.postValue(intent) + val book = if (uri.scheme == "content") { + LocalBook.importFile(uri) } else { - val url = if (uri.scheme == "content") { - "yuedu://${scheme}/importonline?src=$uri" - } else { - "yuedu://${scheme}/importonline?src=${uri.path}" - } - val data = Uri.parse(url) - val newIndent = Intent(Intent.ACTION_VIEW) - newIndent.data = data - successLiveData.postValue(newIndent) + LocalBook.importFile(uri) } + val intent = Intent(context, ReadBookActivity::class.java) + intent.putExtra("bookUrl", book.bookUrl) + successLiveData.postValue(intent) } else { throw Exception("文件不存在") } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 09007b795..c5a060d81 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -52,18 +52,10 @@ class ImportBookSourceActivity : viewModel.importSource(it) return } - intent.getStringExtra("filePath")?.let { - viewModel.importSourceFromFilePath(it) - return - } intent.data?.let { when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> - if (url.startsWith("http", false)) { - viewModel.importSource(url) - } else { - viewModel.importSourceFromFilePath(url) - } + viewModel.importSource(url) } else -> { binding.rotateLoading.hide() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt index 42647cf6e..7a08cacb1 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.association import android.app.Application -import android.net.Uri -import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import com.jayway.jsonpath.JsonPath import io.legado.app.R @@ -13,10 +11,11 @@ import io.legado.app.help.AppConfig import io.legado.app.help.SourceHelp import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.Restore -import io.legado.app.utils.* +import io.legado.app.utils.isAbsUrl +import io.legado.app.utils.isJsonArray +import io.legado.app.utils.isJsonObject import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.toText -import java.io.File class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { var groupName: String? = null @@ -72,32 +71,6 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { } } - - fun importSourceFromFilePath(path: String) { - execute { - val content = if (path.isContentScheme()) { - //在前面被解码了,如果不进行编码,中文会无法识别 - val newPath = Uri.encode(path, ":/.") - DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) - } else { - val file = File(path) - if (file.exists()) { - file.readText() - } else { - null - } - } - if (content != null) { - importSource(content) - } else { - errorLiveData.postValue(context.getString(R.string.error_read_file)) - } - }.onError { - it.printStackTrace() - errorLiveData.postValue(context.getString(R.string.error_read_file)) - } - } - fun importSource(text: String) { execute { val mText = text.trim() From 2b891ccf2b2959bba4ee6542ae5f80300cfa5593 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 00:43:39 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=89=93=E5=BC=80?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/association/ImportReplaceRuleActivity.kt | 10 +--------- .../app/ui/association/ImportRssSourceActivity.kt | 10 +--------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index d048b1264..9596b78c8 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -51,18 +51,10 @@ class ImportReplaceRuleActivity : viewModel.import(it) return } - intent.getStringExtra("filePath")?.let { - viewModel.importFromFilePath(it) - return - } intent.data?.let { when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> - if (url.startsWith("http", false)) { - viewModel.import(url) - } else { - viewModel.importFromFilePath(url) - } + viewModel.import(url) } else -> { binding.rotateLoading.hide() diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index 3a8efd37b..a3fa20cee 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -51,18 +51,10 @@ class ImportRssSourceActivity : viewModel.importSource(it) return } - intent.getStringExtra("filePath")?.let { - viewModel.importSourceFromFilePath(it) - return - } intent.data?.let { when (it.path) { "/importonline" -> it.getQueryParameter("src")?.let { url -> - if (url.startsWith("http", false)) { - viewModel.importSource(url) - } else { - viewModel.importSourceFromFilePath(url) - } + viewModel.importSource(url) } else -> { binding.rotateLoading.hide() From 751a886f19b15c911633eec59e1e8dcb34047e26 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 16:25:00 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../association/ImportReplaceRuleViewModel.kt | 31 ------------------- .../association/ImportRssSourceViewModel.kt | 27 ---------------- 2 files changed, 58 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt index e5e29392f..a9a937114 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt @@ -1,19 +1,13 @@ package io.legado.app.ui.association import android.app.Application -import android.net.Uri -import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData -import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.storage.OldReplace import io.legado.app.utils.isAbsUrl -import io.legado.app.utils.isContentScheme -import io.legado.app.utils.readText import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.toText -import java.io.File class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { val errorLiveData = MutableLiveData() @@ -21,31 +15,6 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { private val allRules = arrayListOf() - fun importFromFilePath(path: String) { - execute { - val content = if (path.isContentScheme()) { - //在前面被解码了,如果不进行编码,中文会无法识别 - val newPath = Uri.encode(path, ":/.") - DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) - } else { - val file = File(path) - if (file.exists()) { - file.readText() - } else { - null - } - } - if (content != null) { - import(content) - } else { - errorLiveData.postValue(context.getString(R.string.error_read_file)) - } - }.onError { - it.printStackTrace() - errorLiveData.postValue(context.getString(R.string.error_read_file)) - } - } - fun import(text: String) { execute { if (text.isAbsUrl()) { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt index 06cf2da11..0db5f7af0 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt @@ -1,8 +1,6 @@ package io.legado.app.ui.association import android.app.Application -import android.net.Uri -import androidx.documentfile.provider.DocumentFile import androidx.lifecycle.MutableLiveData import com.jayway.jsonpath.JsonPath import io.legado.app.R @@ -15,7 +13,6 @@ import io.legado.app.help.storage.Restore import io.legado.app.utils.* import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.toText -import java.io.File class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { var groupName: String? = null @@ -70,30 +67,6 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { } } - fun importSourceFromFilePath(path: String) { - execute { - val content = if (path.isContentScheme()) { - //在前面被解码了,如果不进行编码,中文会无法识别 - val newPath = Uri.encode(path, ":/.") - DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) - } else { - val file = File(path) - if (file.exists()) { - file.readText() - } else { - null - } - } - if (null != content) { - GSON.fromJsonArray(content)?.let { - allSources.addAll(it) - } - } - }.onSuccess { - comparisonSource() - } - } - fun importSource(text: String) { execute { val mText = text.trim() From da7b2276f2513cba4d29286ae9947ccf29972554 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 17:03:09 +0800 Subject: [PATCH 6/7] =?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/AndroidManifest.xml | 2 +- .../app/{help => lib}/permission/ActivitySource.kt | 2 +- .../app/{help => lib}/permission/FragmentSource.kt | 2 +- .../permission/OnPermissionsDeniedCallback.kt | 2 +- .../permission/OnPermissionsGrantedCallback.kt | 2 +- .../permission/OnPermissionsResultCallback.kt | 2 +- .../OnRequestPermissionsResultCallback.kt | 2 +- .../{help => lib}/permission/PermissionActivity.kt | 2 +- .../app/{help => lib}/permission/Permissions.kt | 2 +- .../{help => lib}/permission/PermissionsCompat.kt | 14 +------------- .../legado/app/{help => lib}/permission/Request.kt | 2 +- .../app/{help => lib}/permission/RequestManager.kt | 2 +- .../app/{help => lib}/permission/RequestPlugins.kt | 2 +- .../app/{help => lib}/permission/RequestSource.kt | 2 +- .../app/ui/book/info/edit/BookInfoEditActivity.kt | 4 ++-- .../legado/app/ui/book/local/ImportBookActivity.kt | 4 ++-- .../app/ui/book/read/config/BgTextConfigDialog.kt | 4 ++-- .../io/legado/app/ui/config/BackupRestoreUi.kt | 4 ++-- .../io/legado/app/ui/config/OtherConfigFragment.kt | 4 ++-- .../io/legado/app/ui/config/ThemeConfigFragment.kt | 4 ++-- .../java/io/legado/app/ui/filepicker/FilePicker.kt | 4 ++-- .../legado/app/ui/filepicker/FilePickerDialog.kt | 2 +- .../legado/app/ui/widget/font/FontSelectDialog.kt | 4 ++-- 23 files changed, 31 insertions(+), 43 deletions(-) rename app/src/main/java/io/legado/app/{help => lib}/permission/ActivitySource.kt (92%) rename app/src/main/java/io/legado/app/{help => lib}/permission/FragmentSource.kt (92%) rename app/src/main/java/io/legado/app/{help => lib}/permission/OnPermissionsDeniedCallback.kt (76%) rename app/src/main/java/io/legado/app/{help => lib}/permission/OnPermissionsGrantedCallback.kt (70%) rename app/src/main/java/io/legado/app/{help => lib}/permission/OnPermissionsResultCallback.kt (81%) rename app/src/main/java/io/legado/app/{help => lib}/permission/OnRequestPermissionsResultCallback.kt (88%) rename app/src/main/java/io/legado/app/{help => lib}/permission/PermissionActivity.kt (98%) rename app/src/main/java/io/legado/app/{help => lib}/permission/Permissions.kt (98%) rename app/src/main/java/io/legado/app/{help => lib}/permission/PermissionsCompat.kt (82%) rename app/src/main/java/io/legado/app/{help => lib}/permission/Request.kt (99%) rename app/src/main/java/io/legado/app/{help => lib}/permission/RequestManager.kt (97%) rename app/src/main/java/io/legado/app/{help => lib}/permission/RequestPlugins.kt (92%) rename app/src/main/java/io/legado/app/{help => lib}/permission/RequestSource.kt (80%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8e07090d0..86b75894f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -173,7 +173,7 @@ android:launchMode="singleTask" /> () - pers.addAll(listOf(*permissions)) - val data = request.getDeniedPermissions(pers.toTypedArray()) - return data == null - } - } - class Builder { private val request: Request diff --git a/app/src/main/java/io/legado/app/help/permission/Request.kt b/app/src/main/java/io/legado/app/lib/permission/Request.kt similarity index 99% rename from app/src/main/java/io/legado/app/help/permission/Request.kt rename to app/src/main/java/io/legado/app/lib/permission/Request.kt index 7a26f521f..246844065 100644 --- a/app/src/main/java/io/legado/app/help/permission/Request.kt +++ b/app/src/main/java/io/legado/app/lib/permission/Request.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.permission +package io.legado.app.lib.permission import android.content.Intent import android.content.pm.PackageManager diff --git a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt b/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt similarity index 97% rename from app/src/main/java/io/legado/app/help/permission/RequestManager.kt rename to app/src/main/java/io/legado/app/lib/permission/RequestManager.kt index eb28b9e6c..f75e1cba7 100644 --- a/app/src/main/java/io/legado/app/help/permission/RequestManager.kt +++ b/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.permission +package io.legado.app.lib.permission import android.os.Handler import android.os.Looper diff --git a/app/src/main/java/io/legado/app/help/permission/RequestPlugins.kt b/app/src/main/java/io/legado/app/lib/permission/RequestPlugins.kt similarity index 92% rename from app/src/main/java/io/legado/app/help/permission/RequestPlugins.kt rename to app/src/main/java/io/legado/app/lib/permission/RequestPlugins.kt index 16370193f..59bf0f0eb 100644 --- a/app/src/main/java/io/legado/app/help/permission/RequestPlugins.kt +++ b/app/src/main/java/io/legado/app/lib/permission/RequestPlugins.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.permission +package io.legado.app.lib.permission internal object RequestPlugins { diff --git a/app/src/main/java/io/legado/app/help/permission/RequestSource.kt b/app/src/main/java/io/legado/app/lib/permission/RequestSource.kt similarity index 80% rename from app/src/main/java/io/legado/app/help/permission/RequestSource.kt rename to app/src/main/java/io/legado/app/lib/permission/RequestSource.kt index a822ff5ad..3e029805f 100644 --- a/app/src/main/java/io/legado/app/help/permission/RequestSource.kt +++ b/app/src/main/java/io/legado/app/lib/permission/RequestSource.kt @@ -1,4 +1,4 @@ -package io.legado.app.help.permission +package io.legado.app.lib.permission import android.content.Context import android.content.Intent diff --git a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt index 4d16ba6bd..202e62df0 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt @@ -12,8 +12,8 @@ import io.legado.app.R import io.legado.app.base.VMBaseActivity import io.legado.app.data.entities.Book import io.legado.app.databinding.ActivityBookInfoEditBinding -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.utils.* import java.io.File diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 776d980c5..ea5858eda 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -18,8 +18,8 @@ import io.legado.app.base.VMBaseActivity import io.legado.app.data.appDb import io.legado.app.databinding.ActivityImportBookBinding import io.legado.app.help.AppConfig -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.backgroundColor import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePickerDialog 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 7b4eee738..2d986a27b 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 @@ -17,9 +17,9 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogReadBgTextBinding import io.legado.app.databinding.ItemBgImageBinding import io.legado.app.help.ReadBookConfig -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.bottomBackground import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor 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 d538cc7a8..46fee049a 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 @@ -9,12 +9,12 @@ import io.legado.app.R import io.legado.app.constant.PreferKey import io.legado.app.help.AppConfig import io.legado.app.help.coroutine.Coroutine -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.help.storage.Backup import io.legado.app.help.storage.BookWebDav import io.legado.app.help.storage.ImportOldData import io.legado.app.help.storage.Restore +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.ui.filepicker.FilePicker import io.legado.app.utils.getPrefString import io.legado.app.utils.isContentScheme diff --git a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt index b44909711..e8f27277b 100644 --- a/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt @@ -20,10 +20,10 @@ import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.AppConfig import io.legado.app.help.BookHelp -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.ATH import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.service.WebService diff --git a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt index 834e53eb9..3b13342a7 100644 --- a/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt @@ -22,10 +22,10 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.help.AppConfig import io.legado.app.help.LauncherIconHelp import io.legado.app.help.ThemeConfig -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.selector +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.ATH import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.prefs.ColorPreference diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt index ff099f9ff..1d784ec39 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt @@ -5,9 +5,9 @@ import android.os.Build import androidx.appcompat.app.AppCompatActivity import androidx.fragment.app.Fragment import io.legado.app.R -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat @Suppress("unused") object FilePicker { diff --git a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt index ba708b677..1150a1580 100644 --- a/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt +++ b/app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt @@ -16,7 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.databinding.DialogFileChooserBinding -import io.legado.app.help.permission.Permissions +import io.legado.app.lib.permission.Permissions import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.filepicker.adapter.FileAdapter import io.legado.app.ui.filepicker.adapter.PathAdapter diff --git a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt index 004d3204b..6be1e4d65 100644 --- a/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt +++ b/app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt @@ -16,9 +16,9 @@ import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.PreferKey import io.legado.app.databinding.DialogFontSelectBinding import io.legado.app.help.AppConfig -import io.legado.app.help.permission.Permissions -import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.dialogs.alert +import io.legado.app.lib.permission.Permissions +import io.legado.app.lib.permission.PermissionsCompat import io.legado.app.lib.theme.primaryColor import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePickerDialog From 41ecea7232d4cb3e5bf4d845ad9ae3656a890bd2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 27 Mar 2021 18:19:39 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../permission/OnPermissionsDeniedCallback.kt | 2 +- .../OnPermissionsGrantedCallback.kt | 2 +- .../permission/OnPermissionsResultCallback.kt | 4 ++-- .../OnRequestPermissionsResultCallback.kt | 10 ++------ .../app/lib/permission/PermissionActivity.kt | 16 ++++++------- .../app/lib/permission/PermissionsCompat.kt | 15 +++++------- .../io/legado/app/lib/permission/Request.kt | 23 +++++++++---------- .../app/lib/permission/RequestManager.kt | 4 ++-- .../java/io/legado/app/lib/webdav/WebDav.kt | 3 +-- 9 files changed, 34 insertions(+), 45 deletions(-) diff --git a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsDeniedCallback.kt b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsDeniedCallback.kt index a8a0c9110..0cc6b715b 100644 --- a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsDeniedCallback.kt +++ b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsDeniedCallback.kt @@ -2,6 +2,6 @@ package io.legado.app.lib.permission interface OnPermissionsDeniedCallback { - fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array) + fun onPermissionsDenied(deniedPermissions: Array) } diff --git a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsGrantedCallback.kt b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsGrantedCallback.kt index b50adb849..fe43e947e 100644 --- a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsGrantedCallback.kt +++ b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsGrantedCallback.kt @@ -2,6 +2,6 @@ package io.legado.app.lib.permission interface OnPermissionsGrantedCallback { - fun onPermissionsGranted(requestCode: Int) + fun onPermissionsGranted() } diff --git a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsResultCallback.kt b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsResultCallback.kt index 42e7a3263..41ae2f5fc 100644 --- a/app/src/main/java/io/legado/app/lib/permission/OnPermissionsResultCallback.kt +++ b/app/src/main/java/io/legado/app/lib/permission/OnPermissionsResultCallback.kt @@ -2,8 +2,8 @@ package io.legado.app.lib.permission interface OnPermissionsResultCallback { - fun onPermissionsGranted(requestCode: Int) + fun onPermissionsGranted() - fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array) + fun onPermissionsDenied(deniedPermissions: Array) } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/lib/permission/OnRequestPermissionsResultCallback.kt b/app/src/main/java/io/legado/app/lib/permission/OnRequestPermissionsResultCallback.kt index 682356bfe..2934e4c77 100644 --- a/app/src/main/java/io/legado/app/lib/permission/OnRequestPermissionsResultCallback.kt +++ b/app/src/main/java/io/legado/app/lib/permission/OnRequestPermissionsResultCallback.kt @@ -1,14 +1,8 @@ package io.legado.app.lib.permission -import android.content.Intent - interface OnRequestPermissionsResultCallback { - fun onRequestPermissionsResult( - requestCode: Int, - permissions: Array, - grantResults: IntArray - ) + fun onRequestPermissionsResult(permissions: Array, grantResults: IntArray) - fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) + fun onSettingActivityResult() } diff --git a/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt b/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt index 2e8336a0c..b98b16fde 100644 --- a/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt +++ b/app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt @@ -5,6 +5,7 @@ import android.net.Uri import android.os.Bundle import android.provider.Settings import android.view.KeyEvent +import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import io.legado.app.R @@ -12,6 +13,12 @@ import io.legado.app.utils.toastOnUi class PermissionActivity : AppCompatActivity() { + private val startSettingActivity = + registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { + RequestPlugins.sRequestCallback?.onSettingActivityResult() + finish() + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -30,7 +37,7 @@ class PermissionActivity : AppCompatActivity() { -> try { val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) settingIntent.data = Uri.fromParts("package", packageName, null) - startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING) + startSettingActivity.launch(settingIntent) } catch (e: Exception) { toastOnUi(R.string.tip_cannot_jump_setting_page) finish() @@ -46,19 +53,12 @@ class PermissionActivity : AppCompatActivity() { ) { super.onRequestPermissionsResult(requestCode, permissions, grantResults) RequestPlugins.sRequestCallback?.onRequestPermissionsResult( - requestCode, permissions, grantResults ) finish() } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - RequestPlugins.sRequestCallback?.onActivityResult(requestCode, resultCode, data) - finish() - } - override fun startActivity(intent: Intent) { super.startActivity(intent) overridePendingTransition(0, 0) diff --git a/app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt b/app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt index ca5e19b22..a2d604c99 100644 --- a/app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt +++ b/app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt @@ -34,22 +34,19 @@ class PermissionsCompat private constructor() { return this } - fun onGranted(callback: (requestCode: Int) -> Unit): Builder { + fun onGranted(callback: () -> Unit): Builder { request.setOnGrantedCallback(object : OnPermissionsGrantedCallback { - override fun onPermissionsGranted(requestCode: Int) { - callback(requestCode) + override fun onPermissionsGranted() { + callback() } }) return this } - fun onDenied(callback: (requestCode: Int, deniedPermissions: Array) -> Unit): Builder { + fun onDenied(callback: (deniedPermissions: Array) -> Unit): Builder { request.setOnDeniedCallback(object : OnPermissionsDeniedCallback { - override fun onPermissionsDenied( - requestCode: Int, - deniedPermissions: Array - ) { - callback(requestCode, deniedPermissions) + override fun onPermissionsDenied(deniedPermissions: Array) { + callback(deniedPermissions) } }) return this diff --git a/app/src/main/java/io/legado/app/lib/permission/Request.kt b/app/src/main/java/io/legado/app/lib/permission/Request.kt index 246844065..2de60d059 100644 --- a/app/src/main/java/io/legado/app/lib/permission/Request.kt +++ b/app/src/main/java/io/legado/app/lib/permission/Request.kt @@ -1,6 +1,5 @@ package io.legado.app.lib.permission -import android.content.Intent import android.content.pm.PackageManager import android.os.Build import androidx.annotation.StringRes @@ -12,6 +11,7 @@ import io.legado.app.R import io.legado.app.utils.startActivity import java.util.* +@Suppress("MemberVisibilityCanBePrivate") internal class Request : OnRequestPermissionsResultCallback { internal val requestTime: Long @@ -75,7 +75,7 @@ internal class Request : OnRequestPermissionsResultCallback { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { if (deniedPermissions == null) { - onPermissionsGranted(requestCode) + onPermissionsGranted() } else { val rationale = if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale @@ -98,7 +98,7 @@ internal class Request : OnRequestPermissionsResultCallback { putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions) } } else { - onPermissionsGranted(requestCode) + onPermissionsGranted() } } } @@ -151,26 +151,25 @@ internal class Request : OnRequestPermissionsResultCallback { } } - private fun onPermissionsGranted(requestCode: Int) { + private fun onPermissionsGranted() { try { - grantedCallback?.onPermissionsGranted(requestCode) + grantedCallback?.onPermissionsGranted() } catch (ignore: Exception) { } - RequestPlugins.sResultCallback?.onPermissionsGranted(requestCode) + RequestPlugins.sResultCallback?.onPermissionsGranted() } private fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array) { try { - deniedCallback?.onPermissionsDenied(requestCode, deniedPermissions) + deniedCallback?.onPermissionsDenied(deniedPermissions) } catch (ignore: Exception) { } - RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions) + RequestPlugins.sResultCallback?.onPermissionsDenied(deniedPermissions) } override fun onRequestPermissionsResult( - requestCode: Int, permissions: Array, grantResults: IntArray ) { @@ -184,14 +183,14 @@ internal class Request : OnRequestPermissionsResultCallback { onPermissionsDenied(requestCode, deniedPermissions) } } else { - onPermissionsGranted(requestCode) + onPermissionsGranted() } } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + override fun onSettingActivityResult() { val deniedPermissions = deniedPermissions if (deniedPermissions == null) { - onPermissionsGranted(this.requestCode) + onPermissionsGranted() } else { onPermissionsDenied(this.requestCode, deniedPermissions) } diff --git a/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt b/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt index f75e1cba7..2bc6832c7 100644 --- a/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt +++ b/app/src/main/java/io/legado/app/lib/permission/RequestManager.kt @@ -58,11 +58,11 @@ internal object RequestManager : OnPermissionsResultCallback { } } - override fun onPermissionsGranted(requestCode: Int) { + override fun onPermissionsGranted() { startNextRequest() } - override fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array) { + override fun onPermissionsDenied(deniedPermissions: Array) { startNextRequest() } diff --git a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt index dafedc128..1570bc793 100644 --- a/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt +++ b/app/src/main/java/io/legado/app/lib/webdav/WebDav.kt @@ -98,8 +98,7 @@ class WebDav(urlStr: String) { for (p in propsList) { requestProps.append("\n") } - val requestPropsStr: String - requestPropsStr = if (requestProps.toString().isEmpty()) { + val requestPropsStr: String = if (requestProps.toString().isEmpty()) { DIR.replace("%s", "") } else { String.format(DIR, requestProps.toString() + "\n")