Search in sources :

Example 1 with TimeOfDay

use of com.alexstyl.specialdates.TimeOfDay in project Memento-Calendar by alexstyl.

the class DailyReminderScheduler method updateReminderTime.

public void updateReminderTime(TimeOfDay timeOfDay) {
    PendingIntent pendingIntent = buildPendingIntent();
    DateAndTime dateAndTime = new DateAndTime(Date.Companion.today(), timeOfDay);
    TimeOfDay now = TimeOfDay.now();
    if (now.isAfter(timeOfDay)) {
        // already passed. plan for the next day
        dateAndTime = dateAndTime.addDay(1);
    }
    alarmManager.setExact(AlarmManager.RTC, dateAndTime.toMilis(), pendingIntent);
}
Also used : TimeOfDay(com.alexstyl.specialdates.TimeOfDay) DateAndTime(com.alexstyl.specialdates.date.DateAndTime) PendingIntent(android.app.PendingIntent)

Example 2 with TimeOfDay

use of com.alexstyl.specialdates.TimeOfDay in project Memento-Calendar by alexstyl.

the class DailyReminderFragment method onResume.

@Override
public void onResume() {
    super.onResume();
    enablePreference.setChecked(preferences.isEnabled());
    updateRingtoneSummaryFor(preferences.getRingtoneSelected());
    TimeOfDay timeOfDay = preferences.getDailyReminderTimeSet();
    updateTimeSet(timeOfDay);
}
Also used : TimeOfDay(com.alexstyl.specialdates.TimeOfDay)

Example 3 with TimeOfDay

use of com.alexstyl.specialdates.TimeOfDay in project Memento-Calendar by alexstyl.

the class DailyReminderFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Context context = getActivity().getApplicationContext();
    scheduler = new DailyReminderScheduler(AlarmManagerCompat.from(context), context);
    AppComponent applicationModule = ((MementoApplication) getActivity().getApplication()).getApplicationModule();
    applicationModule.inject(this);
    addPreferencesFromResource(R.xml.preference_dailyreminder);
    permissionChecker = new AndroidPermissions(tracker, getActivity());
    enablePreference = findPreference(R.string.key_daily_reminder);
    preferences = DailyReminderPreferences.newInstance(getActivity());
    enablePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            boolean isEnabled = (boolean) newValue;
            preferences.setEnabled(isEnabled);
            if (isEnabled) {
                analytics.trackDailyReminderEnabled();
                scheduler.setupReminder(preferences);
            } else {
                analytics.trackDailyReminderDisabled();
                scheduler.cancelReminder();
            }
            return true;
        }
    });
    ringtonePreference = findPreference(R.string.key_daily_reminder_ringtone);
    ringtonePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            if (permissionChecker.canReadExternalStorage()) {
                // the permission exists. Let the system handle the event
                return false;
            } else {
                requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, EXTERNAL_STORAGE_REQUEST_CODE);
                return true;
            }
        }
    });
    ringtonePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            updateRingtoneSummaryFor(Uri.parse((String) newValue));
            return true;
        }
    });
    timePreference = findPreference(R.string.key_daily_reminder_time);
    timePreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            int[] time = (int[]) newValue;
            TimeOfDay timeOfDay = new TimeOfDay(time[0], time[1]);
            updateTimeSet(timeOfDay);
            analytics.trackDailyReminderTimeUpdated(timeOfDay);
            preferences.setDailyReminderTime(timeOfDay);
            scheduler.updateReminderTime(timeOfDay);
            return true;
        }
    });
    hideVibratorSettingIfNotPresent();
}
Also used : Context(android.content.Context) TimeOfDay(com.alexstyl.specialdates.TimeOfDay) MementoApplication(com.alexstyl.specialdates.MementoApplication) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener) AndroidPermissions(com.alexstyl.specialdates.permissions.AndroidPermissions) CheckBoxPreference(android.preference.CheckBoxPreference) TimePreference(com.alexstyl.android.preferences.widget.TimePreference) Preference(android.preference.Preference) AppComponent(com.alexstyl.specialdates.AppComponent) DailyReminderScheduler(com.alexstyl.specialdates.dailyreminder.DailyReminderScheduler) OnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)

Example 4 with TimeOfDay

use of com.alexstyl.specialdates.TimeOfDay in project Memento-Calendar by alexstyl.

the class DailyReminderScheduler method setupReminder.

public void setupReminder(DailyReminderPreferences preferences) {
    TimeOfDay timeOfDay = preferences.getDailyReminderTimeSet();
    updateReminderTime(timeOfDay);
}
Also used : TimeOfDay(com.alexstyl.specialdates.TimeOfDay)

Example 5 with TimeOfDay

use of com.alexstyl.specialdates.TimeOfDay in project Memento-Calendar by alexstyl.

the class TimeOfDayTest method toStringReturnsTheSpecifiedLabel.

@Test
public void toStringReturnsTheSpecifiedLabel() {
    TimeOfDay timeOfDay = new TimeOfDay(5, 0);
    assertThat(timeOfDay.toString()).isEqualTo("05:00");
}
Also used : TimeOfDay(com.alexstyl.specialdates.TimeOfDay) Test(org.junit.Test)

Aggregations

TimeOfDay (com.alexstyl.specialdates.TimeOfDay)5 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 CheckBoxPreference (android.preference.CheckBoxPreference)1 Preference (android.preference.Preference)1 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)1 TimePreference (com.alexstyl.android.preferences.widget.TimePreference)1 AppComponent (com.alexstyl.specialdates.AppComponent)1 MementoApplication (com.alexstyl.specialdates.MementoApplication)1 DailyReminderScheduler (com.alexstyl.specialdates.dailyreminder.DailyReminderScheduler)1 DateAndTime (com.alexstyl.specialdates.date.DateAndTime)1 AndroidPermissions (com.alexstyl.specialdates.permissions.AndroidPermissions)1 Test (org.junit.Test)1