- Simplified TransactionsFragment view hierarchy and removed unused files.

- Improved TextViews that appear in both Contacts and Transactions when there are no items to display.
- Cleaned some unused code in different parts of the app.
This commit is contained in:
Severiano Jaramillo 2018-10-15 16:51:48 -05:00
parent d367373d8e
commit ed7dc5424e
10 changed files with 78 additions and 270 deletions

View file

@ -2,48 +2,23 @@ package cy.agorise.crystalwallet.activities;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.SurfaceHolder; import android.view.SurfaceHolder;
import android.view.SurfaceView; import android.view.SurfaceView;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast;
import com.thekhaeng.pushdownanim.PushDownAnim; import com.thekhaeng.pushdownanim.PushDownAnim;
import java.util.List;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.apigenerator.GrapheneApiGenerator;
import cy.agorise.crystalwallet.application.CrystalApplication;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.dialogs.material.ToastIt;
import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.fragments.ImportAccountOptionsFragment; import cy.agorise.crystalwallet.fragments.ImportAccountOptionsFragment;
import cy.agorise.crystalwallet.models.AccountSeed;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoNetAccount;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.network.CryptoNetManager;
import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoCoinBalanceGenerator;
import cy.agorise.crystalwallet.randomdatagenerators.RandomCryptoNetAccountGenerator;
import cy.agorise.crystalwallet.randomdatagenerators.RandomSeedGenerator;
import cy.agorise.crystalwallet.randomdatagenerators.RandomTransactionsGenerator;
import cy.agorise.crystalwallet.application.CrystalSecurityMonitor;
import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel; import cy.agorise.crystalwallet.viewmodels.AccountSeedListViewModel;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
import cy.agorise.crystalwallet.views.TransactionListView;
public class IntroActivity extends CustomActivity { public class IntroActivity extends CustomActivity {

View file

@ -28,8 +28,8 @@ public class ContactsFragment extends Fragment {
@BindView(R.id.rvContacts) @BindView(R.id.rvContacts)
RecyclerView rvContacts; RecyclerView rvContacts;
@BindView(R.id.tvNobalances) @BindView(R.id.tvNoContacts)
public TextView tvNobalances; TextView tvNoContacts;
ContactListAdapter adapter; ContactListAdapter adapter;
@ -91,12 +91,11 @@ public class ContactsFragment extends Fragment {
public void onChanged(@Nullable PagedList<Contact> contacts) { public void onChanged(@Nullable PagedList<Contact> contacts) {
adapter.submitList(contacts); adapter.submitList(contacts);
final int size = contacts.size(); if(contacts != null && contacts.size() > 0){
if(size==0){ tvNoContacts.setVisibility(View.INVISIBLE);
tvNobalances.setVisibility(View.VISIBLE);
} }
else{ else{
tvNobalances.setVisibility(View.INVISIBLE); tvNoContacts.setVisibility(View.VISIBLE);
} }
} }
}); });

View file

@ -5,12 +5,13 @@ import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders; 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.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.Editable; import android.text.Editable;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -26,30 +27,30 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnTextChanged; import butterknife.OnTextChanged;
import cy.agorise.crystalwallet.R; import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended; import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
import cy.agorise.crystalwallet.views.TransactionListView; import cy.agorise.crystalwallet.views.TransactionListAdapter;
import cy.agorise.crystalwallet.views.TransactionOrderSpinnerAdapter; import cy.agorise.crystalwallet.views.TransactionOrderSpinnerAdapter;
public class TransactionsFragment extends Fragment { public class TransactionsFragment extends Fragment {
@BindView(R.id.vTransactionListView)
TransactionListView transactionListView;
@BindView(R.id.spTransactionsOrder) @BindView(R.id.spTransactionsOrder)
Spinner spTransactionsOrder; Spinner spTransactionsOrder;
@BindView(R.id.etTransactionSearch) @BindView(R.id.etTransactionSearch)
EditText etTransactionSearch; EditText etTransactionSearch;
@BindView(R.id.tvNobalances) @BindView(R.id.tvNoTransactions)
public TextView tvNobalances; TextView tvNoTransactions;
@BindView(R.id.rvTransactions)
RecyclerView rvTransactions;
RecyclerView balanceRecyclerView;
FloatingActionButton fabSend; FloatingActionButton fabSend;
FloatingActionButton fabReceive; FloatingActionButton fabReceive;
TransactionListAdapter transactionListAdapter;
TransactionListViewModel transactionListViewModel; TransactionListViewModel transactionListViewModel;
LiveData<PagedList<CryptoCoinTransactionExtended>> transactionsLiveData; LiveData<PagedList<CryptoCoinTransactionExtended>> transactionsLiveData;
@ -70,20 +71,22 @@ public class TransactionsFragment extends Fragment {
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
// Inflate the layout for this fragment // Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_transactions, container, false); View view = inflater.inflate(R.layout.fragment_transactions, container, false);
ButterKnife.bind(this, view); ButterKnife.bind(this, view);
// Gets the Balance RecyclerView rvTransactions.setLayoutManager(new LinearLayoutManager(getContext()));
balanceRecyclerView = view.findViewById(R.id.transactionListView); transactionListAdapter = new TransactionListAdapter(this);
rvTransactions.setAdapter(transactionListAdapter);
fabSend = getActivity().findViewById(R.id.fabSend); fabSend = getActivity().findViewById(R.id.fabSend);
fabReceive = getActivity().findViewById(R.id.fabReceive); fabReceive = getActivity().findViewById(R.id.fabReceive);
// TODO move this listener to the activity, to make this fragment reusable // 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 // Adds listener to the RecyclerView to show and hide buttons at the bottom of the screen
balanceRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { rvTransactions.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
public void onScrolled(RecyclerView recyclerView, int dx,int dy){ public void onScrolled(RecyclerView recyclerView, int dx,int dy){
super.onScrolled(recyclerView, dx, dy); super.onScrolled(recyclerView, dx, dy);
@ -123,19 +126,16 @@ public class TransactionsFragment extends Fragment {
transactionListViewModel.initTransactionList(orderSelected.getField(),etTransactionSearch.getText().toString()); transactionListViewModel.initTransactionList(orderSelected.getField(),etTransactionSearch.getText().toString());
transactionsLiveData = transactionListViewModel.getTransactionList(); transactionsLiveData = transactionListViewModel.getTransactionList();
final Fragment fragment = this;
transactionsLiveData.observe(this, new Observer<PagedList<CryptoCoinTransactionExtended>>() { transactionsLiveData.observe(this, new Observer<PagedList<CryptoCoinTransactionExtended>>() {
@Override @Override
public void onChanged(@Nullable PagedList<CryptoCoinTransactionExtended> cryptoCoinTransactions) { public void onChanged(@Nullable PagedList<CryptoCoinTransactionExtended> transactions) {
Log.i("Transactions","Transactions have change! Count:"+cryptoCoinTransactions.size()); transactionListAdapter.submitList(transactions);
transactionListView.setData(cryptoCoinTransactions, fragment);
final int size = cryptoCoinTransactions.size(); if(transactions != null && transactions.size() > 0){
if(size==0){ tvNoTransactions.setVisibility(View.INVISIBLE);
tvNobalances.setVisibility(View.VISIBLE);
} }
else{ else{
tvNobalances.setVisibility(View.INVISIBLE); tvNoTransactions.setVisibility(View.VISIBLE);
} }
} }
}); });
@ -148,7 +148,7 @@ public class TransactionsFragment extends Fragment {
} }
public void initTransactionsOrderSpinner(){ public void initTransactionsOrderSpinner(){
List<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem> spinnerValues = new ArrayList<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem>(); List<TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem> spinnerValues = new ArrayList<>();
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("date","Date",0,false)); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("date","Date",0,false));
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("amount","Amount",0,false)); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("amount","Amount",0,false));
spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("is_input","In/Out",0,false)); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("is_input","In/Out",0,false));

View file

@ -3,19 +3,12 @@ package cy.agorise.crystalwallet.viewmodels;
import android.app.Application; import android.app.Application;
import android.arch.lifecycle.AndroidViewModel; import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.LiveData; import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.arch.paging.DataSource; import android.arch.paging.DataSource;
import android.arch.paging.LivePagedListBuilder; import android.arch.paging.LivePagedListBuilder;
import android.arch.paging.LivePagedListProvider;
import android.arch.paging.PagedList; import android.arch.paging.PagedList;
import android.content.Context;
import java.util.List;
import cy.agorise.crystalwallet.dao.CrystalDatabase; import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended; import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended;
import cy.agorise.crystalwallet.views.TransactionListView;
/** /**
* Created by Henry Varona on 12/9/2017. * Created by Henry Varona on 12/9/2017.

View file

@ -34,7 +34,7 @@ public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransacti
private Fragment fragment; private Fragment fragment;
TransactionListAdapter(Fragment fragment) { public TransactionListAdapter(Fragment fragment) {
super(CryptoCoinTransactionExtended.DIFF_CALLBACK); super(CryptoCoinTransactionExtended.DIFF_CALLBACK);
this.fragment = fragment; this.fragment = fragment;
} }

View file

@ -1,128 +0,0 @@
package cy.agorise.crystalwallet.views;
import android.arch.paging.PagedList;
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended;
import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel;
/**
* Created by Henry Varona on 10/9/2017.
*
* A list view showing many crypto net account transactions elements
*/
public class TransactionListView extends RelativeLayout {
LayoutInflater mInflater;
/*
* The root view of this view
*/
View rootView;
/*
* The list view that holds every transaction item
*/
RecyclerView listView;
/*
* The adapter for the previous list view
*/
TransactionListAdapter listAdapter;
TransactionListViewModel transactionListViewModel;
/*
* how much transactions will remain to show before the list loads more
*/
private int visibleThreshold = 5;
/*
* if true, the transaction list will be loading new data
*/
private boolean loading = true;
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context){
super(context);
this.mInflater = LayoutInflater.from(context);
init();
}
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context, AttributeSet attrs) {
super(context, attrs);
this.mInflater = LayoutInflater.from(context);
init();
}
/*
* One of three constructors needed to be inflated from a layout
*/
public TransactionListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context);
init();
}
/*
* Initializes this view
*/
public void init(){
rootView = mInflater.inflate(R.layout.transaction_list, this, true);
this.listView = rootView.findViewById(R.id.transactionListView);
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.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
if(!loading && linearLayoutManager.getItemCount() <= (linearLayoutManager.findLastVisibleItemPosition() + visibleThreshold)){
onLoadMore();
loading = true;
}
}
});*/
}
//public void onLoadMore(){
// listAdapter.add();
//}
/*
* Sets the elements data of this view
*
* @param data the transactions that will be showed to the user
*/
public void setData(PagedList<CryptoCoinTransactionExtended> data, Fragment fragment){
//Initializes the adapter of the transaction list
if (this.listAdapter == null) {
this.listAdapter = new TransactionListAdapter(fragment);
this.listView.setAdapter(this.listAdapter);
}
//Sets the data of the transaction list
if (data != null) {
this.listAdapter.submitList(data);
}
}
}

View file

@ -1,24 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!--
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_intro"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="cy.agorise.crystalwallet.activities.IntroActivity">
<cy.agorise.crystalwallet.views.TransactionListView
android:id="@+id/transaction_list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</cy.agorise.crystalwallet.views.TransactionListView>
</RelativeLayout>
-->
<android.support.constraint.ConstraintLayout <android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"

View file

@ -5,14 +5,14 @@
tools:context="cy.agorise.crystalwallet.fragments.ContactsFragment"> tools:context="cy.agorise.crystalwallet.fragments.ContactsFragment">
<TextView <TextView
android:id="@+id/tvNobalances" android:id="@+id/tvNoContacts"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/You_dont_have_contacts" android:text="@string/You_dont_have_contacts"
android:textColor="@color/gray" android:textColor="@color/gray"
android:layout_marginTop="190dp" android:layout_marginTop="190dp"
android:layout_marginLeft="100dp" android:layout_marginStart="100dp"
android:textSize="15dp" /> android:textSize="15sp" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/rvContacts" android:id="@+id/rvContacts"

View file

@ -1,22 +1,57 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <android.support.constraint.ConstraintLayout 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"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="cy.agorise.crystalwallet.fragments.TransactionsFragment"> tools:context="cy.agorise.crystalwallet.fragments.TransactionsFragment">
<TextView <RelativeLayout
android:id="@+id/tvNobalances" android:id="@+id/rlTransactionToolsHeader"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etTransactionSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/btnTransactionsFilterDisplay" />
<Button
android:id="@+id/btnTransactionsFilterDisplay"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/spTransactionsOrder"
android:visibility="gone" />
<Spinner
android:id="@+id/spTransactionsOrder"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_alignParentEnd="true"
android:background="@drawable/sort_transactions_icon"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvTransactions"
android:layout_width="match_parent"
android:layout_height="0dp"
android:padding="4dp"
android:clipToPadding="false"
app:layout_constraintTop_toBottomOf="@id/rlTransactionToolsHeader"
app:layout_constraintBottom_toBottomOf="parent"
tools:listitem="@layout/transaction_list_item" />
<TextView
android:id="@+id/tvNoTransactions"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/You_dont_have_transactions" android:text="@string/You_dont_have_transactions"
android:textColor="@color/gray" android:textColor="@color/gray"
android:layout_marginTop="190dp" android:textSize="15sp"
android:layout_marginLeft="90dp" android:textAlignment="center"
android:textSize="15dp" /> app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
<cy.agorise.crystalwallet.views.TransactionListView </android.support.constraint.ConstraintLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vTransactionListView" />
</FrameLayout>

View file

@ -1,46 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/rlTransactionToolsHeader"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:id="@+id/etTransactionSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_toStartOf="@+id/btnTransactionsFilterDisplay" />
<Button
android:id="@+id/btnTransactionsFilterDisplay"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_alignParentTop="true"
android:layout_toStartOf="@+id/spTransactionsOrder"
android:visibility="gone" />
<Spinner
android:id="@+id/spTransactionsOrder"
android:layout_width="40dip"
android:layout_height="40dip"
android:layout_alignParentEnd="true"
android:background="@drawable/sort_transactions_icon"
android:text="order" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/transactionListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:clipToPadding="false"
tools:listitem="@layout/transaction_list_item"
/>
</LinearLayout>