diff --git a/app/build.gradle b/app/build.gradle index 3dd7bf904c..c39d0dd8a9 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,8 +10,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 26 targetSdkVersion 34 - versionCode 2146 - versionName "0.21.46" + versionCode 2147 + versionName "0.21.47" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt index 2a3017aa89..f83aea55b9 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt @@ -187,25 +187,29 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N when (item.itemId) { R.id.action_chat -> { if (user?.id?.startsWith("guest") == false) { - openCallFragment(ChatHistoryListFragment()) + openCallFragment( + ChatHistoryListFragment(), + ChatHistoryListFragment::class.java.simpleName + ) } else { guestDialog(this) } } R.id.menu_goOnline -> wifiStatusSwitch() - R.id.action_sync -> { - logSyncInSharedPrefs() - } + R.id.action_sync -> logSyncInSharedPrefs() R.id.action_feedback -> { if (user?.id?.startsWith("guest") == false) { - openCallFragment(FeedbackListFragment()) + openCallFragment( + FeedbackListFragment(), + FeedbackListFragment::class.java.simpleName + ) } else { guestDialog(this) } } R.id.action_settings -> startActivity(Intent(this@DashboardActivity, SettingActivity::class.java)) - R.id.action_disclaimer -> openCallFragment(DisclaimerFragment()) - R.id.action_about -> openCallFragment(AboutFragment()) + R.id.action_disclaimer -> openCallFragment(DisclaimerFragment(), DisclaimerFragment::class.java.simpleName) + R.id.action_about -> openCallFragment(AboutFragment(), AboutFragment::class.java.simpleName) R.id.action_logout -> logout() else -> {} } @@ -788,7 +792,8 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N } override fun openCallFragment(f: Fragment) { - openCallFragment(f, "") + val tag = f::class.java.simpleName + openCallFragment(f,tag) } override fun openLibraryDetailFragment(library: RealmMyLibrary?) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite index aa0fee60d1..7255cdff4a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite +++ b/app/src/main/java/org/ole/planet/myplanet/ui/dashboard/DashboardActivity.kt.lite @@ -187,25 +187,29 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N when (item.itemId) { R.id.action_chat -> { if (user?.id?.startsWith("guest") == false) { - openCallFragment(ChatHistoryListFragment()) + openCallFragment( + ChatHistoryListFragment(), + ChatHistoryListFragment::class.java.simpleName + ) } else { guestDialog(this) } } R.id.menu_goOnline -> wifiStatusSwitch() - R.id.action_sync -> { - logSyncInSharedPrefs() - } + R.id.action_sync -> logSyncInSharedPrefs() R.id.action_feedback -> { if (user?.id?.startsWith("guest") == false) { - openCallFragment(FeedbackListFragment()) + openCallFragment( + FeedbackListFragment(), + FeedbackListFragment::class.java.simpleName + ) } else { guestDialog(this) } } R.id.action_settings -> startActivity(Intent(this@DashboardActivity, SettingActivity::class.java)) - R.id.action_disclaimer -> openCallFragment(DisclaimerFragment()) - R.id.action_about -> openCallFragment(AboutFragment()) + R.id.action_disclaimer -> openCallFragment(DisclaimerFragment(), DisclaimerFragment::class.java.simpleName) + R.id.action_about -> openCallFragment(AboutFragment(), AboutFragment::class.java.simpleName) R.id.action_logout -> logout() else -> {} } @@ -788,7 +792,8 @@ class DashboardActivity : DashboardElementActivity(), OnHomeItemClickListener, N } override fun openCallFragment(f: Fragment) { - openCallFragment(f, "") + val tag = f::class.java.simpleName + openCallFragment(f,tag) } override fun openLibraryDetailFragment(library: RealmMyLibrary?) { diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt index 3198454964..ce46332ea7 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/DashboardElementActivity.kt @@ -49,6 +49,8 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack lateinit var navigationView: BottomNavigationView var doubleBackToExitPressedOnce = false private lateinit var goOnline: MenuItem + var c = 0 + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) profileDbHandler = UserProfileDbHandler(this) @@ -84,14 +86,43 @@ abstract class DashboardElementActivity : SyncActivity(), FragmentManager.OnBack } fun openCallFragment(newFragment: Fragment, tag: String?) { - if (!isDestroyed && !isFinishing) { - supportFragmentManager.beginTransaction() - .replace(R.id.fragment_container, newFragment, tag) - .addToBackStack(null) - .commitAllowingStateLoss() + val fragmentManager = supportFragmentManager + if(c<2){ + c=0 + } + val existingFragment = fragmentManager.findFragmentByTag(tag) + if (tag == "") { + c++ + if(c>2){ + c-- + fragmentManager.popBackStack(tag, 0) + }else{ + fragmentManager.beginTransaction() + .replace(R.id.fragment_container, newFragment, tag) + .addToBackStack(tag) + .commit() + } + } else { + if (existingFragment != null && existingFragment.isVisible) { + return + } else if (existingFragment != null) { + if(c>0 && c>2){ + c=0 + } + fragmentManager.popBackStack(tag, 0) + } else { + if(c>0 && c>2){ + c=0 + } + if(tag!="") { + fragmentManager.beginTransaction() + .replace(R.id.fragment_container, newFragment, tag) + .addToBackStack(tag) + .commit() + } + } } } - override fun onPrepareOptionsMenu(menu: Menu): Boolean { goOnline.isVisible = showBetaFeature(Constants.KEY_SYNC, this) return super.onPrepareOptionsMenu(menu)