use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.
the class CreateDateActivity method onStart.
@Override
protected void onStart() {
super.onStart();
Map<String, DateModel> map = new HashMap<>(storage.loadMapData());
DatePicker datePicker = this.findViewById(R.id.datePicker);
TimePicker timePicker = this.findViewById(R.id.timePicker);
EditText title = this.findViewById(R.id.nameText);
if (key != null) {
long l = Long.parseLong(key);
Time time = new Time();
time.set(l);
datePicker.updateDate(time.year, time.month, time.monthDay);
timePicker.setCurrentHour(time.hour);
timePicker.setCurrentMinute(time.minute);
title.setText(map.get(key).getTitle());
}
}
use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.
the class EditDateActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
HashMap<String, DateModel> dateMap = new HashMap<>(storage.loadMapData());
switch(item.getItemId()) {
case R.id.action_save:
if (title.getText().toString().matches("")) {
Toast.makeText(this, "Enter a title to save", Toast.LENGTH_LONG).show();
return true;
}
if (currentlySelectedTime == null || currentlySelectedDate == null) {
Toast.makeText(this, "Enter date and time field to save", Toast.LENGTH_LONG).show();
return true;
}
Calendar newCalendar = new GregorianCalendar(currentlySelectedDate.get(Calendar.YEAR), currentlySelectedDate.get(Calendar.MONTH), currentlySelectedDate.get(Calendar.DAY_OF_MONTH), currentlySelectedTime.getHours(), currentlySelectedTime.getMinutes());
long dateLong = newCalendar.getTimeInMillis();
String calendarKey = Long.toString(dateLong);
// Delete previous instance of item, if changed
if (dateMap.containsKey(key)) {
dateMap.remove(key);
}
DateModel dateModel = new DateModel(title.getText().toString(), dateLong);
dateMap.put(calendarKey, dateModel);
storage.storeMapData(dateMap);
finish();
return true;
case R.id.action_delete:
if (dateMap.containsKey(key)) {
dateMap.remove(key);
storage.storeMapData(dateMap);
Toast.makeText(this, title.getText().toString() + " deleted.", Toast.LENGTH_LONG).show();
finish();
} else {
Toast.makeText(this, "Date not stored yet.", Toast.LENGTH_LONG).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.
the class DateFragment method onStart.
@Override
public void onStart() {
super.onStart();
storage = Global.getStorage(getActivity());
dateAdapter = new DateAdapter(new OnDateClickListener() {
@Override
public void onClick(DateModel item) {
EditDateActivity.start(getActivity(), Long.toString(item.getDateInMillis()));
}
@Override
public void onLongClick(DateModel item) {
showRemoveDialog(item);
}
});
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), 0));
recyclerView.setAdapter(dateAdapter);
}
use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.
the class CreateDateActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == android.R.id.home) {
Log.i(Global.LOG_TAG, "Pressed home");
onBackPressed();
return true;
}
// noinspection SimplifiableIfStatement
if (id == R.id.action_save) {
DatePicker datePicker = this.findViewById(R.id.datePicker);
TimePicker timePicker = this.findViewById(R.id.timePicker);
EditText title = this.findViewById(R.id.nameText);
if (title.getText().toString().matches("")) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
// set dialog message
alertDialogBuilder.setTitle("Error").setMessage("You need to fill the title!").setCancelable(false).setPositiveButton("OK", null);
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
return true;
}
Time time = new Time();
time.year = datePicker.getYear();
time.month = datePicker.getMonth();
time.monthDay = datePicker.getDayOfMonth();
time.hour = timePicker.getCurrentHour();
time.minute = timePicker.getCurrentMinute();
long millis = time.toMillis(false);
String millisStr = String.valueOf(millis);
Map<String, DateModel> dateMap = new HashMap<>(storage.loadMapData());
if (key == null) {
// Sets key to be a the time represented as a long in milliseconds
key = millisStr;
} else {
dateMap.remove(key);
key = millisStr;
}
Log.i(Global.LOG_TAG, "onOptionsItemSelected: " + key + title.getText().toString());
DateModel date = new DateModel(title.getText().toString(), time);
dateMap.put(key, date);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(this, LocalNotification.class);
intent.putExtra("message", title.getText().toString());
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, (int) millis, intent, PendingIntent.FLAG_ONE_SHOT);
alarmManager.set(AlarmManager.RTC_WAKEUP, millis, pendingIntent);
storage.storeMapData(dateMap);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.
the class DateFragment method showRemoveDialog.
private void showRemoveDialog(final Item item) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
// set title
alertDialogBuilder.setTitle("Confirm").setMessage("Remove this date?").setCancelable(true).setPositiveButton("Yes", (dialog, id) -> {
// data.remove(arg2);
long millis = Long.parseLong(item.id);
AlarmManager alarmManager = (AlarmManager) DateFragment.this.getActivity().getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(DateFragment.this.getActivity(), LocalNotification.class);
intent.putExtra("message", item.title);
PendingIntent pendingIntent = PendingIntent.getBroadcast(DateFragment.this.getActivity(), (int) millis, intent, PendingIntent.FLAG_ONE_SHOT);
Map<String, DateModel> mapData = storage.loadMapData();
mapData.remove(item.id);
storage.storeMapData(mapData);
alarmManager.cancel(pendingIntent);
reloadAdapter();
}).setNegativeButton("No", (dialogInterface, i) -> dialogInterface.dismiss());
// create alert dialog
alertDialogBuilder.create().show();
}
Aggregations