Merge pull request #2 from gedoor/master

sys code
pull/915/head
ag2s20150909 4 years ago committed by GitHub
commit 1c205b56b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 37
      app/src/main/AndroidManifest.xml
  2. 3
      app/src/main/assets/updateLog.md
  3. 7
      app/src/main/java/io/legado/app/help/permission/OnPermissionsDeniedCallback.kt
  4. 7
      app/src/main/java/io/legado/app/help/permission/OnPermissionsGrantedCallback.kt
  5. 9
      app/src/main/java/io/legado/app/help/permission/OnPermissionsResultCallback.kt
  6. 14
      app/src/main/java/io/legado/app/help/permission/OnRequestPermissionsResultCallback.kt
  7. 2
      app/src/main/java/io/legado/app/lib/permission/ActivitySource.kt
  8. 2
      app/src/main/java/io/legado/app/lib/permission/FragmentSource.kt
  9. 7
      app/src/main/java/io/legado/app/lib/permission/OnPermissionsDeniedCallback.kt
  10. 7
      app/src/main/java/io/legado/app/lib/permission/OnPermissionsGrantedCallback.kt
  11. 9
      app/src/main/java/io/legado/app/lib/permission/OnPermissionsResultCallback.kt
  12. 8
      app/src/main/java/io/legado/app/lib/permission/OnRequestPermissionsResultCallback.kt
  13. 18
      app/src/main/java/io/legado/app/lib/permission/PermissionActivity.kt
  14. 2
      app/src/main/java/io/legado/app/lib/permission/Permissions.kt
  15. 29
      app/src/main/java/io/legado/app/lib/permission/PermissionsCompat.kt
  16. 25
      app/src/main/java/io/legado/app/lib/permission/Request.kt
  17. 6
      app/src/main/java/io/legado/app/lib/permission/RequestManager.kt
  18. 2
      app/src/main/java/io/legado/app/lib/permission/RequestPlugins.kt
  19. 2
      app/src/main/java/io/legado/app/lib/permission/RequestSource.kt
  20. 3
      app/src/main/java/io/legado/app/lib/webdav/WebDav.kt
  21. 47
      app/src/main/java/io/legado/app/ui/association/FileAssociationViewModel.kt
  22. 8
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  23. 33
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  24. 8
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  25. 31
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt
  26. 8
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  27. 27
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  28. 4
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  29. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  30. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  31. 4
      app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt
  32. 4
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  33. 4
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  34. 4
      app/src/main/java/io/legado/app/ui/filepicker/FilePicker.kt
  35. 2
      app/src/main/java/io/legado/app/ui/filepicker/FilePickerDialog.kt
  36. 4
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  37. 9
      epublib/build.gradle

@ -173,7 +173,7 @@
android:launchMode="singleTask" /> android:launchMode="singleTask" />
<!-- 授权界面 --> <!-- 授权界面 -->
<activity <activity
android:name=".help.permission.PermissionActivity" android:name="io.legado.app.lib.permission.PermissionActivity"
android:theme="@style/Activity.Permission" /> android:theme="@style/Activity.Permission" />
<!-- 二维码扫描 --> <!-- 二维码扫描 -->
<activity <activity
@ -367,16 +367,47 @@
android:name=".ui.association.FileAssociationActivity" android:name=".ui.association.FileAssociationActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/AppTheme.Transparent"> android:theme="@style/AppTheme.Transparent">
<!-- VIEW (Open with) action -->
<!-- Works when an app knows the media type of a file, e.g. Gmail or Chrome. -->
<intent-filter> <intent-filter>
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" /> <data android:scheme="app" />
<data android:scheme="content" /> <data android:scheme="content" />
<data android:scheme="file" />
<!-- text -->
<data android:mimeType="text/plain" /> <data android:mimeType="text/plain" />
<!-- json -->
<data android:mimeType="application/json" /> <data android:mimeType="application/json" />
<data android:mimeType="application/epub" /> <!-- EPUB -->
<data android:mimeType="application/epub+zip" />
</intent-filter>
<!-- Works when an app doesn't know the media type, e.g. Dropbox -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="app" />
<data android:scheme="content" />
<data android:scheme="file" />
<!-- This media type is necessary, otherwise it won't match on the file extension -->
<data android:mimeType="*/*" />
<!--TXT-->
<data android:pathPattern=".*\\.txt" />
<data android:pathPattern=".*\\.TXT" />
<!--JSON-->
<data android:pathPattern=".*\\.json" />
<data android:pathPattern=".*\\.JSON" />
<!-- EPUB -->
<data android:pathPattern=".*\\.epub" />
<data android:pathPattern=".*\\.EPUB" />
</intent-filter> </intent-filter>
</activity> </activity>

@ -3,6 +3,9 @@
* 关注合作公众号 **[小说拾遗]** 获取好看的小说。 * 关注合作公众号 **[小说拾遗]** 获取好看的小说。
* 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。 * 旧版数据导入教程:先在旧版阅读(2.x)中进行备份,然后在新版阅读(3.x)【我的】->【备份与恢复】,选择【导入旧版本数据】。
**2021/03/26**
* 优化epubLib by ag2s20150909
**2021/03/23** **2021/03/23**
* 修复繁简转换“勐”“十”问题。使用了剥离HanLP简繁代码的民间库。APK减少6M左右 * 修复繁简转换“勐”“十”问题。使用了剥离HanLP简繁代码的民间库。APK减少6M左右
* js添加一个并发访问的方法 java.ajaxAll(urlList: Array<String>) 返回 Array<StrResponse?> * js添加一个并发访问的方法 java.ajaxAll(urlList: Array<String>) 返回 Array<StrResponse?>

@ -1,7 +0,0 @@
package io.legado.app.help.permission
interface OnPermissionsDeniedCallback {
fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>)
}

@ -1,7 +0,0 @@
package io.legado.app.help.permission
interface OnPermissionsGrantedCallback {
fun onPermissionsGranted(requestCode: Int)
}

@ -1,9 +0,0 @@
package io.legado.app.help.permission
interface OnPermissionsResultCallback {
fun onPermissionsGranted(requestCode: Int)
fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>)
}

@ -1,14 +0,0 @@
package io.legado.app.help.permission
import android.content.Intent
interface OnRequestPermissionsResultCallback {
fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
grantResults: IntArray
)
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
}

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent

@ -0,0 +1,7 @@
package io.legado.app.lib.permission
interface OnPermissionsDeniedCallback {
fun onPermissionsDenied(deniedPermissions: Array<String>)
}

@ -0,0 +1,7 @@
package io.legado.app.lib.permission
interface OnPermissionsGrantedCallback {
fun onPermissionsGranted()
}

@ -0,0 +1,9 @@
package io.legado.app.lib.permission
interface OnPermissionsResultCallback {
fun onPermissionsGranted()
fun onPermissionsDenied(deniedPermissions: Array<String>)
}

@ -0,0 +1,8 @@
package io.legado.app.lib.permission
interface OnRequestPermissionsResultCallback {
fun onRequestPermissionsResult(permissions: Array<String>, grantResults: IntArray)
fun onSettingActivityResult()
}

@ -1,10 +1,11 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.provider.Settings import android.provider.Settings
import android.view.KeyEvent import android.view.KeyEvent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat import androidx.core.app.ActivityCompat
import io.legado.app.R import io.legado.app.R
@ -12,6 +13,12 @@ import io.legado.app.utils.toastOnUi
class PermissionActivity : AppCompatActivity() { class PermissionActivity : AppCompatActivity() {
private val startSettingActivity =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
RequestPlugins.sRequestCallback?.onSettingActivityResult()
finish()
}
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -30,7 +37,7 @@ class PermissionActivity : AppCompatActivity() {
-> try { -> try {
val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS) val settingIntent = Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
settingIntent.data = Uri.fromParts("package", packageName, null) settingIntent.data = Uri.fromParts("package", packageName, null)
startActivityForResult(settingIntent, Request.TYPE_REQUEST_SETTING) startSettingActivity.launch(settingIntent)
} catch (e: Exception) { } catch (e: Exception) {
toastOnUi(R.string.tip_cannot_jump_setting_page) toastOnUi(R.string.tip_cannot_jump_setting_page)
finish() finish()
@ -46,19 +53,12 @@ class PermissionActivity : AppCompatActivity() {
) { ) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults) super.onRequestPermissionsResult(requestCode, permissions, grantResults)
RequestPlugins.sRequestCallback?.onRequestPermissionsResult( RequestPlugins.sRequestCallback?.onRequestPermissionsResult(
requestCode,
permissions, permissions,
grantResults grantResults
) )
finish() 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) { override fun startActivity(intent: Intent) {
super.startActivity(intent) super.startActivity(intent)
overridePendingTransition(0, 0) overridePendingTransition(0, 0)

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
@Suppress("unused") @Suppress("unused")
object Permissions { object Permissions {

@ -1,9 +1,8 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import androidx.annotation.StringRes import androidx.annotation.StringRes
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import java.util.*
@Suppress("unused") @Suppress("unused")
class PermissionsCompat private constructor() { class PermissionsCompat private constructor() {
@ -14,17 +13,6 @@ class PermissionsCompat private constructor() {
RequestManager.pushRequest(request) RequestManager.pushRequest(request)
} }
companion object {
// 检查权限, 如果已经拥有返回 true
fun check(activity: AppCompatActivity, vararg permissions: String): Boolean {
val request = Request(activity)
val pers = ArrayList<String>()
pers.addAll(listOf(*permissions))
val data = request.getDeniedPermissions(pers.toTypedArray())
return data == null
}
}
class Builder { class Builder {
private val request: Request private val request: Request
@ -46,22 +34,19 @@ class PermissionsCompat private constructor() {
return this return this
} }
fun onGranted(callback: (requestCode: Int) -> Unit): Builder { fun onGranted(callback: () -> Unit): Builder {
request.setOnGrantedCallback(object : OnPermissionsGrantedCallback { request.setOnGrantedCallback(object : OnPermissionsGrantedCallback {
override fun onPermissionsGranted(requestCode: Int) { override fun onPermissionsGranted() {
callback(requestCode) callback()
} }
}) })
return this return this
} }
fun onDenied(callback: (requestCode: Int, deniedPermissions: Array<String>) -> Unit): Builder { fun onDenied(callback: (deniedPermissions: Array<String>) -> Unit): Builder {
request.setOnDeniedCallback(object : OnPermissionsDeniedCallback { request.setOnDeniedCallback(object : OnPermissionsDeniedCallback {
override fun onPermissionsDenied( override fun onPermissionsDenied(deniedPermissions: Array<String>) {
requestCode: Int, callback(deniedPermissions)
deniedPermissions: Array<String>
) {
callback(requestCode, deniedPermissions)
} }
}) })
return this return this

@ -1,6 +1,5 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.content.Intent
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.os.Build import android.os.Build
import androidx.annotation.StringRes import androidx.annotation.StringRes
@ -12,6 +11,7 @@ import io.legado.app.R
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import java.util.* import java.util.*
@Suppress("MemberVisibilityCanBePrivate")
internal class Request : OnRequestPermissionsResultCallback { internal class Request : OnRequestPermissionsResultCallback {
internal val requestTime: Long internal val requestTime: Long
@ -75,7 +75,7 @@ internal class Request : OnRequestPermissionsResultCallback {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
if (deniedPermissions == null) { if (deniedPermissions == null) {
onPermissionsGranted(requestCode) onPermissionsGranted()
} else { } else {
val rationale = val rationale =
if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale if (rationaleResId != 0) source?.context?.getText(rationaleResId) else rationale
@ -98,7 +98,7 @@ internal class Request : OnRequestPermissionsResultCallback {
putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions) putExtra(PermissionActivity.KEY_INPUT_PERMISSIONS, deniedPermissions)
} }
} else { } else {
onPermissionsGranted(requestCode) onPermissionsGranted()
} }
} }
} }
@ -151,26 +151,25 @@ internal class Request : OnRequestPermissionsResultCallback {
} }
} }
private fun onPermissionsGranted(requestCode: Int) { private fun onPermissionsGranted() {
try { try {
grantedCallback?.onPermissionsGranted(requestCode) grantedCallback?.onPermissionsGranted()
} catch (ignore: Exception) { } catch (ignore: Exception) {
} }
RequestPlugins.sResultCallback?.onPermissionsGranted(requestCode) RequestPlugins.sResultCallback?.onPermissionsGranted()
} }
private fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) { private fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) {
try { try {
deniedCallback?.onPermissionsDenied(requestCode, deniedPermissions) deniedCallback?.onPermissionsDenied(deniedPermissions)
} catch (ignore: Exception) { } catch (ignore: Exception) {
} }
RequestPlugins.sResultCallback?.onPermissionsDenied(requestCode, deniedPermissions) RequestPlugins.sResultCallback?.onPermissionsDenied(deniedPermissions)
} }
override fun onRequestPermissionsResult( override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>, permissions: Array<String>,
grantResults: IntArray grantResults: IntArray
) { ) {
@ -184,14 +183,14 @@ internal class Request : OnRequestPermissionsResultCallback {
onPermissionsDenied(requestCode, deniedPermissions) onPermissionsDenied(requestCode, deniedPermissions)
} }
} else { } else {
onPermissionsGranted(requestCode) onPermissionsGranted()
} }
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onSettingActivityResult() {
val deniedPermissions = deniedPermissions val deniedPermissions = deniedPermissions
if (deniedPermissions == null) { if (deniedPermissions == null) {
onPermissionsGranted(this.requestCode) onPermissionsGranted()
} else { } else {
onPermissionsDenied(this.requestCode, deniedPermissions) onPermissionsDenied(this.requestCode, deniedPermissions)
} }

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
@ -58,11 +58,11 @@ internal object RequestManager : OnPermissionsResultCallback {
} }
} }
override fun onPermissionsGranted(requestCode: Int) { override fun onPermissionsGranted() {
startNextRequest() startNextRequest()
} }
override fun onPermissionsDenied(requestCode: Int, deniedPermissions: Array<String>) { override fun onPermissionsDenied(deniedPermissions: Array<String>) {
startNextRequest() startNextRequest()
} }

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
internal object RequestPlugins { internal object RequestPlugins {

@ -1,4 +1,4 @@
package io.legado.app.help.permission package io.legado.app.lib.permission
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent

@ -98,8 +98,7 @@ class WebDav(urlStr: String) {
for (p in propsList) { for (p in propsList) {
requestProps.append("<a:").append(p).append("/>\n") requestProps.append("<a:").append(p).append("/>\n")
} }
val requestPropsStr: String val requestPropsStr: String = if (requestProps.toString().isEmpty()) {
requestPropsStr = if (requestProps.toString().isEmpty()) {
DIR.replace("%s", "") DIR.replace("%s", "")
} else { } else {
String.format(DIR, requestProps.toString() + "\n") String.format(DIR, requestProps.toString() + "\n")

@ -6,6 +6,7 @@ import android.net.Uri
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.help.IntentDataHelp
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.ui.book.read.ReadBookActivity import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.utils.isJsonArray import io.legado.app.utils.isJsonArray
@ -23,7 +24,6 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
execute { execute {
//如果是普通的url,需要根据返回的内容判断是什么 //如果是普通的url,需要根据返回的内容判断是什么
if (uri.scheme == "file" || uri.scheme == "content") { if (uri.scheme == "file" || uri.scheme == "content") {
var scheme = ""
val content = if (uri.scheme == "file") { val content = if (uri.scheme == "file") {
File(uri.path.toString()).readText() File(uri.path.toString()).readText()
} else { } else {
@ -34,17 +34,43 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
//暂时根据文件内容判断属于什么 //暂时根据文件内容判断属于什么
when { when {
content.contains("bookSourceUrl") -> { 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") -> { 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") -> { 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") { val book = if (uri.scheme == "content") {
LocalBook.importFile(uri) LocalBook.importFile(uri)
} else { } else {
@ -53,17 +79,6 @@ class FileAssociationViewModel(application: Application) : BaseViewModel(applica
val intent = Intent(context, ReadBookActivity::class.java) val intent = Intent(context, ReadBookActivity::class.java)
intent.putExtra("bookUrl", book.bookUrl) intent.putExtra("bookUrl", book.bookUrl)
successLiveData.postValue(intent) successLiveData.postValue(intent)
} 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)
}
} else { } else {
throw Exception("文件不存在") throw Exception("文件不存在")
} }

@ -52,18 +52,10 @@ class ImportBookSourceActivity :
viewModel.importSource(it) viewModel.importSource(it)
return return
} }
intent.getStringExtra("filePath")?.let {
viewModel.importSourceFromFilePath(it)
return
}
intent.data?.let { intent.data?.let {
when (it.path) { when (it.path) {
"/importonline" -> it.getQueryParameter("src")?.let { url -> "/importonline" -> it.getQueryParameter("src")?.let { url ->
if (url.startsWith("http", false)) {
viewModel.importSource(url) viewModel.importSource(url)
} else {
viewModel.importSourceFromFilePath(url)
}
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -1,8 +1,6 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.app.Application import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.R 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.SourceHelp
import io.legado.app.help.storage.OldRule import io.legado.app.help.storage.OldRule
import io.legado.app.help.storage.Restore 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.RxHttp
import rxhttp.wrapper.param.toText import rxhttp.wrapper.param.toText
import java.io.File
class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) { class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
var groupName: String? = null 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) { fun importSource(text: String) {
execute { execute {
val mText = text.trim() val mText = text.trim()

@ -51,18 +51,10 @@ class ImportReplaceRuleActivity :
viewModel.import(it) viewModel.import(it)
return return
} }
intent.getStringExtra("filePath")?.let {
viewModel.importFromFilePath(it)
return
}
intent.data?.let { intent.data?.let {
when (it.path) { when (it.path) {
"/importonline" -> it.getQueryParameter("src")?.let { url -> "/importonline" -> it.getQueryParameter("src")?.let { url ->
if (url.startsWith("http", false)) {
viewModel.import(url) viewModel.import(url)
} else {
viewModel.importFromFilePath(url)
}
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -1,19 +1,13 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.app.Application import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.storage.OldReplace import io.legado.app.help.storage.OldReplace
import io.legado.app.utils.isAbsUrl 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.RxHttp
import rxhttp.wrapper.param.toText import rxhttp.wrapper.param.toText
import java.io.File
class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) { class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
val errorLiveData = MutableLiveData<String>() val errorLiveData = MutableLiveData<String>()
@ -21,31 +15,6 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
private val allRules = arrayListOf<ReplaceRule>() private val allRules = arrayListOf<ReplaceRule>()
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) { fun import(text: String) {
execute { execute {
if (text.isAbsUrl()) { if (text.isAbsUrl()) {

@ -51,18 +51,10 @@ class ImportRssSourceActivity :
viewModel.importSource(it) viewModel.importSource(it)
return return
} }
intent.getStringExtra("filePath")?.let {
viewModel.importSourceFromFilePath(it)
return
}
intent.data?.let { intent.data?.let {
when (it.path) { when (it.path) {
"/importonline" -> it.getQueryParameter("src")?.let { url -> "/importonline" -> it.getQueryParameter("src")?.let { url ->
if (url.startsWith("http", false)) {
viewModel.importSource(url) viewModel.importSource(url)
} else {
viewModel.importSourceFromFilePath(url)
}
} }
else -> { else -> {
binding.rotateLoading.hide() binding.rotateLoading.hide()

@ -1,8 +1,6 @@
package io.legado.app.ui.association package io.legado.app.ui.association
import android.app.Application import android.app.Application
import android.net.Uri
import androidx.documentfile.provider.DocumentFile
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.jayway.jsonpath.JsonPath import com.jayway.jsonpath.JsonPath
import io.legado.app.R import io.legado.app.R
@ -15,7 +13,6 @@ import io.legado.app.help.storage.Restore
import io.legado.app.utils.* import io.legado.app.utils.*
import rxhttp.wrapper.param.RxHttp import rxhttp.wrapper.param.RxHttp
import rxhttp.wrapper.param.toText import rxhttp.wrapper.param.toText
import java.io.File
class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) { class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
var groupName: String? = null 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<RssSource>(content)?.let {
allSources.addAll(it)
}
}
}.onSuccess {
comparisonSource()
}
}
fun importSource(text: String) { fun importSource(text: String) {
execute { execute {
val mText = text.trim() val mText = text.trim()

@ -12,8 +12,8 @@ import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.databinding.ActivityBookInfoEditBinding import io.legado.app.databinding.ActivityBookInfoEditBinding
import io.legado.app.help.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.ui.book.changecover.ChangeCoverDialog import io.legado.app.ui.book.changecover.ChangeCoverDialog
import io.legado.app.utils.* import io.legado.app.utils.*
import java.io.File import java.io.File

@ -18,8 +18,8 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.databinding.ActivityImportBookBinding import io.legado.app.databinding.ActivityImportBookBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.permission.Permissions import io.legado.app.lib.permission.Permissions
import io.legado.app.help.permission.PermissionsCompat import io.legado.app.lib.permission.PermissionsCompat
import io.legado.app.lib.theme.backgroundColor import io.legado.app.lib.theme.backgroundColor
import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePicker
import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.ui.filepicker.FilePickerDialog

@ -17,9 +17,9 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.databinding.DialogReadBgTextBinding import io.legado.app.databinding.DialogReadBgTextBinding
import io.legado.app.databinding.ItemBgImageBinding import io.legado.app.databinding.ItemBgImageBinding
import io.legado.app.help.ReadBookConfig 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.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.bottomBackground
import io.legado.app.lib.theme.getPrimaryTextColor import io.legado.app.lib.theme.getPrimaryTextColor
import io.legado.app.lib.theme.getSecondaryTextColor import io.legado.app.lib.theme.getSecondaryTextColor

@ -9,12 +9,12 @@ import io.legado.app.R
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.Coroutine 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.Backup
import io.legado.app.help.storage.BookWebDav import io.legado.app.help.storage.BookWebDav
import io.legado.app.help.storage.ImportOldData import io.legado.app.help.storage.ImportOldData
import io.legado.app.help.storage.Restore 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.ui.filepicker.FilePicker
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import io.legado.app.utils.isContentScheme import io.legado.app.utils.isContentScheme

@ -20,10 +20,10 @@ import io.legado.app.constant.PreferKey
import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.BookHelp 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.alert
import io.legado.app.lib.dialogs.selector 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.lib.theme.ATH
import io.legado.app.receiver.SharedReceiverActivity import io.legado.app.receiver.SharedReceiverActivity
import io.legado.app.service.WebService import io.legado.app.service.WebService

@ -22,10 +22,10 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.help.LauncherIconHelp import io.legado.app.help.LauncherIconHelp
import io.legado.app.help.ThemeConfig 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.alert
import io.legado.app.lib.dialogs.selector 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.lib.theme.ATH
import io.legado.app.ui.widget.number.NumberPickerDialog import io.legado.app.ui.widget.number.NumberPickerDialog
import io.legado.app.ui.widget.prefs.ColorPreference import io.legado.app.ui.widget.prefs.ColorPreference

@ -5,9 +5,9 @@ import android.os.Build
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import io.legado.app.R 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.dialogs.alert
import io.legado.app.lib.permission.Permissions
import io.legado.app.lib.permission.PermissionsCompat
@Suppress("unused") @Suppress("unused")
object FilePicker { object FilePicker {

@ -16,7 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.databinding.DialogFileChooserBinding 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.lib.theme.primaryColor
import io.legado.app.ui.filepicker.adapter.FileAdapter import io.legado.app.ui.filepicker.adapter.FileAdapter
import io.legado.app.ui.filepicker.adapter.PathAdapter import io.legado.app.ui.filepicker.adapter.PathAdapter

@ -16,9 +16,9 @@ import io.legado.app.base.BaseDialogFragment
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.databinding.DialogFontSelectBinding import io.legado.app.databinding.DialogFontSelectBinding
import io.legado.app.help.AppConfig 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.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.lib.theme.primaryColor
import io.legado.app.ui.filepicker.FilePicker import io.legado.app.ui.filepicker.FilePicker
import io.legado.app.ui.filepicker.FilePickerDialog import io.legado.app.ui.filepicker.FilePickerDialog

@ -21,6 +21,8 @@ android {
minifyEnabled false minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
} }
android {
}
} }
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
@ -30,11 +32,4 @@ android {
dependencies { 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'
} }
Loading…
Cancel
Save