- Cleaned unused imports in various Classes.

- Simplified BalancesFragment by removing a couple of unnecessary files and merging its funcionality into more compact classes/layouts
This commit is contained in:
Severiano Jaramillo 2018-10-16 11:39:39 -05:00
parent ed7dc5424e
commit 91bc799310
9 changed files with 54 additions and 188 deletions

View file

@ -3,11 +3,11 @@ package cy.agorise.crystalwallet.fragments;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -19,22 +19,20 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
import cy.agorise.crystalwallet.views.CryptoNetBalanceListView;
import cy.agorise.crystalwallet.views.CryptoNetBalanceListAdapter;
public class BalanceFragment extends Fragment {
CryptoNetBalanceListViewModel cryptoNetBalanceListViewModel;
@BindView(R.id.vCryptoNetBalanceListView)
CryptoNetBalanceListView vCryptoNetBalanceListView;
@BindView(R.id.tvNobalances)
public TextView tvNobalances;
@BindView(R.id.tvNoBalances)
TextView tvNoBalances;
@BindView(R.id.rvBalances)
RecyclerView rvBalances;
CryptoNetBalanceListAdapter balancesAdapter;
public BalanceFragment() {
// Required empty public constructor
@ -53,29 +51,32 @@ public class BalanceFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_balance, container, false);
ButterKnife.bind(this, view);
cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class);
LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList();
vCryptoNetBalanceListView.setData(null, this);
// Configure RecyclerView and its adapter
rvBalances.setLayoutManager(new LinearLayoutManager(getContext()));
balancesAdapter = new CryptoNetBalanceListAdapter(this);
rvBalances.setAdapter(balancesAdapter);
final Fragment fragment = this;
//Prevents the UI from an infinite scrolling of balances
rvBalances.setNestedScrollingEnabled(false);
cryptoNetBalanceListViewModel = ViewModelProviders.of(this).get(CryptoNetBalanceListViewModel.class);
final LiveData<List<CryptoNetBalance>> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList();
cryptoNetBalanceData.observe(this, new Observer<List<CryptoNetBalance>>() {
@Override
public void onChanged(List<CryptoNetBalance> cryptoNetBalances) {
vCryptoNetBalanceListView.setData(cryptoNetBalances, fragment);
balancesAdapter.submitList(cryptoNetBalances);
final int size = cryptoNetBalances.size();
if(size==0){
tvNobalances.setVisibility(View.VISIBLE);
}
else{
tvNobalances.setVisibility(View.INVISIBLE);
if(cryptoNetBalances != null && cryptoNetBalances.size() > 0) {
tvNoBalances.setVisibility(View.INVISIBLE);
} else {
tvNoBalances.setVisibility(View.VISIBLE);
}
}
});

View file

@ -9,7 +9,6 @@ import android.arch.paging.PagedList;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.enums.CryptoNet;
import cy.agorise.crystalwallet.models.Contact;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
/**
* Created by Henry Varona on 1/17/2018.

View file

@ -1,6 +1,7 @@
package cy.agorise.crystalwallet.views;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v7.recyclerview.extensions.ListAdapter;
import android.view.LayoutInflater;
@ -22,22 +23,23 @@ public class CryptoNetBalanceListAdapter extends ListAdapter<CryptoNetBalance, C
/*
* A LifecycleOwner fragment that will be used to call the ViewModelProviders
*/
Fragment fragment;
private Fragment fragment;
public CryptoNetBalanceListAdapter(Fragment fragment) {
super(CryptoNetBalance.DIFF_CALLBACK);
this.fragment = fragment;
}
@NonNull
@Override
public CryptoNetBalanceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public CryptoNetBalanceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.balance_list_item,parent,false);
return new CryptoNetBalanceViewHolder(v, fragment);
}
@Override
public void onBindViewHolder(CryptoNetBalanceViewHolder holder, int position) {
public void onBindViewHolder(@NonNull CryptoNetBalanceViewHolder holder, int position) {
CryptoNetBalance balance = getItem(position);
if (balance != null) {
holder.bindTo(balance);

View file

@ -1,107 +0,0 @@
package cy.agorise.crystalwallet.views;
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 java.util.List;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
import cy.agorise.crystalwallet.viewmodels.CryptoNetBalanceListViewModel;
/**
* Created by Henry Varona on 10/9/2017.
*
* A view that show the list of crypto net balances of the user.
* Each crypto net has its own list of crypto coin balances.
*
* With this view the user can see all of his/her account balances of
* every crypto coin.
*/
public class CryptoNetBalanceListView extends RelativeLayout {
LayoutInflater mInflater;
/*
* The root container of this view. Its a relative layout
*/
View rootView;
/*
* The list view that holds every crypto net balance item
*/
RecyclerView listView;
/*
* The adapter for the previous list view
*/
CryptoNetBalanceListAdapter listAdapter;
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoNetBalanceListView(Context context){
super(context);
this.mInflater = LayoutInflater.from(context);
init();
}
/*
* One of three constructors needed to be inflated from a layout
*/
public CryptoNetBalanceListView(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 CryptoNetBalanceListView(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
this.mInflater = LayoutInflater.from(context);
init();
}
/**
* Initialize the list view holding the crypto net balances
*/
public void init(){
//inflates the corresponding view
rootView = mInflater.inflate(R.layout.balance_list, this, true);
this.listView = rootView.findViewById(R.id.balanceListView);
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this.getContext());
this.listView.setLayoutManager(linearLayoutManager);
//Prevents the UI from an infinite scrolling of balances
this.listView.setNestedScrollingEnabled(false);
}
/*main_content
* Sets the data for the list of balances.
*
* @param data the list of crypto net balances that will be show to the user
* @param fragment a LifecycleOwner fragment to allow the inners views to use the ViewModels
*/
public void setData(List<CryptoNetBalance> data, Fragment fragment){
//initializes the list adapter
if (this.listAdapter == null) {
this.listAdapter = new CryptoNetBalanceListAdapter(fragment);
this.listView.setAdapter(this.listAdapter);
}
//sets the data of the list adapter
if (data != null) {
this.listAdapter.submitList(data);
}
}
}

View file

@ -1,15 +1,12 @@
package cy.agorise.crystalwallet.views;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.arch.lifecycle.LifecycleOwner;
import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.arch.paging.PagedList;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.RecyclerView;
import android.view.View;
@ -21,16 +18,11 @@ import java.util.HashMap;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.activities.SendTransactionActivity;
import cy.agorise.crystalwallet.dao.CrystalDatabase;
import cy.agorise.crystalwallet.fragments.ReceiveTransactionFragment;
import cy.agorise.crystalwallet.fragments.SendTransactionFragment;
import cy.agorise.crystalwallet.models.CryptoCoinBalance;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence;
import cy.agorise.crystalwallet.models.CryptoNetBalance;
import cy.agorise.crystalwallet.models.GeneralSetting;
import cy.agorise.crystalwallet.viewmodels.CryptoCoinBalanceListViewModel;
@ -45,7 +37,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
/*
* the view holding the icon of the crypto net
*/
ImageView cryptoNetIcon;
private ImageView cryptoNetIcon;
/*
* the view holding the name of the crypto net
@ -97,12 +89,12 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
this.cryptoNetAccountId = -1;
//TODO: use ButterKnife to load the views
cryptoNetIcon = (ImageView) itemView.findViewById(R.id.ivCryptoNetIcon);
cryptoNetName = (TextView) itemView.findViewById(R.id.tvCryptoNetName);
cryptoNetEquivalentTotal = (TextView) itemView.findViewById(R.id.tvCryptoNetEquivalentTotal);
cryptoCoinBalanceListView = (CryptoCoinBalanceListView) itemView.findViewById(R.id.cryptoCoinBalancesListView);
btnSendFromThisAccount = (Button) itemView.findViewById(R.id.btnSendFromThisAccount);
btnReceiveToThisAccount = (Button) itemView.findViewById(R.id.btnReceiveWithThisAccount);
cryptoNetIcon = itemView.findViewById(R.id.ivCryptoNetIcon);
cryptoNetName = itemView.findViewById(R.id.tvCryptoNetName);
cryptoNetEquivalentTotal = itemView.findViewById(R.id.tvCryptoNetEquivalentTotal);
cryptoCoinBalanceListView = itemView.findViewById(R.id.cryptoCoinBalancesListView);
btnSendFromThisAccount = itemView.findViewById(R.id.btnSendFromThisAccount);
btnReceiveToThisAccount = itemView.findViewById(R.id.btnReceiveWithThisAccount);
//Setting the send button
btnSendFromThisAccount.setOnClickListener(new View.OnClickListener() {
@ -211,9 +203,9 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
this.cryptoNetAccountId = balance.getAccountId();
/*
* The first letter should be in mayus
* The first letter should be in Uppercase
* */
final String crypto = balance.getCryptoNet().getLabel().toString().toLowerCase();
final String crypto = balance.getCryptoNet().getLabel().toLowerCase();
final String upperString = crypto.substring(0,1).toUpperCase() + crypto.substring(1);
cryptoNetName.setText(upperString);
@ -225,7 +217,7 @@ public class CryptoNetBalanceViewHolder extends RecyclerView.ViewHolder {
cryptoCoinBalanceListView.setData(null, this);
//Observes the livedata, so any of its changes on the database will be reloaded here
//Observes the LiveData, so any of its changes on the database will be reloaded here
cryptoCoinBalanceData.observe((LifecycleOwner)this.itemView.getContext(), new Observer<List<CryptoCoinBalance>>() {
@Override
public void onChanged(List<CryptoCoinBalance> cryptoCoinBalances) {

View file

@ -1,24 +1,13 @@
package cy.agorise.crystalwallet.views;
import android.arch.lifecycle.LiveData;
import android.arch.paging.PagedListAdapter;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
import java.util.List;
import cy.agorise.crystalwallet.R;
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended;
/**
@ -39,8 +28,9 @@ public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransacti
this.fragment = fragment;
}
@NonNull
@Override
public TransactionViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public TransactionViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.transaction_list_item,parent,false);
@ -48,7 +38,7 @@ public class TransactionListAdapter extends PagedListAdapter<CryptoCoinTransacti
}
@Override
public void onBindViewHolder(TransactionViewHolder holder, int position) {
public void onBindViewHolder(@NonNull TransactionViewHolder holder, int position) {
CryptoCoinTransactionExtended transaction = getItem(position);
if (transaction != null) {
holder.bindTo(transaction);

View file

@ -1,13 +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"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/balanceListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

View file

@ -1,23 +1,25 @@
<FrameLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="cy.agorise.crystalwallet.fragments.BalanceFragment">
<TextView
android:id="@+id/tvNobalances"
android:id="@+id/tvNoBalances"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/You_dont_have_balances"
android:textColor="@color/gray"
android:layout_marginTop="190dp"
android:layout_marginLeft="90dp"
android:textSize="15dp" />
android:layout_marginStart="100dp"
android:textSize="15sp" />
<cy.agorise.crystalwallet.views.CryptoNetBalanceListView
<android.support.v7.widget.RecyclerView
android:id="@+id/rvBalances"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/vCryptoNetBalanceListView" />
tools:listitem="@layout/balance_list_item"
tools:itemCount="1"/>
</FrameLayout>

View file

@ -10,9 +10,9 @@
android:layout_height="wrap_content"
android:text="@string/You_dont_have_contacts"
android:textColor="@color/gray"
android:textSize="15sp"
android:layout_marginTop="190dp"
android:layout_marginStart="100dp"
android:textSize="15sp" />
android:layout_marginStart="100dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvContacts"