1
0
Fork 0
mirror of https://github.com/MatomoCamp/matomocamp-companion-android.git synced 2024-09-19 16:13:46 +02:00

Changed event id and person id to long type instead of int.

Only broadcast bookmark added/removed on success.
This commit is contained in:
Christophe Beyls 2014-01-08 21:19:26 +01:00
parent 2a3f717e92
commit 6e11286b26
7 changed files with 53 additions and 39 deletions

View file

@ -69,12 +69,8 @@ public class SearchResultActivity extends ActionBarActivity {
} else if (Intent.ACTION_VIEW.equals(intentAction)) {
// Search suggestion, dispatch to EventDetailsActivity
try {
Intent dispatchIntent = new Intent(this, EventDetailsActivity.class).setData(intent.getData());
startActivity(dispatchIntent);
} catch (NumberFormatException e) {
// Ignore invalid data
}
if (!isNewIntent) {
finish();

View file

@ -638,7 +638,7 @@ public class DatabaseManager {
day.getDate().setTime(cursor.getLong(11));
}
event.setId(cursor.getInt(0));
event.setId(cursor.getLong(0));
if (cursor.isNull(1)) {
event.setStartTime(null);
} else {
@ -678,8 +678,8 @@ public class DatabaseManager {
return toEvent(cursor, null);
}
public static int toEventId(Cursor cursor) {
return cursor.getInt(0);
public static long toEventId(Cursor cursor) {
return cursor.getLong(0);
}
public static long toEventStartTimeMillis(Cursor cursor) {
@ -721,7 +721,7 @@ public class DatabaseManager {
if (person == null) {
person = new Person();
}
person.setId(cursor.getInt(0));
person.setId(cursor.getLong(0));
person.setName(cursor.getString(1));
return person;
@ -755,6 +755,8 @@ public class DatabaseManager {
}
public boolean addBookmark(Event event) {
boolean complete = false;
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
@ -768,25 +770,29 @@ public class DatabaseManager {
}
db.setTransactionSuccessful();
complete = true;
return true;
} finally {
db.endTransaction();
if (complete) {
context.getContentResolver().notifyChange(URI_BOOKMARKS, null);
Intent intent = new Intent(ACTION_ADD_BOOKMARK).putExtra(EXTRA_EVENT, event);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
}
}
}
public boolean removeBookmark(Event event) {
return removeBookmark(new int[] { event.getId() });
return removeBookmarks(new long[] { event.getId() });
}
public boolean removeBookmark(int eventId) {
return removeBookmark(new int[] { eventId });
public boolean removeBookmark(long eventId) {
return removeBookmarks(new long[] { eventId });
}
public boolean removeBookmark(int[] eventIds) {
public boolean removeBookmarks(long[] eventIds) {
int length = eventIds.length;
if (length == 0) {
throw new IllegalArgumentException("At least one bookmark id to remove must be passed");
@ -796,6 +802,8 @@ public class DatabaseManager {
stringEventIds[i] = String.valueOf(eventIds[i]);
}
boolean complete = false;
SQLiteDatabase db = helper.getWritableDatabase();
db.beginTransaction();
try {
@ -807,9 +815,12 @@ public class DatabaseManager {
}
db.setTransactionSuccessful();
complete = true;
return true;
} finally {
db.endTransaction();
if (complete) {
context.getContentResolver().notifyChange(URI_BOOKMARKS, null);
Intent intent = new Intent(ACTION_REMOVE_BOOKMARKS).putExtra(EXTRA_EVENT_IDS, eventIds);
@ -817,3 +828,4 @@ public class DatabaseManager {
}
}
}
}

View file

@ -21,6 +21,12 @@ import be.digitalia.fosdem.db.DatabaseManager;
import be.digitalia.fosdem.loaders.SimpleCursorLoader;
import be.digitalia.fosdem.model.Event;
/**
* Bookmarks list, optionally filterable.
*
* @author Christophe Beyls
*
*/
public class BookmarksListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
private static final int BOOKMARKS_LOADER_ID = 1;

View file

@ -11,7 +11,7 @@ import be.digitalia.fosdem.db.DatabaseManager;
public class Event implements Parcelable {
private int id;
private long id;
private Day day;
private Date startTime;
private Date endTime;
@ -29,11 +29,11 @@ public class Event implements Parcelable {
public Event() {
}
public int getId() {
public long getId() {
return id;
}
public void setId(int id) {
public void setId(long id) {
this.id = id;
}
@ -166,7 +166,7 @@ public class Event implements Parcelable {
@Override
public int hashCode() {
return id;
return (int) (id ^ (id >>> 32));
}
@Override
@ -186,7 +186,7 @@ public class Event implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(id);
out.writeLong(id);
day.writeToParcel(out, flags);
out.writeLong((startTime == null) ? 0L : startTime.getTime());
out.writeLong((endTime == null) ? 0L : endTime.getTime());
@ -223,7 +223,7 @@ public class Event implements Parcelable {
};
private Event(Parcel in) {
id = in.readInt();
id = in.readLong();
day = Day.CREATOR.createFromParcel(in);
long time = in.readLong();
if (time != 0L) {

View file

@ -8,17 +8,17 @@ import android.os.Parcelable;
public class Person implements Parcelable {
private int id;
private long id;
private String name;
public Person() {
}
public int getId() {
public long getId() {
return id;
}
public void setId(int id) {
public void setId(long id) {
this.id = id;
}
@ -41,7 +41,7 @@ public class Person implements Parcelable {
@Override
public int hashCode() {
return id;
return (int) (id ^ (id >>> 32));
}
@Override
@ -63,7 +63,7 @@ public class Person implements Parcelable {
@Override
public void writeToParcel(Parcel out, int flags) {
out.writeInt(id);
out.writeLong(id);
out.writeString(name);
}
@ -78,7 +78,7 @@ public class Person implements Parcelable {
};
private Person(Parcel in) {
id = in.readInt();
id = in.readLong();
name = in.readString();
}
}

View file

@ -80,7 +80,7 @@ public class EventsParser extends IterableAbstractPullParser<Event> {
currentRoom = parser.getAttributeValue(null, "name");
} else if ("event".equals(name)) {
Event event = new Event();
event.setId(Integer.parseInt(parser.getAttributeValue(null, "id")));
event.setId(Long.parseLong(parser.getAttributeValue(null, "id")));
event.setDay(currentDay);
event.setRoomName(currentRoom);
// Initialize empty lists
@ -129,7 +129,7 @@ public class EventsParser extends IterableAbstractPullParser<Event> {
while (!isNextEndTag("persons")) {
if (isStartTag("person")) {
Person person = new Person();
person.setId(Integer.parseInt(parser.getAttributeValue(null, "id")));
person.setId(Long.parseLong(parser.getAttributeValue(null, "id")));
person.setName(parser.nextText());
persons.add(person);

View file

@ -51,7 +51,7 @@ public class AlarmIntentService extends IntentService {
alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
}
private PendingIntent getAlarmPendingIntent(int eventId) {
private PendingIntent getAlarmPendingIntent(long eventId) {
Intent intent = new Intent(this, AlarmReceiver.class).setAction(AlarmReceiver.ACTION_NOTIFY_EVENT).setData(Uri.parse(String.valueOf(eventId)));
return PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
}
@ -68,7 +68,7 @@ public class AlarmIntentService extends IntentService {
Cursor cursor = DatabaseManager.getInstance().getBookmarks(now);
try {
while (cursor.moveToNext()) {
int eventId = DatabaseManager.toEventId(cursor);
long eventId = DatabaseManager.toEventId(cursor);
long notificationTime = DatabaseManager.toEventStartTimeMillis(cursor) - delay;
PendingIntent pi = getAlarmPendingIntent(eventId);
if (notificationTime < now) {
@ -93,7 +93,7 @@ public class AlarmIntentService extends IntentService {
Cursor cursor = DatabaseManager.getInstance().getBookmarks(System.currentTimeMillis());
try {
while (cursor.moveToNext()) {
int eventId = DatabaseManager.toEventId(cursor);
long eventId = DatabaseManager.toEventId(cursor);
alarmManager.cancel(getAlarmPendingIntent(eventId));
}
} finally {
@ -114,8 +114,8 @@ public class AlarmIntentService extends IntentService {
} else if (DatabaseManager.ACTION_REMOVE_BOOKMARKS.equals(action)) {
// Cancel matching alarms, might they exist or not
int[] eventIds = intent.getIntArrayExtra(DatabaseManager.EXTRA_EVENT_IDS);
for (int eventId : eventIds) {
long[] eventIds = intent.getLongArrayExtra(DatabaseManager.EXTRA_EVENT_IDS);
for (long eventId : eventIds) {
alarmManager.cancel(getAlarmPendingIntent(eventId));
}
} else if (AlarmReceiver.ACTION_NOTIFY_EVENT.equals(action)) {