]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
fix the 'Posting committed' switch in the profile editor
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 1afc155d39e8e7d0bc6cd4dd7038406352e59476..fb8a732748a5a4bfc63246df8aa5dd2eb520386e 100644 (file)
@@ -22,6 +22,7 @@ import android.content.pm.PackageInfo;
 import android.os.Build;
 import android.os.Bundle;
 import android.support.annotation.ColorInt;
+import android.support.design.widget.FloatingActionButton;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentPagerAdapter;
@@ -62,6 +63,7 @@ public class MainActivity extends AppCompatActivity {
     private LinearLayout progressLayout;
     private SectionsPagerAdapter mSectionsPagerAdapter;
     private ViewPager mViewPager;
+    private FloatingActionButton fab;
 
     @Override
     protected void onStart() {
@@ -87,6 +89,7 @@ public class MainActivity extends AppCompatActivity {
         setContentView(R.layout.activity_main);
         Toolbar toolbar = findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
+        fab = findViewById(R.id.btn_add_transaction);
 
         Data.profile.addObserver((o, arg) -> {
             MobileLedgerProfile profile = Data.profile.get();
@@ -94,6 +97,14 @@ public class MainActivity extends AppCompatActivity {
                 if (profile == null) setTitle(R.string.app_name);
                 else setTitle(profile.getName());
                 updateLastUpdateTextFromDB();
+                if (profile.isPostingPermitted()) {
+                    toolbar.setSubtitle(null);
+                    fab.show();
+                }
+                else {
+                    toolbar.setSubtitle(R.string.profile_subitlte_read_only);
+                    fab.hide();
+                }
             });
         });
 
@@ -166,6 +177,8 @@ public class MainActivity extends AppCompatActivity {
         });
 
         findViewById(R.id.btn_no_profiles_add).setOnClickListener(v -> startAddProfileActivity());
+
+        findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked);
     }
     @Override
     protected void onResume() {
@@ -381,5 +394,8 @@ public class MainActivity extends AppCompatActivity {
             return 2;
         }
     }
-
+    public void fabShouldShow() {
+        MobileLedgerProfile profile = Data.profile.get();
+        if (profile.isPostingPermitted()) fab.show();
+    }
 }