优化
This commit is contained in:
@@ -44,7 +44,7 @@ class ReadRssActivity : VMBaseActivity<ActivityRssReadBinding, ReadRssViewModel>
|
|||||||
private val saveImage = registerForActivityResult(HandleFileContract()) {
|
private val saveImage = registerForActivityResult(HandleFileContract()) {
|
||||||
it.uri?.let { uri ->
|
it.uri?.let { uri ->
|
||||||
ACache.get(this).put(imagePathKey, uri.toString())
|
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()) {
|
if (path.isNullOrEmpty()) {
|
||||||
selectSaveFolder()
|
selectSaveFolder()
|
||||||
} else {
|
} 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
|
webPic ?: return
|
||||||
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.isContentScheme()) {
|
if (uri.isContentScheme()) {
|
||||||
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)
|
||||||
?.writeBytes(context, biteArray)
|
?.writeBytes(context, biteArray)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val file = FileUtils.createFileIfNotExist(File(path), fileName)
|
val file =
|
||||||
|
FileUtils.createFileIfNotExist(File(uri.path ?: uri.toString()), fileName)
|
||||||
file.writeBytes(biteArray)
|
file.writeBytes(biteArray)
|
||||||
}
|
}
|
||||||
} ?: throw Throwable("NULL")
|
} ?: throw Throwable("NULL")
|
||||||
|
|||||||
Reference in New Issue
Block a user