Search in sources :

Example 21 with Date

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

the class DailyReminderIntentService method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    Date today = getDayDateToDisplay();
    if (hasContactPermission()) {
        List<ContactEvent> celebrationDate = peopleEventsProvider.fetchEventsBetween(TimePeriod.Companion.between(today, today));
        if (containsAnyContactEvents(celebrationDate)) {
            notifier.forDailyReminder(today, celebrationDate);
        }
    }
    if (namedaysAreEnabledForAllCases()) {
        notifyForNamedaysFor(today);
    }
    if (bankholidaysAreEnabled()) {
        notifyForBankholidaysFor(today);
    }
    DailyReminderPreferences preferences = DailyReminderPreferences.newInstance(this);
    if (preferences.isEnabled()) {
        new DailyReminderScheduler(AlarmManagerCompat.from(this), this).setupReminder(preferences);
    }
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) NamesInADate(com.alexstyl.specialdates.events.namedays.NamesInADate)

Example 22 with Date

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

the class UpcomingEventsFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_upcoming_events, container, false);
    root = Views.findById(view, R.id.root);
    progressBar = Views.findById(view, R.id.upcoming_events_progress);
    emptyView = Views.findById(view, R.id.upcoming_events_emptyview);
    upcomingList = Views.findById(view, R.id.upcoming_events_list);
    upcomingList.setHasFixedSize(true);
    upcomingList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
    upcomingList.addItemDecoration(new UpcomingEventsDecorator(getResources().getDimensionPixelSize(R.dimen.upcoming_event_header_vertical_spacing), getResources().getDimensionPixelSize(R.dimen.upcoming_event_vertical_spacing)));
    adapter = new UpcomingEventsAdapter(new UpcomingViewHolderFactory(inflater, imageLoader), new OnUpcomingEventClickedListener() {

        @Override
        public void onContactClicked(Contact contact) {
            navigator.toContactDetails(contact, getActivity());
        }

        @Override
        public void onNamedayClicked(Date date) {
            navigator.toDateDetails(date, getActivity());
        }
    });
    adapter.setHasStableIds(true);
    upcomingList.setAdapter(adapter);
    return view;
}
Also used : OnUpcomingEventClickedListener(com.alexstyl.specialdates.upcoming.view.OnUpcomingEventClickedListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) UpcomingEventsView(com.alexstyl.specialdates.UpcomingEventsView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact)

Example 23 with Date

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

the class RomanianEasterSpecialCalculatorTest method calculatesSundayBeforeEasterCorrectly.

@Test
public void calculatesSundayBeforeEasterCorrectly() {
    RomanianEasterSpecialCalculator calculator = new RomanianEasterSpecialCalculator(OrthodoxEasterCalculator.INSTANCE);
    List<Date> expectedDates = buildExpectedDates();
    for (Date expectedDate : expectedDates) {
        Date actualDate = calculator.calculateSpecialRomanianDayForYear(expectedDate.getYear());
        assertThat(expectedDate).isEqualTo(actualDate);
    }
}
Also used : Date(com.alexstyl.specialdates.date.Date) Test(org.junit.Test)

Example 24 with Date

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

the class PeopleDynamicNamedaysProviderTest method gettingSpecialNamedaysOnSpecificDateOnlyReturnsTheEventsForThatDate.

@Test
public void gettingSpecialNamedaysOnSpecificDateOnlyReturnsTheEventsForThatDate() {
    List<Contact> testContacts = createSomeContacts();
    testContacts.add(EASTER_CELEBRATING_CONTACT);
    when(mockContactsProvider.getAllContacts()).thenReturn(testContacts);
    Date easterDate = OrthodoxEasterCalculator.INSTANCE.calculateEasterForYear(YEAR);
    List<ContactEvent> contactEvents = calculator.fetchEventsBetween(TimePeriod.Companion.between(easterDate, easterDate));
    assertThat(contactEvents).hasSize(1);
    assertThat(contactEvents.get(0).getContact()).isEqualTo(EASTER_CELEBRATING_CONTACT);
}
Also used : ContactEvent(com.alexstyl.specialdates.date.ContactEvent) Date(com.alexstyl.specialdates.date.Date) Contact(com.alexstyl.specialdates.contact.Contact) Test(org.junit.Test)

Example 25 with Date

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

the class DebugFragment method onCreate.

@Override
public void onCreate(Bundle paramBundle) {
    super.onCreate(paramBundle);
    DebugAppComponent debugAppComponent = ((DebugApplication) getActivity().getApplication()).getDebugAppComponent();
    debugAppComponent.inject(this);
    addPreferencesFromResource(R.xml.preference_debug);
    dailyReminderDebugPreferences = DailyReminderDebugPreferences.newInstance(getActivity());
    findPreference(R.string.key_debug_refresh_db).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            DebugPeopleEventsUpdater.newInstance(getActivity(), namedayUserSettings, contactsProvider, tracker, dateParser).refresh();
            showToast("Refreshing Database");
            return true;
        }
    });
    findPreference(R.string.key_debug_refresh_widget).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            refresher.refreshViews();
            showToast("Widget(s) refreshed");
            return true;
        }
    });
    findPreference(R.string.key_debug_daily_reminder_date_enable).setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            dailyReminderDebugPreferences.setEnabled((boolean) newValue);
            return true;
        }
    });
    findPreference(R.string.key_debug_daily_reminder_date).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Date today = dailyReminderDebugPreferences.getSelectedDate();
            DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), onDailyReminderDateSelectedListener, today.getYear(), today.getMonth() - 1, today.getDayOfMonth());
            datePickerDialog.show();
            return false;
        }
    });
    findPreference(R.string.key_debug_daily_reminder).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            DailyReminderIntentService.startService(getActivity());
            showToast("Daily Reminder Triggered");
            return true;
        }
    });
    findPreference(R.string.key_debug_start_calendar).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            startDateIntent();
            return true;
        }
    });
    findPreference(R.string.key_debug_trigger_wear_service).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            new WearSyncUpcomingEventsView(getActivity()).reloadUpcomingEventsView();
            return true;
        }
    });
    findPreference(R.string.key_debug_reset_donations).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            DebugDonationPreferences.newInstance(preference.getContext(), monitor).reset();
            Toast.makeText(preference.getContext(), "Donations reset. You should see ads from now on", Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    findPreference(R.string.key_debug_trigger_support).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            DebugPreferences.newInstance(preference.getContext(), R.string.pref_call_to_rate).wipe();
            new AskForSupport(preference.getContext()).requestForRatingSooner();
            String message = "Support triggered. You should now see a prompt to rate the app when you launch it";
            showToast(message);
            return true;
        }
    });
    findPreference(R.string.key_debug_facebook).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), FacebookLogInActivity.class);
            startActivity(intent);
            return true;
        }
    });
    findPreference(R.string.key_debug_facebook_fetch_friends).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent intent = new Intent(getActivity(), FacebookFriendsIntentService.class);
            getActivity().startService(intent);
            return true;
        }
    });
    findPreference(R.string.key_debug_open_contact).setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {

        @Override
        public boolean onPreferenceClick(Preference preference) {
            Intent contactPickerIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
            startActivityForResult(contactPickerIntent, RESULT_PICK_CONTACT);
            return true;
        }
    });
}
Also used : DebugAppComponent(com.alexstyl.specialdates.DebugAppComponent) DatePickerDialog(android.app.DatePickerDialog) AskForSupport(com.alexstyl.specialdates.support.AskForSupport) Intent(android.content.Intent) Date(com.alexstyl.specialdates.date.Date) FacebookLogInActivity(com.alexstyl.specialdates.facebook.login.FacebookLogInActivity) Preference(android.preference.Preference) DebugApplication(com.alexstyl.specialdates.DebugApplication) WearSyncUpcomingEventsView(com.alexstyl.specialdates.wear.WearSyncUpcomingEventsView) FacebookFriendsIntentService(com.alexstyl.specialdates.facebook.friendimport.FacebookFriendsIntentService)

Aggregations

Date (com.alexstyl.specialdates.date.Date)53 Test (org.junit.Test)34 ContactEvent (com.alexstyl.specialdates.date.ContactEvent)12 Contact (com.alexstyl.specialdates.contact.Contact)6 ContactEventsOnADate (com.alexstyl.specialdates.events.peopleevents.ContactEventsOnADate)6 ArrayList (java.util.ArrayList)4 View (android.view.View)3 Intent (android.content.Intent)2 RecyclerView (android.support.v7.widget.RecyclerView)2 TextView (android.widget.TextView)2 NamedayBundle (com.alexstyl.specialdates.events.namedays.NamedayBundle)2 NamedaysList (com.alexstyl.specialdates.events.namedays.NamedaysList)2 NamesInADate (com.alexstyl.specialdates.events.namedays.NamesInADate)2 Calendar (java.util.Calendar)2 DatePickerDialog (android.app.DatePickerDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Preference (android.preference.Preference)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RemoteViews (android.widget.RemoteViews)1