Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for General Reports in AMMEX #2138 #2222

Merged
merged 9 commits into from
Feb 9, 2025
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

<!-- xmlns:tools="http://schemas.android.com/tools" -->

<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE" />
Expand Down Expand Up @@ -60,6 +67,9 @@
android:theme="@style/Theme.Splash"
tools:replace="android:label"
android:supportsRtl="true">

<activity android:name=".reports.GeneralReportActivity" />

<meta-data
android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIV3RVD4VMl2dthsS81qkxq7MW12Iy_LR3_gWXuQ" />
Expand Down
136 changes: 136 additions & 0 deletions app/src/main/java/com/money/manager/ex/home/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@
*/
package com.money.manager.ex.home;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
Expand All @@ -34,9 +39,11 @@
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.view.animation.RotateAnimation;
import android.widget.AdapterView;
import android.widget.ExpandableListView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -47,6 +54,7 @@
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;
import androidx.sqlite.db.SupportSQLiteDatabase;

import com.amplitude.android.Amplitude;
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
Expand All @@ -55,6 +63,7 @@
import com.money.manager.ex.HelpActivity;
import com.money.manager.ex.MmexApplication;
import com.money.manager.ex.reports.CashFlowReportActivity;
import com.money.manager.ex.database.MmxOpenHelper;
import com.money.manager.ex.tag.TagListFragment;
import com.money.manager.ex.nestedcategory.NestedCategoryListFragment;
import com.money.manager.ex.passcode.PasscodeActivity;
Expand Down Expand Up @@ -88,6 +97,7 @@
import com.money.manager.ex.notifications.RecurringTransactionProcess;
import com.money.manager.ex.scheduled.ScheduledTransactionListFragment;
import com.money.manager.ex.reports.CategoriesReportActivity;
import com.money.manager.ex.reports.GeneralReportActivity;
import com.money.manager.ex.reports.IncomeVsExpensesActivity;
import com.money.manager.ex.reports.PayeesReportActivity;
import com.money.manager.ex.search.SearchActivity;
Expand Down Expand Up @@ -623,6 +633,8 @@ public boolean onDrawerMenuAndOptionMenuSelected(DrawerMenuItem item) {
startActivity(new Intent(this, CategoriesReportActivity.class));
} else if (itemId == R.id.menu_settings) {
startActivity(new Intent(MainActivity.this, SettingsActivity.class));
} else if (itemId == R.id.menu_general_report_group) {
showGeneralReportsSelector(item.getText());
} else if (itemId == R.id.menu_report_payees) {
startActivity(new Intent(this, PayeesReportActivity.class));
} else if (itemId == R.id.menu_report_where_money_goes) {
Expand Down Expand Up @@ -887,6 +899,9 @@ private void createExpandableDrawer() {

childItems.add(childReports);

// general reports
childItems.add(getGeneralReportGroupDrawerMenuItems());

// Settings
childItems.add(null);

Expand Down Expand Up @@ -1055,6 +1070,14 @@ private ArrayList<DrawerMenuItem> getDrawerMenuItems() {
.withIconDrawable(uiHelper.getIcon(GoogleMaterial.Icon.gmd_equalizer)
.color(iconColor)));
// .withDivider(true));

// General reports
menuItems.add(new DrawerMenuItem().withId(R.id.menu_general_report_group)
velmuruganc marked this conversation as resolved.
Show resolved Hide resolved
.withText(getString(R.string.menu_general_report_group))
.withIconDrawable(uiHelper.getIcon(MMXIconFont.Icon.mmx_reports)
.color(iconColor)));
// .withDivider(true));

// Settings
menuItems.add(new DrawerMenuItem().withId(R.id.menu_settings)
.withText(getString(R.string.settings))
Expand All @@ -1066,6 +1089,7 @@ private ArrayList<DrawerMenuItem> getDrawerMenuItems() {
// .withIconDrawable(uiHelper.getIcon(GoogleMaterial.Icon.gmd_card_giftcard)
// .color(iconColor))
// .withDivider(Boolean.TRUE));

// Help
menuItems.add(new DrawerMenuItem().withId(R.id.menu_about)
.withText(getString(R.string.about))
Expand Down Expand Up @@ -1412,4 +1436,116 @@ private void showSelectDatabaseActivity() {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}

private ArrayList<DrawerMenuItem> getGeneralReportGroupDrawerMenuItems() {

UIHelper uiHelper = new UIHelper(this);
int iconColor = uiHelper.getSecondaryTextColor();
ArrayList<DrawerMenuItem> childReportGroup = new ArrayList<>();

// Db setup
MmxOpenHelper MmxHelper = new MmxOpenHelper(this, new AppSettings(this).getDatabaseSettings().getDatabasePath());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not the best way to get dB data.

Create a content provider and register with Uri, so you can use mmx infrastructure to get data

SupportSQLiteDatabase db = MmxHelper.getReadableDatabase();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above


try
{
Cursor groupCursor = db.query("SELECT DISTINCT GROUPNAME FROM REPORT_V1");
int groupIndex = 0;

if(groupCursor.moveToFirst())
{
while(!groupCursor.isAfterLast()){
groupIndex = groupCursor.getColumnIndex("GROUPNAME");
childReportGroup.add(new DrawerMenuItem().withId(R.id.menu_general_report_group)
.withText(groupCursor.getString(groupIndex))
.withIconDrawable(uiHelper.getIcon(MMXIconFont.Icon.mmx_report_page)
.color(iconColor)));

groupCursor.moveToNext();
}
}

groupCursor.close();

}
catch(Exception e)
{
//System.err.println("EXCEPTION:"+e);
}

return childReportGroup;
}

@SuppressLint("Range")
private void showGeneralReportsSelector(String groupName) {

//added by velmuruganc
final DrawerMenuItemAdapter adapter = new DrawerMenuItemAdapter(this);
UIHelper uiHelper = new UIHelper(this);
int iconColor = uiHelper.getSecondaryTextColor();

// Db setup
MmxOpenHelper MmxHelper = new MmxOpenHelper(this, new AppSettings(this).getDatabaseSettings().getDatabasePath());
SupportSQLiteDatabase db = MmxHelper.getReadableDatabase();
Comment on lines +1488 to +1489
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above . You reopen dB too many times


Cursor menuCursor = db.query("SELECT REPORTNAME FROM REPORT_V1 WHERE GROUPNAME = '"+ groupName +"'");
ArrayList<String> reportName = new ArrayList<>();

if(menuCursor.moveToFirst())
{
while(!menuCursor.isAfterLast()){
reportName.add(menuCursor.getString(menuCursor.getColumnIndex("REPORTNAME")));
//custom report for given group
adapter.add(new DrawerMenuItem().withId(R.id.menu_general_report)
.withText(menuCursor.getString(menuCursor.getColumnIndex("REPORTNAME")))
.withIconDrawable(uiHelper.getIcon(MMXIconFont.Icon.mmx_report_page)
.color(iconColor)));

menuCursor.moveToNext();
}
}

menuCursor.close();

//*********** build custom dialog ************
// Inflate the custom dialog layout
AlertDialog.Builder builder = new AlertDialog.Builder(this);

// Create a TextView for the title with added space in place of builder.setTitle(groupName)
TextView title = new TextView(this);
title.setText(groupName);
title.setTextSize(20);
title.setPadding(40, 20, 0, 20); // Adds space above and below the title

builder.setCustomTitle(title);
title.setTypeface(null, Typeface.BOLD); // Makes the title bold
title.setTextColor(Color.BLACK);

// Inflate the custom layout that contains the ListView
View customView = getLayoutInflater().inflate(R.layout.dialog_general_report, null);
builder.setView(customView);

// Set up ListView and adapter
ListView listView = customView.findViewById(R.id.listView);

listView.setAdapter(adapter);
// Create and show the dialog
AlertDialog dialog = builder.create();

// Set item click listener for ListView
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//Toast.makeText(getApplicationContext(), "Item clicked: " + reportName.get(position), Toast.LENGTH_SHORT).show();

Intent intent = new Intent(MainActivity.this, GeneralReportActivity.class);
intent.putExtra(GeneralReportActivity.GENERAL_REPORT_NAME, reportName.get(position) );
intent.putExtra(GeneralReportActivity.GENERAL_REPORT_GROUP_NAME, groupName );
startActivity(intent);
dialog.dismiss();
}
});

dialog.show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void onReceive(Context context, Intent intent) {
msgBody += msgs[i].getMessageBody();
}

//msgSender = "AT-SIBSMS";
msgSender = "AT-SIBSMS";

if(isTransactionSms(msgSender)) {
// Transaction Sms sender will have format like this AT-SIBSMS,
Expand Down Expand Up @@ -984,14 +984,12 @@ private static void getAccountDetails(String[] reqMatch)

public boolean validateData() {

boolean isTransfer = mCommon.transactionEntity.getTransactionType().equals(TransactionTypes.Transfer);

if (mCommon.transactionEntity.getAccountId().equals(Constants.NOT_SET)) {
//Toast.makeText(mContext, "MMEX : " + (R.string.error_toaccount_not_selected), Toast.LENGTH_LONG).show();
return false;
}

if (isTransfer) {
if (mCommon.transactionEntity.getTransactionType().equals(TransactionTypes.Transfer)) {
if (mCommon.transactionEntity.getAccountToId().equals(Constants.NOT_SET)) {
//Toast.makeText(mContext, "MMEX : " + (R.string.error_toaccount_not_selected), Toast.LENGTH_LONG).show();
return false;
Expand Down Expand Up @@ -1023,12 +1021,8 @@ public boolean validateData() {
}

// Category is required if tx is not a split or transfer.
if (!mCommon.transactionEntity.hasCategory()) {
//Toast.makeText(mContext, "MMEX : " + (R.string.error_category_not_selected), Toast.LENGTH_LONG).show();
return false;
}
return mCommon.transactionEntity.hasCategory();

return isTransfer;
}

public boolean saveTransaction() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.money.manager.ex.reports;

import android.os.Bundle;
import androidx.appcompat.widget.Toolbar;
import com.money.manager.ex.R;
import com.money.manager.ex.common.MmxBaseFragmentActivity;
import android.text.TextUtils;

public class GeneralReportActivity extends MmxBaseFragmentActivity {

public static final String GENERAL_REPORT_NAME = "GeneralReportActivity:ReportName";
public static final String GENERAL_REPORT_GROUP_NAME = "GeneralReportActivity:GroupName";
public static String currentReportName = "";

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_general_report);

if (getIntent() != null && !TextUtils.isEmpty(getIntent().getStringExtra(GENERAL_REPORT_NAME)) ) {
currentReportName = getIntent().getStringExtra(GENERAL_REPORT_NAME);
}

Toolbar toolbar = findViewById(R.id.toolbar);

if (toolbar != null) {
setSupportActionBar(toolbar);
// set actionbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle(currentReportName);
}

GeneralReportFragment fragment = new GeneralReportFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.GeneralReportFragment, fragment, GeneralReportFragment.class.getSimpleName())
.commit();

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.money.manager.ex.reports;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import java.util.List;

public class GeneralReportArrayAdapter extends ArrayAdapter<String> {

public GeneralReportArrayAdapter(Context context, List<String> items) {
// Using default simple item layout
super(context, android.R.layout.simple_list_item_1, items);
}

// You can override getView if you want to customize the item layout further
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
// Customize view if needed (e.g., add icons, change text color, etc.)
return view;
}
}
Loading