Skip to content

Commit

Permalink
TimeDateDialog
Browse files Browse the repository at this point in the history
"The date selector should make it impossible to select an unsupported date." (#770)
  • Loading branch information
forrestguice committed Feb 13, 2024
1 parent 82806b8 commit 2c601bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ private void handleIntent(Intent intent)
configDate();

} else if (action.equals(ACTION_SHOW_DATE)) {
showDate(intent.getLongExtra(EXTRA_SHOW_DATE, -1));
showDate(intent.getLongExtra(EXTRA_SHOW_DATE, (Long) null));

} else if (action.equals(ACTION_NOTE_SEEK)) {
String eventID = intent.getStringExtra(EXTRA_SOLAREVENT);
Expand Down Expand Up @@ -1423,17 +1423,19 @@ public boolean onOptionsItemSelected(MenuItem item)
protected void showDate()
{
int position = card_layout.findFirstVisibleItemPosition();
long datetime = (position != CardAdapter.TODAY_POSITION) ? card_adapter.findDateForPosition(this, position) : -1L;
Long datetime = (position != CardAdapter.TODAY_POSITION) ? card_adapter.findDateForPosition(this, position) : null;
showDate(datetime);
}
protected void showDate(long datetime)
protected void showDate(@Nullable Long datetime)
{
final TimeDateDialog datePicker = new TimeDateDialog();
datePicker.setDialogTitle(getString(R.string.configAction_viewDate));
datePicker.setTimezone(dataset.timezone());
datePicker.setMinDate( card_adapter.findDateForPosition(this, 0) );
datePicker.setMaxDate( card_adapter.findDateForPosition(this, CardAdapter.MAX_POSITIONS-1) );
datePicker.setOnAcceptedListener(onSeekDate(datePicker));

if (datetime != -1) {
if (datetime != null) {
datePicker.setInitialDateTime(datetime);
}
datePicker.show(getSupportFragmentManager(), DIALOGTAG_DATE_SEEK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ public void init(int year, int month, int day)
protected void initViews(Context context, View dialogContent)
{
picker = (DatePicker) dialogContent.findViewById(R.id.appwidget_date_custom);
if (getArguments().containsKey(KEY_MIN_DATETIME)) {
picker.setMinDate(getArguments().getLong(KEY_MIN_DATETIME));
}
if (getArguments().containsKey(KEY_MAX_DATETIME)) {
picker.setMaxDate(getArguments().getLong(KEY_MAX_DATETIME));
}

ImageButton btn_cancel = (ImageButton) dialogContent.findViewById(R.id.dialog_button_cancel);
TooltipCompat.setTooltipText(btn_cancel, btn_cancel.getContentDescription());
Expand Down Expand Up @@ -320,6 +326,16 @@ protected void expandSheet(DialogInterface dialog)
}
}

public static final String KEY_MIN_DATETIME = "min_datetime";
public void setMinDate(long datetime) {
getArguments().putLong(KEY_MIN_DATETIME, datetime);
}

public static final String KEY_MAX_DATETIME = "max_datetime";
public void setMaxDate(long datetime) {
getArguments().putLong(KEY_MAX_DATETIME, datetime);
}

public static final String KEY_INITIAL_DATETIME = "initial_datetime";
public void setInitialDateTime(long datetime) {
getArguments().putLong(KEY_INITIAL_DATETIME, datetime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.graphics.Color;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v7.widget.LinearSmoothScroller;
Expand Down Expand Up @@ -163,9 +164,9 @@ public long findDateForPosition(Context context, int position)
Calendar calendar = null;
Pair<SuntimesRiseSetDataset, SuntimesMoonData> data = initData(context, position);
if (data != null && data.first != null) {
calendar = data.first.calendar();
calendar = data.first.dataActual.calendar();
}
return (calendar != null) ? calendar.getTimeInMillis() : -1;
return (calendar != null) ? calendar.getTimeInMillis() : null;
}

public int findPositionForDate(Context context, long dateMillis)
Expand Down

0 comments on commit 2c601bb

Please sign in to comment.