Search in sources :

Example 1 with Reminder

use of com.eveningoutpost.dexdrip.Models.Reminder in project xDrip by NightscoutFoundation.

the class Reminders method processIncomingBundle.

private void processIncomingBundle(Bundle bundle) {
    final PowerManager.WakeLock wl = JoH.getWakeLock("reminder-bundler", 10000);
    if (bundle != null) {
        if ((bundle != null) && (d)) {
            for (String key : bundle.keySet()) {
                Object value = bundle.get(key);
                if (value != null) {
                    Log.d(TAG, String.format("Bundle: %s %s (%s)", key, value.toString(), value.getClass().getName()));
                }
            }
        }
        if (bundle.getString("snooze") != null) {
            long id = bundle.getLong("snooze_id");
            Log.d(TAG, "Reminder id for snooze: " + id);
            final Reminder reminder = Reminder.byid(id);
            if (reminder != null) {
                final long snooze_time = reminder.last_snoozed_for > 0 ? reminder.last_snoozed_for : default_snooze;
                snoozeReminder(reminder, snooze_time);
                JoH.static_toast_long(xdrip.getAppContext().getString(R.string.snoozed_reminder_for) + " " + JoH.niceTimeScalar(snooze_time));
                reloadList();
                hideSnoozeFloater();
                hideKeyboard(recyclerView);
            }
        } else {
            Log.d(TAG, "Processing non null default bundle");
            reloadList();
            hideSnoozeFloater();
            hideKeyboard(recyclerView);
            JoH.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    wakeUpScreen(false);
                }
            });
            if (bundle.getString(REMINDER_WAKEUP) != null) {
                try {
                    recyclerView.smoothScrollToPosition(getPositionFromReminderId(Integer.parseInt(bundle.getString(REMINDER_WAKEUP))));
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Couldn't scroll to position");
                }
                JoH.runOnUiThreadDelayed(new Runnable() {

                    @Override
                    public void run() {
                        Log.d(TAG, "Checking for sensor: " + proximity);
                        if (!proximity) {
                            wakeUpScreen(true);
                        }
                    }
                }, 2000);
            }
        }
    }
// intentionally don't release wakelock for proximity detection etc
}
Also used : PowerManager(android.os.PowerManager) Reminder(com.eveningoutpost.dexdrip.Models.Reminder)

Example 2 with Reminder

use of com.eveningoutpost.dexdrip.Models.Reminder in project xDrip-plus by jamorham.

the class Reminders method processIncomingBundle.

private void processIncomingBundle(Bundle bundle) {
    final PowerManager.WakeLock wl = JoH.getWakeLock("reminder-bundler", 10000);
    if (bundle != null) {
        if ((bundle != null) && (d)) {
            for (String key : bundle.keySet()) {
                Object value = bundle.get(key);
                if (value != null) {
                    Log.d(TAG, String.format("Bundle: %s %s (%s)", key, value.toString(), value.getClass().getName()));
                }
            }
        }
        if (bundle.getString("snooze") != null) {
            long id = bundle.getLong("snooze_id");
            Log.d(TAG, "Reminder id for snooze: " + id);
            final Reminder reminder = Reminder.byid(id);
            if (reminder != null) {
                final long snooze_time = reminder.last_snoozed_for > 0 ? reminder.last_snoozed_for : default_snooze;
                snoozeReminder(reminder, snooze_time);
                JoH.static_toast_long(xdrip.getAppContext().getString(R.string.snoozed_reminder_for) + " " + JoH.niceTimeScalar(snooze_time));
                reloadList();
                hideSnoozeFloater();
                hideKeyboard(recyclerView);
            }
        } else {
            Log.d(TAG, "Processing non null default bundle");
            reloadList();
            hideSnoozeFloater();
            hideKeyboard(recyclerView);
            JoH.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    wakeUpScreen(false);
                }
            });
            if (bundle.getString(REMINDER_WAKEUP) != null) {
                try {
                    recyclerView.smoothScrollToPosition(getPositionFromReminderId(Integer.parseInt(bundle.getString(REMINDER_WAKEUP))));
                } catch (IllegalArgumentException e) {
                    Log.e(TAG, "Couldn't scroll to position");
                }
                JoH.runOnUiThreadDelayed(new Runnable() {

                    @Override
                    public void run() {
                        Log.d(TAG, "Checking for sensor: " + proximity);
                        if (!proximity) {
                            wakeUpScreen(true);
                        }
                    }
                }, 2000);
            }
        }
    }
// intentionally don't release wakelock for proximity detection etc
}
Also used : PowerManager(android.os.PowerManager) Reminder(com.eveningoutpost.dexdrip.Models.Reminder)

Example 3 with Reminder

use of com.eveningoutpost.dexdrip.Models.Reminder in project xDrip by NightscoutFoundation.

the class Reminders method showReminderDialog.

// TODO edit mode
private void showReminderDialog(View myitem, final Reminder reminder, int position) {
    if ((dialog != null) && (dialog.isShowing()))
        return;
    final Activity activity = this;
    final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = this.getLayoutInflater();
    dialogView = inflater.inflate(R.layout.reminder_new_dialog, null);
    dialogBuilder.setView(dialogView);
    // New Reminder title
    final EditText titleEditText = (EditText) dialogView.findViewById(R.id.reminder_edit_new);
    final EditText alternateEditText = (EditText) dialogView.findViewById(R.id.reminder_edit_alt_title);
    final RadioButton rbday = (RadioButton) dialogView.findViewById(R.id.reminderDayButton);
    final RadioButton rbhour = (RadioButton) dialogView.findViewById(R.id.reminderHourButton);
    final RadioButton rbweek = (RadioButton) dialogView.findViewById(R.id.reminderWeekButton);
    if (reminder == null) {
        rbday.setChecked(PersistentStore.getBoolean("reminders-rbday"));
        rbhour.setChecked(PersistentStore.getBoolean("reminders-rbhour"));
        rbweek.setChecked(PersistentStore.getBoolean("reminders-rbweek"));
    } else {
        rbday.setChecked(reminder.isDaysPeriod());
        rbhour.setChecked(reminder.isHoursPeriod());
        rbweek.setChecked(reminder.isWeeksPeriod());
    }
    // first run if nothing set default to day
    if (!rbday.isChecked() && !rbhour.isChecked() && !rbweek.isChecked()) {
        rbday.setChecked(true);
    }
    titleEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // hide remove done button if no title present
            try {
                if (s.length() < 3) {
                    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.INVISIBLE);
                } else {
                    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
                }
            } catch (NullPointerException e) {
            // dialog not showing yet
            }
        }
    });
    reminderDaysEdt = (EditText) dialogView.findViewById(R.id.reminderRepeatDays);
    final CheckBox repeatingCheckbox = (CheckBox) dialogView.findViewById(R.id.reminderRepeatcheckBox);
    final CheckBox chimeOnlyCheckbox = (CheckBox) dialogView.findViewById(R.id.chimeonlycheckbox);
    final CheckBox alternatingCheckbox = (CheckBox) dialogView.findViewById(R.id.alternatingcheckbox);
    final CheckBox weekendsCheckbox = (CheckBox) dialogView.findViewById(R.id.weekEndsCheckbox);
    final CheckBox weekdaysCheckbox = (CheckBox) dialogView.findViewById(R.id.weekDaysCheckbox);
    final CheckBox megapriorityCheckbox = (CheckBox) dialogView.findViewById(R.id.highPriorityCheckbox);
    final CheckBox homeOnlyCheckbox = (CheckBox) dialogView.findViewById(R.id.homeOnlyCheckbox);
    final CheckBox speechCheckbox = (CheckBox) dialogView.findViewById(R.id.speakCheckbox);
    final ImageButton swapButton = (ImageButton) dialogView.findViewById(R.id.reminderSwapButton);
    if (reminder == null) {
        repeatingCheckbox.setChecked(PersistentStore.getLong("reminders-last-repeating") != 2);
        chimeOnlyCheckbox.setChecked(PersistentStore.getLong("reminders-last-chimeonly") == 1);
        alternatingCheckbox.setChecked(PersistentStore.getLong("reminders-last-alternating") == 1);
        // defaults to false
        homeOnlyCheckbox.setChecked(false);
        try {
            reminderDaysEdt.setText(!PersistentStore.getString("reminders-last-number").equals("") ? Integer.toString(Integer.parseInt(PersistentStore.getString("reminders-last-number"))) : "1");
        } catch (Exception e) {
        // 
        }
    } else {
        selectedSound = reminder.sound_uri;
        titleEditText.setText(reminder.title);
        alternateEditText.setText(reminder.getAlternateTitle());
        repeatingCheckbox.setChecked(reminder.repeating);
        chimeOnlyCheckbox.setChecked(reminder.chime_only);
        alternatingCheckbox.setChecked(reminder.alternating);
        megapriorityCheckbox.setChecked(reminder.priority > MEGA_PRIORITY);
        if (!reminder.weekdays && !reminder.weekends) {
            // this shouldn't be possible so we think it pre-dates the current schema so fix it
            reminder.weekdays = true;
            reminder.weekends = true;
        }
        weekdaysCheckbox.setChecked(reminder.weekdays);
        weekendsCheckbox.setChecked(reminder.weekends);
        homeOnlyCheckbox.setChecked(reminder.homeonly);
        speechCheckbox.setChecked(reminder.speak);
        reminderDaysEdt.setText(Long.toString(reminder.periodInUnits()));
    }
    maskAlternatingCheckbox(repeatingCheckbox.isChecked(), alternatingCheckbox);
    swapButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Editable swappage = alternateEditText.getText();
            alternateEditText.setText(titleEditText.getText());
            titleEditText.setText(swappage);
        }
    });
    repeatingCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            final String insert = chimeOnlyCheckbox.isChecked() ? xdrip.getAppContext().getString(R.string.sound_once) : xdrip.getAppContext().getString(R.string.alert_until_dismissed);
            final String second_insert = isChecked ? xdrip.getAppContext().getString(R.string.and_then_repeat) + " " + JoH.niceTimeScalarNatural(getPeriod(rbday, rbhour, rbweek)) : xdrip.getAppContext().getString(R.string.will_not_repeat);
            JoH.static_toast_long(xdrip.getAppContext().getString(R.string.reminder_will) + " " + insert + " " + second_insert);
            maskAlternatingCheckbox(isChecked, alternatingCheckbox);
        }
    });
    chimeOnlyCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            final String insert = isChecked ? xdrip.getAppContext().getString(R.string.sound_once) : xdrip.getAppContext().getString(R.string.alert_until_dismissed);
            final String second_insert = repeatingCheckbox.isChecked() ? xdrip.getAppContext().getString(R.string.and_then_repeat) + " " + JoH.niceTimeScalar(getPeriod(rbday, rbhour, rbweek)) : xdrip.getAppContext().getString(R.string.will_not_repeat);
            JoH.static_toast_long(xdrip.getAppContext().getString(R.string.reminder_will) + " " + insert + " " + second_insert);
        }
    });
    alternatingCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            alternateEditText.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            swapButton.setVisibility(isChecked ? View.VISIBLE : View.GONE);
            final String insert = isChecked ? xdrip.getAppContext().getString(R.string.alternate_between_titles) + " " + JoH.niceTimeScalar(getPeriod(rbday, rbhour, rbweek)) : xdrip.getAppContext().getString(R.string.always_use_same_title);
            JoH.static_toast_long(xdrip.getAppContext().getString(R.string.reminder_will) + " " + insert);
        }
    });
    alternateEditText.setVisibility(alternatingCheckbox.isChecked() ? View.VISIBLE : View.GONE);
    swapButton.setVisibility(alternatingCheckbox.isChecked() ? View.VISIBLE : View.GONE);
    dialogBuilder.setTitle(((reminder == null) ? xdrip.getAppContext().getString(R.string.title_add_reminder) : xdrip.getAppContext().getString(R.string.title_edit_reminder)));
    // dialogBuilder.setMessage("Enter text below");
    dialogBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String reminder_title = titleEditText.getText().toString().trim();
            Log.d(TAG, "Got reminder title: " + reminder_title);
            // get and scale period
            long period = getPeriod(rbday, rbhour, rbweek);
            PersistentStore.setBoolean("reminders-rbday", rbday.isChecked());
            PersistentStore.setBoolean("reminders-rbhour", rbhour.isChecked());
            PersistentStore.setBoolean("reminders-rbweek", rbweek.isChecked());
            Reminder new_reminder = reminder;
            if (new_reminder == null) {
                new_reminder = Reminder.create(reminder_title, period);
            }
            if (new_reminder != null) {
                if (reminder != null) {
                    new_reminder.title = reminder_title;
                    new_reminder.period = period;
                }
                final String alternate_text = alternateEditText.getText().toString();
                if (alternate_text.length() > 2) {
                    new_reminder.alternate_title = alternate_text;
                }
                new_reminder.sound_uri = selectedSound;
                new_reminder.repeating = repeatingCheckbox.isChecked();
                new_reminder.chime_only = chimeOnlyCheckbox.isChecked();
                new_reminder.alternating = alternatingCheckbox.isChecked();
                new_reminder.weekdays = weekdaysCheckbox.isChecked();
                new_reminder.weekends = weekendsCheckbox.isChecked();
                new_reminder.homeonly = homeOnlyCheckbox.isChecked();
                new_reminder.speak = speechCheckbox.isChecked();
                if ((new_reminder.priority > MEGA_PRIORITY) && (!megapriorityCheckbox.isChecked())) {
                    new_reminder.priority -= MEGA_PRIORITY;
                } else if ((new_reminder.priority < MEGA_PRIORITY) && (megapriorityCheckbox.isChecked())) {
                    new_reminder.priority += MEGA_PRIORITY;
                }
                new_reminder.save();
                freshen(new_reminder);
                PersistentStore.setString("reminders-last-number", reminderDaysEdt.getText().toString());
                PersistentStore.setLong("reminders-last-repeating", repeatingCheckbox.isChecked() ? 1 : 2);
                PersistentStore.setLong("reminders-last-chimeonly", chimeOnlyCheckbox.isChecked() ? 1 : 2);
                PersistentStore.setLong("reminders-last-alternating", alternatingCheckbox.isChecked() ? 1 : 2);
                showcase(activity, Home.SHOWCASE_REMINDER2);
            } else {
                JoH.static_toast_long(xdrip.getAppContext().getString(R.string.something_went_wrong_reminder));
            }
            dialog = null;
            dialogView = null;
        }
    });
    dialogBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            dialog = null;
            dialogView = null;
        }
    });
    dialog = dialogBuilder.create();
    titleEditText.setInputType(InputType.TYPE_CLASS_TEXT);
    titleEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                if (dialog != null)
                    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            }
        }
    });
    dialog.show();
    if ((reminder != null) && (reminder.title.length() > 2)) {
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.VISIBLE);
    } else {
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setVisibility(View.INVISIBLE);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) ImageButton(android.widget.ImageButton) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditText(android.widget.EditText) Reminder(com.eveningoutpost.dexdrip.Models.Reminder) RadioButton(android.widget.RadioButton) ShowcaseView(com.github.amlcurran.showcaseview.ShowcaseView) View(android.view.View) CardView(android.support.v7.widget.CardView) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) CheckBox(android.widget.CheckBox) LayoutInflater(android.view.LayoutInflater) CompoundButton(android.widget.CompoundButton)

Example 4 with Reminder

use of com.eveningoutpost.dexdrip.Models.Reminder in project xDrip by NightscoutFoundation.

the class Reminders method askTime.

// //
private void askTime(final int position) {
    final Calendar calendar = Calendar.getInstance();
    final Reminder reminder = reminders.get(position);
    calendar.setTimeInMillis(reminder.next_due);
    final TimePickerFragment timePickerFragment = new TimePickerFragment();
    timePickerFragment.setTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
    timePickerFragment.setTitle(xdrip.getAppContext().getString(R.string.title_what_time_day));
    timePickerFragment.setTimeCallback(new ProfileAdapter.TimePickerCallbacks() {

        @Override
        public void onTimeUpdated(int newmins) {
            int min = newmins % 60;
            int hour = (newmins - min) / 60;
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hour, min);
            reminder.next_due = calendar.getTimeInMillis();
            // reset this field
            reminder.snoozed_till = 0;
            reminder.save();
            freshen(reminder);
        }
    });
    timePickerFragment.show(this.getFragmentManager(), "TimePicker");
    // appears on top
    if (JoH.msTill(reminder.next_due) > Constants.DAY_IN_MS) {
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        datePickerFragment.setAllowFuture(true);
        datePickerFragment.setEarliestDate(JoH.tsl());
        datePickerFragment.setInitiallySelectedDate(reminder.next_due);
        datePickerFragment.setTitle(xdrip.getAppContext().getString(R.string.title_which_day));
        datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

            @Override
            public void onDateSet(int year, int month, int day) {
                calendar.set(year, month, day);
            }
        });
        datePickerFragment.show(this.getFragmentManager(), "DatePicker");
    }
}
Also used : ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter) DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) Reminder(com.eveningoutpost.dexdrip.Models.Reminder) TimePickerFragment(com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment) Calendar(java.util.Calendar)

Example 5 with Reminder

use of com.eveningoutpost.dexdrip.Models.Reminder in project xDrip-plus by jamorham.

the class Reminders method askTime.

// //
private void askTime(final int position) {
    final Calendar calendar = Calendar.getInstance();
    final Reminder reminder = reminders.get(position);
    calendar.setTimeInMillis(reminder.next_due);
    final TimePickerFragment timePickerFragment = new TimePickerFragment();
    timePickerFragment.setTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
    timePickerFragment.setTitle(xdrip.getAppContext().getString(R.string.title_what_time_day));
    timePickerFragment.setTimeCallback(new ProfileAdapter.TimePickerCallbacks() {

        @Override
        public void onTimeUpdated(int newmins) {
            int min = newmins % 60;
            int hour = (newmins - min) / 60;
            calendar.set(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH), hour, min);
            reminder.next_due = calendar.getTimeInMillis();
            // reset this field
            reminder.snoozed_till = 0;
            reminder.save();
            freshen(reminder);
        }
    });
    timePickerFragment.show(this.getFragmentManager(), "TimePicker");
    // appears on top
    if (JoH.msTill(reminder.next_due) > Constants.DAY_IN_MS) {
        final DatePickerFragment datePickerFragment = new DatePickerFragment();
        datePickerFragment.setAllowFuture(true);
        datePickerFragment.setEarliestDate(JoH.tsl());
        datePickerFragment.setInitiallySelectedDate(reminder.next_due);
        datePickerFragment.setTitle(xdrip.getAppContext().getString(R.string.title_which_day));
        datePickerFragment.setDateCallback(new ProfileAdapter.DatePickerCallbacks() {

            @Override
            public void onDateSet(int year, int month, int day) {
                calendar.set(year, month, day);
            }
        });
        datePickerFragment.show(this.getFragmentManager(), "DatePicker");
    }
}
Also used : ProfileAdapter(com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter) DatePickerFragment(com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment) Reminder(com.eveningoutpost.dexdrip.Models.Reminder) TimePickerFragment(com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment) Calendar(java.util.Calendar)

Aggregations

Reminder (com.eveningoutpost.dexdrip.Models.Reminder)6 Activity (android.app.Activity)2 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 PowerManager (android.os.PowerManager)2 CardView (android.support.v7.widget.CardView)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2 CheckBox (android.widget.CheckBox)2 CompoundButton (android.widget.CompoundButton)2 EditText (android.widget.EditText)2 ImageButton (android.widget.ImageButton)2 RadioButton (android.widget.RadioButton)2 TextView (android.widget.TextView)2 DatePickerFragment (com.eveningoutpost.dexdrip.profileeditor.DatePickerFragment)2 ProfileAdapter (com.eveningoutpost.dexdrip.profileeditor.ProfileAdapter)2 TimePickerFragment (com.eveningoutpost.dexdrip.profileeditor.TimePickerFragment)2