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

Dark theme compatibility for dialogs. #218

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Prepare Java
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: temurin
- name: Prepare Gradle
uses: gradle/actions/setup-gradle@v3
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Prepare Java
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: temurin
- name: Prepare Gradle
uses: gradle/actions/setup-gradle@v3
Expand Down Expand Up @@ -145,7 +145,7 @@ jobs:
- name: Prepare Java
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: temurin
- name: Prepare Gradle
uses: gradle/actions/setup-gradle@v3
Expand All @@ -164,7 +164,7 @@ jobs:
- name: Prepare Java
uses: actions/setup-java@v4
with:
java-version: "17"
java-version: "21"
distribution: temurin
- name: Prepare Gradle
uses: gradle/actions/setup-gradle@v3
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ dependencies {
// Debug
debugImplementation 'com.facebook.stetho:stetho:1.5.0'

testImplementation 'org.robolectric:robolectric:4.11.1'
testImplementation 'org.robolectric:robolectric:4.14.1'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.assertj:assertj-core:3.26.3'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.gnucash.android.ui.budget;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
Expand All @@ -29,7 +30,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.DatePicker;
import android.widget.Toast;

import androidx.annotation.NonNull;
Expand All @@ -38,7 +39,6 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment;
import com.codetroopers.betterpickers.recurrencepicker.EventRecurrence;
import com.codetroopers.betterpickers.recurrencepicker.EventRecurrenceFormatter;
import com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialogFragment;
Expand All @@ -60,20 +60,20 @@
import org.gnucash.android.ui.transaction.TransactionFormFragment;
import org.gnucash.android.ui.util.RecurrenceParser;
import org.gnucash.android.ui.util.RecurrenceViewClickListener;
import org.gnucash.android.ui.util.dialog.DatePickerDialogFragment;
import org.gnucash.android.ui.util.widget.CalculatorKeyboard;
import org.gnucash.android.util.QualifiedAccountNameCursorAdapter;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;

import timber.log.Timber;

/**
* Fragment for creating or editing Budgets
*/
public class BudgetFormFragment extends Fragment implements RecurrencePickerDialogFragment.OnRecurrenceSetListener, CalendarDatePickerDialogFragment.OnDateSetListener {
public class BudgetFormFragment extends Fragment implements RecurrencePickerDialogFragment.OnRecurrenceSetListener, DatePickerDialog.OnDateSetListener {

public static final int REQUEST_EDIT_BUDGET_AMOUNTS = 0xBA;

Expand All @@ -83,8 +83,8 @@ public class BudgetFormFragment extends Fragment implements RecurrencePickerDial
private BudgetsDbAdapter mBudgetsDbAdapter;

private Budget mBudget;
private Calendar mStartDate;
private ArrayList<BudgetAmount> mBudgetAmounts;
private final Calendar mStartDate = Calendar.getInstance();
private ArrayList<BudgetAmount> mBudgetAmounts = new ArrayList<>();
private AccountsDbAdapter mAccountsDbAdapter;
private QualifiedAccountNameCursorAdapter mAccountsCursorAdapter;

Expand All @@ -108,8 +108,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mBudgetsDbAdapter = BudgetsDbAdapter.getInstance();
mStartDate = Calendar.getInstance();
mBudgetAmounts = new ArrayList<>();
mBudgetAmounts.clear();
String conditions = "(" + DatabaseSchema.AccountEntry.COLUMN_HIDDEN + " = 0 )";
mAccountsDbAdapter = AccountsDbAdapter.getInstance();
Cursor accountCursor = mAccountsDbAdapter.fetchAccountsOrderedByFavoriteAndFullName(conditions, null);
Expand Down Expand Up @@ -156,7 +155,7 @@ private void initViews(Budget budget) {
mEventRecurrence.parse(recurrenceRuleString);
mBinding.inputRecurrence.setText(budget.getRecurrence().getRepeatString(context));

mBudgetAmounts = (ArrayList<BudgetAmount>) budget.getCompactedBudgetAmounts();
mBudgetAmounts = new ArrayList(budget.getCompactedBudgetAmounts());
toggleAmountInputVisibility();
}

Expand Down Expand Up @@ -275,22 +274,9 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
}

private void onClickBudgetStartDate(View v) {
long dateMillis = 0;
try {
dateMillis = TransactionFormFragment.DATE_FORMATTER.parseMillis(((TextView) v).getText().toString());
} catch (IllegalArgumentException e) {
Timber.e("Error converting input time to Date object");
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(dateMillis);

int year = calendar.get(Calendar.YEAR);
int monthOfYear = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
CalendarDatePickerDialogFragment datePickerDialog = new CalendarDatePickerDialogFragment();
datePickerDialog.setOnDateSetListener(BudgetFormFragment.this);
datePickerDialog.setPreselectedDate(year, monthOfYear, dayOfMonth);
datePickerDialog.show(getFragmentManager(), "date_picker_fragment");
long dateMillis = mStartDate.getTimeInMillis();
DatePickerDialogFragment.newInstance(BudgetFormFragment.this, dateMillis)
.show(getParentFragmentManager(), "date_picker_fragment");
}

private void onOpenBudgetAmountEditor(View v) {
Expand Down Expand Up @@ -318,12 +304,11 @@ public void onRecurrenceSet(String rrule) {
}

@Override
public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
Calendar cal = new GregorianCalendar(year, monthOfYear, dayOfMonth);
mBinding.inputStartDate.setText(TransactionFormFragment.DATE_FORMATTER.print(cal.getTimeInMillis()));
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
mStartDate.set(Calendar.YEAR, year);
mStartDate.set(Calendar.MONTH, monthOfYear);
mStartDate.set(Calendar.MONTH, month);
mStartDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
mBinding.inputStartDate.setText(TransactionFormFragment.DATE_FORMATTER.print(mStartDate.getTimeInMillis()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import static org.gnucash.android.util.ContentExtKt.getDocumentName;

import android.app.Activity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -39,7 +41,9 @@
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.RadioButton;
import android.widget.TimePicker;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -48,8 +52,6 @@
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;

import com.codetroopers.betterpickers.calendardatepicker.CalendarDatePickerDialogFragment;
import com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialogFragment;
import com.codetroopers.betterpickers.recurrencepicker.EventRecurrence;
import com.codetroopers.betterpickers.recurrencepicker.EventRecurrenceFormatter;
import com.codetroopers.betterpickers.recurrencepicker.RecurrencePickerDialogFragment;
Expand All @@ -74,6 +76,8 @@
import org.gnucash.android.ui.transaction.TransactionFormFragment;
import org.gnucash.android.ui.util.RecurrenceParser;
import org.gnucash.android.ui.util.RecurrenceViewClickListener;
import org.gnucash.android.ui.util.dialog.DatePickerDialogFragment;
import org.gnucash.android.ui.util.dialog.TimePickerDialogFragment;
import org.gnucash.android.util.PreferencesHelper;
import org.gnucash.android.util.TimestampHelper;

Expand All @@ -92,8 +96,8 @@
*/
public class ExportFormFragment extends Fragment implements
RecurrencePickerDialogFragment.OnRecurrenceSetListener,
CalendarDatePickerDialogFragment.OnDateSetListener,
RadialTimePickerDialogFragment.OnTimeSetListener {
DatePickerDialog.OnDateSetListener,
TimePickerDialog.OnTimeSetListener {

/**
* Request code for intent to pick export file destination
Expand Down Expand Up @@ -458,43 +462,19 @@ public void onNothingSelected(AdapterView<?> parent) {

@Override
public void onClick(View v) {
long dateMillis = 0;
try {
dateMillis = TransactionFormFragment.DATE_FORMATTER.parseMillis(mBinding.exportStartDate.getText().toString());
} catch (IllegalArgumentException e) {
Timber.e(e, "Error converting input time to Date object");
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(dateMillis);

int year = calendar.get(Calendar.YEAR);
int monthOfYear = calendar.get(Calendar.MONTH);
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
CalendarDatePickerDialogFragment datePickerDialog = new CalendarDatePickerDialogFragment();
datePickerDialog.setOnDateSetListener(ExportFormFragment.this);
datePickerDialog.setPreselectedDate(year, monthOfYear, dayOfMonth);
datePickerDialog.show(getFragmentManager(), "date_picker_fragment");
long dateMillis = mExportStartCalendar.getTimeInMillis();
DatePickerDialogFragment.newInstance(ExportFormFragment.this, dateMillis)
.show(getParentFragmentManager(), "date_picker_fragment");
}
});

mBinding.exportStartTime.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
long timeMillis = 0;
try {
timeMillis = TransactionFormFragment.TIME_FORMATTER.parseMillis(mBinding.exportStartDate.getText().toString());
} catch (IllegalArgumentException e) {
Timber.e(e, "Error converting input time to Date object");
}
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(timeMillis);

RadialTimePickerDialogFragment timePickerDialog = new RadialTimePickerDialogFragment();
timePickerDialog.setOnTimeSetListener(ExportFormFragment.this);
timePickerDialog.setStartTime(calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE));
timePickerDialog.show(getFragmentManager(), "time_picker_dialog_fragment");
long timeMillis = mExportStartCalendar.getTimeInMillis();
TimePickerDialogFragment.newInstance(ExportFormFragment.this, timeMillis)
.show(getParentFragmentManager(), "time_picker_dialog_fragment");
}
});

Expand Down Expand Up @@ -659,20 +639,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}

@Override
public void onDateSet(CalendarDatePickerDialogFragment dialog, int year, int monthOfYear, int dayOfMonth) {
Calendar cal = new GregorianCalendar(year, monthOfYear, dayOfMonth);
mBinding.exportStartDate.setText(TransactionFormFragment.DATE_FORMATTER.print(cal.getTimeInMillis()));
public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
mExportStartCalendar.set(Calendar.YEAR, year);
mExportStartCalendar.set(Calendar.MONTH, monthOfYear);
mExportStartCalendar.set(Calendar.MONTH, month);
mExportStartCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
mBinding.exportStartDate.setText(TransactionFormFragment.DATE_FORMATTER.print(mExportStartCalendar.getTimeInMillis()));
}

@Override
public void onTimeSet(RadialTimePickerDialogFragment dialog, int hourOfDay, int minute) {
Calendar cal = new GregorianCalendar(0, 0, 0, hourOfDay, minute);
mBinding.exportStartTime.setText(TransactionFormFragment.TIME_FORMATTER.print(cal.getTimeInMillis()));
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
mExportStartCalendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
mExportStartCalendar.set(Calendar.MINUTE, minute);
mBinding.exportStartTime.setText(TransactionFormFragment.TIME_FORMATTER.print(mExportStartCalendar.getTimeInMillis()));
}
}

Expand Down
Loading
Loading