From 43ac9b2571710fe200554340a2123d3257cd87ee Mon Sep 17 00:00:00 2001 From: "Emmanuele (WolfSolver)" Date: Sun, 1 Dec 2024 17:01:12 +0100 Subject: [PATCH] Clean code for nestedcategoruy Step 2 for remove unused code #1792 --- .../manager/ex/budget/BudgetAdapter.java | 45 ++++-------------- .../manager/ex/budget/BudgetEditActivity.java | 5 -- .../ex/budget/BudgetEntryFragment.java | 41 +++++----------- .../ex/common/CategoryListActivity.java | 25 ++-------- .../ex/datalayer/BudgetEntryRepository.java | 47 +++++-------------- .../money/manager/ex/home/MainActivity.java | 7 +-- .../ex/search/SearchParametersFragment.java | 5 +- 7 files changed, 37 insertions(+), 138 deletions(-) diff --git a/app/src/main/java/com/money/manager/ex/budget/BudgetAdapter.java b/app/src/main/java/com/money/manager/ex/budget/BudgetAdapter.java index 43a033cef..dedbaea05 100644 --- a/app/src/main/java/com/money/manager/ex/budget/BudgetAdapter.java +++ b/app/src/main/java/com/money/manager/ex/budget/BudgetAdapter.java @@ -33,10 +33,10 @@ import com.money.manager.ex.R; import com.money.manager.ex.core.UIHelper; import com.money.manager.ex.currency.CurrencyService; -import com.money.manager.ex.database.QueryCategorySubCategory; import com.money.manager.ex.database.ViewMobileData; import com.money.manager.ex.datalayer.BudgetEntryRepository; import com.money.manager.ex.domainmodel.BudgetEntry; +import com.money.manager.ex.nestedcategory.QueryNestedCategory; import com.money.manager.ex.settings.AppSettings; import com.squareup.sqlbrite3.BriteDatabase; @@ -82,11 +82,6 @@ public BudgetAdapter(Context context, Cursor cursor, String[] from, int[] to, in MmexApplication.getApp().iocComponent.inject(this); - try { - useNestedCategory = (new AppSettings(context).getBehaviourSettings().getUseNestedCategory()); - } catch (Exception e) { - } - } @Inject Lazy databaseLazy; @@ -96,8 +91,6 @@ public BudgetAdapter(Context context, Cursor cursor, String[] from, int[] to, in private long mBudgetYearId; private HashMap mBudgetEntries; - private boolean useNestedCategory = false; // new NestedCateg - @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { @@ -111,28 +104,18 @@ public void bindView(View view, Context context, Cursor cursor) { // Category boolean hasSubcategory; - if (!useNestedCategory) { - hasSubcategory = cursor.getInt(cursor.getColumnIndex(QueryCategorySubCategory.SUBCATEGID)) != Constants.NOT_SET; - } else { - hasSubcategory = false; - } + hasSubcategory = false; + TextView categoryTextView = view.findViewById(R.id.categoryTextView); if (categoryTextView != null) { - int categoryColumnIndex = cursor.getColumnIndex( - (!useNestedCategory ) ? QueryCategorySubCategory.CATEGSUBNAME : QueryCategorySubCategory.CATEGNAME - ); + int categoryColumnIndex = cursor.getColumnIndex( QueryNestedCategory.CATEGNAME ); categoryTextView.setText(cursor.getString(categoryColumnIndex)); } long categoryId; long subCategoryId; - if (!useNestedCategory) { - categoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.CATEGID)); - subCategoryId = cursor.getInt(cursor.getColumnIndex(BudgetQuery.SUBCATEGID)); - } else { - categoryId = cursor.getInt(cursor.getColumnIndex(BudgetNestedQuery.CATEGID)); - subCategoryId = -1; - } + categoryId = cursor.getInt(cursor.getColumnIndex(BudgetNestedQuery.CATEGID)); + subCategoryId = -1; // Frequency @@ -228,20 +211,8 @@ public void setBudgetYearId(long budgetYearId) { private double getActualAmount(boolean hasSubcategory, Cursor cursor) { double actual; // wolfsolver since category can be neested we need to consider always category as master - // probabily until we don't handle third and other level actual value does not count correctlry - if (!useNestedCategory) { - if (!hasSubcategory) { - long categoryId = cursor.getLong(cursor.getColumnIndex(BudgetQuery.CATEGID)); - actual = getAmountForCategory(categoryId); - } else { - long subCategoryId = cursor.getLong(cursor.getColumnIndex(BudgetQuery.SUBCATEGID)); - actual = getAmountForCategory(subCategoryId); - // actual = getAmountForSubCategory(subCategoryId); - } - } else { - long categoryId = cursor.getLong(cursor.getColumnIndex(BudgetNestedQuery.CATEGID)); - actual = getAmountForCategory(categoryId); - } + long categoryId = cursor.getLong(cursor.getColumnIndex(BudgetNestedQuery.CATEGID)); + actual = getAmountForCategory(categoryId); return actual; } diff --git a/app/src/main/java/com/money/manager/ex/budget/BudgetEditActivity.java b/app/src/main/java/com/money/manager/ex/budget/BudgetEditActivity.java index a8dc56a80..fed383019 100644 --- a/app/src/main/java/com/money/manager/ex/budget/BudgetEditActivity.java +++ b/app/src/main/java/com/money/manager/ex/budget/BudgetEditActivity.java @@ -34,7 +34,6 @@ import com.money.manager.ex.core.MenuHelper; import com.money.manager.ex.datalayer.BudgetRepository; import com.money.manager.ex.domainmodel.Budget; -import com.money.manager.ex.settings.AppSettings; import com.money.manager.ex.utils.MmxDate; import timber.log.Timber; @@ -49,8 +48,6 @@ public class BudgetEditActivity extends MmxBaseFragmentActivity { private TextView budgetYearTextView; private TextView budgetMonthTextView; - private boolean useNestedCategory = false; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -60,8 +57,6 @@ protected void onCreate(Bundle savedInstanceState) { budgetYearTextView = findViewById(R.id.budgetYearTextView); budgetMonthTextView = findViewById(R.id.budgetMonthTextView); - useNestedCategory = (new AppSettings(this.getBaseContext()).getBehaviourSettings().getUseNestedCategory()); - initializeToolbar(); initializeModel(); diff --git a/app/src/main/java/com/money/manager/ex/budget/BudgetEntryFragment.java b/app/src/main/java/com/money/manager/ex/budget/BudgetEntryFragment.java index 20c12f480..e6ef57592 100644 --- a/app/src/main/java/com/money/manager/ex/budget/BudgetEntryFragment.java +++ b/app/src/main/java/com/money/manager/ex/budget/BudgetEntryFragment.java @@ -27,7 +27,6 @@ import com.money.manager.ex.R; import com.money.manager.ex.common.BaseListFragment; import com.money.manager.ex.common.MmxCursorLoader; -import com.money.manager.ex.database.QueryCategorySubCategory; import com.money.manager.ex.datalayer.Select; import com.money.manager.ex.nestedcategory.QueryNestedCategory; import com.money.manager.ex.settings.AppSettings; @@ -49,8 +48,6 @@ public class BudgetEntryFragment private long mBudgetYearId = Constants.NOT_SET; private String mBudgetName; private View mHeader; - private boolean useNestedCategory = false; // new NestedCateg - /** * Use this factory method to create a new instance of @@ -81,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) { mBudgetYearId = getArguments().getLong(ARG_BUDGET_YEAR_ID); mBudgetName = getArguments().getString(ARG_BUDGET_NAME_ID); } - useNestedCategory = (new AppSettings(getContext()).getBehaviourSettings().getUseNestedCategory()); + } @Override @@ -133,19 +130,11 @@ private void displayBudget() { private void setUpAdapter() { BudgetAdapter adapter; - if (!useNestedCategory) { - adapter = new BudgetAdapter(getActivity(), - null, - new String[]{BudgetQuery.CATEGNAME}, - new int[]{R.id.categoryTextView}, - 0); - } else { - adapter = new BudgetAdapter(getActivity(), - null, - new String[]{BudgetNestedQuery.CATEGNAME}, - new int[]{R.id.categoryTextView}, - 0); - } + adapter = new BudgetAdapter(getActivity(), + null, + new String[]{BudgetNestedQuery.CATEGNAME}, + new int[]{R.id.categoryTextView}, + 0); adapter.setBudgetName(mBudgetName); adapter.setBudgetYearId(mBudgetYearId); @@ -160,19 +149,11 @@ public Loader onCreateLoader(int id, Bundle args) { Loader result = null; if (id == LOADER_BUDGET) { - if (!useNestedCategory) { - QueryCategorySubCategory categories = new QueryCategorySubCategory(getActivity()); - Select query = new Select(categories.getAllColumns()) - .orderBy(QueryCategorySubCategory.CATEGSUBNAME); - - result = new MmxCursorLoader(getActivity(), categories.getUri(), query); - } else { - // useNestedCategory - QueryNestedCategory categories = new QueryNestedCategory(getActivity()); - Select query = new Select(categories.getAllColumns()) - .orderBy(QueryNestedCategory.CATEGNAME); - result = new MmxCursorLoader(getActivity(), categories.getUri(), query); - } + // useNestedCategory + QueryNestedCategory categories = new QueryNestedCategory(getActivity()); + Select query = new Select(categories.getAllColumns()) + .orderBy(QueryNestedCategory.CATEGNAME); + result = new MmxCursorLoader(getActivity(), categories.getUri(), query); } return result; } diff --git a/app/src/main/java/com/money/manager/ex/common/CategoryListActivity.java b/app/src/main/java/com/money/manager/ex/common/CategoryListActivity.java index a426a6b3d..7393582c4 100644 --- a/app/src/main/java/com/money/manager/ex/common/CategoryListActivity.java +++ b/app/src/main/java/com/money/manager/ex/common/CategoryListActivity.java @@ -48,7 +48,6 @@ public class CategoryListActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - boolean useNestedCategory = (new AppSettings(this).getBehaviourSettings().getUseNestedCategory()); setContentView(R.layout.base_toolbar_activity); @@ -69,16 +68,9 @@ protected void onCreate(Bundle savedInstanceState) { // management fragment FragmentManager fm = getSupportFragmentManager(); if (fm.findFragmentById(R.id.content) == null) { - if (!useNestedCategory) { - // todo: use replace? - fm.beginTransaction() - .add(R.id.content, listFragment, FRAGMENTTAG) - .commit(); - } else { fm.beginTransaction() .add(R.id.content, nestedListFragment, FRAGMENTTAG) .commit(); - } } } @@ -86,19 +78,10 @@ protected void onCreate(Bundle savedInstanceState) { public boolean onKeyUp(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { // set result and terminate activity - boolean useNestedCategory = (new AppSettings(this).getBehaviourSettings().getUseNestedCategory()); - if (!useNestedCategory) { - CategoryListFragment fragment = - (CategoryListFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENTTAG); - if (fragment != null) { - fragment.setResultAndFinish(); - } - } else { - NestedCategoryListFragment fragment = - (NestedCategoryListFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENTTAG); - if (fragment != null) { - fragment.setResultAndFinish(); - } + NestedCategoryListFragment fragment = + (NestedCategoryListFragment) getSupportFragmentManager().findFragmentByTag(FRAGMENTTAG); + if (fragment != null) { + fragment.setResultAndFinish(); } } return super.onKeyUp(keyCode, event); diff --git a/app/src/main/java/com/money/manager/ex/datalayer/BudgetEntryRepository.java b/app/src/main/java/com/money/manager/ex/datalayer/BudgetEntryRepository.java index 66f712309..ef4f6afb0 100644 --- a/app/src/main/java/com/money/manager/ex/datalayer/BudgetEntryRepository.java +++ b/app/src/main/java/com/money/manager/ex/datalayer/BudgetEntryRepository.java @@ -39,15 +39,8 @@ public class BudgetEntryRepository public static final String TABLE_NAME = "budgettable_v1"; - private boolean useNestedCategory = false; // new NestedCateg - public BudgetEntryRepository(Context context) { super(context, TABLE_NAME, DatasetType.TABLE, "budgettable"); - try { - useNestedCategory = (new AppSettings(context).getBehaviourSettings().getUseNestedCategory()); - } catch (Exception e) { - - } } @Override @@ -105,38 +98,20 @@ public HashMap loadForYear(long budgetYearId) { HashMap budgetEntryHashMap = new HashMap<>(); - if (!useNestedCategory) { - // use old way - CategoryRepository categoryRepository = new CategoryRepository(getContext()); - - while (cursor.moveToNext()) { - BudgetEntry budgetEntry = new BudgetEntry(); - budgetEntry.loadFromCursor(cursor); + // use nested category + QueryNestedCategory categoryRepositoryNested = new QueryNestedCategory(null); + while (cursor.moveToNext()) { + BudgetEntry budgetEntry = new BudgetEntry(); + budgetEntry.loadFromCursor(cursor); - long categoryId = cursor.getLong(cursor.getColumnIndex(BudgetEntry.CATEGID)); - Category category = categoryRepository.load(categoryId); - if (category == null) { - continue; - } - budgetEntryHashMap.put(getKeyForCategories(category.getParentId(), categoryId), budgetEntry); + NestedCategoryEntity nestedCategory = categoryRepositoryNested.getOneCategoryEntity(budgetEntry.getCategId()); + if (nestedCategory == null) { + continue; } - cursor.close(); - } else { - // use nested category - QueryNestedCategory categoryRepositoryNested = new QueryNestedCategory(null); - while (cursor.moveToNext()) { - BudgetEntry budgetEntry = new BudgetEntry(); - budgetEntry.loadFromCursor(cursor); - - NestedCategoryEntity nestedCategory = categoryRepositoryNested.getOneCategoryEntity(budgetEntry.getCategId()); - if (nestedCategory == null) { - continue; - } - budgetEntryHashMap.put(getKeyForCategories(nestedCategory.getParentId(), nestedCategory.getCategoryId()), budgetEntry); - } - cursor.close(); - + budgetEntryHashMap.put(getKeyForCategories(nestedCategory.getParentId(), nestedCategory.getCategoryId()), budgetEntry); } + cursor.close(); + return budgetEntryHashMap; } diff --git a/app/src/main/java/com/money/manager/ex/home/MainActivity.java b/app/src/main/java/com/money/manager/ex/home/MainActivity.java index e0d518fa3..8c785f1f4 100644 --- a/app/src/main/java/com/money/manager/ex/home/MainActivity.java +++ b/app/src/main/java/com/money/manager/ex/home/MainActivity.java @@ -616,12 +616,7 @@ public boolean onDrawerMenuAndOptionMenuSelected(DrawerMenuItem item) { } else if (itemId == R.id.menu_account) { showFragment(AccountListFragment.class); } else if (itemId == R.id.menu_category) { - boolean useNestedCategory = (new AppSettings(this).getBehaviourSettings().getUseNestedCategory()); - if (!useNestedCategory) { - showFragment(CategoryListFragment.class); - } else { - showFragment(NestedCategoryListFragment.class); - } + showFragment(NestedCategoryListFragment.class); } else if (itemId == R.id.menu_currency) { Intent intent = new Intent(MainActivity.this, CurrencyListActivity.class); intent.setAction(Intent.ACTION_EDIT); diff --git a/app/src/main/java/com/money/manager/ex/search/SearchParametersFragment.java b/app/src/main/java/com/money/manager/ex/search/SearchParametersFragment.java index 35a18dfa5..c250b738a 100644 --- a/app/src/main/java/com/money/manager/ex/search/SearchParametersFragment.java +++ b/app/src/main/java/com/money/manager/ex/search/SearchParametersFragment.java @@ -727,9 +727,8 @@ private void displaySearchCriteria(View view) { viewHolder.txtSelectPayee.setText(searchParameters.payeeName); // Category displayCategory(searchParameters.category); - boolean useNestedCategory = (new AppSettings(getContext()).getBehaviourSettings().getUseNestedCategory()); - cbxSearchSubCategory.setEnabled(useNestedCategory); - cbxSearchSubCategory.setChecked(useNestedCategory); + cbxSearchSubCategory.setEnabled(true); + cbxSearchSubCategory.setChecked(true); // Transaction number viewHolder.txtTransNumber.setText(searchParameters.transactionNumber);