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. 5
      app/src/main/java/io/legado/app/ui/config/CoverConfigFragment.kt
  5. 5
      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 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?.second) { name, bytes -> readUri(it?.uri) { name, bytes ->
var file = requireContext().externalFiles var file = requireContext().externalFiles
file = FileUtils.createFileIfNotExist(file, "covers", name) file = FileUtils.createFileIfNotExist(file, "covers", name)
file.writeBytes(bytes) file.writeBytes(bytes)

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

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

@ -21,12 +21,13 @@ class CoverConfigFragment : BasePreferenceFragment(),
private val requestCodeCover = 111 private val requestCodeCover = 111
private val requestCodeCoverDark = 112 private val requestCodeCoverDark = 112
private val selectImage = registerForActivityResult(SelectImageContract()) { private val selectImage = registerForActivityResult(SelectImageContract()) {
val uri = it?.second ?: return@registerForActivityResult it.uri?.let { uri ->
when (it.first) { when (it.requestCode) {
requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri) requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri)
requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri) requestCodeCoverDark -> setCoverFromUri(PreferKey.defaultCoverDark, uri)
} }
} }
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_cover) addPreferencesFromResource(R.xml.pref_config_cover)

@ -38,8 +38,8 @@ class ThemeConfigFragment : BasePreferenceFragment(),
private val requestCodeBgLight = 121 private val requestCodeBgLight = 121
private val requestCodeBgDark = 122 private val requestCodeBgDark = 122
private val selectImage = registerForActivityResult(SelectImageContract()) { private val selectImage = registerForActivityResult(SelectImageContract()) {
val uri = it?.second ?: return@registerForActivityResult it.uri?.let { uri ->
when (it.first) { when (it.requestCode) {
requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) { requestCodeBgLight -> setBgFromUri(uri, PreferKey.bgImage) {
upTheme(false) upTheme(false)
} }
@ -48,6 +48,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
} }
} }
} }
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.pref_config_theme) addPreferencesFromResource(R.xml.pref_config_theme)

@ -20,7 +20,7 @@ class QrCodeActivity : BaseActivity<ActivityQrcodeCaptureBinding>(), OnScanResul
override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate) override val binding by viewBinding(ActivityQrcodeCaptureBinding::inflate)
private val selectQrImage = registerForActivityResult(SelectImageContract()) { 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) val bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.size)
onScanResultCallback(QRCodeUtils.parseCodeResult(bitmap)) onScanResultCallback(QRCodeUtils.parseCodeResult(bitmap))
} }

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

Loading…
Cancel
Save