diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt index 6f4edd3d5..4b2303df0 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt @@ -61,8 +61,7 @@ class AudioPlayActivity : } } private val sourceEditResult = - registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { - it ?: return@registerForActivityResult + registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { if (it.resultCode == RESULT_OK) { viewModel.upSource() } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index 0847b10fd..918c8b4f5 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -48,7 +48,7 @@ class ChangeSourceDialog() : BaseDialogFragment(R.layout.dialog_change_source), private val viewModel: ChangeSourceViewModel by viewModels() private val adapter by lazy { ChangeSourceAdapter(requireContext(), viewModel, this) } private val editSourceResult = - registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { + registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { viewModel.startSearch() } diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt index 60f39936e..12e8d132f 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt @@ -85,7 +85,7 @@ class BookInfoActivity : } } private val infoEditResult = registerForActivityResult( - StartActivityForResult(BookInfoEditActivity::class.java) + StartActivityContract(BookInfoEditActivity::class.java) ) { if (it.resultCode == RESULT_OK) { viewModel.upEditBook() diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index c566d6aab..755ddade9 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -79,8 +79,7 @@ class ReadBookActivity : BaseReadBookActivity(), } } private val sourceEditActivity = - registerForActivityResult(StartActivityForResult(BookSourceEditActivity::class.java)) { - it ?: return@registerForActivityResult + registerForActivityResult(StartActivityContract(BookSourceEditActivity::class.java)) { if (it.resultCode == RESULT_OK) { viewModel.upBookSource { upMenuView() diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt index 81289c08c..296965a1e 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssSortActivity.kt @@ -16,7 +16,7 @@ import io.legado.app.databinding.DialogEditTextBinding import io.legado.app.lib.dialogs.alert import io.legado.app.ui.login.SourceLoginActivity 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.startActivity import io.legado.app.utils.viewbindingdelegate.viewBinding @@ -33,7 +33,7 @@ class RssSortActivity : VMBaseActivity>() private val fragmentMap = hashMapOf() private val editSourceResult = registerForActivityResult( - StartActivityForResult(RssSourceEditActivity::class.java) + StartActivityContract(RssSourceEditActivity::class.java) ) { if (it.resultCode == RESULT_OK) { viewModel.initData(intent) { diff --git a/app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt b/app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt index cf1ce1262..3c3a89b75 100644 --- a/app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt +++ b/app/src/main/java/io/legado/app/utils/ActivityResultContracts.kt @@ -32,7 +32,7 @@ class SelectImageContract : ActivityResultContract) : +class StartActivityContract(private val cls: Class<*>) : ActivityResultContract Unit, ActivityResult>() { override fun createIntent(context: Context, input: Intent.() -> Unit): Intent { @@ -47,4 +47,4 @@ class StartActivityForResult(private val cls: Class<*>) : return ActivityResult(resultCode, intent) } -} \ No newline at end of file +}