From 4e61fce0868c152f2a0b15ff537c469ba2d0741f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=A1=D1=83=D1=80?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Thu, 23 Aug 2018 17:23:06 +0800 Subject: [PATCH] v2.6.2 --- app/build.gradle | 4 +- .../com/yoshione/fingen/ActivityMain.java | 4 +- .../java/com/yoshione/fingen/ActivityPro.java | 10 +- .../java/com/yoshione/fingen/FgConst.java | 2 + .../com/yoshione/fingen/FragmentAccounts.java | 2 +- .../com/yoshione/fingen/FragmentPayee.java | 10 +- .../yoshione/fingen/FragmentTransactions.java | 154 ++++++++------- .../fingen/adapter/AdapterTransactions.java | 181 ++++++------------ .../adapter/TransactionsArrayAdapter.java | 22 ++- .../viewholders/TransactionViewHolder.java | 108 ++++------- .../TransactionViewHolderParams.java | 78 +++++--- .../com/yoshione/fingen/di/AppComponent.java | 2 + .../interfaces/ITransactionClickListener.java | 9 + .../ITransactionItemEventListener.java | 9 + .../res/layout/list_item_transactions_2.xml | 20 +- app/src/main/res/raw-ru/changelog.xml | 3 + app/src/main/res/raw/changelog.xml | 3 + 17 files changed, 320 insertions(+), 301 deletions(-) create mode 100644 app/src/main/java/com/yoshione/fingen/interfaces/ITransactionClickListener.java create mode 100644 app/src/main/java/com/yoshione/fingen/interfaces/ITransactionItemEventListener.java diff --git a/app/build.gradle b/app/build.gradle index f92cdff2..6c689649 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,8 +28,8 @@ android { applicationId "com.yoshione.fingen" minSdkVersion 21 targetSdkVersion 27 - versionCode 125 - versionName "2.6" + versionCode 127 + versionName "2.6.2" resValue "string", "app_name", "Fingen" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/com/yoshione/fingen/ActivityMain.java b/app/src/main/java/com/yoshione/fingen/ActivityMain.java index 49c58024..89c82fdb 100644 --- a/app/src/main/java/com/yoshione/fingen/ActivityMain.java +++ b/app/src/main/java/com/yoshione/fingen/ActivityMain.java @@ -55,7 +55,6 @@ import com.mikepenz.materialdrawer.model.DividerDrawerItem; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.sothree.slidinguppanel.SlidingUpPanelLayout; -import com.yoshione.fingen.adapter.AdapterTransactions; import com.yoshione.fingen.adapter.TransactionsArrayAdapter; import com.yoshione.fingen.dao.SendersDAO; import com.yoshione.fingen.dao.SmsDAO; @@ -66,6 +65,7 @@ import com.yoshione.fingen.fts.ActivityScanQR; import com.yoshione.fingen.iab.BillingService; import com.yoshione.fingen.interfaces.IAbstractModel; +import com.yoshione.fingen.interfaces.ITransactionItemEventListener; import com.yoshione.fingen.managers.AccountsSetManager; import com.yoshione.fingen.managers.TransactionManager; import com.yoshione.fingen.model.AccountsSet; @@ -900,7 +900,7 @@ protected void onActivityResult(final int requestCode, final int resultCode, fin final Dialog[] dialog = new Dialog[]{null}; final TransactionsArrayAdapter arrayAdapter = new TransactionsArrayAdapter( - this, transactions, new AdapterTransactions.OnTransactionItemEventListener() { + this, transactions, new ITransactionItemEventListener() { @Override public void onTransactionItemClick(Transaction foundTransaction) { dialog[0].dismiss(); diff --git a/app/src/main/java/com/yoshione/fingen/ActivityPro.java b/app/src/main/java/com/yoshione/fingen/ActivityPro.java index 96e4bbf1..7f6dd89d 100644 --- a/app/src/main/java/com/yoshione/fingen/ActivityPro.java +++ b/app/src/main/java/com/yoshione/fingen/ActivityPro.java @@ -80,11 +80,11 @@ private void updateRW() { if (!skuDetailsWrapper.isPurchased()) { mBillingService.getBillingProcessor().purchase(ActivityPro.this, skuDetailsWrapper.getSkuDetails().productId); } else { - unsubscribeOnDestroy( - mBillingService.consumePurchase(skuDetailsWrapper.getSkuDetails().productId) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(() -> mAdapterSku.notifyDataSetChanged())); +// unsubscribeOnDestroy( +// mBillingService.consumePurchase(skuDetailsWrapper.getSkuDetails().productId) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(() -> mAdapterSku.notifyDataSetChanged())); } }); mAdapterSku.getItemList().add(reportsItem); diff --git a/app/src/main/java/com/yoshione/fingen/FgConst.java b/app/src/main/java/com/yoshione/fingen/FgConst.java index aa76fa62..70bc5b59 100644 --- a/app/src/main/java/com/yoshione/fingen/FgConst.java +++ b/app/src/main/java/com/yoshione/fingen/FgConst.java @@ -12,6 +12,8 @@ public class FgConst { public static final String FRAGMENT_TRANSACTIONS = "transactions"; // + public static final int NUMBER_ITEMS_TO_BE_LOADED = 25; + public static final String TEI_DATETIME = "datetime"; public static final String TEI_ACCOUNT = "account"; public static final String TEI_PAYEE_DEST_ACC = "payee_dest_acc"; diff --git a/app/src/main/java/com/yoshione/fingen/FragmentAccounts.java b/app/src/main/java/com/yoshione/fingen/FragmentAccounts.java index 50afa834..9ecffbe6 100644 --- a/app/src/main/java/com/yoshione/fingen/FragmentAccounts.java +++ b/app/src/main/java/com/yoshione/fingen/FragmentAccounts.java @@ -386,7 +386,7 @@ public void initContextMenuAccounts(MenuItem item) { case R.id.action_show_transactions: { if (Objects.requireNonNull(getActivity()).getClass().equals(ActivityMain.class)) { ActivityMain activityMain = (ActivityMain) getActivity(); - if (activityMain.fragmentTransactions.adapterFilters != null) { + if (activityMain.fragmentTransactions.adapterF != null) { Account account = mAccountsDAO.get().getAccountByID(info.id); AccountFilter filter = new AccountFilter(0); filter.addAccount(account.getID()); diff --git a/app/src/main/java/com/yoshione/fingen/FragmentPayee.java b/app/src/main/java/com/yoshione/fingen/FragmentPayee.java index cde73a33..b006f370 100644 --- a/app/src/main/java/com/yoshione/fingen/FragmentPayee.java +++ b/app/src/main/java/com/yoshione/fingen/FragmentPayee.java @@ -1,5 +1,6 @@ package com.yoshione.fingen; +import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.os.Handler; @@ -115,9 +116,12 @@ public void afterTextChanged(Editable editable) { if (mCallback.isShowKeyboard()) { if (hasFocus) { new Handler().postDelayed(() -> { - InputMethodManager imm = (InputMethodManager) FragmentPayee.this.getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); - if (imm != null) { - imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); + Activity activity = FragmentPayee.this.getActivity(); + if (activity != null) { + InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT); + } } }, 200); } diff --git a/app/src/main/java/com/yoshione/fingen/FragmentTransactions.java b/app/src/main/java/com/yoshione/fingen/FragmentTransactions.java index 89ae98dd..300b2c86 100644 --- a/app/src/main/java/com/yoshione/fingen/FragmentTransactions.java +++ b/app/src/main/java/com/yoshione/fingen/FragmentTransactions.java @@ -55,6 +55,7 @@ import com.yoshione.fingen.interfaces.IAbstractModel; import com.yoshione.fingen.interfaces.ILoadMoreFinish; import com.yoshione.fingen.interfaces.IOnLoadMore; +import com.yoshione.fingen.interfaces.ITransactionItemEventListener; import com.yoshione.fingen.managers.AccountsSetManager; import com.yoshione.fingen.managers.FilterManager; import com.yoshione.fingen.managers.SumsManager; @@ -99,10 +100,9 @@ */ public class FragmentTransactions extends BaseListFragment implements AdapterFilters.OnFilterChangeListener, - AdapterTransactions.OnTransactionItemEventListener, IOnLoadMore { + ITransactionItemEventListener, IOnLoadMore { private static final String TAG = "FragmentTransactions"; - public static final int NUMBER_ITEMS_TO_BE_LOADED = 25; private static final int CONTEXT_MENU_TRANSACTIONS = 0; // @@ -167,12 +167,15 @@ public class FragmentTransactions extends BaseListFragment implements AdapterFil View mFabBGLayout; // - private AdapterTransactions adapter; - AdapterFilters adapterFilters; + private AdapterTransactions adapterT; + AdapterFilters adapterF; private int contextMenuTarget = -1; private boolean isInSelectionMode; private StickyHeaderDecoration stickyHeaderDecoration; FabMenuController mFabMenuController; + private volatile boolean loading; + private final int visibleThreshold = 10; + public volatile boolean endOfList = false; @Inject BillingService mBillingService; @@ -213,20 +216,38 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, FgLinearLayoutManager layoutManagerFilters = new FgLinearLayoutManager(getActivity()); recyclerViewFilters.setLayoutManager(layoutManagerFilters); - adapter = new AdapterTransactions(recyclerView, this, (ToolbarActivity) getActivity()); - adapter.setHasStableIds(true); - adapter.setmOnTransactionItemClickListener(this); - adapterFilters = new AdapterFilters(getActivity(), this, this::editFilter); - adapterFilters.setHasStableIds(true); + adapterT = new AdapterTransactions(this, this, (ToolbarActivity) getActivity()); + adapterT.setHasStableIds(true); + adapterF = new AdapterFilters(getActivity(), this, this::editFilter); + adapterF.setHasStableIds(true); - stickyHeaderDecoration = new StickyHeaderDecoration(adapter); + stickyHeaderDecoration = new StickyHeaderDecoration(adapterT); - recyclerView.setAdapter(adapter); + final LinearLayoutManager linearLayoutManager = new FgLinearLayoutManager(getActivity()); + + recyclerView.setLayoutManager(linearLayoutManager); + recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + @Override + public synchronized void onScrolled(RecyclerView recyclerView,int dx, int dy) { + super.onScrolled(recyclerView, dx, dy); + int totalItemCount = linearLayoutManager.getItemCount(); + int lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); + if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { + // End has been reached + // Do something + if (!endOfList) { + loading = true; + loadMore(FgConst.NUMBER_ITEMS_TO_BE_LOADED, () -> /*new Handler().postDelayed(() -> */adapterT.notifyDataSetChanged()/*, 100)*/); + } + } + } + }); + recyclerView.setAdapter(adapterT); recyclerView.addItemDecoration(stickyHeaderDecoration); - recyclerViewFilters.setAdapter(adapterFilters); + recyclerViewFilters.setAdapter(adapterF); switchAllFilters.setOnClickListener(v -> { - for (AbstractFilter filter : adapterFilters.getFilterList()) { + for (AbstractFilter filter : adapterF.getFilterList()) { filter.setEnabled(switchAllFilters.isChecked()); } @@ -250,7 +271,7 @@ public void onPanelSlide(View panel, float slideOffset) { @Override public void onPanelStateChanged(View panel, SlidingUpPanelLayout.PanelState previousState, SlidingUpPanelLayout.PanelState newState) { if (previousState != newState && newState == SlidingUpPanelLayout.PanelState.COLLAPSED) { - onSelectionChange(adapter.getSelectedCount()); + onSelectionChange(adapterT.getSelectedCount()); } // if (previousState == SlidingUpPanelLayout.PanelState.HIDDEN & newState == SlidingUpPanelLayout.PanelState.COLLAPSED) { // animatePullMe(); @@ -268,7 +289,7 @@ public void beforeTextChanged(CharSequence s, int start, int count, int after) { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { - adapter.setSearchString(s.toString()); + adapterT.setSearchString(s.toString()); fullUpdate(-1); } @@ -334,7 +355,7 @@ private void initFabMenu() { mFabGoTop.setOnClickListener(v -> { FgLinearLayoutManager linearLayoutManager = (FgLinearLayoutManager) recyclerView.getLayoutManager(); - if (adapter.getTransactionListSize() > 0) { + if (adapterT.getTransactionListSize() > 0) { linearLayoutManager.scrollToPositionWithOffset(0, 0); } }); @@ -361,7 +382,7 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) { private void saveFilters() { StringBuilder sb = new StringBuilder(); - for (AbstractFilter filter : adapterFilters.getFilterList()) { + for (AbstractFilter filter : adapterF.getFilterList()) { if (!filter.getClass().equals(AccountFilter.class) || !((AccountFilter) filter).isSystem()) { sb.append(filter.getId()); sb.append("/"); @@ -389,7 +410,7 @@ private boolean CreateFilterListFromIntent() { if (filters == null || filters.isEmpty()) { return false; } else { - adapterFilters.setFilterList(filters); + adapterF.setFilterList(filters); onFilterChange(false); return true; } @@ -399,19 +420,19 @@ private boolean CreateFilterListFromIntent() { } private void loadFilters() { - adapterFilters.getFilterList().clear(); - adapterFilters.getFilterList().addAll(FilterManager.loadFiltersFromPreferences(mPreferences, mContext)); + adapterF.getFilterList().clear(); + adapterF.getFilterList().addAll(FilterManager.loadFiltersFromPreferences(mPreferences, mContext)); } private void setAccountSetFilter() { - if (adapterFilters.getFilterList().size() > 0 - && adapterFilters.getFilterList().get(0).getClass().equals(AccountFilter.class) - && ((AccountFilter) adapterFilters.getFilterList().get(0)).isSystem()) { - adapterFilters.getFilterList().remove(0); + if (adapterF.getFilterList().size() > 0 + && adapterF.getFilterList().get(0).getClass().equals(AccountFilter.class) + && ((AccountFilter) adapterF.getFilterList().get(0)).isSystem()) { + adapterF.getFilterList().remove(0); } //Если в списке фильтров уже есть фильтр по счету, то фильтр набора счетов не добавляем - for (AbstractFilter filter : adapterFilters.getFilterList()) { + for (AbstractFilter filter : adapterF.getFilterList()) { if (filter.getClass().equals(AccountFilter.class)) { return; } @@ -423,7 +444,7 @@ private void setAccountSetFilter() { AccountFilter accountFilter = new AccountFilter(0); accountFilter.addList(accountsIDs); accountFilter.setSystem(true); - adapterFilters.getFilterList().add(0, accountFilter); + adapterF.getFilterList().add(0, accountFilter); } } @@ -436,7 +457,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { } if (data != null && resultCode == RESULT_OK && requestCode == RequestCodes.REQUEST_CODE_SELECT_MODEL) { IAbstractModel model = data.getParcelableExtra("model"); - if (adapter.getSelectedCount() >= 0 & data.getStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS) != null) { + if (adapterT.getSelectedCount() >= 0 & data.getStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS) != null) { switch (model.getModelType()) { case IAbstractModel.MODEL_TYPE_ACCOUNT: case IAbstractModel.MODEL_TYPE_PAYEE: @@ -460,7 +481,7 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { ArrayList checkedIDs = (ArrayList) data.getSerializableExtra("checked_ids"); NestedModelFilter filter = null; - for (AbstractFilter f : adapterFilters.getFilterList()) { + for (AbstractFilter f : adapterF.getFilterList()) { if (f instanceof NestedModelFilter) { if (f.getId() == filterID) { filter = (NestedModelFilter) f; @@ -474,22 +495,22 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { filter.getIDsSet().addAll(checkedIDs); } } else { - adapterFilters.getFilterList().remove(filter); + adapterF.getFilterList().remove(filter); } - adapterFilters.notifyDataSetChanged(); + adapterF.notifyDataSetChanged(); FragmentTransactions.this.onFilterChange(true); } else { - for (int i = adapterFilters.getItemCount() - 1; i >= 0; i--) { - AbstractFilter filter = adapterFilters.getFilterList().get(i); + for (int i = adapterF.getItemCount() - 1; i >= 0; i--) { + AbstractFilter filter = adapterF.getFilterList().get(i); if (filter.getClass().equals(NestedModelFilter.class)) { if ((filter).getIDsSet().isEmpty()) { - adapterFilters.getFilterList().remove(i); + adapterF.getFilterList().remove(i); } } } - adapterFilters.notifyDataSetChanged(); + adapterF.notifyDataSetChanged(); FragmentTransactions.this.onFilterChange(true); } } @@ -520,8 +541,8 @@ public void onSelectionChange(int selectedCount) { ListSumsByCabbage listSumsByCabbage; try { - listSumsByCabbage = mTransactionsDAO.getGroupedSums(new FilterListHelper(adapterFilters.getFilterList(), - mEditTextSearch.getText().toString(), getActivity()), true, adapter.getSelectedTransactionsIDsAsLong(), getActivity()); + listSumsByCabbage = mTransactionsDAO.getGroupedSums(new FilterListHelper(adapterF.getFilterList(), + mEditTextSearch.getText().toString(), getActivity()), true, adapterT.getSelectedTransactionsIDsAsLong(), getActivity()); } catch (Exception e) { listSumsByCabbage = new ListSumsByCabbage(); } @@ -562,7 +583,7 @@ private void initSlidePanelButtons() { }); builderSingle.show(); }); - mButtonClearFilters.setOnClickListener(v -> adapterFilters.clearData()); + mButtonClearFilters.setOnClickListener(v -> adapterF.clearData()); mButtonReports.setOnClickListener(v -> ((ToolbarActivity) Objects.requireNonNull(getActivity())).unsubscribeOnDestroy( mBillingService.getReportsIapInfo() .subscribeOn(Schedulers.io()) @@ -572,7 +593,7 @@ private void initSlidePanelButtons() { Intent intent; if (skuDetailsWrapper.isPurchased()) { intent = new Intent(getActivity(), ActivityReports.class); - intent.putParcelableArrayListExtra("filter_list", adapterFilters.getFilterList()); + intent.putParcelableArrayListExtra("filter_list", adapterF.getFilterList()); mSlidingLayoutTransactions.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED); startActivity(intent); } else { @@ -712,7 +733,7 @@ private void editFilterAccounts(final AccountFilter filter) { filter.removeAccount(accId); } } - adapterFilters.notifyDataSetChanged(); + adapterF.notifyDataSetChanged(); FragmentTransactions.this.onFilterChange(true); }); @@ -766,7 +787,7 @@ private void initContextMenuTransactions(final MenuItem item) { addFilter(checkedModel.getModelType(), checkedModel.getID()); break; case R.id.action_select_on_selected: - adapter.selectByModel(checkedModel); + adapterT.selectByModel(checkedModel); break; } }); @@ -832,7 +853,7 @@ private void initContextMenuTransactions(final MenuItem item) { private void addFilter(int filtType, long modelID) { AbstractFilter filter = null; - long id = adapterFilters.getFilterList().size(); + long id = adapterF.getFilterList().size(); switch (filtType) { case IAbstractModel.MODEL_TYPE_AMOUNT_FILTER: filter = new AmountFilter(id); @@ -856,8 +877,8 @@ private void addFilter(int filtType, long modelID) { if (modelID >= 0) { filter.getIDsSet().add(modelID); } - adapterFilters.getFilterList().add(filter); - adapterFilters.notifyItemInserted(adapterFilters.getFilterList().size() - 1); + adapterF.getFilterList().add(filter); + adapterF.notifyItemInserted(adapterF.getFilterList().size() - 1); if (modelID < 0) { saveFilters(); editFilter(filter); @@ -879,12 +900,12 @@ public void onFilterChange(boolean save) { saveFilters(); } fullUpdate(-1); - onSelectionChange(adapter.getSelectedCount()); + onSelectionChange(adapterT.getSelectedCount()); } private boolean isFiltersEnabled() { boolean result = false; - for (AbstractFilter filter : adapterFilters.getFilterList()) { + for (AbstractFilter filter : adapterF.getFilterList()) { if (!filter.getClass().equals(AccountFilter.class) || !((AccountFilter) filter).isSystem()) { result = result | filter.getEnabled(); } @@ -893,7 +914,7 @@ private boolean isFiltersEnabled() { } private boolean isFiltersAdded() { - return adapterFilters.getFilterList().size() > 0; + return adapterF.getFilterList().size() > 0; } private void showSearchView() { @@ -937,14 +958,15 @@ public void loadData(long itemID) { FgLinearLayoutManager linearLayoutManager = (FgLinearLayoutManager) recyclerView.getLayoutManager(); int currentItem = linearLayoutManager.findFirstVisibleItemPosition(); - adapter.clearTransactionList(); + endOfList = false; + adapterT.clearTransactionList(); - int count = Math.max(adapter.getItemCount(), NUMBER_ITEMS_TO_BE_LOADED); + int count = Math.max(adapterT.getItemCount(), FgConst.NUMBER_ITEMS_TO_BE_LOADED); loadMore(count, () -> { - adapter.getParams().clearCaches(); + adapterT.getParams().clearCaches(); if (itemID >= 0) { - int ind = adapter.getItemIndexByID(itemID); + int ind = adapterT.getItemIndexByID(itemID); if (ind >= 0) { updateLists(ind); } @@ -957,26 +979,26 @@ public void loadData(long itemID) { @Override public void loadMore(int numberItems, ILoadMoreFinish loadMoreFinish) { - int start = adapter.getTransactionListSize(); - if (!adapter.endOfList) { + int start = adapterT.getTransactionListSize(); + if (!endOfList) { long curTime = System.currentTimeMillis(); ToolbarActivity activity = (ToolbarActivity) getActivity(); Objects.requireNonNull(activity).unsubscribeOnDestroy( mTransactionsDAO.getRangeTransactionsRx( start, numberItems, - new FilterListHelper(adapterFilters.getFilterList(), mEditTextSearch.getText().toString(), getActivity()), + new FilterListHelper(adapterF.getFilterList(), mEditTextSearch.getText().toString(), getActivity()), getActivity()) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(transactions -> { - adapter.endOfList = transactions.size() < numberItems; - adapter.addTransactions(transactions, false); + endOfList = transactions.size() < numberItems; + adapterT.addTransactions(transactions, false); if (loadMoreFinish != null) { loadMoreFinish.onLoadMoreFinish(); } - adapter.setLoaded(); + loading = false; }, throwable -> { })); curTime = System.currentTimeMillis() - curTime; @@ -988,8 +1010,8 @@ public void loadSums() { ToolbarActivity activity = (ToolbarActivity) getActivity(); HashMap cabbages = mCabbagesDAO.getCabbagesMap(); Objects.requireNonNull(activity).unsubscribeOnDestroy( - mTransactionsDAO.getGroupedSumsRx(new FilterListHelper(adapterFilters.getFilterList(), - mEditTextSearch.getText().toString(), getActivity()), true, adapter.getSelectedTransactionsIDsAsLong(), getActivity()) + mTransactionsDAO.getGroupedSumsRx(new FilterListHelper(adapterF.getFilterList(), + mEditTextSearch.getText().toString(), getActivity()), true, adapterT.getSelectedTransactionsIDsAsLong(), getActivity()) .map(listSumsByCabbage -> SumsManager.formatSums(listSumsByCabbage, cabbages, false)) .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) @@ -999,8 +1021,8 @@ public void loadSums() { } public void updateLists(long itemID) { - adapter.notifyDataSetChanged(); - adapterFilters.notifyDataSetChanged(); + adapterT.notifyDataSetChanged(); + adapterF.notifyDataSetChanged(); if (recyclerView != null && itemID >= 0) { FgLinearLayoutManager linearLayoutManager = (FgLinearLayoutManager) recyclerView.getLayoutManager(); linearLayoutManager.scrollToPosition((int) itemID); @@ -1023,11 +1045,11 @@ private class FabMenuSelectionItemClickListener implements View.OnClickListener public void onClick(View v) { switch (v.getId()) { case R.id.fabSelectAll: { - adapter.selectAll(); + adapterT.selectAll(); break; } case R.id.fabUnselectAll: { - adapter.unselectAll(); + adapterT.unselectAll(); break; } case R.id.fabEditSelected: { @@ -1063,7 +1085,7 @@ public void onClick(View v) { intent.putExtra("showHomeButton", false); intent.putExtra("model", new Account()); intent.putExtra("destAccount", false); - intent.putStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS, adapter.getSelectedTransactionsIDs()); + intent.putStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS, adapterT.getSelectedTransactionsIDs()); startActivityForResult(intent, REQUEST_CODE_SELECT_MODEL); break; case IAbstractModel.MODEL_TYPE_PAYEE: @@ -1076,7 +1098,7 @@ public void onClick(View v) { intent.putExtra("showHomeButton", false); intent.putExtra("model", BaseModel.createModelByType(checkedItem.getID())); intent.putExtra("requestCode", REQUEST_CODE_SELECT_MODEL); - intent.putStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS, adapter.getSelectedTransactionsIDs()); + intent.putStringArrayListExtra(FgConst.SELECTED_TRANSACTIONS_IDS, adapterT.getSelectedTransactionsIDs()); startActivityForResult(intent, REQUEST_CODE_SELECT_MODEL); break; } @@ -1086,12 +1108,12 @@ public void onClick(View v) { } case R.id.fabExportSelected: { Intent intent = new Intent(getActivity(), ActivityExportCSV.class); - intent.putParcelableArrayListExtra("transactions", adapter.getSelectedTransactions()); + intent.putParcelableArrayListExtra("transactions", adapterT.getSelectedTransactions()); startActivity(intent); break; } case R.id.fabDeleteSelected: { - final List transactionsToDelete = adapter.removeSelectedTransactions(); + final List transactionsToDelete = adapterT.removeSelectedTransactions(); final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Objects.requireNonNull(getActivity())); alertDialogBuilder .setTitle(R.string.ttl_confirm_action) diff --git a/app/src/main/java/com/yoshione/fingen/adapter/AdapterTransactions.java b/app/src/main/java/com/yoshione/fingen/adapter/AdapterTransactions.java index f40ee897..ae7b3e6a 100644 --- a/app/src/main/java/com/yoshione/fingen/adapter/AdapterTransactions.java +++ b/app/src/main/java/com/yoshione/fingen/adapter/AdapterTransactions.java @@ -1,25 +1,22 @@ package com.yoshione.fingen.adapter; import android.annotation.SuppressLint; -import android.app.Activity; -import android.os.Handler; import android.support.annotation.NonNull; -import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import android.widget.TextView; import com.l4digital.fastscroll.FastScroller; -import com.yoshione.fingen.FragmentTransactions; import com.yoshione.fingen.R; import com.yoshione.fingen.adapter.viewholders.TransactionViewHolder; import com.yoshione.fingen.adapter.viewholders.TransactionViewHolderParams; import com.yoshione.fingen.interfaces.IAbstractModel; import com.yoshione.fingen.interfaces.ILoadMoreFinish; import com.yoshione.fingen.interfaces.IOnLoadMore; +import com.yoshione.fingen.interfaces.ITransactionClickListener; +import com.yoshione.fingen.interfaces.ITransactionItemEventListener; import com.yoshione.fingen.model.Transaction; import com.yoshione.fingen.utils.DateTimeFormatter; import com.yoshione.fingen.widgets.ToolbarActivity; @@ -38,18 +35,16 @@ * a */ public class AdapterTransactions extends RecyclerView.Adapter implements FastScroller.SectionIndexer, - StickyHeaderAdapter { + StickyHeaderAdapter, ITransactionClickListener { // private static final String TAG = "AdapterTransactions"; - protected final Handler handler; + private int lastYear; + private int lastDay; + private Date lastDate; private final ArrayList transactionList; private final List headerList; - private final int visibleThreshold = 10; - public volatile boolean endOfList = false; - private int lastVisibleItem, totalItemCount; - private volatile boolean loading; - private Date lastDate; private IOnLoadMore mOnLoadMore; + private ITransactionItemEventListener mTransactionItemEventListener; private ToolbarActivity mActivity; public TransactionViewHolderParams getParams() { @@ -64,58 +59,16 @@ public void setSearchString(String searchString) { //Конструктор @SuppressLint("UseSparseArrays") - public AdapterTransactions(RecyclerView recyclerView, IOnLoadMore onLoadMore, ToolbarActivity activity) { + public AdapterTransactions(IOnLoadMore onLoadMore, ITransactionItemEventListener transactionItemEventListener, ToolbarActivity activity) { mActivity = activity; setHasStableIds(true); + mTransactionItemEventListener = transactionItemEventListener; mOnLoadMore = onLoadMore; transactionList = new ArrayList<>(); headerList = new ArrayList<>(); - LinearLayout linearLayout = new LinearLayout(activity); - linearLayout.layout(0, 0, 56, 56); - linearLayout.setLayoutParams(new LinearLayout.LayoutParams(56, 56)); - linearLayout.setOrientation(LinearLayout.HORIZONTAL); - handler = new Handler(); - - if (recyclerView.getLayoutManager() instanceof LinearLayoutManager) { - - final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView - .getLayoutManager(); - - - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public synchronized void onScrolled(RecyclerView recyclerView, - int dx, int dy) { - super.onScrolled(recyclerView, dx, dy); - - totalItemCount = linearLayoutManager.getItemCount(); - lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition(); - if (!loading && totalItemCount <= (lastVisibleItem + visibleThreshold)) { - // End has been reached - // Do something - if (!endOfList) { - loading = true; - loadMore(FragmentTransactions.NUMBER_ITEMS_TO_BE_LOADED, new ILoadMoreFinish() { - @Override - public void onLoadMoreFinish() { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - notifyDataSetChanged(); - } - }, 100); - - } - }); - } - } - } - }); - } - mParams = new TransactionViewHolderParams(activity); mParams.mShowDateInsteadOfRunningBalance = false; } @@ -127,7 +80,6 @@ private void loadMore(final int numberItems, final ILoadMoreFinish loadMoreFinis public void clearTransactionList() { transactionList.clear(); headerList.clear(); - endOfList = false; } public int getTransactionListSize() { @@ -143,9 +95,6 @@ public int getItemIndexByID(long itemID) { return -1; } - private int lastYear; - private int lastDay; - public void addTransactions(List input, boolean clearLists) { synchronized (headerList) { if (clearLists) { @@ -154,7 +103,7 @@ public void addTransactions(List input, boolean clearLists) { } Transaction transaction; - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.getInstance(mParams.mContext); + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.getInstance(mActivity); if (input.size() == 0) { headerList.add(dateTimeFormatter.getDateLongStringWithDayOfWeekName(new Date())); @@ -203,16 +152,11 @@ public void addTransactions(List input, boolean clearLists) { } } - public void setmOnTransactionItemClickListener(OnTransactionItemEventListener onTransactionItemEventListener) { - mParams.mOnTransactionItemEventListener = onTransactionItemEventListener; - } - @Override public long getItemId(int position) { return transactionList.get(position).getID(); } - @NonNull @Override public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { @@ -242,10 +186,6 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int po tvh.bindTransaction(transaction); } - public void setLoaded() { - loading = false; - } - @Override public int getItemCount() { return transactionList.size(); @@ -279,60 +219,54 @@ public synchronized int getSelectedCount() { } public void selectAll() { - loadMore(Integer.MAX_VALUE, new ILoadMoreFinish() { - @Override - public void onLoadMoreFinish() { - for (Transaction transaction : transactionList) { - transaction.setSelected(true); - } - mParams.mOnTransactionItemEventListener.onSelectionChange(AdapterTransactions.this.getSelectedCount()); - AdapterTransactions.this.notifyDataSetChanged(); + loadMore(Integer.MAX_VALUE, () -> { + for (Transaction transaction : transactionList) { + transaction.setSelected(true); } + mTransactionItemEventListener.onSelectionChange(AdapterTransactions.this.getSelectedCount()); + AdapterTransactions.this.notifyDataSetChanged(); }); } public void selectByModel(final IAbstractModel model) { - loadMore(Integer.MAX_VALUE, new ILoadMoreFinish() { - @Override - public void onLoadMoreFinish() { - for (Transaction transaction : transactionList) { - switch (model.getModelType()) { - case IAbstractModel.MODEL_TYPE_ACCOUNT: - if (transaction.getAccountID() == model.getID()) { - transaction.setSelected(true); - } - break; - case IAbstractModel.MODEL_TYPE_CATEGORY: - if (transaction.getCategoryID() == model.getID()) { - transaction.setSelected(true); - } - break; - case IAbstractModel.MODEL_TYPE_PAYEE: - if (transaction.getPayeeID() == model.getID()) { - transaction.setSelected(true); - } - break; - case IAbstractModel.MODEL_TYPE_LOCATION: - if (transaction.getLocationID() == model.getID()) { - transaction.setSelected(true); - } - break; - case IAbstractModel.MODEL_TYPE_DEPARTMENT: - if (transaction.getDepartmentID() == model.getID()) { - transaction.setSelected(true); - } - break; - case IAbstractModel.MODEL_TYPE_PROJECT: - if (transaction.getProjectID() == model.getID()) { - transaction.setSelected(true); - } - break; - } - + loadMore(Integer.MAX_VALUE, () -> { + for (Transaction transaction : transactionList) { + switch (model.getModelType()) { + case IAbstractModel.MODEL_TYPE_ACCOUNT: + if (transaction.getAccountID() == model.getID()) { + transaction.setSelected(true); + } + break; + case IAbstractModel.MODEL_TYPE_CATEGORY: + if (transaction.getCategoryID() == model.getID()) { + transaction.setSelected(true); + } + break; + case IAbstractModel.MODEL_TYPE_PAYEE: + if (transaction.getPayeeID() == model.getID()) { + transaction.setSelected(true); + } + break; + case IAbstractModel.MODEL_TYPE_LOCATION: + if (transaction.getLocationID() == model.getID()) { + transaction.setSelected(true); + } + break; + case IAbstractModel.MODEL_TYPE_DEPARTMENT: + if (transaction.getDepartmentID() == model.getID()) { + transaction.setSelected(true); + } + break; + case IAbstractModel.MODEL_TYPE_PROJECT: + if (transaction.getProjectID() == model.getID()) { + transaction.setSelected(true); + } + break; } - mParams.mOnTransactionItemEventListener.onSelectionChange(AdapterTransactions.this.getSelectedCount()); - AdapterTransactions.this.notifyDataSetChanged(); + } + mTransactionItemEventListener.onSelectionChange(AdapterTransactions.this.getSelectedCount()); + AdapterTransactions.this.notifyDataSetChanged(); }); } @@ -340,7 +274,7 @@ public void unselectAll() { for (Transaction transaction : transactionList) { transaction.setSelected(false); } - mParams.mOnTransactionItemEventListener.onSelectionChange(getSelectedCount()); + mTransactionItemEventListener.onSelectionChange(getSelectedCount()); notifyDataSetChanged(); } @@ -389,10 +323,14 @@ public ArrayList getSelectedTransactions() { return selectedTransactions; } - public interface OnTransactionItemEventListener { - void onTransactionItemClick(Transaction transaction); + @Override + public void onSelectButtonClick() { + mTransactionItemEventListener.onSelectionChange(getSelectedCount()); + } - void onSelectionChange(int selectedCount); + @Override + public void onTransactionItemClick(Transaction transaction) { + mTransactionItemEventListener.onTransactionItemClick(transaction); } class HeaderViewHolder extends RecyclerView.ViewHolder { @@ -410,5 +348,4 @@ void bindHeader(String s) { text.setText(s); } } - } diff --git a/app/src/main/java/com/yoshione/fingen/adapter/TransactionsArrayAdapter.java b/app/src/main/java/com/yoshione/fingen/adapter/TransactionsArrayAdapter.java index 83723e20..8c0d3e0c 100644 --- a/app/src/main/java/com/yoshione/fingen/adapter/TransactionsArrayAdapter.java +++ b/app/src/main/java/com/yoshione/fingen/adapter/TransactionsArrayAdapter.java @@ -1,7 +1,6 @@ package com.yoshione.fingen.adapter; import android.annotation.SuppressLint; -import android.app.Activity; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; @@ -16,6 +15,8 @@ import com.yoshione.fingen.R; import com.yoshione.fingen.adapter.viewholders.TransactionViewHolder; import com.yoshione.fingen.adapter.viewholders.TransactionViewHolderParams; +import com.yoshione.fingen.interfaces.ITransactionClickListener; +import com.yoshione.fingen.interfaces.ITransactionItemEventListener; import com.yoshione.fingen.model.Transaction; import com.yoshione.fingen.utils.ScreenUtils; import com.yoshione.fingen.widgets.ToolbarActivity; @@ -23,14 +24,16 @@ import java.util.ArrayList; import java.util.List; -public class TransactionsArrayAdapter extends ArrayAdapter { +public class TransactionsArrayAdapter extends ArrayAdapter implements ITransactionClickListener { private final ContextThemeWrapper mContextThemeWrapper; private List mTransactionList = new ArrayList<>(); private TransactionViewHolderParams mParams; private ToolbarActivity mActivity; + private ITransactionItemEventListener mITransactionItemEventListener; - public TransactionsArrayAdapter(@NonNull ToolbarActivity activity, List list, AdapterTransactions.OnTransactionItemEventListener eventListener) { + public TransactionsArrayAdapter(@NonNull ToolbarActivity activity, List list, ITransactionItemEventListener eventListener) { super(activity, 0, list); + mITransactionItemEventListener = eventListener; mTransactionList.clear(); mTransactionList.addAll(list); @@ -40,7 +43,6 @@ public TransactionsArrayAdapter(@NonNull ToolbarActivity activity, List Account srcAccount; Account destAccount; - if (mParams.mAccountCache.containsKey(t.getAccountID())) { + if (mParams.mAccountCache.indexOfKey(t.getAccountID()) >= 0) { srcAccount = mParams.mAccountCache.get(t.getAccountID()); } else { - srcAccount = TransactionManager.getSrcAccount(t, mParams.mContext); + srcAccount = mParams.mAccountsDAO.getAccountByID(t.getAccountID()); mParams.mAccountCache.put(srcAccount.getID(), srcAccount); } - if (mParams.mAccountCache.containsKey(t.getDestAccountID())) { + if (mParams.mAccountCache.indexOfKey(t.getDestAccountID()) >= 0) { destAccount = mParams.mAccountCache.get(t.getDestAccountID()); } else { - destAccount = TransactionManager.getDestAccount(t, mParams.mContext); + destAccount = mParams.mAccountsDAO.getAccountByID(t.getDestAccountID()); mParams.mAccountCache.put(destAccount.getID(), destAccount); } // @@ -123,10 +115,10 @@ public void bindTransaction(final Transaction t) { text = srcAccount.getName(); } else { Department department; - if (mParams.mDepartmentCache.containsKey(t.getDepartmentID())) { + if (mParams.mDepartmentCache.indexOfKey(t.getDepartmentID()) >= 0) { department = mParams.mDepartmentCache.get(t.getDepartmentID()); } else { - department = DepartmentsDAO.getInstance(mParams.mContext).getDepartmentByID(t.getDepartmentID()); + department = mParams.mDepartmentsDAO.getDepartmentByID(t.getDepartmentID()); mParams.mDepartmentCache.put(department.getID(), department); } @@ -143,10 +135,10 @@ public void bindTransaction(final Transaction t) { // CabbageFormatter cabbageFormatter; - if (mParams.mCabbageCache.containsKey(srcAccount.getCabbageId())) { + if (mParams.mCabbageCache.indexOfKey(srcAccount.getCabbageId()) >= 0) { cabbageFormatter = mParams.mCabbageCache.get(srcAccount.getCabbageId()); } else { - Cabbage cabbage = CabbagesDAO.getInstance(mParams.mContext).getCabbageByID(srcAccount.getCabbageId()); + Cabbage cabbage = mParams.mCabbagesDAO.getCabbageByID(srcAccount.getCabbageId()); cabbageFormatter = new CabbageFormatter(cabbage); mParams.mCabbageCache.put(cabbage.getID(), cabbageFormatter); } @@ -158,12 +150,6 @@ public void bindTransaction(final Transaction t) { .subscribe(s -> textViewAmount.setText(s)) ); -// if (t.getTransactionType() == Transaction.TRANSACTION_TYPE_TRANSFER) { -// textViewAmount.setText(cabbageFormatter.format(t.getAmount().abs())); -// } else { -// textViewAmount.setText(cabbageFormatter.format(t.getAmount())); -// } - textViewAccountBalance.setTextColor(getAmountColor(t.getFromAccountBalance())); mUnsubscriber.unsubscribeOnDestroy( cabbageFormatter.formatRx(t.getFromAccountBalance()) @@ -172,14 +158,11 @@ public void bindTransaction(final Transaction t) { .subscribe(s -> textViewAccountBalance.setText(s)) ); -// String fromAmount = cabbageFormatter.format(t.getFromAccountBalance()); -// textViewAccountBalance.setText(fromAmount); - if (t.getDestAccountID() >= 0) { - if (mParams.mCabbageCache.containsKey(destAccount.getCabbageId())) { + if (mParams.mCabbageCache.indexOfKey(destAccount.getCabbageId()) >= 0) { cabbageFormatter = mParams.mCabbageCache.get(destAccount.getCabbageId()); } else { - Cabbage cabbage = CabbagesDAO.getInstance(mParams.mContext).getCabbageByID(destAccount.getCabbageId()); + Cabbage cabbage = mParams.mCabbagesDAO.getCabbageByID(destAccount.getCabbageId()); cabbageFormatter = new CabbageFormatter(cabbage); mParams.mCabbageCache.put(cabbage.getID(), cabbageFormatter); } @@ -192,8 +175,6 @@ public void bindTransaction(final Transaction t) { .subscribe(s -> textViewDestAccountBalance.setText(s)) ); -// String toAmount = cabbageFormatter.format(t.getToAccountBalance()); -// textViewDestAccountBalance.setText(toAmount); imageViewChevronRight.setVisibility(View.VISIBLE); textViewDestAccountBalance.setVisibility(View.VISIBLE); } else { @@ -219,10 +200,10 @@ public void bindTransaction(final Transaction t) { } else { mImageViewDestAccount.setVisibility(View.GONE); Payee payee; - if (mParams.mPayeeCache.containsKey(t.getPayeeID())) { + if (mParams.mPayeeCache.indexOfKey(t.getPayeeID()) >= 0) { payee = mParams.mPayeeCache.get(t.getPayeeID()); } else { - payee = PayeesDAO.getInstance(mParams.mContext).getPayeeByID(t.getPayeeID()); + payee = mParams.mPayeesDAO.getPayeeByID(t.getPayeeID()); mParams.mPayeeCache.put(payee.getID(), payee); } String payeeFullName = payee.getFullName(); @@ -230,10 +211,10 @@ public void bindTransaction(final Transaction t) { text = payeeFullName; } else { Location location; - if (mParams.mLocationCache.containsKey(t.getLocationID())) { + if (mParams.mLocationCache.indexOfKey(t.getLocationID()) >= 0) { location = mParams.mLocationCache.get(t.getLocationID()); } else { - location = LocationsDAO.getInstance(mParams.mContext).getLocationByID(t.getLocationID()); + location = mParams.mLocationsDAO.getLocationByID(t.getLocationID()); mParams.mLocationCache.put(location.getID(), location); } text = payeeFullName + " (" + location.getFullName() + ")"; @@ -293,10 +274,10 @@ public void bindTransaction(final Transaction t) { } } if (!isSplitCategory) {//это не сплит, выводим имя категории транзакции - if (mParams.mCategoryCache.containsKey(t.getCategoryID())) { + if (mParams.mCategoryCache.indexOfKey(t.getCategoryID()) >= 0) { category = mParams.mCategoryCache.get(t.getCategoryID()); } else { - category = CategoriesDAO.getInstance(mParams.mContext).getCategoryByID(t.getCategoryID()); + category = mParams.mCategoriesDAO.getCategoryByID(t.getCategoryID()); mParams.mCategoryCache.put(category.getID(), category); } } else if (!sameCategory) {//это сплит и у товаров разные категории, выводим надпись "Сплит" @@ -312,18 +293,18 @@ public void bindTransaction(final Transaction t) { } else { catID = entry.getCategoryID(); } - if (mParams.mCategoryCache.containsKey(catID)) { + if (mParams.mCategoryCache.indexOfKey(catID) >= 0) { category = mParams.mCategoryCache.get(catID); } else { - category = CategoriesDAO.getInstance(mParams.mContext).getCategoryByID(catID); + category = mParams.mCategoriesDAO.getCategoryByID(catID); mParams.mCategoryCache.put(category.getID(), category); } } if (!isSplitProject) {//это не сплит, выводим имя проекта транзакции - if (mParams.mProjectCache.containsKey(t.getProjectID())) { + if (mParams.mProjectCache.indexOfKey(t.getProjectID()) >= 0) { project = mParams.mProjectCache.get(t.getProjectID()); } else { - project = ProjectsDAO.getInstance(mParams.mContext).getProjectByID(t.getProjectID()); + project = mParams.mProjectsDAO.getProjectByID(t.getProjectID()); mParams.mProjectCache.put(project.getID(), project); } } else if (!sameProject) {//это сплит и у товаров разные проекты, выводим надпись "Сплит" @@ -339,10 +320,10 @@ public void bindTransaction(final Transaction t) { } else { catID = entry.getProjectID(); } - if (mParams.mProjectCache.containsKey(catID)) { + if (mParams.mProjectCache.indexOfKey(catID) >= 0) { project = mParams.mProjectCache.get(catID); } else { - project = ProjectsDAO.getInstance(mParams.mContext).getProjectByID(catID); + project = mParams.mProjectsDAO.getProjectByID(catID); mParams.mProjectCache.put(project.getID(), project); } } @@ -388,7 +369,7 @@ public void bindTransaction(final Transaction t) { textViewComment.setText(text); } else { spannable = new SpannableString(text); - spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mParams.mContext, R.color.fg_white_color)), text.toLowerCase().indexOf(search), text.toLowerCase().indexOf(search) + search.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + spannable.setSpan(new ForegroundColorSpan(mParams.mWhiteColor), text.toLowerCase().indexOf(search), text.toLowerCase().indexOf(search) + search.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new BackgroundColorSpan(mParams.mColorSpan), text.toLowerCase().indexOf(search), text.toLowerCase().indexOf(search) + search.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textViewComment.setText(spannable); } @@ -431,15 +412,23 @@ public void bindTransaction(final Transaction t) { flipViewIcon.getRearImageView().setScaleType(ImageView.ScaleType.CENTER); flipViewIcon.flipSilently(t.isSelected()); - flipViewIcon.setOnClickListener(new ImageViewIconClickListener(t)); + flipViewIcon.setOnClickListener(view -> { + t.setSelected(!t.isSelected()); + flipViewIcon.flip(t.isSelected()); + if (mTransactionClickListener != null) { + mTransactionClickListener.onSelectButtonClick(); + } + }); itemView.setOnClickListener(v -> { - if (mParams.mOnTransactionItemEventListener != null) { - mParams.mOnTransactionItemEventListener.onTransactionItemClick(t); + if (mTransactionClickListener != null) { + mTransactionClickListener.onTransactionItemClick(t); } }); // + + spaceBottom.setVisibility(t.isDayLast() ? View.INVISIBLE : View.VISIBLE); } @@ -456,7 +445,7 @@ private Tag getTag(String text, int color, float radius) { tag.radius = radius; tag.isDeletable = false; tag.tagTextSize = mParams.mTagTextSize; - tag.tagTextColor = Color.WHITE;//ColorUtils.ContrastColor(color); + tag.tagTextColor = Color.WHITE; return tag; } @@ -473,21 +462,4 @@ private int getAmountColor(BigDecimal amount) { } } - private class ImageViewIconClickListener implements View.OnClickListener { - private final Transaction mTransaction; - - ImageViewIconClickListener(Transaction transaction) { - mTransaction = transaction; - } - - @Override - public void onClick(View v) { - if (mAdapterTransactions != null) { - mTransaction.setSelected(!mTransaction.isSelected()); - flipViewIcon.flip(mTransaction.isSelected()); - mParams.mOnTransactionItemEventListener.onSelectionChange(mAdapterTransactions.getSelectedCount()); - } - } - } - } diff --git a/app/src/main/java/com/yoshione/fingen/adapter/viewholders/TransactionViewHolderParams.java b/app/src/main/java/com/yoshione/fingen/adapter/viewholders/TransactionViewHolderParams.java index 81b0db1e..a0871e13 100644 --- a/app/src/main/java/com/yoshione/fingen/adapter/viewholders/TransactionViewHolderParams.java +++ b/app/src/main/java/com/yoshione/fingen/adapter/viewholders/TransactionViewHolderParams.java @@ -4,12 +4,22 @@ import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; import android.support.v4.content.ContextCompat; +import android.util.LongSparseArray; import android.view.ContextThemeWrapper; +import com.yoshione.fingen.FGApplication; import com.yoshione.fingen.FgConst; import com.yoshione.fingen.R; import com.yoshione.fingen.adapter.AdapterTransactions; +import com.yoshione.fingen.dao.AccountsDAO; +import com.yoshione.fingen.dao.CabbagesDAO; +import com.yoshione.fingen.dao.CategoriesDAO; +import com.yoshione.fingen.dao.DepartmentsDAO; +import com.yoshione.fingen.dao.LocationsDAO; +import com.yoshione.fingen.dao.PayeesDAO; +import com.yoshione.fingen.dao.ProjectsDAO; import com.yoshione.fingen.model.Account; +import com.yoshione.fingen.model.Cabbage; import com.yoshione.fingen.model.Category; import com.yoshione.fingen.model.Department; import com.yoshione.fingen.model.Location; @@ -22,12 +32,15 @@ import java.util.HashMap; +import javax.inject.Inject; + public class TransactionViewHolderParams { public final AmountColorizer mAmountColorizer; public final Drawable iconSelected; public final DateTimeFormatter mDateTimeFormatter; public final int mColorSpan; + public final int mWhiteColor; public int mPositiveAmountColor; public int mNegativeAmountColor; public int mColorInactive; @@ -35,45 +48,58 @@ public class TransactionViewHolderParams { public int mColorTag; public String mSplitStringCategory; public String mSplitStringProject; - public HashMap mAccountCache; - public HashMap mPayeeCache; - public HashMap mCategoryCache; - public HashMap mDepartmentCache; - public HashMap mProjectCache; - public HashMap mLocationCache; - public HashMap mCabbageCache; + public LongSparseArray mAccountCache; + public LongSparseArray mPayeeCache; + public LongSparseArray mCategoryCache; + public LongSparseArray mDepartmentCache; + public LongSparseArray mProjectCache; + public LongSparseArray mLocationCache; + public LongSparseArray mCabbageCache; public String mSearchString; public ContextThemeWrapper mContextThemeWrapper; public Float mTagTextSize; public boolean isTagsColored; - public AdapterTransactions.OnTransactionItemEventListener mOnTransactionItemEventListener; public boolean mShowDateInsteadOfRunningBalance; - public final Activity mContext; + @Inject + public AccountsDAO mAccountsDAO; + @Inject + public DepartmentsDAO mDepartmentsDAO; + @Inject + public CabbagesDAO mCabbagesDAO; + @Inject + public PayeesDAO mPayeesDAO; + @Inject + public LocationsDAO mLocationsDAO; + @Inject + public CategoriesDAO mCategoriesDAO; + @Inject + public ProjectsDAO mProjectsDAO; public TransactionViewHolderParams(Activity context) { - mContext = context; + FGApplication.getAppComponent().inject(this); mSearchString = ""; mAmountColorizer = new AmountColorizer(context); - iconSelected = ContextCompat.getDrawable(mContext, R.drawable.ic_check_circle_blue); + iconSelected = ContextCompat.getDrawable(context, R.drawable.ic_check_circle_blue); mDateTimeFormatter = DateTimeFormatter.getInstance(context); - mPositiveAmountColor = ContextCompat.getColor(mContext, R.color.positive_color); - mNegativeAmountColor = ContextCompat.getColor(mContext, R.color.negative_color); - mColorInactive = ContextCompat.getColor(mContext, R.color.light_gray_text); - mColorSplit = ContextCompat.getColor(mContext, R.color.blue_color); - mColorTag = ContextCompat.getColor(mContext, R.color.ColorAccent); + mPositiveAmountColor = ContextCompat.getColor(context, R.color.positive_color); + mNegativeAmountColor = ContextCompat.getColor(context, R.color.negative_color); + mColorInactive = ContextCompat.getColor(context, R.color.light_gray_text); + mColorSplit = ContextCompat.getColor(context, R.color.blue_color); + mColorTag = ContextCompat.getColor(context, R.color.ColorAccent); mColorSpan = ContextCompat.getColor(context, R.color.ColorPrimary); - mSplitStringCategory = mContext.getString(R.string.ent_split_category); - mSplitStringProject = mContext.getString(R.string.ent_split_project); - mAccountCache = new HashMap<>(); - mPayeeCache = new HashMap<>(); - mCategoryCache = new HashMap<>(); - mDepartmentCache = new HashMap<>(); - mProjectCache = new HashMap<>(); - mLocationCache = new HashMap<>(); - mCabbageCache = new HashMap<>(); + mWhiteColor = ContextCompat.getColor(context, R.color.fg_white_color); + mSplitStringCategory = context.getString(R.string.ent_split_category); + mSplitStringProject = context.getString(R.string.ent_split_project); + mAccountCache = new LongSparseArray<>(); + mPayeeCache = new LongSparseArray<>(); + mCategoryCache = new LongSparseArray<>(); + mDepartmentCache = new LongSparseArray<>(); + mProjectCache = new LongSparseArray<>(); + mLocationCache = new LongSparseArray<>(); + mCabbageCache = new LongSparseArray<>(); if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(FgConst.PREF_COMPACT_VIEW_MODE, false)) { mContextThemeWrapper = new ContextThemeWrapper(context, R.style.StyleListItemTransationsCompact); @@ -82,7 +108,7 @@ public TransactionViewHolderParams(Activity context) { } isTagsColored = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(FgConst.PREF_COLORED_TAGS, true); - mTagTextSize = ScreenUtils.PxToDp(mContext, mContext.getResources().getDimension(R.dimen.text_size_micro)); + mTagTextSize = ScreenUtils.PxToDp(context, context.getResources().getDimension(R.dimen.text_size_micro)); } public void clearCaches() { diff --git a/app/src/main/java/com/yoshione/fingen/di/AppComponent.java b/app/src/main/java/com/yoshione/fingen/di/AppComponent.java index 242aedf1..1a19e0db 100644 --- a/app/src/main/java/com/yoshione/fingen/di/AppComponent.java +++ b/app/src/main/java/com/yoshione/fingen/di/AppComponent.java @@ -8,6 +8,7 @@ import com.yoshione.fingen.FragmentAccounts; import com.yoshione.fingen.FragmentSummary; import com.yoshione.fingen.FragmentTransactions; +import com.yoshione.fingen.adapter.viewholders.TransactionViewHolderParams; import com.yoshione.fingen.di.modules.BillingModule; import com.yoshione.fingen.di.modules.ContextModule; import com.yoshione.fingen.di.modules.DaoModule; @@ -38,4 +39,5 @@ public interface AppComponent { void inject(ToolbarActivity toolbarActivity); void inject(ActivityEditTransaction activityEditTransaction); void inject(FtsHelper ftsHelper); + void inject(TransactionViewHolderParams transactionViewHolderParams); } diff --git a/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionClickListener.java b/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionClickListener.java new file mode 100644 index 00000000..e65ec298 --- /dev/null +++ b/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionClickListener.java @@ -0,0 +1,9 @@ +package com.yoshione.fingen.interfaces; + +import com.yoshione.fingen.model.Transaction; + +public interface ITransactionClickListener { + void onSelectButtonClick(); + + void onTransactionItemClick(Transaction transaction); +} diff --git a/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionItemEventListener.java b/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionItemEventListener.java new file mode 100644 index 00000000..04a6672e --- /dev/null +++ b/app/src/main/java/com/yoshione/fingen/interfaces/ITransactionItemEventListener.java @@ -0,0 +1,9 @@ +package com.yoshione.fingen.interfaces; + +import com.yoshione.fingen.model.Transaction; + +public interface ITransactionItemEventListener { + void onTransactionItemClick(Transaction transaction); + + void onSelectionChange(int selectedCount); +} diff --git a/app/src/main/res/layout/list_item_transactions_2.xml b/app/src/main/res/layout/list_item_transactions_2.xml index 143d648b..f71a35ba 100644 --- a/app/src/main/res/layout/list_item_transactions_2.xml +++ b/app/src/main/res/layout/list_item_transactions_2.xml @@ -216,6 +216,24 @@ tools:ignore="ContentDescription" /> + + + app:layout_constraintTop_toBottomOf="@id/textViewProductList" /> \ No newline at end of file diff --git a/app/src/main/res/raw-ru/changelog.xml b/app/src/main/res/raw-ru/changelog.xml index bb7fa88d..19f9e4a5 100644 --- a/app/src/main/res/raw-ru/changelog.xml +++ b/app/src/main/res/raw-ru/changelog.xml @@ -1,5 +1,8 @@ + + Исправлена ошибка + Возможность создания СМС из интента с последующим парсингом Значительно ускорен процесс востановления базы из резервной копии diff --git a/app/src/main/res/raw/changelog.xml b/app/src/main/res/raw/changelog.xml index 65a2df98..34f084d7 100644 --- a/app/src/main/res/raw/changelog.xml +++ b/app/src/main/res/raw/changelog.xml @@ -1,5 +1,8 @@ + + Bug fix + Add create SMS from intent Fix clear notification after edit transaction from it