-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add observer for add, update and delete reminder, and update event
- Loading branch information
Showing
10 changed files
with
250 additions
and
76 deletions.
There are no files selected for viewing
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
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
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
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
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
97 changes: 97 additions & 0 deletions
97
...rthday-UI/src/main/java/com/kunzisoft/remembirthday/adapter/ReminderCalendarObserver.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.kunzisoft.remembirthday.adapter; | ||
|
||
import android.content.ContentProviderOperation; | ||
import android.content.ContentProviderResult; | ||
import android.content.ContentResolver; | ||
import android.content.Context; | ||
import android.content.OperationApplicationException; | ||
import android.os.RemoteException; | ||
import android.provider.CalendarContract; | ||
import android.util.Log; | ||
|
||
import com.kunzisoft.remembirthday.element.CalendarEvent; | ||
import com.kunzisoft.remembirthday.element.Reminder; | ||
import com.kunzisoft.remembirthday.provider.ReminderProvider; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Observer who do actions for reminders | ||
* Created by joker on 04/08/17. | ||
*/ | ||
public class ReminderCalendarObserver implements AbstractReminderAdapter.ReminderDataObserver<Reminder> { | ||
|
||
private Context context; | ||
private CalendarEvent event; | ||
private ContentResolver contentResolver; | ||
private ArrayList<ContentProviderOperation> ops; | ||
|
||
public ReminderCalendarObserver(Context context, CalendarEvent calendarEvent) { | ||
this.context = context; | ||
this.event = calendarEvent; | ||
this.contentResolver = context.getContentResolver(); | ||
this.ops = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void onReminderAdded(Reminder reminder) { | ||
ops.add(ReminderProvider.insert(context, event.getId(), reminder)); | ||
//TODO Add id to reminder | ||
applyBatch(); | ||
} | ||
|
||
@Override | ||
public void onRemindersAdded(List<Reminder> reminders) { | ||
//TODO Add id to reminder | ||
for(Reminder reminder : reminders) { | ||
ops.add(ReminderProvider.insert(context, event.getId(), reminder)); | ||
} | ||
applyBatch(); | ||
} | ||
|
||
@Override | ||
public void onReminderUpdated(Reminder reminder) { | ||
ops.add(ReminderProvider.update(context, event.getId(), reminder)); | ||
applyBatch(); | ||
} | ||
|
||
@Override | ||
public void onRemindersUpdated(List<Reminder> reminders) { | ||
for(Reminder reminder : reminders) { | ||
ops.add(ReminderProvider.update(context, event.getId(), reminder)); | ||
} | ||
applyBatch(); | ||
} | ||
|
||
@Override | ||
public void onReminderDeleted(Reminder reminder) { | ||
ops.add(ReminderProvider.delete(context, event.getId(), reminder)); | ||
applyBatch(); | ||
} | ||
|
||
@Override | ||
public void onRemindersDeleted(List<Reminder> reminders) { | ||
for(Reminder reminder : reminders) { | ||
ops.add(ReminderProvider.delete(context, event.getId(), reminder)); | ||
} | ||
applyBatch(); | ||
} | ||
|
||
/** | ||
* Apply operations | ||
*/ | ||
private void applyBatch() { | ||
try { | ||
ContentProviderResult[] contentProviderResults = | ||
contentResolver.applyBatch(CalendarContract.AUTHORITY, ops); | ||
for(ContentProviderResult result : contentProviderResults) | ||
if(result.uri != null) | ||
Log.d(this.getClass().getSimpleName(), result.uri.toString()); | ||
} catch (RemoteException|OperationApplicationException e) { | ||
Log.e(this.getClass().getSimpleName(), e.getMessage()); | ||
} finally { | ||
ops.clear(); | ||
} | ||
} | ||
} |
28 changes: 0 additions & 28 deletions
28
RememBirthday-UI/src/main/java/com/kunzisoft/remembirthday/adapter/ReminderDataObserver.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.