mirror of
https://github.com/bitfireAT/davx5-ose
synced 2024-07-23 19:50:18 +00:00
Migrated startActivityForResult
(bitfireAT/davx5#407)
Migrated activity result Signed-off-by: Arnau Mora <arnyminerz@proton.me>
This commit is contained in:
parent
6d30ef42e4
commit
0ba00d7bb0
|
@ -37,15 +37,17 @@ import javax.inject.Inject
|
|||
@AndroidEntryPoint
|
||||
class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
companion object {
|
||||
const val REQUEST_INTRO = 0
|
||||
}
|
||||
|
||||
@Inject lateinit var accountsDrawerHandler: AccountsDrawerHandler
|
||||
|
||||
private lateinit var binding: ActivityAccountsBinding
|
||||
val model by viewModels<Model>()
|
||||
|
||||
private val introActivityLauncher = registerForActivityResult(IntroActivity.Contract) { cancelled ->
|
||||
if (cancelled) {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -54,8 +56,7 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
|
|||
CoroutineScope(Dispatchers.Default).launch {
|
||||
// use a separate thread to check whether IntroActivity should be shown
|
||||
if (IntroActivity.shouldShowIntroActivity(this@AccountsActivity)) {
|
||||
val intro = Intent(this@AccountsActivity, IntroActivity::class.java)
|
||||
startActivityForResult(intro, REQUEST_INTRO)
|
||||
introActivityLauncher.launch(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -89,14 +90,6 @@ class AccountsActivity: AppCompatActivity(), NavigationView.OnNavigationItemSele
|
|||
accountsDrawerHandler.initMenu(this, binding.navView.menu)
|
||||
}
|
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (requestCode == REQUEST_INTRO && resultCode == Activity.RESULT_CANCELED)
|
||||
finish()
|
||||
else
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (binding.drawerLayout.isDrawerOpen(GravityCompat.START))
|
||||
binding.drawerLayout.closeDrawer(GravityCompat.START)
|
||||
|
|
|
@ -5,7 +5,10 @@
|
|||
package at.bitfire.davdroid.ui.intro
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.result.contract.ActivityResultContract
|
||||
import androidx.core.content.res.ResourcesCompat
|
||||
import androidx.fragment.app.Fragment
|
||||
import at.bitfire.davdroid.R
|
||||
|
@ -79,4 +82,17 @@ class IntroActivity: AppIntro2() {
|
|||
finish()
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* For launching the [IntroActivity]. Result is `true` when the user cancelled the intro.
|
||||
*/
|
||||
object Contract: ActivityResultContract<Unit?, Boolean>() {
|
||||
override fun createIntent(context: Context, input: Unit?): Intent =
|
||||
Intent(context, IntroActivity::class.java)
|
||||
|
||||
override fun parseResult(resultCode: Int, intent: Intent?): Boolean {
|
||||
return resultCode == Activity.RESULT_CANCELED
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue