]> git.ktnx.net Git - mobile-ledger.git/commitdiff
keep the new transaction FAB hidden when the profile doesn't permit new transactions
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 27 Jan 2019 18:19:09 +0000 (20:19 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 27 Jan 2019 18:19:09 +0000 (20:19 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java

index 0944d1fa5dba521fd9f2c3675b14018ae2a503ae..6ce84c7827ec93338f814b0632e00b4c133f89c9 100644 (file)
@@ -144,12 +144,12 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
                     }
                 }));
 
-        fab.show();
+        mActivity.fabShouldShow();
         root.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                 if (fab != null) {
-                    if (dy < 0) fab.show();
+                    if (dy < 0) mActivity.fabShouldShow();
                     if (dy > 0) fab.hide();
                 }
             }
index f8bb6ce37c39727a9a8e958d11a11e06129d517b..83b608bff321561f3b0caac9ce191fead44beeff 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,8 @@ public class MainActivity extends AppCompatActivity {
                 if (profile == null) setTitle(R.string.app_name);
                 else setTitle(profile.getName());
                 updateLastUpdateTextFromDB();
+                if (profile.isPostingPermitted()) fab.show();
+                else fab.hide();
             });
         });
 
@@ -383,5 +388,8 @@ public class MainActivity extends AppCompatActivity {
             return 2;
         }
     }
-
+    public void fabShouldShow() {
+        MobileLedgerProfile profile = Data.profile.get();
+        if (profile.isPostingPermitted()) fab.show();
+    }
 }
index 6610c3b2deccd783f55a4f22d161c7663e378169..1f6fbda69e5e2d83d23ae77fe02e2d73898bf2c1 100644 (file)
@@ -149,11 +149,11 @@ public class TransactionListFragment extends MobileLedgerListFragment {
 
         FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
 
-        fab.show();
+        mActivity.fabShouldShow();
         root.addOnScrollListener(new RecyclerView.OnScrollListener() {
             @Override
             public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
-                if (dy < 0) fab.show();
+                if (dy < 0) mActivity.fabShouldShow();
                 if (dy > 0) fab.hide();
             }
         });