From: Damyan Ivanov Date: Sun, 27 Jan 2019 18:19:09 +0000 (+0200) Subject: keep the new transaction FAB hidden when the profile doesn't permit new transactions X-Git-Tag: v0.4~9 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=22f72903c1b7d827064c90b4472ff5c69ab3ba2f;p=mobile-ledger.git keep the new transaction FAB hidden when the profile doesn't permit new transactions --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 0944d1fa..6ce84c78 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -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(); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index f8bb6ce3..83b608bf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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(); + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index 6610c3b2..1f6fbda6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -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(); } });