Skip to content

Commit

Permalink
fix: date picker last date (#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
laxyapahuja authored and luckyman20 committed Dec 15, 2019
1 parent 5c96db2 commit b1c4bec
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@ data class LoanTemplate(
}
return 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public class LoanApplicationFragment extends BaseFragment implements LoanApplica
private String submittedDate;
private boolean isDisbursementDate = false;
private boolean isLoanUpdatePurposesInitialization = true;
public boolean active = false;


/**
Expand Down Expand Up @@ -325,8 +326,9 @@ public void inflateSubmissionDate() {
* Initializes {@code tvExpectedDisbursementDate} with current Date
*/
public void inflateDisbursementDate() {
mfDatePicker = MFDatePicker.newInstance(this, MFDatePicker.FUTURE_DAYS);
mfDatePicker = MFDatePicker.newInstance(this, MFDatePicker.FUTURE_DAYS, active);
tvExpectedDisbursementDate.setText(MFDatePicker.getDatePickedAsString());
active = true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public class SavingAccountsTransactionFragment extends BaseFragment
private List<CheckboxStatus> statusList;
private boolean isCheckBoxPeriod;
private int selectedRadioButtonId;
public boolean active = false;


public static SavingAccountsTransactionFragment newInstance(long savingsId) {
Expand Down Expand Up @@ -168,7 +169,8 @@ public void showUserInterface() {
rvSavingAccountsTransaction.setAdapter(transactionListAdapter);

// radioGroup.setOnCheckedChangeListener(this);
mfDatePicker = MFDatePicker.newInstance(this, MFDatePicker.ALL_DAYS);
mfDatePicker = MFDatePicker.newInstance(this, MFDatePicker.ALL_DAYS, active);
active = true;
}

/**
Expand Down
33 changes: 18 additions & 15 deletions app/src/main/java/org/mifos/mobile/utils/MFDatePicker.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnD

public static final String TAG = "MFDatePicker";
static String dateSet;
static Calendar calendar;
static Calendar mCalendar;
private String startDateString;
private long startDate;
private int datePickerType = ALL_DAYS;
Expand All @@ -39,17 +39,17 @@ public class MFDatePicker extends DialogFragment implements DatePickerDialog.OnD

static {

calendar = Calendar.getInstance();
mCalendar = Calendar.getInstance();
dateSet = new StringBuilder()
.append(calendar.get(Calendar.DAY_OF_MONTH) < 10 ?
("0" + calendar.get(Calendar.DAY_OF_MONTH))
: calendar.get(Calendar.DAY_OF_MONTH))
.append(mCalendar.get(Calendar.DAY_OF_MONTH) < 10 ?
("0" + mCalendar.get(Calendar.DAY_OF_MONTH))
: mCalendar.get(Calendar.DAY_OF_MONTH))
.append("-")
.append(calendar.get(Calendar.MONTH) + 1 < 10 ?
("0" + (calendar.get(Calendar.MONTH) + 1))
: calendar.get(Calendar.MONTH) + 1)
.append(mCalendar.get(Calendar.MONTH) + 1 < 10 ?
("0" + (mCalendar.get(Calendar.MONTH) + 1))
: mCalendar.get(Calendar.MONTH) + 1)
.append("-")
.append(calendar.get(Calendar.YEAR))
.append(mCalendar.get(Calendar.YEAR))
.toString();
}

Expand All @@ -59,7 +59,7 @@ public MFDatePicker() {

}

public static MFDatePicker newInstance(Fragment fragment, int datePickerType) {
public static MFDatePicker newInstance(Fragment fragment, int datePickerType, boolean active) {
MFDatePicker mfDatePicker = new MFDatePicker();

Bundle args = new Bundle();
Expand All @@ -68,6 +68,10 @@ public static MFDatePicker newInstance(Fragment fragment, int datePickerType) {
mfDatePicker.setArguments(args);

mfDatePicker.onDatePickListener = (OnDatePickListener) fragment;

if (!active) {
mCalendar = Calendar.getInstance();
}
return mfDatePicker;
}

Expand All @@ -81,9 +85,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
DatePickerDialog dialog = new DatePickerDialog(getActivity(),
R.style.MaterialDatePickerTheme,
this,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH));
mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH));

Bundle args = getArguments();
this.datePickerType = args.getInt(Constants.DATE_PICKER_TYPE, this.ALL_DAYS);
Expand All @@ -103,13 +107,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
@Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
//TODO Fix Single digit problem that fails with the locale
Calendar calendar = Calendar.getInstance();
Calendar calendar = mCalendar;
calendar.set(year, month, day);
Date date = calendar.getTime();
onDatePickListener.onDatePicked(startDateString = DateFormat.
format("dd-MM-yyyy", date).toString());
startDate = DateHelper.getDateAsLongFromString(startDateString, "dd-MM-yyyy");

}

public void setOnDatePickListener(OnDatePickListener onDatePickListener) {
Expand Down

0 comments on commit b1c4bec

Please sign in to comment.