From 0753a4b43679eb933a6178b8e2e91dfc39f2d0c2 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Thu, 15 Mar 2018 14:12:46 -0600 Subject: [PATCH] Send and Receive FloatingActionButtons hide when scrolling down on the TransactionsFragment --- .../activities/BoardActivity.java | 14 ++----- .../fragments/TransactionsFragment.java | 41 +++++++++++++++++-- .../views/TransactionListView.java | 2 +- app/src/main/res/layout/board.xml | 2 +- .../main/res/layout/fragment_transactions.xml | 23 +++-------- 5 files changed, 48 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java index 95c7fb4..bd5ff97 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/BoardActivity.java @@ -1,7 +1,6 @@ package cy.agorise.crystalwallet.activities; import android.app.ActivityOptions; -import android.arch.lifecycle.LiveData; import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; import android.content.res.Resources; @@ -23,9 +22,6 @@ import android.view.View; import android.view.animation.LinearInterpolator; import android.widget.ImageView; -import java.util.List; - -import butterknife.BindColor; import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; @@ -36,7 +32,6 @@ import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.fragments.TransactionsFragment; import de.hdodenhof.circleimageview.CircleImageView; -import cy.agorise.crystalwallet.models.CryptoNetBalance; import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; /** @@ -49,9 +44,6 @@ public class BoardActivity extends AppCompatActivity { @BindView(R.id.pager) public ViewPager mPager; - //@BindView(R.id.btnGeneralSettings) - //public ImageButton btnGeneralSettings; - @BindView(R.id.fabSend) public FloatingActionButton fabSend; @@ -182,7 +174,7 @@ public class BoardActivity extends AppCompatActivity { }); } - /* + /** * dispatch the user to the accounts fragment */ @OnClick(R.id.toolbar_user_img) @@ -221,7 +213,7 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); - long receiveCryptoNetAccountId = -1; + long receiveCryptoNetAccountId; if (this.cryptoNetAccountId != -1){ receiveCryptoNetAccountId = this.cryptoNetAccountId; } else { @@ -245,7 +237,7 @@ public class BoardActivity extends AppCompatActivity { } ft.addToBackStack(null); - long sendCryptoNetAccountId = -1; + long sendCryptoNetAccountId; if (this.cryptoNetAccountId != -1){ sendCryptoNetAccountId = this.cryptoNetAccountId; } else { diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java index 7bd7edb..fadbe25 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java @@ -6,7 +6,9 @@ import android.arch.lifecycle.ViewModelProviders; import android.arch.paging.PagedList; import android.os.Bundle; import android.support.annotation.Nullable; +import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -25,6 +27,10 @@ public class TransactionsFragment extends Fragment { @BindView(R.id.vTransactionListView) TransactionListView transactionListView; + RecyclerView balanceRecyclerView; + FloatingActionButton fabSend; + FloatingActionButton fabReceive; + public TransactionsFragment() { // Required empty public constructor } @@ -45,8 +51,37 @@ public class TransactionsFragment extends Fragment { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment - View v = inflater.inflate(R.layout.fragment_transactions, container, false); - ButterKnife.bind(this, v); + View view = inflater.inflate(R.layout.fragment_transactions, container, false); + ButterKnife.bind(this, view); + + // Gets the Balance RecyclerView + balanceRecyclerView = view.findViewById(R.id.transactionListView); + fabSend = getActivity().findViewById(R.id.fabSend); + fabReceive = getActivity().findViewById(R.id.fabReceive); + + // TODO move this listener to the activity, to make this fragment reusable + // Adds listener to the RecyclerView to show and hide buttons at the bottom of the screen + balanceRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public void onScrolled(RecyclerView recyclerView, int dx,int dy){ + super.onScrolled(recyclerView, dx, dy); + + // Scroll Down + if( dy >0 ) { + if( fabSend.isShown() ) + fabSend.hide(); + if( fabReceive.isShown() ) + fabReceive.hide(); + } + // Scroll Up + else if( dy <0 ) { + if( !fabSend.isShown() ) + fabSend.show(); + if( !fabReceive.isShown() ) + fabReceive.show(); + } + } + }); TransactionListViewModel transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class); LiveData> transactionsLiveData = transactionListViewModel.getTransactionList(); @@ -59,6 +94,6 @@ public class TransactionsFragment extends Fragment { } }); - return v; + return view; } } diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java index c828de0..c929844 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java @@ -85,7 +85,7 @@ public class TransactionListView extends RelativeLayout { final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); this.listView.setLayoutManager(linearLayoutManager); //Prevents the list to start again when scrolling to the end - this.listView.setNestedScrollingEnabled(false); + // this.listView.setNestedScrollingEnabled(false); /*this.listView.addOnScrollListener(new RecyclerView.OnScrollListener() { diff --git a/app/src/main/res/layout/board.xml b/app/src/main/res/layout/board.xml index 49f9d44..c6ae433 100644 --- a/app/src/main/res/layout/board.xml +++ b/app/src/main/res/layout/board.xml @@ -162,7 +162,7 @@ android:layout_height="wrap_content" android:layout_gravity="end|bottom" android:layout_margin="@dimen/fab_margin" - app:backgroundTint="@color/colorPrimaryDark" + app:backgroundTint="@color/colorPrimary" app:srcCompat="@drawable/ic_person_add" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_transactions.xml b/app/src/main/res/layout/fragment_transactions.xml index 881c8da..c847c93 100644 --- a/app/src/main/res/layout/fragment_transactions.xml +++ b/app/src/main/res/layout/fragment_transactions.xml @@ -1,25 +1,12 @@ - - + android:layout_height="wrap_content" + android:id="@+id/vTransactionListView" /> - - - - +