Skip to content

Commit

Permalink
all: smoother navigation (fixes#4886) (#4889)
Browse files Browse the repository at this point in the history
Co-authored-by: Gideon Okuro <[email protected]>
Co-authored-by: dogi <[email protected]>
  • Loading branch information
3 people authored Dec 20, 2024
1 parent 0475249 commit 77ae301
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {}
}
Expand Down Expand Up @@ -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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {}
}
Expand Down Expand Up @@ -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?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 77ae301

Please sign in to comment.