Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
aint committed Oct 6, 2015
1 parent 496be34 commit 15caa85
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.joda.time.LocalDateTime;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -68,7 +67,6 @@ public class PieChartFragment extends Fragment implements OnChartValueSelectedLi
ReportOptionsListener {

public static final String SELECTED_VALUE_PATTERN = "%s - %.2f (%.2f %%)";
public static final String DATE_PATTERN = "MMMM\nYYYY";
public static final String TOTAL_VALUE_LABEL_PATTERN = "%s\n%.2f %s";
private static final int ANIMATION_DURATION = 1800;
public static final int NO_DATA_COLOR = Color.LTGRAY;
Expand All @@ -82,17 +80,12 @@ public class PieChartFragment extends Fragment implements OnChartValueSelectedLi
*/
private static final double GROUPING_SMALLER_SLICES_THRESHOLD = 5;

private LocalDateTime mChartDate = new LocalDateTime();

@Bind(R.id.pie_chart) PieChart mChart;
@Bind(R.id.selected_chart_slice) TextView mSelectedValueTextView;

private AccountsDbAdapter mAccountsDbAdapter;
private TransactionsDbAdapter mTransactionsDbAdapter;

private LocalDateTime mEarliestTransactionDate;
private LocalDateTime mLatestTransactionDate;

private AccountType mAccountType;

private boolean mChartDataPresent = true;
Expand Down Expand Up @@ -125,8 +118,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
((AppCompatActivity)getActivity()).getSupportActionBar().setTitle(R.string.title_pie_chart);

((AppCompatActivity)getActivity()).getSupportActionBar().setTitle(R.string.title_pie_chart);
setHasOptionsMenu(true);

mUseAccountColor = PreferenceManager.getDefaultSharedPreferences(getActivity())
Expand Down Expand Up @@ -199,7 +192,8 @@ private PieData getData() {
&& !account.isPlaceholderAccount()
&& account.getCurrency() == Currency.getInstance(mCurrencyCode)) {

double balance = mAccountsDbAdapter.getAccountsBalance(Collections.singletonList(account.getUID()), mReportStartTime, mReportEndTime).absolute().asDouble();
double balance = mAccountsDbAdapter.getAccountsBalance(Collections.singletonList(account.getUID()),
mReportStartTime, mReportEndTime).absolute().asDouble();
if (balance != 0) {
dataSet.addEntry(new Entry((float) balance, dataSet.getEntryCount()));
colors.add(mUseAccountColor && account.getColorHexCode() != null
Expand All @@ -225,17 +219,13 @@ public void onTimeRangeUpdated(long start, long end) {

@Override
public void onGroupingUpdated(ReportsActivity.GroupInterval groupInterval) {
//TODO: Does this make sense for a pie chart? Don't think so
//nothing to see here, this doesn't make sense for a pie chart
}

@Override
public void onAccountTypeUpdated(AccountType accountType) {
if (mAccountType != accountType) {
mAccountType = accountType;
mEarliestTransactionDate = new LocalDateTime(mTransactionsDbAdapter.getTimestampOfEarliestTransaction(mAccountType, mCurrencyCode));
mLatestTransactionDate = new LocalDateTime(mTransactionsDbAdapter.getTimestampOfLatestTransaction(mAccountType, mCurrencyCode));
mChartDate = mLatestTransactionDate;

displayChart();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import org.gnucash.android.model.Account;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Transaction;
import org.gnucash.android.ui.transaction.TransactionsActivity;
import org.joda.time.LocalDateTime;

Expand All @@ -63,6 +62,9 @@
* @author Ngewi Fet <ngewif@gmail.com>
*/
public class ReportSummaryFragment extends Fragment {

public static final int LEGEND_TEXT_SIZE = 14;

@Bind(R.id.btn_pie_chart) Button mPieChartButton;
@Bind(R.id.btn_bar_chart) Button mBarChartButton;
@Bind(R.id.btn_line_chart) Button mLineChartButton;
Expand All @@ -73,7 +75,7 @@ public class ReportSummaryFragment extends Fragment {
@Bind(R.id.total_liabilities) TextView mTotalLiabilities;
@Bind(R.id.net_worth) TextView mNetWorth;

AccountsDbAdapter mAccountsDbAdapter;
private AccountsDbAdapter mAccountsDbAdapter;

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -138,8 +140,7 @@ public void onActivityCreated(@Nullable Bundle savedInstanceState) {
mChart.setDescription("");
mChart.getLegend().setEnabled(true);
mChart.getLegend().setPosition(Legend.LegendPosition.RIGHT_OF_CHART_CENTER);
mChart.getLegend().setTextSize(14);
// mChart.setOnChartValueSelectedListener(this);
mChart.getLegend().setTextSize(LEGEND_TEXT_SIZE);

ColorStateList csl = new ColorStateList(new int[][]{new int[0]}, new int[]{getResources().getColor(R.color.account_green)});
setButtonTint(mPieChartButton, csl);
Expand Down Expand Up @@ -255,8 +256,7 @@ public void setButtonTint(Button button, ColorStateList tint) {

private void loadFragment(Fragment fragment){
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

fragmentTransaction.replace(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
Expand All @@ -41,7 +40,6 @@
import org.gnucash.android.app.GnuCashApplication;
import org.gnucash.android.db.TransactionsDbAdapter;
import org.gnucash.android.model.AccountType;
import org.gnucash.android.model.Money;
import org.gnucash.android.ui.common.BaseDrawerActivity;
import org.gnucash.android.ui.report.dialog.DateRangePickerDialogFragment;
import org.joda.time.LocalDate;
Expand Down Expand Up @@ -76,7 +74,7 @@ public class ReportsActivity extends BaseDrawerActivity implements AdapterView.O
@Bind(R.id.time_range_spinner) Spinner mTimeRangeSpinner;
@Bind(R.id.report_account_type_spinner) Spinner mAccountTypeSpinner;

TransactionsDbAdapter mTransactionsDbAdapter;
private TransactionsDbAdapter mTransactionsDbAdapter;
private AccountType mAccountType = AccountType.EXPENSE;

public enum GroupInterval {WEEK, MONTH, QUARTER, YEAR, ALL}
Expand All @@ -85,8 +83,7 @@ public enum GroupInterval {WEEK, MONTH, QUARTER, YEAR, ALL}
private long mReportStartTime = new LocalDate().minusMonths(2).dayOfMonth().withMinimumValue().toDate().getTime();
private long mReportEndTime = new LocalDate().plusDays(1).toDate().getTime();


GroupInterval mReportGroupInterval = GroupInterval.MONTH;
private GroupInterval mReportGroupInterval = GroupInterval.MONTH;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -273,9 +270,8 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long
mReportEndTime = -1;
break;
case 5:
String mCurrencyCode = PreferenceManager.getDefaultSharedPreferences(this).getString(getString(R.string.key_report_currency), Money.DEFAULT_CURRENCY_CODE);
String mCurrencyCode = GnuCashApplication.getDefaultCurrencyCode();
long earliestTransactionTime = mTransactionsDbAdapter.getTimestampOfEarliestTransaction(mAccountType, mCurrencyCode);
long latestTransactionTime = mTransactionsDbAdapter.getTimestampOfLatestTransaction(mAccountType, mCurrencyCode);
DialogFragment rangeFragment = DateRangePickerDialogFragment.newInstance(
earliestTransactionTime,
new LocalDate().plusDays(1).toDate().getTime(),
Expand Down

0 comments on commit 15caa85

Please sign in to comment.