Commit b72fb267 authored by Mygod's avatar Mygod

Prevent fragment recreations

parent 86ebbd0d
...@@ -244,6 +244,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -244,6 +244,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
if (tf != null) title.setTypeface(tf) if (tf != null) title.setTypeface(tf)
if (savedInstanceState == null) displayFragment(new ProfilesFragment) if (savedInstanceState == null) displayFragment(new ProfilesFragment)
else previousPosition = drawer.getCurrentSelectedPosition
statusText = findViewById(R.id.status).asInstanceOf[TextView] statusText = findViewById(R.id.status).asInstanceOf[TextView]
txText = findViewById(R.id.tx).asInstanceOf[TextView] txText = findViewById(R.id.tx).asInstanceOf[TextView]
txRateText = findViewById(R.id.txRate).asInstanceOf[TextView] txRateText = findViewById(R.id.txRate).asInstanceOf[TextView]
...@@ -356,8 +357,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -356,8 +357,9 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
drawer.closeDrawer() drawer.closeDrawer()
} }
private var previousPosition: Int = _
override def onItemClick(view: View, position: Int, drawerItem: IDrawerItem[_, _ <: ViewHolder]): Boolean = { override def onItemClick(view: View, position: Int, drawerItem: IDrawerItem[_, _ <: ViewHolder]): Boolean = {
drawerItem.getIdentifier match { if (position == previousPosition) drawer.closeDrawer() else drawerItem.getIdentifier match {
case DRAWER_PROFILES => displayFragment(new ProfilesFragment) case DRAWER_PROFILES => displayFragment(new ProfilesFragment)
case DRAWER_RECOVERY => case DRAWER_RECOVERY =>
app.track("GlobalConfigFragment", "reset") app.track("GlobalConfigFragment", "reset")
...@@ -379,6 +381,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe ...@@ -379,6 +381,7 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
case DRAWER_CUSTOM_RULES => displayFragment(new CustomRulesFragment) case DRAWER_CUSTOM_RULES => displayFragment(new CustomRulesFragment)
case _ => // Ignore case _ => // Ignore
} }
previousPosition = position
true // unexpected cases will throw exception true // unexpected cases will throw exception
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment