Skip to content

Commit

Permalink
Merge pull request #1777 from moneymanagerex/scheduled
Browse files Browse the repository at this point in the history
refactor: reports code clean up
  • Loading branch information
guanlisheng authored Aug 21, 2024
2 parents 8c4b101 + 8c3bfb3 commit d8ca67a
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 93 deletions.
109 changes: 45 additions & 64 deletions app/src/main/java/com/money/manager/ex/reports/BaseReportFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.money.manager.ex.reports;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -155,53 +154,38 @@ public boolean onOptionsItemSelected(MenuItem item) {
// MmxDateTimeUtils dateUtils = dateTimeUtilsLazy.get();
MmxDate dateTime = MmxDate.newDate();

switch (item.getItemId()) {
case R.id.menu_current_month:
mDateFrom = dateTime.firstDayOfMonth().toDate();
mDateTo = dateTime.lastDayOfMonth().toDate();
break;

case R.id.menu_last_month:
mDateFrom = dateTime.minusMonths(1)
.firstDayOfMonth().toDate();
mDateTo = dateTime.lastDayOfMonth().toDate();
break;

case R.id.menu_last_30_days:
mDateTo = dateTime.toDate();
mDateFrom = dateTime.minusDays(30).toDate();
break;

case R.id.menu_current_year:
mDateFrom = dateTime.firstMonthOfYear().firstDayOfMonth().toDate();
mDateTo = dateTime.lastMonthOfYear().lastDayOfMonth().toDate();
break;

case R.id.menu_last_year:
mDateFrom = dateTime.minusYears(1)
.firstMonthOfYear()
.firstDayOfMonth()
.toDate();
mDateTo = dateTime
.lastMonthOfYear()
.lastDayOfMonth()
.toDate();
break;

case R.id.menu_all_time:
mDateFrom = null;
mDateTo = null;
break;
case R.id.menu_custom_dates:
//check item
item.setChecked(true);
mItemSelected = item.getItemId();
//show binaryDialog
showDialogCustomDates();
return true;
// break;
default:
return super.onOptionsItemSelected(item);
int itemId = item.getItemId();

if (itemId == R.id.menu_current_month) {
mDateFrom = dateTime.firstDayOfMonth().toDate();
mDateTo = dateTime.lastDayOfMonth().toDate();
} else if (itemId == R.id.menu_last_month) {
mDateFrom = dateTime.minusMonths(1).firstDayOfMonth().toDate();
mDateTo = dateTime.lastDayOfMonth().toDate();
} else if (itemId == R.id.menu_last_30_days) {
mDateTo = dateTime.toDate();
mDateFrom = dateTime.minusDays(30).toDate();
} else if (itemId == R.id.menu_current_year) {
mDateFrom = dateTime.firstMonthOfYear().firstDayOfMonth().toDate();
mDateTo = dateTime.lastMonthOfYear().lastDayOfMonth().toDate();
} else if (itemId == R.id.menu_last_year) {
mDateFrom = dateTime.minusYears(1)
.firstMonthOfYear()
.firstDayOfMonth()
.toDate();
mDateTo = dateTime.lastMonthOfYear().lastDayOfMonth().toDate();
} else if (itemId == R.id.menu_all_time) {
mDateFrom = null;
mDateTo = null;
} else if (itemId == R.id.menu_custom_dates) {
// Check item
item.setChecked(true);
mItemSelected = itemId;
// Show custom dates dialog
showDialogCustomDates();
return true;
} else {
return super.onOptionsItemSelected(item);
}

String whereClause = null;
Expand Down Expand Up @@ -276,22 +260,19 @@ private void showDialogCustomDates() {

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setView(dialogView)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mDateFrom = dateTimeUtilsLazy.get().from(fromDatePicker);
mDateTo = dateTimeUtilsLazy.get().from(toDatePicker);

String whereClause =
QueryAllData.Date + ">='" + new MmxDate(mDateFrom).toIsoDateString() +
"' AND " +
QueryAllData.Date + "<='" + new MmxDate(mDateTo).toIsoDateString() + "'";

Bundle args = new Bundle();
args.putString(KEY_WHERE_CLAUSE, whereClause);

startLoader(args);
}
.setPositiveButton(android.R.string.ok, (dialog, which) -> {
mDateFrom = dateTimeUtilsLazy.get().from(fromDatePicker);
mDateTo = dateTimeUtilsLazy.get().from(toDatePicker);

String whereClause =
QueryAllData.Date + ">='" + new MmxDate(mDateFrom).toIsoDateString() +
"' AND " +
QueryAllData.Date + "<='" + new MmxDate(mDateTo).toIsoDateString() + "'";

Bundle args = new Bundle();
args.putString(KEY_WHERE_CLAUSE, whereClause);

startLoader(args);
})
.setNegativeButton(android.R.string.cancel, null)
.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteQueryBuilder;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
Expand Down Expand Up @@ -146,14 +145,7 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {

if (((CategoriesReportActivity) getActivity()).mIsDualPanel) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {

@Override
public void run() {
showChart();

}
}, 1000);
handler.postDelayed(() -> showChart(), 1000);
}
}
}
Expand Down Expand Up @@ -250,11 +242,7 @@ protected String prepareQuery(String whereClause) {
builder.setTables(mobileData.getSource());

//return query
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, null);
} else {
return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, null);
}
return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void bindView(View view, Context context, Cursor cursor) {
month = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Month));
Calendar calendar = Calendar.getInstance();
calendar.set(year, month - 1, 1);
double income = 0, expenses = 0;
double income, expenses;
expenses = cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Expenses));
income = cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Income));
// attach data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteQueryBuilder;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
Expand Down Expand Up @@ -153,13 +152,7 @@ public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// handler to show chart
if (((PayeesReportActivity) getActivity()).mIsDualPanel) {
Handler handler = new Handler();
handler.postDelayed(new Runnable() {

@Override
public void run() {
showChart();
}
}, 1000);
handler.postDelayed(() -> showChart(), 1000);
}
}
}
Expand All @@ -184,11 +177,7 @@ protected String prepareQuery(String whereClause) {
//compose builder
builder.setTables(mobileData.getSource());
//return query
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
} else {
return builder.buildQuery(projectionIn, selection, null, groupBy, having, sortOrder, limit);
}
return builder.buildQuery(projectionIn, selection, groupBy, having, sortOrder, limit);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ValuePieEntry(String text, double value) {
public ValuePieEntry(String text, double value, String valueFormatted) {
setText(text);
setValue(value);
setValueFormatted(valueFormatted);
setValueFormatted(valueFormatted);
}

/**
Expand Down

0 comments on commit d8ca67a

Please sign in to comment.