Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 65c59746 authored by Sebastiano Barezzi's avatar Sebastiano Barezzi
Browse files

Twelve: MainActivity: Move intent flow handing to the usual `loadData()`

Change-Id: I5b9e1a78f0484c4ef2bd7abc2bfdfa41e46cb60d
parent f9fd41cb
Loading
Loading
Loading
Loading
+72 −65
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavOptions
import androidx.navigation.fragment.NavHostFragment
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
import org.lineageos.twelve.ext.navigateSafe
@@ -54,6 +55,19 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {

        lifecycleScope.launch {
            lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
                loadData()
            }
        }
    }

    override fun onDestroy() {
        removeOnNewIntentListener(intentListener)

        super.onDestroy()
    }

    private fun CoroutineScope.loadData() {
        launch {
            intentsViewModel.parsedIntent.collectLatest { parsedIntent ->
                parsedIntent?.handle {
                    when (it.action) {
@@ -125,13 +139,6 @@ class MainActivity : AppCompatActivity(R.layout.activity_main) {
            }
        }
    }
    }

    override fun onDestroy() {
        removeOnNewIntentListener(intentListener)

        super.onDestroy()
    }

    companion object {
        private val LOG_TAG = MainActivity::class.simpleName!!