pull/1403/head
gedoor 3 years ago
parent 351b4340b8
commit d2c7512e6d
  1. 3
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  4. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  5. 4
      app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt
  6. 4
      app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt

@ -61,8 +61,7 @@ class AudioPlayActivity :
} }
} }
private val sourceEditResult = private val sourceEditResult =
registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) {
it ?: return@registerForActivityResult
if (it.resultCode == RESULT_OK) { if (it.resultCode == RESULT_OK) {
viewModel.upSource() viewModel.upSource()
} }

@ -48,7 +48,7 @@ class ChangeSourceDialog() : BaseDialogFragment(R.layout.dialog_change_source),
private val viewModel: ChangeSourceViewModel by viewModels() private val viewModel: ChangeSourceViewModel by viewModels()
private val adapter by lazy { ChangeSourceAdapter(requireContext(), viewModel, this) } private val adapter by lazy { ChangeSourceAdapter(requireContext(), viewModel, this) }
private val editSourceResult = private val editSourceResult =
registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) {
viewModel.startSearch() viewModel.startSearch()
} }

@ -85,7 +85,7 @@ class BookInfoActivity :
} }
} }
private val infoEditResult = registerForActivityResult( private val infoEditResult = registerForActivityResult(
StartActivityForResult(BookInfoEditActivity::class.java) StartActivityContract(BookInfoEditActivity::class.java)
) { ) {
if (it.resultCode == RESULT_OK) { if (it.resultCode == RESULT_OK) {
viewModel.upEditBook() viewModel.upEditBook()

@ -79,8 +79,7 @@ class ReadBookActivity : BaseReadBookActivity(),
} }
} }
private val sourceEditActivity = private val sourceEditActivity =
registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) {
it ?: return@registerForActivityResult
if (it.resultCode == RESULT_OK) { if (it.resultCode == RESULT_OK) {
viewModel.upBookSource { viewModel.upBookSource {
upMenuView() upMenuView()

@ -16,7 +16,7 @@ import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.lib.dialogs.alert import io.legado.app.lib.dialogs.alert
import io.legado.app.ui.login.SourceLoginActivity import io.legado.app.ui.login.SourceLoginActivity
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.StartActivityForResult import io.legado.app.utils.StartActivityContract
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.startActivity import io.legado.app.utils.startActivity
import io.legado.app.utils.viewbindingdelegate.viewBinding import io.legado.app.utils.viewbindingdelegate.viewBinding
@ -33,7 +33,7 @@ class RssSortActivity : VMBaseActivity<ActivityRssArtivlesBinding, RssSortViewMo
private val sortList = mutableListOf<Pair<String, String>>() private val sortList = mutableListOf<Pair<String, String>>()
private val fragmentMap = hashMapOf<String, Fragment>() private val fragmentMap = hashMapOf<String, Fragment>()
private val editSourceResult = registerForActivityResult( private val editSourceResult = registerForActivityResult(
StartActivityForResult(RssSourceEditActivity::class.java) StartActivityContract(RssSourceEditActivity::class.java)
) { ) {
if (it.resultCode == RESULT_OK) { if (it.resultCode == RESULT_OK) {
viewModel.initData(intent) { viewModel.initData(intent) {

@ -32,7 +32,7 @@ class SelectImageContract : ActivityResultContract<Int, SelectImageContract.Resu
} }
class StartActivityForResult(private val cls: Class<*>) : class StartActivityContract(private val cls: Class<*>) :
ActivityResultContract<Intent.() -> Unit, ActivityResult>() { ActivityResultContract<Intent.() -> Unit, ActivityResult>() {
override fun createIntent(context: Context, input: Intent.() -> Unit): Intent { override fun createIntent(context: Context, input: Intent.() -> Unit): Intent {
@ -47,4 +47,4 @@ class StartActivityForResult(private val cls: Class<*>) :
return ActivityResult(resultCode, intent) return ActivityResult(resultCode, intent)
} }
} }

Loading…
Cancel
Save