Search in sources :

Example 6 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 DateModel 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 = item.getDateInMillis();
        AlarmManager alarmManager = (AlarmManager) DateFragment.this.getActivity().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(DateFragment.this.getActivity(), LocalNotification.class);
        intent.putExtra("message", item.getTitle());
        PendingIntent pendingIntent = PendingIntent.getBroadcast(DateFragment.this.getActivity(), (int) millis, intent, PendingIntent.FLAG_ONE_SHOT);
        Map<String, DateModel> mapData = storage.loadMapData();
        mapData.remove(Long.toString(item.getDateInMillis()));
        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) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Context(android.content.Context) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Date(java.util.Date) ImageView(android.widget.ImageView) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) ArrayList(java.util.ArrayList) Constants(com.zendesk.rememberthedate.Constants) Global(com.zendesk.rememberthedate.Global) Map(java.util.Map) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) RecyclerView(androidx.recyclerview.widget.RecyclerView) Log(android.util.Log) AlarmManager(android.app.AlarmManager) LayoutInflater(android.view.LayoutInflater) AppStorage(com.zendesk.rememberthedate.storage.AppStorage) R(com.zendesk.rememberthedate.R) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) List(java.util.List) TextView(android.widget.TextView) DateModel(com.zendesk.rememberthedate.model.DateModel) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) 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)

Example 7 with DateModel

use of com.zendesk.rememberthedate.model.DateModel in project sdk_demo_app_android by zendesk.

the class EditDateActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edit_date);
    bindViews();
    setSupportActionBar(findViewById(R.id.toolbar));
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    if (getIntent().getExtras() != null) {
        key = getIntent().getExtras().getString("key");
    }
    storage = Global.getStorage(getApplicationContext());
    DateModel selectedDate = storage.loadMapData().get(key);
    if (selectedDate != null) {
        Date date = selectedDate.getDate();
        currentlySelectedDate = new GregorianCalendar();
        currentlySelectedDate.setTime(date);
        currentlySelectedTime = date;
        String dateString = Constants.HUMAN_READABLE_DATE.format(date);
        String timeString = Constants.HUMAN_READABLE_TIME.format(date);
        title.setText(selectedDate.getTitle());
        dateView.setText(dateString);
        timeView.setText(timeString);
    }
}
Also used : DateModel(com.zendesk.rememberthedate.model.DateModel) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

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