pull/1738/head
kunfei 3 years ago
parent 222a560d2b
commit 1562e956cd
  1. 4
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt
  2. 8
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -44,7 +44,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
private val saveImage = registerForActivityResult(HandleFileContract()) {
it.uri?.let { uri ->
ACache.get(this).put(imagePathKey, uri.toString())
viewModel.saveImage(webPic, uri.toString())
viewModel.saveImage(webPic, uri)
}
}
@ -155,7 +155,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
if (path.isNullOrEmpty()) {
selectSaveFolder()
} else {
viewModel.saveImage(webPic, path)
viewModel.saveImage(webPic, Uri.parse(path))
}
}

@ -131,19 +131,19 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application),
}
}
fun saveImage(webPic: String?, path: String) {
fun saveImage(webPic: String?, uri: Uri) {
webPic ?: return
execute {
val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg"
webData2bitmap(webPic)?.let { biteArray ->
if (path.isContentScheme()) {
val uri = Uri.parse(path)
if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(context, uri)?.let { doc ->
DocumentUtils.createFileIfNotExist(doc, fileName)
?.writeBytes(context, biteArray)
}
} else {
val file = FileUtils.createFileIfNotExist(File(path), fileName)
val file =
FileUtils.createFileIfNotExist(File(uri.path ?: uri.toString()), fileName)
file.writeBytes(biteArray)
}
} ?: throw Throwable("NULL")

Loading…
Cancel
Save