Last active
August 29, 2015 14:20
-
-
Save kmdupr33/bfc68c1e4cc60172bc86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Background {@link android.app.Service} that adds or removes session Calendar events through | |
* the {@link CalendarContract} API available in Android 4.0 or above. | |
*/ | |
public class SessionCalendarService extends IntentService { | |
private static final String TAG = makeLogTag(SessionCalendarService.class); | |
public SessionCalendarService() { | |
super(TAG); | |
} | |
@Override | |
protected void onHandleIntent(Intent intent) { | |
final String action = intent.getAction(); | |
Log.d(TAG, "Received intent: " + action); | |
final ContentResolver resolver = getContentResolver(); | |
Broadcaster broadcaster = new AndroidBroadcaster(this); | |
SessionCalendarDatabase sessionCalendarDatabase = new AndroidSessionCalendarDatabase(resolver, | |
broadcaster); | |
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); | |
SessionCalendarUserPreferences sessionCalendarUserPreferences = new AndroidSessionCalendarUserPreferences(defaultSharedPreferences); | |
SessionCalendarUpdater sessionCalendarUpdater | |
= new SessionCalendarUpdater(sessionCalendarDatabase, | |
sessionCalendarUserPreferences); | |
AccountNameRepository accountNameRepository = new AndroidAccountNameRepository(intent, this); | |
String accountName = accountNameRepository.getAccountName(); | |
long calendarId = sessionCalendarDatabase.getCalendarId(accountName); | |
CalendarSession calendarSessionToUpdate = CalendarSession.fromIntent(intent); | |
CalendarUpdateRequest calendarUpdateRequest = new CalendarUpdateRequest(action, calendarId, calendarSessionToUpdate); | |
sessionCalendarUpdater.updateCalendar(calendarUpdateRequest); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment