MainActivity: Bring back reworked quick exit feature as default
If we are on topLevelFragments but not appsContainerFragment, go back to it. If we are on appsContainerFragment, exit the app. If we are on any other fragment, go back normally. Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -32,6 +32,7 @@ import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.annotation.IdRes
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@@ -83,6 +84,13 @@ class MainActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
|
||||
private val gson: Gson = GsonBuilder().excludeFieldsWithModifiers(Modifier.TRANSIENT).create()
|
||||
|
||||
// TopLevelFragments
|
||||
private val topLevelFrags = listOf(
|
||||
R.id.appsContainerFragment,
|
||||
R.id.gamesContainerFragment,
|
||||
R.id.updatesFragment
|
||||
)
|
||||
|
||||
private lateinit var appConfig: AppBarConfiguration
|
||||
|
||||
override fun onConnected() {
|
||||
@@ -178,6 +186,23 @@ class MainActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
/* Check self update only for stable release, skip debug & nightlies*/
|
||||
if (BuildConfig.APPLICATION_ID == Constants.APP_ID) checkSelfUpdate()
|
||||
|
||||
// Handle quick exit from back actions
|
||||
onBackPressedDispatcher.addCallback(this) {
|
||||
if (!B.drawerLayout.isOpen) {
|
||||
if (navController.currentDestination?.id in topLevelFrags) {
|
||||
if (navController.currentDestination?.id == R.id.appsContainerFragment) {
|
||||
finish()
|
||||
} else {
|
||||
navController.navigate(R.id.appsContainerFragment)
|
||||
}
|
||||
} else {
|
||||
navController.navigateUp()
|
||||
}
|
||||
} else {
|
||||
B.drawerLayout.close()
|
||||
}
|
||||
}
|
||||
|
||||
// Handle intents
|
||||
when (intent?.action) {
|
||||
Constants.NAVIGATION_UPDATES -> B.navView.selectedItemId = R.id.updatesFragment
|
||||
@@ -187,9 +212,7 @@ class MainActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
// Handle views on fragments
|
||||
navController.addOnDestinationChangedListener { _, navDestination, _ ->
|
||||
when (navDestination.id) {
|
||||
R.id.appsContainerFragment,
|
||||
R.id.gamesContainerFragment,
|
||||
R.id.updatesFragment -> {
|
||||
in topLevelFrags -> {
|
||||
B.searchFab.visibility = View.VISIBLE
|
||||
B.navView.visibility = View.VISIBLE
|
||||
B.toolbar.visibility = View.VISIBLE
|
||||
@@ -244,11 +267,9 @@ class MainActivity : AppCompatActivity(), NetworkProvider.NetworkListener {
|
||||
("v${BuildConfig.VERSION_NAME}.${BuildConfig.VERSION_CODE}")
|
||||
}
|
||||
|
||||
appConfig = AppBarConfiguration.Builder(
|
||||
R.id.appsContainerFragment,
|
||||
R.id.gamesContainerFragment,
|
||||
R.id.updatesFragment
|
||||
).setOpenableLayout(B.root).build()
|
||||
appConfig = AppBarConfiguration.Builder(topLevelFrags.toSet())
|
||||
.setOpenableLayout(B.root)
|
||||
.build()
|
||||
setupActionBarWithNavController(navController, appConfig)
|
||||
B.navigation.setupWithNavController(navController)
|
||||
}
|
||||
|
||||
@@ -270,7 +270,13 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
binding.layoutDetailsToolbar.toolbar.apply {
|
||||
elevation = 0f
|
||||
navigationIcon = ContextCompat.getDrawable(view.context, R.drawable.ic_arrow_back)
|
||||
setNavigationOnClickListener { findNavController().navigateUp() }
|
||||
setNavigationOnClickListener {
|
||||
if (isExternal) {
|
||||
activity?.finish()
|
||||
} else {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
inflateMenu(R.menu.menu_details)
|
||||
|
||||
setOnMenuItemClickListener {
|
||||
@@ -306,15 +312,6 @@ class AppDetailsFragment : BaseFragment(R.layout.fragment_details) {
|
||||
uninstallActionEnabled = installed
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
activity?.onBackPressedDispatcher?.addCallback(this) {
|
||||
if (isExternal) {
|
||||
activity?.finish()
|
||||
} else {
|
||||
findNavController().navigateUp()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
||||
@@ -21,7 +21,6 @@ package com.aurora.store.view.ui.onboarding
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.activity.addCallback
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import androidx.navigation.fragment.findNavController
|
||||
@@ -76,14 +75,6 @@ class OnboardingFragment : Fragment(R.layout.fragment_onboarding) {
|
||||
binding.btnBackward.setOnClickListener {
|
||||
moveBackward()
|
||||
}
|
||||
|
||||
activity?.onBackPressedDispatcher?.addCallback(this) {
|
||||
if (binding.viewpager2.currentItem == 0) {
|
||||
activity?.finish()
|
||||
} else {
|
||||
binding.viewpager2.currentItem = binding.viewpager2.currentItem - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
||||
Reference in New Issue
Block a user