From 91bc799310c8d7b993977b16357e4a119dbfe1bb Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Tue, 16 Oct 2018 11:39:39 -0500 Subject: [PATCH] - Cleaned unused imports in various Classes. - Simplified BalancesFragment by removing a couple of unnecessary files and merging its funcionality into more compact classes/layouts --- .../fragments/BalanceFragment.java | 49 ++++---- .../viewmodels/ContactListViewModel.java | 1 - .../views/CryptoNetBalanceListAdapter.java | 8 +- .../views/CryptoNetBalanceListView.java | 107 ------------------ .../views/CryptoNetBalanceViewHolder.java | 28 ++--- .../views/TransactionListAdapter.java | 16 +-- app/src/main/res/layout/balance_list.xml | 13 --- app/src/main/res/layout/fragment_balance.xml | 16 +-- app/src/main/res/layout/fragment_contacts.xml | 4 +- 9 files changed, 54 insertions(+), 188 deletions(-) delete mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListView.java delete mode 100644 app/src/main/res/layout/balance_list.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/BalanceFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/BalanceFragment.java index 8522f47..a716892 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/BalanceFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/BalanceFragment.java @@ -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> 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> cryptoNetBalanceData = cryptoNetBalanceListViewModel.getCryptoNetBalanceList(); cryptoNetBalanceData.observe(this, new Observer>() { @Override public void onChanged(List 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); } } }); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/ContactListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/ContactListViewModel.java index 5a1a512..38da032 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/ContactListViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/ContactListViewModel.java @@ -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. diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java index 8469213..76b0f55 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceListAdapter.java @@ -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 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); - } - } - - -} diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java index 4a2e126..132c312 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/CryptoNetBalanceViewHolder.java @@ -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>() { @Override public void onChanged(List cryptoCoinBalances) { diff --git a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java index 09b782b..ae8d482 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java @@ -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 - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_balance.xml b/app/src/main/res/layout/fragment_balance.xml index 781c0da..804708c 100644 --- a/app/src/main/res/layout/fragment_balance.xml +++ b/app/src/main/res/layout/fragment_balance.xml @@ -1,23 +1,25 @@ - + android:layout_marginStart="100dp" + android:textSize="15sp" /> - + tools:listitem="@layout/balance_list_item" + tools:itemCount="1"/> diff --git a/app/src/main/res/layout/fragment_contacts.xml b/app/src/main/res/layout/fragment_contacts.xml index 0f5e196..318cd6e 100644 --- a/app/src/main/res/layout/fragment_contacts.xml +++ b/app/src/main/res/layout/fragment_contacts.xml @@ -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" />