]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
set title when fragment is changed
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index ad124667f5b788088a7009e8151c7420fadd94ec..64f613827dc730e2e6f9efe654dabddb58bb1a85 100644 (file)
@@ -21,6 +21,7 @@ import android.content.Intent;
 import android.content.pm.PackageInfo;
 import android.os.Build;
 import android.os.Bundle;
+import android.support.annotation.ColorInt;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
@@ -34,6 +35,7 @@ import android.view.ContextMenu;
 import android.view.MenuItem;
 import android.view.View;
 import android.widget.LinearLayout;
+import android.widget.TextView;
 
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerAccount;
@@ -76,31 +78,6 @@ public class MainActivity extends AppCompatActivity {
 
         onAccountSummaryClicked(null);
     }
-
-    @Override
-    protected void onStart() {
-        super.onStart();
-        LinearLayout grp = drawer.findViewById(R.id.nav_actions);
-        for (int i = 0; i < grp.getChildCount(); i++) {
-            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-                grp.getChildAt(i).setBackgroundColor(
-                        getResources().getColor(R.color.drawer_background, getTheme()));
-            }
-            else {
-                grp.getChildAt(i)
-                        .setBackgroundColor(getResources().getColor(R.color.drawer_background));
-            }
-        }
-        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-            drawer.findViewById(R.id.nav_account_summary).setBackgroundColor(
-                    getResources().getColor(R.color.table_row_even_bg, getTheme()));
-        }
-        else {
-            drawer.findViewById(R.id.nav_account_summary)
-                    .setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
-        }
-    }
-
     public void fab_new_transaction_clicked(View view) {
         Intent intent = new Intent(this, NewTransactionActivity.class);
         startActivity(intent);
@@ -117,7 +94,7 @@ public class MainActivity extends AppCompatActivity {
         startActivity(intent);
     }
     public void markDrawerItemCurrent(int id) {
-        View item = drawer.findViewById(id);
+        TextView item = drawer.findViewById(id);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
         }
@@ -125,11 +102,15 @@ public class MainActivity extends AppCompatActivity {
             item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
         }
 
+        setTitle(item.getText());
+
+        @ColorInt int transparent = getResources().getColor(android.R.color.transparent);
+
         LinearLayout actions = drawer.findViewById(R.id.nav_actions);
         for (int i = 0; i < actions.getChildCount(); i++) {
             View view = actions.getChildAt(i);
             if (view.getId() != id) {
-                view.setBackgroundColor(getResources().getColor(android.R.color.transparent));
+                view.setBackgroundColor(transparent);
             }
         }
     }