Search in sources :

Example 1 with DateModel

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());
    }
}
Also used : EditText(android.widget.EditText) TimePicker(android.widget.TimePicker) HashMap(java.util.HashMap) DateModel(com.zendesk.rememberthedate.model.DateModel) Time(android.text.format.Time) DatePicker(android.widget.DatePicker)

Example 2 with DateModel

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);
    }
}
Also used : HashMap(java.util.HashMap) DateModel(com.zendesk.rememberthedate.model.DateModel) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar)

Example 3 with DateModel

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);
}
Also used : DateModel(com.zendesk.rememberthedate.model.DateModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration)

Example 4 with DateModel

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);
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) TimePicker(android.widget.TimePicker) HashMap(java.util.HashMap) DateModel(com.zendesk.rememberthedate.model.DateModel) Time(android.text.format.Time) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) AlarmManager(android.app.AlarmManager) DatePicker(android.widget.DatePicker) PendingIntent(android.app.PendingIntent)

Example 5 with DateModel

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();
}
Also used : AlertDialog(android.app.AlertDialog) Context(android.content.Context) Bundle(android.os.Bundle) AlarmManager(android.app.AlarmManager) LayoutInflater(android.view.LayoutInflater) Fragment(android.support.v4.app.Fragment) AppStorage(com.zendesk.rememberthedate.storage.AppStorage) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PendingIntent(android.app.PendingIntent) NonNull(android.support.annotation.NonNull) R(com.zendesk.rememberthedate.R) ViewGroup(android.view.ViewGroup) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) ArrayList(java.util.ArrayList) AlertDialog(android.app.AlertDialog) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) TextView(android.widget.TextView) Global(com.zendesk.rememberthedate.Global) Map(java.util.Map) View(android.view.View) DateModel(com.zendesk.rememberthedate.model.DateModel) LocalNotification(com.zendesk.rememberthedate.LocalNotification) AlarmManager(android.app.AlarmManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) LocalNotification(com.zendesk.rememberthedate.LocalNotification) PendingIntent(android.app.PendingIntent) Map(java.util.Map)

Aggregations

DateModel (com.zendesk.rememberthedate.model.DateModel)7 AlarmManager (android.app.AlarmManager)3 AlertDialog (android.app.AlertDialog)3 PendingIntent (android.app.PendingIntent)3 Intent (android.content.Intent)3 HashMap (java.util.HashMap)3 Context (android.content.Context)2 Bundle (android.os.Bundle)2 Time (android.text.format.Time)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 DatePicker (android.widget.DatePicker)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 TimePicker (android.widget.TimePicker)2 DividerItemDecoration (androidx.recyclerview.widget.DividerItemDecoration)2 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)2 Global (com.zendesk.rememberthedate.Global)2 LocalNotification (com.zendesk.rememberthedate.LocalNotification)2