Fixed bug where clearing numpad did not disable the FAB

This commit is contained in:
Phillip Hsu
2016-07-16 00:39:39 -07:00
parent 231aa9a280
commit c0b914500d
3 changed files with 33 additions and 29 deletions
@@ -92,8 +92,8 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
@Override
protected void onDigitsCleared() {
mFormattedInput.delete(0, mFormattedInput.length());
updateNumpadStates();
mAmPmState = UNSPECIFIED;
updateNumpadStates(); // TOneverDO: before resetting mAmPmState to UNSPECIFIED
super.onDigitsCleared();
}
@@ -155,8 +155,14 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
* state must be set.
*/
public boolean checkTimeValid() {
if (mAmPmState == UNSPECIFIED || mAmPmState == HRS_24 && count() < 3)
// While the test looks bare, it is actually comprehensive.
// mAmPmState will remain UNSPECIFIED until a legal
// sequence of digits is inputted, no matter the clock system in use.
// TODO: So if that's the case, do we actually need 'count() < 3' here? Or better yet,
// can we simplify the code to just 'return mAmPmState != UNSPECIFIED'?
if (mAmPmState == UNSPECIFIED || mAmPmState == HRS_24 && count() < 3) {
return false;
}
// AM or PM can only be set if the time was already valid previously, so we don't need
// to check for them.
return true;
@@ -306,7 +312,7 @@ public class NumpadTimePicker extends GridLayoutNumpad implements TimePicker {
}
} else if (count() == MAX_DIGITS) {
int colonAt = mFormattedInput.indexOf(":");
// Since we now batch updating the formatted input whenever
// Since we now batch update the formatted input whenever
// digits are inserted, the colon may legitimately not be
// present in the formatted input when this is initialized.
if (colonAt != -1) {
@@ -2,6 +2,7 @@ package com.philliphsu.clock2.editalarm;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -12,7 +13,6 @@ import com.philliphsu.clock2.R;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnTouch;
/**
@@ -94,6 +94,16 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
View view = inflater.inflate(R.layout.dialog_time_picker_numpad, container, false);
ButterKnife.bind(this, view);
Toolbar toolbar = ButterKnife.findById(view, R.id.toolbar);
toolbar.setNavigationIcon(android.R.drawable.ic_menu_close_clear_cancel);
// Can't do a method bind on the navigation icon because we don't own it
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
// Can't do a method bind because the FAB is not part of this dialog's layout
// Also can't do the bind in the Numpad's class, because it doesn't have access to
// the OnTimeSetListener callback contained here or the dialog's dismiss()
@@ -146,11 +156,6 @@ public class NumpadTimePickerDialog extends DialogFragment implements NumpadTime
return true;
}
@OnClick(R.id.cancel_icon)
void myCancel() {
dismiss();
}
private void updateInputText(String inputText) {
mInputField.setText(inputText);
// Move the cursor