From ed7dc5424e7a4c8297cec07d8bdd3c3cbb094067 Mon Sep 17 00:00:00 2001 From: Severiano Jaramillo Date: Mon, 15 Oct 2018 16:51:48 -0500 Subject: [PATCH] - 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. --- .../activities/IntroActivity.java | 25 ---- .../fragments/ContactsFragment.java | 11 +- .../fragments/TransactionsFragment.java | 44 +++--- .../viewmodels/TransactionListViewModel.java | 7 - .../views/TransactionListAdapter.java | 2 +- .../views/TransactionListView.java | 128 ------------------ app/src/main/res/layout/activity_intro.xml | 20 --- app/src/main/res/layout/fragment_contacts.xml | 6 +- .../main/res/layout/fragment_transactions.xml | 59 ++++++-- app/src/main/res/layout/transaction_list.xml | 46 ------- 10 files changed, 78 insertions(+), 270 deletions(-) delete mode 100644 app/src/main/java/cy/agorise/crystalwallet/views/TransactionListView.java delete mode 100644 app/src/main/res/layout/transaction_list.xml diff --git a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java index 5da0a81..d66a163 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java +++ b/app/src/main/java/cy/agorise/crystalwallet/activities/IntroActivity.java @@ -2,48 +2,23 @@ package cy.agorise.crystalwallet.activities; import android.arch.lifecycle.ViewModelProviders; import android.content.Intent; -import android.content.pm.PackageManager; import android.media.MediaPlayer; 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.FragmentTransaction; -import android.support.v7.app.AppCompatActivity; import android.view.SurfaceHolder; import android.view.SurfaceView; import android.view.View; import android.widget.Button; -import android.widget.Toast; import com.thekhaeng.pushdownanim.PushDownAnim; -import java.util.List; - import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; 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.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.TransactionListViewModel; -import cy.agorise.crystalwallet.views.TransactionListView; public class IntroActivity extends CustomActivity { diff --git a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java index 644c213..3962380 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/ContactsFragment.java @@ -28,8 +28,8 @@ public class ContactsFragment extends Fragment { @BindView(R.id.rvContacts) RecyclerView rvContacts; - @BindView(R.id.tvNobalances) - public TextView tvNobalances; + @BindView(R.id.tvNoContacts) + TextView tvNoContacts; ContactListAdapter adapter; @@ -91,12 +91,11 @@ public class ContactsFragment extends Fragment { public void onChanged(@Nullable PagedList contacts) { adapter.submitList(contacts); - final int size = contacts.size(); - if(size==0){ - tvNobalances.setVisibility(View.VISIBLE); + if(contacts != null && contacts.size() > 0){ + tvNoContacts.setVisibility(View.INVISIBLE); } else{ - tvNobalances.setVisibility(View.INVISIBLE); + tvNoContacts.setVisibility(View.VISIBLE); } } }); 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 860c769..5291761 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java +++ b/app/src/main/java/cy/agorise/crystalwallet/fragments/TransactionsFragment.java @@ -5,12 +5,13 @@ import android.arch.lifecycle.Observer; import android.arch.lifecycle.ViewModelProviders; import android.arch.paging.PagedList; import android.os.Bundle; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; import android.support.v4.app.Fragment; +import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.text.Editable; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -26,30 +27,30 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnTextChanged; import cy.agorise.crystalwallet.R; -import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended; import cy.agorise.crystalwallet.viewmodels.TransactionListViewModel; -import cy.agorise.crystalwallet.views.TransactionListView; +import cy.agorise.crystalwallet.views.TransactionListAdapter; import cy.agorise.crystalwallet.views.TransactionOrderSpinnerAdapter; public class TransactionsFragment extends Fragment { - @BindView(R.id.vTransactionListView) - TransactionListView transactionListView; - @BindView(R.id.spTransactionsOrder) Spinner spTransactionsOrder; @BindView(R.id.etTransactionSearch) EditText etTransactionSearch; - @BindView(R.id.tvNobalances) - public TextView tvNobalances; + @BindView(R.id.tvNoTransactions) + TextView tvNoTransactions; + + @BindView(R.id.rvTransactions) + RecyclerView rvTransactions; - RecyclerView balanceRecyclerView; FloatingActionButton fabSend; FloatingActionButton fabReceive; + + TransactionListAdapter transactionListAdapter; TransactionListViewModel transactionListViewModel; LiveData> transactionsLiveData; @@ -70,20 +71,22 @@ public class TransactionsFragment 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_transactions, container, false); ButterKnife.bind(this, view); - // Gets the Balance RecyclerView - balanceRecyclerView = view.findViewById(R.id.transactionListView); + rvTransactions.setLayoutManager(new LinearLayoutManager(getContext())); + transactionListAdapter = new TransactionListAdapter(this); + rvTransactions.setAdapter(transactionListAdapter); + 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() { + rvTransactions.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx,int dy){ super.onScrolled(recyclerView, dx, dy); @@ -123,19 +126,16 @@ public class TransactionsFragment extends Fragment { transactionListViewModel.initTransactionList(orderSelected.getField(),etTransactionSearch.getText().toString()); transactionsLiveData = transactionListViewModel.getTransactionList(); - final Fragment fragment = this; transactionsLiveData.observe(this, new Observer>() { @Override - public void onChanged(@Nullable PagedList cryptoCoinTransactions) { - Log.i("Transactions","Transactions have change! Count:"+cryptoCoinTransactions.size()); - transactionListView.setData(cryptoCoinTransactions, fragment); + public void onChanged(@Nullable PagedList transactions) { + transactionListAdapter.submitList(transactions); - final int size = cryptoCoinTransactions.size(); - if(size==0){ - tvNobalances.setVisibility(View.VISIBLE); + if(transactions != null && transactions.size() > 0){ + tvNoTransactions.setVisibility(View.INVISIBLE); } else{ - tvNobalances.setVisibility(View.INVISIBLE); + tvNoTransactions.setVisibility(View.VISIBLE); } } }); @@ -148,7 +148,7 @@ public class TransactionsFragment extends Fragment { } public void initTransactionsOrderSpinner(){ - List spinnerValues = new ArrayList(); + List spinnerValues = new ArrayList<>(); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("date","Date",0,false)); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("amount","Amount",0,false)); spinnerValues.add(new TransactionOrderSpinnerAdapter.TransactionOrderSpinnerItem("is_input","In/Out",0,false)); diff --git a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java index 95fc64a..706cf6d 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java +++ b/app/src/main/java/cy/agorise/crystalwallet/viewmodels/TransactionListViewModel.java @@ -3,19 +3,12 @@ package cy.agorise.crystalwallet.viewmodels; import android.app.Application; import android.arch.lifecycle.AndroidViewModel; import android.arch.lifecycle.LiveData; -import android.arch.lifecycle.ViewModel; import android.arch.paging.DataSource; import android.arch.paging.LivePagedListBuilder; -import android.arch.paging.LivePagedListProvider; import android.arch.paging.PagedList; -import android.content.Context; - -import java.util.List; import cy.agorise.crystalwallet.dao.CrystalDatabase; -import cy.agorise.crystalwallet.models.CryptoCoinTransaction; import cy.agorise.crystalwallet.models.CryptoCoinTransactionExtended; -import cy.agorise.crystalwallet.views.TransactionListView; /** * Created by Henry Varona on 12/9/2017. 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 066c44f..09b782b 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java +++ b/app/src/main/java/cy/agorise/crystalwallet/views/TransactionListAdapter.java @@ -34,7 +34,7 @@ public class TransactionListAdapter extends PagedListAdapter 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); - } - } - - -} diff --git a/app/src/main/res/layout/activity_intro.xml b/app/src/main/res/layout/activity_intro.xml index b2b5066..3f7805d 100644 --- a/app/src/main/res/layout/activity_intro.xml +++ b/app/src/main/res/layout/activity_intro.xml @@ -1,24 +1,4 @@ - + android:layout_marginStart="100dp" + android:textSize="15sp" /> - + + + +