|
|
@ -12,6 +12,7 @@ import io.legado.app.lib.dialogs.alert |
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
import io.legado.app.lib.theme.primaryColor |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.* |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
import io.legado.app.utils.viewbindingdelegate.viewBinding |
|
|
|
|
|
|
|
import splitties.init.appCtx |
|
|
|
import splitties.views.onClick |
|
|
|
import splitties.views.onClick |
|
|
|
import java.io.FileOutputStream |
|
|
|
import java.io.FileOutputStream |
|
|
|
|
|
|
|
|
|
|
@ -27,17 +28,23 @@ class GroupEditDialog() : BaseDialogFragment(R.layout.dialog_book_group_edit) { |
|
|
|
private val viewModel by viewModels<GroupViewModel>() |
|
|
|
private val viewModel by viewModels<GroupViewModel>() |
|
|
|
private var bookGroup: BookGroup? = null |
|
|
|
private var bookGroup: BookGroup? = null |
|
|
|
val selectImage = registerForActivityResult(SelectImageContract()) { |
|
|
|
val selectImage = registerForActivityResult(SelectImageContract()) { |
|
|
|
readUri(it?.uri) { fileDoc, inputStream -> |
|
|
|
it ?: return@registerForActivityResult |
|
|
|
var file = requireContext().externalFiles |
|
|
|
it.uri ?: return@registerForActivityResult |
|
|
|
val suffix = fileDoc.name.substringAfterLast(".") |
|
|
|
readUri(it.uri) { fileDoc, inputStream -> |
|
|
|
val fileName = it.uri!!.inputStream(requireContext())!!.use { |
|
|
|
try { |
|
|
|
MD5Utils.md5Encode(it) + ".$suffix" |
|
|
|
var file = requireContext().externalFiles |
|
|
|
} |
|
|
|
val suffix = fileDoc.name.substringAfterLast(".") |
|
|
|
file = FileUtils.createFileIfNotExist(file, "covers", fileName) |
|
|
|
val fileName = it.uri.inputStream(requireContext()).getOrThrow().use { tmp -> |
|
|
|
FileOutputStream(file).use { outputStream -> |
|
|
|
MD5Utils.md5Encode(tmp) + ".$suffix" |
|
|
|
inputStream.copyTo(outputStream) |
|
|
|
} |
|
|
|
|
|
|
|
file = FileUtils.createFileIfNotExist(file, "covers", fileName) |
|
|
|
|
|
|
|
FileOutputStream(file).use { outputStream -> |
|
|
|
|
|
|
|
inputStream.copyTo(outputStream) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
binding.ivCover.load(file.absolutePath) |
|
|
|
|
|
|
|
} catch (e: Exception) { |
|
|
|
|
|
|
|
appCtx.toastOnUi(e.localizedMessage) |
|
|
|
} |
|
|
|
} |
|
|
|
binding.ivCover.load(file.absolutePath) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|