From 2f41f41a6e66045bdccaab8f49bdf0dda9dc4002 Mon Sep 17 00:00:00 2001 From: "Emmanuele (WolfSolver)" Date: Sat, 21 Dec 2024 09:47:22 +0100 Subject: [PATCH] Add Tag in SearchTransaction --- app/src/main/AndroidManifest.xml | 8 ++++ .../manager/ex/common/BaseListFragment.java | 2 + .../ex/common/MmxBaseFragmentActivity.java | 42 +++++++++++++++++++ .../money/manager/ex/core/RequestCodes.java | 2 + .../manager/ex/domainmodel/EntityBase.java | 8 ++-- .../manager/ex/search/SearchParameters.java | 3 ++ .../ex/search/SearchParametersFragment.java | 25 +++++++++++ .../ex/search/SearchParametersViewHolder.java | 2 + .../com/money/manager/ex/tag/TagActivity.java | 25 +---------- .../money/manager/ex/tag/TagListFragment.java | 20 +++++---- .../res/layout/search_parameters_fragment.xml | 10 +++++ 11 files changed, 110 insertions(+), 37 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 673a95d4cd..28a0cf74e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -191,6 +191,14 @@ + + + + + + diff --git a/app/src/main/java/com/money/manager/ex/common/BaseListFragment.java b/app/src/main/java/com/money/manager/ex/common/BaseListFragment.java index b74cbfa61b..a22717b38b 100644 --- a/app/src/main/java/com/money/manager/ex/common/BaseListFragment.java +++ b/app/src/main/java/com/money/manager/ex/common/BaseListFragment.java @@ -54,6 +54,8 @@ public abstract class BaseListFragment // hint search view private String mSearchHint = ""; + public static String mAction = null; + // abstract method public abstract String getSubTitle(); diff --git a/app/src/main/java/com/money/manager/ex/common/MmxBaseFragmentActivity.java b/app/src/main/java/com/money/manager/ex/common/MmxBaseFragmentActivity.java index 976dc57a0d..e29bc5baab 100644 --- a/app/src/main/java/com/money/manager/ex/common/MmxBaseFragmentActivity.java +++ b/app/src/main/java/com/money/manager/ex/common/MmxBaseFragmentActivity.java @@ -25,8 +25,10 @@ import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.FragmentManager; import android.provider.DocumentsContract; +import android.view.KeyEvent; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; @@ -53,6 +55,9 @@ public abstract class MmxBaseFragmentActivity private Toolbar mToolbar; private boolean mDisplayHomeAsUpEnabled = false; + private BaseListFragment listFragment; + private String FRAGMENTTAG = null; + @Override protected void onCreate(Bundle savedInstanceState) { setTheme(); @@ -271,4 +276,41 @@ public void openDirectoryPicker(Uri uri) { // intent.putExtra(DocumentsContract.EXTRA_INITIAL_URI, uri); directoryPickerLauncher.launch(intent); } + + protected void inizializeCommon(BaseListFragment mListFragment, String mFragmentTAG) { + setContentView(R.layout.base_toolbar_activity); + listFragment = mListFragment; + FRAGMENTTAG = mFragmentTAG; + + // enable home button + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + // process intent + FragmentManager fm = getSupportFragmentManager(); + // attach fragment activity + if (fm.findFragmentById(R.id.content) == null) { + // todo: use .replace + fm.beginTransaction() + .add(R.id.content, listFragment, FRAGMENTTAG) + .commit(); + } + + } + + @Override + public boolean onKeyUp(int keyCode, KeyEvent event) { + if (FRAGMENTTAG == null) return super.onKeyUp(keyCode, event); + + if (keyCode == KeyEvent.KEYCODE_BACK) { + // set result + BaseListFragment fragment = (BaseListFragment) getSupportFragmentManager() + .findFragmentByTag(FRAGMENTTAG); + if (fragment != null) { + fragment.getActivity().setResult(RESULT_CANCELED); + fragment.getActivity().finish(); + } + } + return super.onKeyUp(keyCode, event); + } + } diff --git a/app/src/main/java/com/money/manager/ex/core/RequestCodes.java b/app/src/main/java/com/money/manager/ex/core/RequestCodes.java index 411cc961f3..c26d841f6d 100644 --- a/app/src/main/java/com/money/manager/ex/core/RequestCodes.java +++ b/app/src/main/java/com/money/manager/ex/core/RequestCodes.java @@ -34,6 +34,8 @@ public class RequestCodes { public static final int PASSCODE = 7; public static final int PAYEE = 8; public static final int PRICE = 9; + public static final int TAG = 21; + /** * Used when selecting a database from a storage access framework. */ diff --git a/app/src/main/java/com/money/manager/ex/domainmodel/EntityBase.java b/app/src/main/java/com/money/manager/ex/domainmodel/EntityBase.java index 5c8f4a269a..73f003615d 100644 --- a/app/src/main/java/com/money/manager/ex/domainmodel/EntityBase.java +++ b/app/src/main/java/com/money/manager/ex/domainmodel/EntityBase.java @@ -39,19 +39,19 @@ public class EntityBase implements IEntity { + public ContentValues contentValues; + /** * Default constructor. */ - protected EntityBase() { + public EntityBase() { contentValues = new ContentValues(); } - protected EntityBase(ContentValues contentValues) { + public EntityBase(ContentValues contentValues) { this.contentValues = contentValues; } - public ContentValues contentValues; - public void loadFromCursor(Cursor c) { this.contentValues.clear(); diff --git a/app/src/main/java/com/money/manager/ex/search/SearchParameters.java b/app/src/main/java/com/money/manager/ex/search/SearchParameters.java index 41ddcc13c9..c85f957ab2 100644 --- a/app/src/main/java/com/money/manager/ex/search/SearchParameters.java +++ b/app/src/main/java/com/money/manager/ex/search/SearchParameters.java @@ -70,4 +70,7 @@ public SearchParameters() { public String transactionNumber; public String notes; + + public Long tagId; + public String tagName; } 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 dd56916aab..103aa69881 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 @@ -61,6 +61,7 @@ import com.money.manager.ex.servicelayer.AccountService; import com.money.manager.ex.settings.AppSettings; import com.money.manager.ex.settings.LookAndFeelSettings; +import com.money.manager.ex.tag.TagActivity; import com.money.manager.ex.utils.MmxDate; import com.money.manager.ex.utils.MmxDateTimeUtils; @@ -199,6 +200,16 @@ public void onClick(View v) { } }); + //Payee + viewHolder.txtSelectTag.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(getContext(), TagActivity.class); + intent.setAction(Intent.ACTION_PICK); + startActivityForResult(intent, RequestCodes.TAG); + } + }); + //Category txtSelectCategory.setOnClickListener(new OnClickListener() { @Override @@ -247,6 +258,10 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) { viewHolder.txtSelectPayee.setTag(data.getLongExtra(PayeeActivity.INTENT_RESULT_PAYEEID, Constants.NOT_SET)); viewHolder.txtSelectPayee.setText(data.getStringExtra(PayeeActivity.INTENT_RESULT_PAYEENAME)); break; + case RequestCodes.TAG: + viewHolder.txtSelectTag.setTag(data.getLongExtra(TagActivity.INTENT_RESULT_TAGID, Constants.NOT_SET)); + viewHolder.txtSelectTag.setText(data.getStringExtra(TagActivity.INTENT_RESULT_TAGNAME)); + break; case RequestCodes.CATEGORY: //create class for store data CategorySub categorySub = new CategorySub(); @@ -528,6 +543,11 @@ private String assembleWhereClause() { where.addStatement(QueryAllData.Notes + " LIKE '%" + searchParameters.notes + "%'"); } + // tag + if (searchParameters.tagId != null) { + where.addStatement(QueryAllData.TAGS + " LIKE '%" + searchParameters.tagName +"%'"); + } + return where.getWhere(); } @@ -633,6 +653,11 @@ private SearchParameters collectSearchCriteria() { searchParameters.payeeId = Long.parseLong(viewHolder.txtSelectPayee.getTag().toString()); searchParameters.payeeName = viewHolder.txtSelectPayee.getText().toString(); } + // tag + if (viewHolder.txtSelectTag.getTag() != null) { + searchParameters.tagId = Long.parseLong(viewHolder.txtSelectTag.getTag().toString()); + searchParameters.tagName = viewHolder.txtSelectTag.getText().toString(); + } // Category if (txtSelectCategory.getTag() != null) { searchParameters.category = (CategorySub) txtSelectCategory.getTag(); diff --git a/app/src/main/java/com/money/manager/ex/search/SearchParametersViewHolder.java b/app/src/main/java/com/money/manager/ex/search/SearchParametersViewHolder.java index 61a35f937f..54e734e2d3 100644 --- a/app/src/main/java/com/money/manager/ex/search/SearchParametersViewHolder.java +++ b/app/src/main/java/com/money/manager/ex/search/SearchParametersViewHolder.java @@ -37,6 +37,7 @@ public class SearchParametersViewHolder { public TextView txtSelectPayee; public TextView txtDateTo; public EditText edtNotes; + public TextView txtSelectTag; public SearchParametersViewHolder(View view) { // Initialize views using findViewById @@ -48,5 +49,6 @@ public SearchParametersViewHolder(View view) { txtSelectPayee = view.findViewById(R.id.textViewSelectPayee); txtDateTo = view.findViewById(R.id.textViewToDate); edtNotes = view.findViewById(R.id.editTextNotes); + txtSelectTag = view.findViewById(R.id.textViewSelectTag); } } diff --git a/app/src/main/java/com/money/manager/ex/tag/TagActivity.java b/app/src/main/java/com/money/manager/ex/tag/TagActivity.java index 9a5010e58b..bc2d7bbf8d 100644 --- a/app/src/main/java/com/money/manager/ex/tag/TagActivity.java +++ b/app/src/main/java/com/money/manager/ex/tag/TagActivity.java @@ -41,9 +41,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.base_toolbar_activity); - // enable home button - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - + super.inizializeCommon(listFragment,FRAGMENTTAG); // process intent Intent intent = getIntent(); String action = intent.getAction(); @@ -51,27 +49,6 @@ protected void onCreate(Bundle savedInstanceState) { if (!TextUtils.isEmpty(action)) { TagListFragment.mAction = action; } - FragmentManager fm = getSupportFragmentManager(); - // attach fragment activity - if (fm.findFragmentById(R.id.content) == null) { - // todo: use .replace - fm.beginTransaction() - .add(R.id.content, listFragment, FRAGMENTTAG) - .commit(); - } - } - @Override - public boolean onKeyUp(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - // set result - BaseListFragment fragment = (BaseListFragment) getSupportFragmentManager() - .findFragmentByTag(FRAGMENTTAG); - if (fragment != null) { - fragment.getActivity().setResult(RESULT_CANCELED); - fragment.getActivity().finish(); - } - } - return super.onKeyUp(keyCode, event); } } diff --git a/app/src/main/java/com/money/manager/ex/tag/TagListFragment.java b/app/src/main/java/com/money/manager/ex/tag/TagListFragment.java index 2a8591fbda..0c6376c098 100644 --- a/app/src/main/java/com/money/manager/ex/tag/TagListFragment.java +++ b/app/src/main/java/com/money/manager/ex/tag/TagListFragment.java @@ -1,5 +1,6 @@ package com.money.manager.ex.tag; +import android.annotation.SuppressLint; import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; @@ -30,11 +31,13 @@ import com.money.manager.ex.common.BaseListFragment; import com.money.manager.ex.common.MmxCursorLoader; import com.money.manager.ex.core.ContextMenuIds; +import com.money.manager.ex.core.IntentFactory; import com.money.manager.ex.core.UIHelper; import com.money.manager.ex.database.SQLTypeTransaction; import com.money.manager.ex.datalayer.Select; import com.money.manager.ex.datalayer.TagRepository; import com.money.manager.ex.domainmodel.Tag; +import com.money.manager.ex.search.SearchParameters; import com.money.manager.ex.servicelayer.TagService; import com.money.manager.ex.settings.AppSettings; @@ -143,6 +146,7 @@ public boolean onOptionsItemSelected(MenuItem item) { // Context Menu + @SuppressLint("Range") @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; @@ -199,13 +203,11 @@ public boolean onContextItemSelected(android.view.MenuItem item) { break; case VIEW_TRANSACTIONS: - // TODO: implement search parameter - Toast.makeText(getContext(), "View Transaction is still not implemented", Toast.LENGTH_SHORT).show(); -// SearchParameters parameters = new SearchParameters(); -// parameters.tagId = tag.getId(); -// parameters.tagName = tag.getName(); -// Intent intent = IntentFactory.getSearchIntent(getActivity(), parameters); -// startActivity(intent); + SearchParameters parameters = new SearchParameters(); + parameters.tagId = tag.getId(); + parameters.tagName = tag.getName(); + Intent intent = IntentFactory.getSearchIntent(getActivity(), parameters); + startActivity(intent); } return false; } @@ -280,8 +282,8 @@ protected void setResult() { if (Intent.ACTION_PICK.equals(mAction)) { // Cursor that is already in the desired position, because positioned in the event onListItemClick Cursor cursor = ((SimpleCursorAdapter) getListAdapter()).getCursor(); - long tagId = cursor.getLong(cursor.getColumnIndex(Tag.TAGID)); - String tagName = cursor.getString(cursor.getColumnIndex(Tag.TAGNAME)); + @SuppressLint("Range") long tagId = cursor.getLong(cursor.getColumnIndex(Tag.TAGID)); + @SuppressLint("Range") String tagName = cursor.getString(cursor.getColumnIndex(Tag.TAGNAME)); sendResultToActivity(tagId, tagName); diff --git a/app/src/main/res/layout/search_parameters_fragment.xml b/app/src/main/res/layout/search_parameters_fragment.xml index cdacfeafe3..11a3288259 100644 --- a/app/src/main/res/layout/search_parameters_fragment.xml +++ b/app/src/main/res/layout/search_parameters_fragment.xml @@ -212,6 +212,16 @@ android:hint="@string/transaction_number" /> + +