Skip to content

Commit

Permalink
Merge pull request #1985 from wolfsolver/tag-management
Browse files Browse the repository at this point in the history
Add Tag in SearchTransaction
  • Loading branch information
guanlisheng authored Dec 21, 2024
2 parents 72c3a00 + 2f41f41 commit d8b00e8
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 37 deletions.
8 changes: 8 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@
<action android:name="android.intent.action.EDIT" />
</intent-filter>
</activity>
<activity
android:name=".tag.TagActivity"
android:label="@string/tag" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PICK" />
<action android:name="android.intent.action.EDIT" />
</intent-filter>
</activity>
<activity android:name=".account.AccountListActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PICK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}

}
2 changes: 2 additions & 0 deletions app/src/main/java/com/money/manager/ex/core/RequestCodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,7 @@ public SearchParameters() {

public String transactionNumber;
public String notes;

public Long tagId;
public String tagName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
}
25 changes: 1 addition & 24 deletions app/src/main/java/com/money/manager/ex/tag/TagActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,37 +41,14 @@ 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();

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);
}
}
20 changes: 11 additions & 9 deletions app/src/main/java/com/money/manager/ex/tag/TagListFragment.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/search_parameters_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@
android:hint="@string/transaction_number" />
</com.google.android.material.textfield.TextInputLayout>

<com.money.manager.ex.view.RobotoTextView
android:id="@+id/textViewSelectTag"
style="?attr/holoSpinnerStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:focusable="false"
android:focusableInTouchMode="false"
android:hint="@string/select_tag" />

<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
Expand Down

0 comments on commit d8b00e8

Please sign in to comment.