Send and Receive FloatingActionButtons hide when scrolling down on the TransactionsFragment

This commit is contained in:
Severiano Jaramillo 2018-03-15 14:12:46 -06:00
parent 247afeefcd
commit 0753a4b436
5 changed files with 48 additions and 34 deletions

View file

@ -1,7 +1,6 @@
package cy.agorise.crystalwallet.activities; package cy.agorise.crystalwallet.activities;
import android.app.ActivityOptions; import android.app.ActivityOptions;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent; import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
@ -23,9 +22,6 @@ import android.view.View;
import android.view.animation.LinearInterpolator; import android.view.animation.LinearInterpolator;
import android.widget.ImageView; import android.widget.ImageView;
import java.util.List;
import butterknife.BindColor;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
@ -36,7 +32,6 @@ import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment;
import cy.agorise.crystalwallet.fragments.SendTransactionFragment; import cy.agorise.crystalwallet.fragments.SendTransactionFragment;
import cy.agorise.crystalwallet.fragments.TransactionsFragment; import cy.agorise.crystalwallet.fragments.TransactionsFragment;
import de.hdodenhof.circleimageview.CircleImageView; import de.hdodenhof.circleimageview.CircleImageView;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel; import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
/** /**
@ -49,9 +44,6 @@ public class BoardActivity extends AppCompatActivity {
@BindView(R.id.pager) @BindView(R.id.pager)
public ViewPager mPager; public ViewPager mPager;
//@BindView(R.id.btnGeneralSettings)
//public ImageButton btnGeneralSettings;
@BindView(R.id.fabSend) @BindView(R.id.fabSend)
public FloatingActionButton fabSend; public FloatingActionButton fabSend;
@ -182,7 +174,7 @@ public class BoardActivity extends AppCompatActivity {
}); });
} }
/* /**
* dispatch the user to the accounts fragment * dispatch the user to the accounts fragment
*/ */
@OnClick(R.id.toolbar_user_img) @OnClick(R.id.toolbar_user_img)
@ -221,7 +213,7 @@ public class BoardActivity extends AppCompatActivity {
} }
ft.addToBackStack(null); ft.addToBackStack(null);
long receiveCryptoNetAccountId = -1; long receiveCryptoNetAccountId;
if (this.cryptoNetAccountId != -1){ if (this.cryptoNetAccountId != -1){
receiveCryptoNetAccountId = this.cryptoNetAccountId; receiveCryptoNetAccountId = this.cryptoNetAccountId;
} else { } else {
@ -245,7 +237,7 @@ public class BoardActivity extends AppCompatActivity {
} }
ft.addToBackStack(null); ft.addToBackStack(null);
long sendCryptoNetAccountId = -1; long sendCryptoNetAccountId;
if (this.cryptoNetAccountId != -1){ if (this.cryptoNetAccountId != -1){
sendCryptoNetAccountId = this.cryptoNetAccountId; sendCryptoNetAccountId = this.cryptoNetAccountId;
} else { } else {

View file

@ -6,7 +6,9 @@ import android.arch.lifecycle.ViewModelProviders;
import android.arch.paging.PagedList; import android.arch.paging.PagedList;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -25,6 +27,10 @@ public class TransactionsFragment extends Fragment {
@BindView(R.id.vTransactionListView) @BindView(R.id.vTransactionListView)
TransactionListView transactionListView; TransactionListView transactionListView;
RecyclerView balanceRecyclerView;
FloatingActionButton fabSend;
FloatingActionButton fabReceive;
public TransactionsFragment() { public TransactionsFragment() {
// Required empty public constructor // Required empty public constructor
} }
@ -45,8 +51,37 @@ public class TransactionsFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_transactions, container, false); View view = inflater.inflate(R.layout.fragment_transactions, container, false);
ButterKnife.bind(this, v); 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); TransactionListViewModel transactionListViewModel = ViewModelProviders.of(this).get(TransactionListViewModel.class);
LiveData<PagedList<CryptoCoinTransaction>> transactionsLiveData = transactionListViewModel.getTransactionList(); LiveData<PagedList<CryptoCoinTransaction>> transactionsLiveData = transactionListViewModel.getTransactionList();
@ -59,6 +94,6 @@ public class TransactionsFragment extends Fragment {
} }
}); });
return v; return view;
} }
} }

View file

@ -85,7 +85,7 @@ public class TransactionListView extends RelativeLayout {
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext()); final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager); this.listView.setLayoutManager(linearLayoutManager);
//Prevents the list to start again when scrolling to the end //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() { /*this.listView.addOnScrollListener(new RecyclerView.OnScrollListener() {

View file

@ -162,7 +162,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="end|bottom" android:layout_gravity="end|bottom"
android:layout_margin="@dimen/fab_margin" android:layout_margin="@dimen/fab_margin"
app:backgroundTint="@color/colorPrimaryDark" app:backgroundTint="@color/colorPrimary"
app:srcCompat="@drawable/ic_person_add" /> app:srcCompat="@drawable/ic_person_add" />
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>

View file

@ -1,25 +1,12 @@
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context="cy.agorise.crystalwallet.fragments.TransactionsFragment"> tools:context="cy.agorise.crystalwallet.fragments.TransactionsFragment">
<RelativeLayout <cy.agorise.crystalwallet.views.TransactionListView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:id="@+id/vTransactionListView" />
<!--<TextView </FrameLayout>
android:id="@+id/tvTransactionSearch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android: />
<Spinner
android:layout_width="match_parent"
android:layout_height="match_parent"></Spinner>
-->
<cy.agorise.crystalwallet.views.TransactionListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vTransactionListView" />
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>