]> git.ktnx.net Git - mobile-ledger.git/commitdiff
change toolbar title when editing/adding a pattern
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Jan 2021 13:26:01 +0000 (13:26 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 31 Jan 2021 13:26:01 +0000 (13:26 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/patterns/PatternsActivity.java
app/src/main/res/values/strings.xml

index c787769481cd6078759e899484f4d83236986890..793a2be207f52cf8619ec3019e66c2f4c75698bd 100644 (file)
@@ -20,13 +20,10 @@ package net.ktnx.mobileledger.ui.patterns;
 import android.os.Bundle;
 import android.view.Menu;
 
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
 import androidx.appcompat.app.ActionBar;
 import androidx.lifecycle.ViewModelProvider;
 import androidx.lifecycle.ViewModelStoreOwner;
 import androidx.navigation.NavController;
-import androidx.navigation.NavDestination;
 import androidx.navigation.fragment.NavHostFragment;
 
 import net.ktnx.mobileledger.R;
@@ -64,22 +61,17 @@ public class PatternsActivity extends CrashReportingActivity
                 getSupportFragmentManager().findFragmentById(R.id.fragment_container));
         navController = navHostFragment.getNavController();
 
-        navController.addOnDestinationChangedListener(
-                new NavController.OnDestinationChangedListener() {
-                    @Override
-                    public void onDestinationChanged(@NonNull NavController controller,
-                                                     @NonNull NavDestination destination,
-                                                     @Nullable Bundle arguments) {
-                        if (destination.getId() == R.id.patternListFragment) {
-                            b.fabAdd.show();
-                            b.fabSave.hide();
-                        }
-                        if (destination.getId() == R.id.patternDetailsFragment) {
-                            b.fabAdd.hide();
-                            b.fabSave.show();
-                        }
-                    }
-                });
+        navController.addOnDestinationChangedListener((controller, destination, arguments) -> {
+            if (destination.getId() == R.id.patternListFragment) {
+                b.fabAdd.show();
+                b.fabSave.hide();
+                b.toolbarLayout.setTitle(getString(R.string.title_activity_patterns));
+            }
+            if (destination.getId() == R.id.patternDetailsFragment) {
+                b.fabAdd.hide();
+                b.fabSave.show();
+            }
+        });
 
         b.toolbarLayout.setTitle(getString(R.string.title_activity_patterns));
 
@@ -88,13 +80,16 @@ public class PatternsActivity extends CrashReportingActivity
     }
     @Override
     public void onEditPattern(Long id) {
-        if (id == null){
+        if (id == null) {
             navController.navigate(R.id.action_patternListFragment_to_patternDetailsFragment);
+            b.toolbarLayout.setTitle(getString(R.string.title_new_pattern));
         }
-        else{
+        else {
             Bundle bundle = new Bundle();
             bundle.putLong(PatternDetailsFragment.ARG_PATTERN_ID, id);
-            navController.navigate(R.id.action_patternListFragment_to_patternDetailsFragment, bundle);
+            navController.navigate(R.id.action_patternListFragment_to_patternDetailsFragment,
+                    bundle);
+            b.toolbarLayout.setTitle(getString(R.string.title_edit_pattern));
         }
     }
     @Override
index 5682e8a4f13eb3de6d04a44bd5fc6b208ad54872..87efc191615188247a0f214fea26a0b0294d6005 100644 (file)
     <string name="choose_pattern_to_apply">Choose pattern to apply</string>
     <string name="pattern_name">Pattern name</string>
     <string name="implementation_pending">Not implemented yet</string>
+    <string name="title_edit_pattern">Edit pattern</string>
+    <string name="title_new_pattern">New pattern</string>
 </resources>