pull/1226/head
gedoor 3 years ago
parent 42576d6d0b
commit 766ccc7029
  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. 10
      app/src/main/java/io/legado/app/ui/book/read/config/BgTextConfigDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/config/ThemeConfigFragment.kt
  5. 32
      app/src/main/java/io/legado/app/utils/ActivityResultContractUtils.kt
  6. 27
      app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt

@ -33,7 +33,7 @@ class GroupEditDialog : BaseDialogFragment() {
private val binding by viewBinding(DialogBookGroupEditBinding::bind) private val binding by viewBinding(DialogBookGroupEditBinding::bind)
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(ActivityResultContractUtils.SelectImage()) { val selectImage = registerForActivityResult(SelectImageContract()) {
it?.second?.let { uri -> it?.second?.let { uri ->
if (uri.isContentScheme()) { if (uri.isContentScheme()) {
binding.ivCover.load(uri.toString()) binding.ivCover.load(uri.toString())

@ -22,7 +22,7 @@ class BookInfoEditActivity :
VMBaseActivity<ActivityBookInfoEditBinding, BookInfoEditViewModel>(), VMBaseActivity<ActivityBookInfoEditBinding, BookInfoEditViewModel>(),
ChangeCoverDialog.CallBack { ChangeCoverDialog.CallBack {
private val selectCover = registerForActivityResult(ActivityResultContractUtils.SelectImage()) { private val selectCover = registerForActivityResult(SelectImageContract()) {
it?.second?.let { uri -> it?.second?.let { uri ->
coverChangeTo(uri) coverChangeTo(uri)
} }

@ -6,7 +6,6 @@ import android.graphics.Color
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.view.* import android.view.*
import androidx.activity.result.contract.ActivityResultContracts
import androidx.documentfile.provider.DocumentFile import androidx.documentfile.provider.DocumentFile
import com.jaredrummler.android.colorpicker.ColorPickerDialog import com.jaredrummler.android.colorpicker.ColorPickerDialog
import io.legado.app.R import io.legado.app.R
@ -46,9 +45,10 @@ class BgTextConfigDialog : BaseDialogFragment() {
private var primaryTextColor = 0 private var primaryTextColor = 0
private var secondaryTextColor = 0 private var secondaryTextColor = 0
private val importFormNet = "网络导入" private val importFormNet = "网络导入"
private val selectBgImage = registerForActivityResult(ActivityResultContracts.GetContent()) { private val selectBgImage = registerForActivityResult(SelectImageContract()) {
it ?: return@registerForActivityResult it?.second?.let { uri ->
setBgFromUri(it) setBgFromUri(uri)
}
} }
private val selectExportDir = registerForActivityResult(FilePicker()) { private val selectExportDir = registerForActivityResult(FilePicker()) {
it ?: return@registerForActivityResult it ?: return@registerForActivityResult
@ -122,7 +122,7 @@ class BgTextConfigDialog : BaseDialogFragment() {
ivBg.setImageResource(R.drawable.ic_image) ivBg.setImageResource(R.drawable.ic_image)
ivBg.setColorFilter(primaryTextColor) ivBg.setColorFilter(primaryTextColor)
root.setOnClickListener { root.setOnClickListener {
selectBgImage.launch("image/*") selectBgImage.launch(null)
} }
} }
} }

@ -42,7 +42,7 @@ class ThemeConfigFragment : BasePreferenceFragment(),
private val requestCodeCoverDark = 112 private val requestCodeCoverDark = 112
private val requestCodeBgLight = 121 private val requestCodeBgLight = 121
private val requestCodeBgDark = 122 private val requestCodeBgDark = 122
private val selectImage = registerForActivityResult(ActivityResultContractUtils.SelectImage()) { private val selectImage = registerForActivityResult(SelectImageContract()) {
val uri = it?.second ?: return@registerForActivityResult val uri = it?.second ?: return@registerForActivityResult
when (it.first) { when (it.first) {
requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri) requestCodeCover -> setCoverFromUri(PreferKey.defaultCover, uri)

@ -1,32 +0,0 @@
package io.legado.app.utils
import android.app.Activity.RESULT_OK
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract
object ActivityResultContractUtils {
class SelectImage : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
var requestCode: Int? = null
override fun createIntent(context: Context, input: Int?): Intent {
requestCode = input
return Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType("image/*")
}
override fun parseResult(resultCode: Int, intent: Intent?): Pair<Int?, Uri?>? {
if (resultCode == RESULT_OK) {
return Pair(requestCode, intent?.data)
}
return null
}
}
}

@ -0,0 +1,27 @@
package io.legado.app.utils
import android.app.Activity.RESULT_OK
import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.result.contract.ActivityResultContract
class SelectImageContract : ActivityResultContract<Int, Pair<Int?, Uri?>?>() {
var requestCode: Int? = null
override fun createIntent(context: Context, input: Int?): Intent {
requestCode = input
return Intent(Intent.ACTION_OPEN_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE)
.setType("image/*")
}
override fun parseResult(resultCode: Int, intent: Intent?): Pair<Int?, Uri?>? {
if (resultCode == RESULT_OK) {
return Pair(requestCode, intent?.data)
}
return null
}
}
Loading…
Cancel
Save