pull/461/head
gedoor 4 years ago
parent 91be3bbb03
commit 1cd696cc9c
  1. 6
      app/src/main/java/io/legado/app/help/ImageLoader.kt
  2. 2
      app/src/main/java/io/legado/app/help/storage/Backup.kt
  3. 4
      app/src/main/java/io/legado/app/help/storage/ImportOldData.kt
  4. 2
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  5. 2
      app/src/main/java/io/legado/app/model/localBook/AnalyzeTxtFile.kt
  6. 2
      app/src/main/java/io/legado/app/model/localBook/EPUBFile.kt
  7. 4
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  8. 2
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceViewModel.kt
  9. 4
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleViewModel.kt
  10. 2
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceViewModel.kt
  11. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt
  12. 2
      app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt
  13. 2
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  14. 6
      app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt
  15. 3
      app/src/main/java/io/legado/app/ui/book/local/ImportBookAdapter.kt
  16. 4
      app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt
  17. 4
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  18. 4
      app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt
  19. 2
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  20. 12
      app/src/main/java/io/legado/app/ui/config/BackupRestoreUi.kt
  21. 2
      app/src/main/java/io/legado/app/ui/config/OtherConfigFragment.kt
  22. 2
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  23. 6
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt
  24. 2
      app/src/main/java/io/legado/app/ui/rss/source/manage/RssSourceActivity.kt
  25. 4
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt
  26. 2
      app/src/main/java/io/legado/app/utils/DocumentUtils.kt
  27. 4
      app/src/main/java/io/legado/app/utils/StringExtensions.kt
  28. 6
      app/src/main/java/io/legado/app/utils/UriExtensions.kt

@ -7,9 +7,9 @@ import android.net.Uri
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.bumptech.glide.RequestBuilder import com.bumptech.glide.RequestBuilder
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentPath
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isContentScheme
import java.io.File import java.io.File
object ImageLoader { object ImageLoader {
@ -21,7 +21,7 @@ object ImageLoader {
return when { return when {
path.isNullOrEmpty() -> Glide.with(context).load(path) path.isNullOrEmpty() -> Glide.with(context).load(path)
path.isAbsUrl() -> Glide.with(context).load(AnalyzeUrl(path).getGlideUrl()) path.isAbsUrl() -> Glide.with(context).load(AnalyzeUrl(path).getGlideUrl())
path.isContentPath() -> Glide.with(context).load(Uri.parse(path)) path.isContentScheme() -> Glide.with(context).load(Uri.parse(path))
else -> try { else -> try {
Glide.with(context).load(File(path)) Glide.with(context).load(File(path))
} catch (e: Exception) { } catch (e: Exception) {

@ -92,7 +92,7 @@ object Backup {
edit.commit() edit.commit()
} }
WebDavHelp.backUpWebDav(backupPath) WebDavHelp.backUpWebDav(backupPath)
if (path.isContentPath()) { if (path.isContentScheme()) {
copyBackup(context, Uri.parse(path), isAuto) copyBackup(context, Uri.parse(path), isAuto)
} else { } else {
if (path.isEmpty()) { if (path.isEmpty()) {

@ -7,14 +7,14 @@ import io.legado.app.App
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.isContentPath import io.legado.app.utils.isContentScheme
import org.jetbrains.anko.toast import org.jetbrains.anko.toast
import java.io.File import java.io.File
object ImportOldData { object ImportOldData {
fun importUri(context: Context, uri: Uri) { fun importUri(context: Context, uri: Uri) {
if (uri.isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach { DocumentFile.fromTreeUri(context, uri)?.listFiles()?.forEach {
when (it.name) { when (it.name) {
"myBookShelf.json" -> "myBookShelf.json" ->

@ -73,7 +73,7 @@ object Restore {
suspend fun restore(context: Context, path: String) { suspend fun restore(context: Context, path: String) {
withContext(IO) { withContext(IO) {
if (path.isContentPath()) { if (path.isContentScheme()) {
DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc -> DocumentFile.fromTreeUri(context, Uri.parse(path))?.listFiles()?.forEach { doc ->
for (fileName in Backup.backupFileNames) { for (fileName in Backup.backupFileNames) {
if (doc.name == fileName) { if (doc.name == fileName) {

@ -261,7 +261,7 @@ class AnalyzeTxtFile {
} }
private fun getBookFile(book: Book): File { private fun getBookFile(book: Book): File {
if (book.bookUrl.isContentPath()) { if (book.bookUrl.isContentScheme()) {
val uri = Uri.parse(book.bookUrl) val uri = Uri.parse(book.bookUrl)
val bookFile = FileUtils.getFile(LocalBook.cacheFolder, book.originName) val bookFile = FileUtils.getFile(LocalBook.cacheFolder, book.originName)
if (!bookFile.exists()) { if (!bookFile.exists()) {

@ -57,7 +57,7 @@ class EPUBFile(val book: io.legado.app.data.entities.Book) {
init { init {
try { try {
val epubReader = EpubReader() val epubReader = EpubReader()
val inputStream = if (book.bookUrl.isContentPath()) { val inputStream = if (book.bookUrl.isContentScheme()) {
val uri = Uri.parse(book.bookUrl) val uri = Uri.parse(book.bookUrl)
App.INSTANCE.contentResolver.openInputStream(uri) App.INSTANCE.contentResolver.openInputStream(uri)
} else { } else {

@ -37,7 +37,7 @@ object LocalBook {
fun importFile(uri: Uri): Book { fun importFile(uri: Uri): Book {
val path: String val path: String
val fileName = if (uri.isContentPath()) { val fileName = if (uri.isContentScheme()) {
path = uri.toString() path = uri.toString()
val doc = DocumentFile.fromSingleUri(App.INSTANCE, uri) val doc = DocumentFile.fromSingleUri(App.INSTANCE, uri)
doc?.let { doc?.let {
@ -94,7 +94,7 @@ object LocalBook {
} }
if (deleteOriginal) { if (deleteOriginal) {
if (book.bookUrl.isContentPath()) { if (book.bookUrl.isContentScheme()) {
val uri = Uri.parse(book.bookUrl) val uri = Uri.parse(book.bookUrl)
DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete()
} else { } else {

@ -26,7 +26,7 @@ class ImportBookSourceViewModel(app: Application) : BaseViewModel(app) {
fun importSourceFromFilePath(path: String) { fun importSourceFromFilePath(path: String) {
execute { execute {
val content = if (path.isContentPath()) { val content = if (path.isContentScheme()) {
//在前面被解码了,如果不进行编码,中文会无法识别 //在前面被解码了,如果不进行编码,中文会无法识别
val newPath = Uri.encode(path, ":/.") val newPath = Uri.encode(path, ":/.")
DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context)

@ -10,7 +10,7 @@ import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
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.isContentPath import io.legado.app.utils.isContentScheme
import io.legado.app.utils.readText import io.legado.app.utils.readText
import java.io.File import java.io.File
@ -22,7 +22,7 @@ class ImportReplaceRuleViewModel(app: Application) : BaseViewModel(app) {
fun importFromFilePath(path: String) { fun importFromFilePath(path: String) {
execute { execute {
val content = if (path.isContentPath()) { val content = if (path.isContentScheme()) {
//在前面被解码了,如果不进行编码,中文会无法识别 //在前面被解码了,如果不进行编码,中文会无法识别
val newPath = Uri.encode(path, ":/.") val newPath = Uri.encode(path, ":/.")
DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context)

@ -26,7 +26,7 @@ class ImportRssSourceViewModel(app: Application) : BaseViewModel(app) {
fun importSourceFromFilePath(path: String) { fun importSourceFromFilePath(path: String) {
execute { execute {
val content = if (path.isContentPath()) { val content = if (path.isContentScheme()) {
//在前面被解码了,如果不进行编码,中文会无法识别 //在前面被解码了,如果不进行编码,中文会无法识别
val newPath = Uri.encode(path, ":/.") val newPath = Uri.encode(path, ":/.")
DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context) DocumentFile.fromSingleUri(context, Uri.parse(newPath))?.readText(context)

@ -207,7 +207,7 @@ class CacheActivity : VMBaseActivity<CacheViewModel>(R.layout.activity_download)
when (requestCode) { when (requestCode) {
exportRequestCode -> if (resultCode == Activity.RESULT_OK) { exportRequestCode -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.isContentPath()) { if (uri.isContentScheme()) {
contentResolver.takePersistableUriPermission( contentResolver.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION

@ -20,7 +20,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) {
fun export(path: String, book: Book, finally: (msg: String) -> Unit) { fun export(path: String, book: Book, finally: (msg: String) -> Unit) {
execute { execute {
if (path.isContentPath()) { if (path.isContentScheme()) {
val uri = Uri.parse(path) val uri = Uri.parse(path)
DocumentFile.fromTreeUri(context, uri)?.let { DocumentFile.fromTreeUri(context, uri)?.let {
export(it, book) export(it, book)

@ -107,7 +107,7 @@ class BookInfoEditActivity :
} }
private fun coverChangeTo(uri: Uri) { private fun coverChangeTo(uri: Uri) {
if (uri.toString().isContentPath()) { if (uri.isContentScheme()) {
val doc = DocumentFile.fromSingleUri(this, uri) val doc = DocumentFile.fromSingleUri(this, uri)
doc?.name?.let { doc?.name?.let {
var file = this.externalFilesDir var file = this.externalFilesDir

@ -128,7 +128,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
tv_empty_msg.visible() tv_empty_msg.visible()
FilePicker.selectFolder(this, requestCodeSelectFolder) FilePicker.selectFolder(this, requestCodeSelectFolder)
} }
lastPath.isContentPath() -> { lastPath.isContentScheme() -> {
val rootUri = Uri.parse(lastPath) val rootUri = Uri.parse(lastPath)
rootDoc = DocumentFile.fromTreeUri(this, rootUri) rootDoc = DocumentFile.fromTreeUri(this, rootUri)
if (rootDoc == null) { if (rootDoc == null) {
@ -276,7 +276,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
when (requestCode) { when (requestCode) {
requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) { requestCodeSelectFolder -> if (resultCode == Activity.RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.isContentPath()) { if (uri.isContentScheme()) {
contentResolver.takePersistableUriPermission( contentResolver.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION or Intent.FLAG_GRANT_WRITE_URI_PERMISSION
@ -296,7 +296,7 @@ class ImportBookActivity : VMBaseActivity<ImportBookViewModel>(R.layout.activity
@Synchronized @Synchronized
override fun nextDoc(uri: Uri) { override fun nextDoc(uri: Uri) {
if (uri.toString().isContentPath()) { if (uri.toString().isContentScheme()) {
subDocs.add(DocumentFile.fromSingleUri(this, uri)!!) subDocs.add(DocumentFile.fromSingleUri(this, uri)!!)
} else { } else {
path = uri.path.toString() path = uri.path.toString()

@ -84,7 +84,8 @@ class ImportBookAdapter(context: Context, val callBack: CallBack) :
ll_brief.gone() ll_brief.gone()
cb_select.isChecked = false cb_select.isChecked = false
} else { } else {
val path = if (item.uri.isContentPath()) item.uri.toString() else item.uri.path val path =
if (item.uri.isContentScheme()) item.uri.toString() else item.uri.path
if (bookPaths.contains(path)) { if (bookPaths.contains(path)) {
iv_icon.setImageResource(R.drawable.ic_book_has) iv_icon.setImageResource(R.drawable.ic_book_has)
iv_icon.visible() iv_icon.visible()

@ -7,7 +7,7 @@ import io.legado.app.base.BaseViewModel
import io.legado.app.model.localBook.LocalBook import io.legado.app.model.localBook.LocalBook
import io.legado.app.utils.DocItem import io.legado.app.utils.DocItem
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.isContentPath import io.legado.app.utils.isContentScheme
import java.io.File import java.io.File
import java.util.* import java.util.*
@ -28,7 +28,7 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application)
execute { execute {
uriList.forEach { uriList.forEach {
val uri = Uri.parse(it) val uri = Uri.parse(it)
if (uri.isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromSingleUri(context, uri)?.delete() DocumentFile.fromSingleUri(context, uri)?.delete()
} else { } else {
uri.path?.let { path -> uri.path?.let { path ->

@ -248,7 +248,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
} }
val configZipPath = FileUtils.getPath(requireContext().eCacheDir, configFileName) val configZipPath = FileUtils.getPath(requireContext().eCacheDir, configFileName)
if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) { if (ZipUtils.zipFiles(exportFiles, File(configZipPath))) {
if (uri.isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc -> DocumentFile.fromTreeUri(requireContext(), uri)?.let { treeDoc ->
treeDoc.findFile(configFileName)?.delete() treeDoc.findFile(configFileName)?.delete()
treeDoc.createFile("", configFileName) treeDoc.createFile("", configFileName)
@ -391,7 +391,7 @@ class BgTextConfigDialog : BaseDialogFragment(), FilePickerDialog.CallBack {
} }
private fun setBgFromUri(uri: Uri) { private fun setBgFromUri(uri: Uri) {
if (uri.toString().isContentPath()) { if (uri.toString().isContentScheme()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri) val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc?.name?.let { doc?.name?.let {
val file = val file =

@ -381,13 +381,13 @@ object ChapterProvider {
typeface = try { typeface = try {
val fontPath = ReadBookConfig.textFont val fontPath = ReadBookConfig.textFont
when { when {
fontPath.isContentPath() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> { fontPath.isContentScheme() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O -> {
val fd = App.INSTANCE.contentResolver val fd = App.INSTANCE.contentResolver
.openFileDescriptor(Uri.parse(fontPath), "r")!! .openFileDescriptor(Uri.parse(fontPath), "r")!!
.fileDescriptor .fileDescriptor
Typeface.Builder(fd).build() Typeface.Builder(fd).build()
} }
fontPath.isContentPath() -> { fontPath.isContentScheme() -> {
Typeface.createFromFile(RealPathUtil.getPath(App.INSTANCE, Uri.parse(fontPath))) Typeface.createFromFile(RealPathUtil.getPath(App.INSTANCE, Uri.parse(fontPath)))
} }
fontPath.isNotEmpty() -> Typeface.createFromFile(fontPath) fontPath.isNotEmpty() -> Typeface.createFromFile(fontPath)

@ -477,7 +477,7 @@ class BookSourceActivity : VMBaseActivity<BookSourceViewModel>(R.layout.activity
} }
exportRequestCode -> { exportRequestCode -> {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.toString().isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(this, uri)?.let { DocumentFile.fromTreeUri(this, uri)?.let {
viewModel.exportSelection(adapter.getSelection(), it) viewModel.exportSelection(adapter.getSelection(), it)
} }

@ -18,7 +18,7 @@ import io.legado.app.help.storage.Restore
import io.legado.app.help.storage.WebDavHelp import io.legado.app.help.storage.WebDavHelp
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.isContentPath import io.legado.app.utils.isContentScheme
import io.legado.app.utils.longToast import io.legado.app.utils.longToast
import io.legado.app.utils.toast import io.legado.app.utils.toast
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -35,7 +35,7 @@ object BackupRestoreUi {
if (backupPath.isNullOrEmpty()) { if (backupPath.isNullOrEmpty()) {
selectBackupFolder(fragment, backupSelectRequestCode) selectBackupFolder(fragment, backupSelectRequestCode)
} else { } else {
if (backupPath.isContentPath()) { if (backupPath.isContentScheme()) {
val uri = Uri.parse(backupPath) val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri)
if (doc?.canWrite() == true) { if (doc?.canWrite() == true) {
@ -82,7 +82,7 @@ object BackupRestoreUi {
fragment.longToast("WebDavError:${it.localizedMessage}\n将从本地备份恢复。") fragment.longToast("WebDavError:${it.localizedMessage}\n将从本地备份恢复。")
val backupPath = fragment.getPrefString(PreferKey.backupPath) val backupPath = fragment.getPrefString(PreferKey.backupPath)
if (backupPath?.isNotEmpty() == true) { if (backupPath?.isNotEmpty() == true) {
if (backupPath.isContentPath()) { if (backupPath.isContentScheme()) {
val uri = Uri.parse(backupPath) val uri = Uri.parse(backupPath)
val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri) val doc = DocumentFile.fromTreeUri(fragment.requireContext(), uri)
if (doc?.canWrite() == true) { if (doc?.canWrite() == true) {
@ -125,7 +125,7 @@ object BackupRestoreUi {
when (requestCode) { when (requestCode) {
backupSelectRequestCode -> if (resultCode == RESULT_OK) { backupSelectRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.isContentPath()) { if (uri.isContentScheme()) {
App.INSTANCE.contentResolver.takePersistableUriPermission( App.INSTANCE.contentResolver.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION
@ -151,7 +151,7 @@ object BackupRestoreUi {
} }
restoreSelectRequestCode -> if (resultCode == RESULT_OK) { restoreSelectRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.isContentPath()) { if (uri.isContentScheme()) {
App.INSTANCE.contentResolver.takePersistableUriPermission( App.INSTANCE.contentResolver.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION
@ -173,7 +173,7 @@ object BackupRestoreUi {
} }
selectFolderRequestCode -> if (resultCode == RESULT_OK) { selectFolderRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.isContentPath()) { if (uri.isContentScheme()) {
App.INSTANCE.contentResolver.takePersistableUriPermission( App.INSTANCE.contentResolver.takePersistableUriPermission(
uri, uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION Intent.FLAG_GRANT_READ_URI_PERMISSION

@ -186,7 +186,7 @@ class OtherConfigFragment : BasePreferenceFragment(),
} }
private fun setCoverFromUri(uri: Uri) { private fun setCoverFromUri(uri: Uri) {
if (uri.toString().isContentPath()) { if (uri.isContentScheme()) {
val doc = DocumentFile.fromSingleUri(requireContext(), uri) val doc = DocumentFile.fromSingleUri(requireContext(), uri)
doc?.name?.let { doc?.name?.let {
var file = requireContext().externalFilesDir var file = requireContext().externalFilesDir

@ -262,7 +262,7 @@ class ReplaceRuleActivity :
} }
exportRequestCode -> if (resultCode == RESULT_OK) { exportRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.toString().isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(this, uri)?.let { DocumentFile.fromTreeUri(this, uri)?.let {
viewModel.exportSelection(adapter.getSelection(), it) viewModel.exportSelection(adapter.getSelection(), it)
} }

@ -17,11 +17,11 @@ import io.legado.app.data.entities.RssArticle
import io.legado.app.data.entities.RssSource import io.legado.app.data.entities.RssSource
import io.legado.app.data.entities.RssStar import io.legado.app.data.entities.RssStar
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.model.rss.Rss
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.rss.Rss
import io.legado.app.utils.DocumentUtils import io.legado.app.utils.DocumentUtils
import io.legado.app.utils.FileUtils import io.legado.app.utils.FileUtils
import io.legado.app.utils.isContentPath import io.legado.app.utils.isContentScheme
import io.legado.app.utils.writeBytes import io.legado.app.utils.writeBytes
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -111,7 +111,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
execute { execute {
val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg" val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg"
webData2bitmap(webPic)?.let { biteArray -> webData2bitmap(webPic)?.let { biteArray ->
if (path.isContentPath()) { if (path.isContentScheme()) {
val uri = Uri.parse(path) val uri = Uri.parse(path)
DocumentFile.fromTreeUri(context, uri)?.let { doc -> DocumentFile.fromTreeUri(context, uri)?.let { doc ->
DocumentUtils.createFileIfNotExist(doc, fileName) DocumentUtils.createFileIfNotExist(doc, fileName)

@ -268,7 +268,7 @@ class RssSourceActivity : VMBaseActivity<RssSourceViewModel>(R.layout.activity_r
} }
exportRequestCode -> if (resultCode == RESULT_OK) { exportRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.toString().isContentPath()) { if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(this, uri)?.let { DocumentFile.fromTreeUri(this, uri)?.let {
viewModel.exportSelection(adapter.getSelection(), it) viewModel.exportSelection(adapter.getSelection(), it)
} }

@ -68,7 +68,7 @@ class FontSelectDialog : BaseDialogFragment(),
if (fontPath.isNullOrEmpty()) { if (fontPath.isNullOrEmpty()) {
openFolder() openFolder()
} else { } else {
if (fontPath.isContentPath()) { if (fontPath.isContentScheme()) {
val doc = DocumentFile.fromTreeUri(requireContext(), Uri.parse(fontPath)) val doc = DocumentFile.fromTreeUri(requireContext(), Uri.parse(fontPath))
if (doc?.canRead() == true) { if (doc?.canRead() == true) {
loadFontFiles(doc) loadFontFiles(doc)
@ -209,7 +209,7 @@ class FontSelectDialog : BaseDialogFragment(),
when (requestCode) { when (requestCode) {
fontFolderRequestCode -> if (resultCode == RESULT_OK) { fontFolderRequestCode -> if (resultCode == RESULT_OK) {
data?.data?.let { uri -> data?.data?.let { uri ->
if (uri.toString().isContentPath()) { if (uri.toString().isContentScheme()) {
putPrefString(PreferKey.fontFolder, uri.toString()) putPrefString(PreferKey.fontFolder, uri.toString())
val doc = DocumentFile.fromTreeUri(requireContext(), uri) val doc = DocumentFile.fromTreeUri(requireContext(), uri)
if (doc != null) { if (doc != null) {

@ -139,7 +139,7 @@ data class DocItem(
DocumentsContract.Document.MIME_TYPE_DIR == attr DocumentsContract.Document.MIME_TYPE_DIR == attr
} }
val isContentPath get() = uri.toString().isContentPath() val isContentPath get() = uri.isContentScheme()
} }
@Throws(Exception::class) @Throws(Exception::class)

@ -11,10 +11,10 @@ val notImgHtmlRegex = "</?(?!img)\\w+[^>]*>".toRegex()
fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim() fun String?.safeTrim() = if (this.isNullOrBlank()) null else this.trim()
fun String?.isContentPath(): Boolean = this?.startsWith("content://") == true fun String?.isContentScheme(): Boolean = this?.startsWith("content://") == true
fun String.parseToUri(): Uri { fun String.parseToUri(): Uri {
return if (isContentPath()) { return if (isContentScheme()) {
Uri.parse(this) Uri.parse(this)
} else { } else {
Uri.fromFile(File(this)) Uri.fromFile(File(this))

@ -4,11 +4,11 @@ import android.content.Context
import android.net.Uri import android.net.Uri
import java.io.File import java.io.File
fun Uri.isContentPath() = this.toString().isContentPath() fun Uri.isContentScheme() = this.scheme == "content"
@Throws(Exception::class) @Throws(Exception::class)
fun Uri.readBytes(context: Context): ByteArray? { fun Uri.readBytes(context: Context): ByteArray? {
if (this.toString().isContentPath()) { if (this.toString().isContentScheme()) {
return DocumentUtils.readBytes(context, this) return DocumentUtils.readBytes(context, this)
} else { } else {
val path = RealPathUtil.getPath(context, this) val path = RealPathUtil.getPath(context, this)
@ -32,7 +32,7 @@ fun Uri.writeBytes(
context: Context, context: Context,
byteArray: ByteArray byteArray: ByteArray
): Boolean { ): Boolean {
if (this.toString().isContentPath()) { if (this.toString().isContentScheme()) {
return DocumentUtils.writeBytes(context, byteArray, this) return DocumentUtils.writeBytes(context, byteArray, this)
} else { } else {
val path = RealPathUtil.getPath(context, this) val path = RealPathUtil.getPath(context, this)

Loading…
Cancel
Save