pull/1403/head
gedoor 3 years ago
parent 8100913489
commit 351b4340b8
  1. 2
      app/src/main/java/io/legado/app/ui/book/group/GroupEditDialog.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/info/edit/BookInfoEditActivity.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  4. 9
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  5. 15
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  6. 2
      app/src/main/java/io/legado/app/ui/qrcode/QrCodeActivity.kt
  7. 13
      app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt

@ -26,7 +26,7 @@ class GroupEditDialog() : BaseDialogFragment(R.layout.dialog_book_group_edit) {
private val viewModel by viewModels<GroupViewModel>()
private var bookGroup: BookGroup? = null
val selectImage = registerForActivityResult(SelectImageContract()) {
readUri(it?.second) { name, bytes ->
readUri(it?.uri) { name, bytes ->
var file = requireContext().externalFiles
file = FileUtils.createFileIfNotExist(file, "covers", name)
file.writeBytes(bytes)

@ -19,7 +19,7 @@ class BookInfoEditActivity :
ChangeCoverDialog.CallBack {
private val selectCover = registerForActivityResult(SelectImageContract()) {
it?.second?.let { uri ->
it.uri?.let { uri ->
coverChangeTo(uri)
}
}

@ -48,7 +48,7 @@ class BgTextConfigDialog : BaseDialogFragment(R.layout.dialog_read_bg_text) {
private var secondaryTextColor = 0
private val importFormNet = "网络导入"
private val selectBgImage = registerForActivityResult(SelectImageContract()) {
it?.second?.let { uri ->
it.uri?.let { uri ->
setBgFromUri(uri)
}
}

@ -21,10 +21,11 @@ class CoverConfigFragment : BasePreferenceFragment(),
private val requestCodeCover = 111
private val requestCodeCoverDark = 112
private val selectImage = registerForActivityResult(SelectImageContract()) {
val uri = it?.second ?: return@registerForActivityResult
when (it.first) {
requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri)
requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri)
it.uri?.let { uri ->
when (it.requestCode) {
requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri)
requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri)
}
}
}

@ -38,13 +38,14 @@ class ThemeConfigFragment : BasePreferenceFragment(),
private val requestCodeBgLight = 121
private val requestCodeBgDark = 122
private val selectImage = registerForActivityResult(SelectImageContract()) {
val uri = it?.second ?: return@registerForActivityResult
when (it.first) {
requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false)
}
requestCodeBgDark -> setBgFromUri(uri, PreferKey.bgImageN) {
upTheme(true)
it.uri?.let { uri ->
when (it.requestCode) {
requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false)
}
requestCodeBgDark -> setBgFromUri(uri, PreferKey.bgImageN) {
upTheme(true)
}
}
}
}

@ -20,7 +20,7 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResul
override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate)
private val selectQrImage = registerForActivityResult(SelectImageContract()) {
it?.second?.readBytes(this)?.let { bytes ->
it?.uri?.readBytes(this)?.let { bytes ->
val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
onScanResultCallback(QRCodeUtils.parseCodeResult(bitmap))
}

@ -7,7 +7,7 @@ import android.net.Uri
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContract
class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
class SelectImageContract : ActivityResultContract<Int, SelectImageContract.Result>() {
var requestCode: Int? = null
@ -18,13 +18,18 @@ class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
.setType("image/*")
}
override fun parseResult(resultCode: Int, intent: Intent?): Pair<Int?, Uri?>? {
override fun parseResult(resultCode: Int, intent: Intent?): Result {
if (resultCode == RESULT_OK) {
return Pair(requestCode, intent?.data)
return Result(requestCode, intent?.data)
}
return null
return Result(requestCode, null)
}
data class Result(
val requestCode: Int?,
val uri: Uri? = null
)
}
class StartActivityForResult(private val cls: Class<*>) :

Loading…
Cancel
Save