Skip to content

Commit

Permalink
MainActivity doesn't lose title when rotating
Browse files Browse the repository at this point in the history
  • Loading branch information
mvarnagiris committed Oct 26, 2014
1 parent 471751f commit 4d07dc9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
- ```new``` Navigation drawer is below toolbar.
- ```new``` Overview landscape layout.
- ```fix``` Fixed calculator crash.
- ```fix``` Fixed import when categories went missing. By @i906.
- ```fix``` Fixed calculator buttons on pre-Lollipop devices. By @i906.
- ```fix``` Fixed import when categories went missing. (**@i906**)
- ```fix``` Fixed calculator buttons on pre-Lollipop devices. (**@i906**)
- ```fix``` Better handling of large numbers in calculator.
- ```fix``` Fixed disappearing note issue.
- ```fix``` Title not resetting any more when rotating device in home screen.

###Version: 0.11.5
- ```fix``` Fixed account balance calculation. Again.
Expand Down
28 changes: 16 additions & 12 deletions financius/src/main/java/com/code44/finance/ui/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.code44.finance.ui;

import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
Expand Down Expand Up @@ -99,31 +99,26 @@ public class MainActivity extends BaseActivity implements NavigationFragment.Nav
switch (item.getId()) {
case NavigationAdapter.NAV_ID_USER:
baseFragment = UserFragment.newInstance();
getSupportActionBar().setTitle(R.string.user);
break;

case NavigationAdapter.NAV_ID_OVERVIEW:
baseFragment = OverviewFragment.newInstance();
getAnalytics().trackScreen(Analytics.Screen.Overview);
getSupportActionBar().setTitle(R.string.overview);
break;

case NavigationAdapter.NAV_ID_ACCOUNTS:
baseFragment = AccountsFragment.newInstance(ModelListFragment.Mode.VIEW);
getAnalytics().trackScreen(Analytics.Screen.AccountList);
getSupportActionBar().setTitle(R.string.accounts);
break;

case NavigationAdapter.NAV_ID_TRANSACTIONS:
baseFragment = TransactionsFragment.newInstance();
getAnalytics().trackScreen(Analytics.Screen.TransactionList);
getSupportActionBar().setTitle(R.string.transactions);
break;

case NavigationAdapter.NAV_ID_REPORTS:
baseFragment = CategoriesReportFragment.newInstance();
getAnalytics().trackScreen(Analytics.Screen.CategoriesReport);
getSupportActionBar().setTitle("");
break;

default:
Expand All @@ -149,12 +144,21 @@ private void loadFragment(BaseFragment fragment) {
}

private void onFragmentLoaded(BaseFragment fragment) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (fragment instanceof OverviewFragment || fragment instanceof CategoriesReportFragment) {
getToolbar().setElevation(0);
} else {
getToolbar().setElevation(getResources().getDimension(R.dimen.elevation_header));
}
if (fragment instanceof UserFragment) {
getSupportActionBar().setTitle(R.string.user);
ViewCompat.setElevation(getToolbar(), getResources().getDimension(R.dimen.elevation_header));
} else if (fragment instanceof OverviewFragment) {
getSupportActionBar().setTitle(R.string.overview);
ViewCompat.setElevation(getToolbar(), 0);
} else if (fragment instanceof AccountsFragment) {
getSupportActionBar().setTitle(R.string.accounts);
ViewCompat.setElevation(getToolbar(), getResources().getDimension(R.dimen.elevation_header));
} else if (fragment instanceof TransactionsFragment) {
getSupportActionBar().setTitle(R.string.transactions);
ViewCompat.setElevation(getToolbar(), getResources().getDimension(R.dimen.elevation_header));
} else if (fragment instanceof CategoriesReportFragment) {
getSupportActionBar().setTitle("");
ViewCompat.setElevation(getToolbar(), 0);
}
}

Expand Down

0 comments on commit 4d07dc9

Please sign in to comment.