mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-23 22:19:13 +00:00
Update only marks with marker service and refresh
This commit is contained in:
+9
-1
@@ -219,9 +219,17 @@ public class AnalyticsProvider extends ContentProvider {
|
||||
ExLog.i(getContext(), TAG, message);
|
||||
}
|
||||
|
||||
// final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
|
||||
|
||||
switch (sUriMatcher.match(uri)) {
|
||||
case LEADERBOARD:
|
||||
int numLeaderboardRowsUpdated = db.update(Tables.LEADERBOARDS, values, selection, selectionArgs);
|
||||
notifyChange(uri);
|
||||
return numLeaderboardRowsUpdated;
|
||||
case MARK:
|
||||
int numMarkRowsUpdated = db.update(Tables.MARKS, values, selection, selectionArgs);
|
||||
notifyChange(uri);
|
||||
return numMarkRowsUpdated;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unknown uri: " + uri);
|
||||
}
|
||||
|
||||
+1
-2
@@ -30,8 +30,7 @@ public class MarkerService extends IntentService implements CheckinManager.Data
|
||||
try {
|
||||
CheckinData checkinData = (CheckinData) data;
|
||||
DatabaseHelper helper = DatabaseHelper.getInstance();
|
||||
helper.deleteRegattaFromDatabase(this, checkinData.checkinDigest);
|
||||
helper.storeCheckinRow(this, checkinData.marks, checkinData.getLeaderboard(), checkinData.getCheckinUrl(), checkinData.pings);
|
||||
helper.updateMarks(this, checkinData.marks, checkinData.getLeaderboard());
|
||||
} catch (DatabaseHelper.GeneralDatabaseHelperException e) {
|
||||
Log.e(TAG, "Error trying to analyze mark checkin data", e);
|
||||
}
|
||||
|
||||
+1
-3
@@ -145,9 +145,7 @@ public class RegattaActivity extends AbstractRegattaActivity {
|
||||
public void onCheckinDataAvailable(AbstractCheckinData checkinData) {
|
||||
CheckinData data = (CheckinData) checkinData;
|
||||
try {
|
||||
DatabaseHelper.getInstance().deleteRegattaFromDatabase(this, data.checkinDigest);
|
||||
DatabaseHelper.getInstance().storeCheckinRow(this, data.marks, data.getLeaderboard(), data.getCheckinUrl(),
|
||||
data.pings);
|
||||
DatabaseHelper.getInstance().updateMarks(this, data.marks, data.getLeaderboard());
|
||||
getRegattaFragment().getAdapter().notifyDataSetChanged();
|
||||
} catch (DatabaseHelper.GeneralDatabaseHelperException e) {
|
||||
ExLog.e(this, TAG, "Batch insert failed: " + e.getMessage());
|
||||
|
||||
+58
-4
@@ -65,7 +65,7 @@ public class DatabaseHelper {
|
||||
checkinUrlInfo.checkinDigest = checkinDigest;
|
||||
|
||||
Cursor uc = context.getContentResolver().query(CheckinUri.CONTENT_URI, null,
|
||||
CheckinUri.CHECKIN_URI_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
|
||||
CheckinUri.CHECKIN_URI_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
|
||||
if (uc != null) {
|
||||
if (uc.moveToFirst()) {
|
||||
checkinUrlInfo.rowId = uc.getInt(uc.getColumnIndex(BaseColumns._ID));
|
||||
@@ -81,7 +81,7 @@ public class DatabaseHelper {
|
||||
public List<MarkInfo> getMarks(Context context, String checkinDigest) {
|
||||
List<MarkInfo> marks = new ArrayList<>();
|
||||
Cursor mc = context.getContentResolver().query(Mark.CONTENT_URI, null,
|
||||
Mark.MARK_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
|
||||
Mark.MARK_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
|
||||
if (mc != null) {
|
||||
mc.moveToFirst();
|
||||
while (!mc.isAfterLast()) {
|
||||
@@ -102,7 +102,7 @@ public class DatabaseHelper {
|
||||
public List<MarkPingInfo> getMarkPings(Context context, String markID) {
|
||||
List<MarkPingInfo> marks = new ArrayList<>();
|
||||
Cursor mpc = context.getContentResolver().query(MarkPing.CONTENT_URI, null,
|
||||
MarkPing.MARK_ID + " = ?", new String[] { markID }, MarkPing.MARK_PING_TIMESTAMP + " DESC");
|
||||
MarkPing.MARK_ID + " = ?", new String[] { markID }, MarkPing.MARK_PING_TIMESTAMP + " DESC");
|
||||
if (mpc != null) {
|
||||
mpc.moveToFirst();
|
||||
while (!mpc.isAfterLast()) {
|
||||
@@ -178,7 +178,7 @@ public class DatabaseHelper {
|
||||
|
||||
// now insert marks
|
||||
|
||||
ArrayList<ContentProviderOperation> opList = new ArrayList<ContentProviderOperation>();
|
||||
ArrayList<ContentProviderOperation> opList = new ArrayList<>();
|
||||
|
||||
// marks
|
||||
for (MarkInfo mark : markList) {
|
||||
@@ -217,6 +217,60 @@ public class DatabaseHelper {
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteMark(Context context, MarkInfo markInfo) {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
cr.delete(Mark.CONTENT_URI, Mark.MARK_ID + " = ?", new String[] { markInfo.getId() });
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
ExLog.i(context, TAG, "Deleted mark with id: " + markInfo.getId());
|
||||
}
|
||||
}
|
||||
|
||||
public void updateMarks(Context context, List<MarkInfo> markList, LeaderboardInfo leaderboard) throws GeneralDatabaseHelperException {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
|
||||
// Update Leaderboard
|
||||
ContentValues leaderboardValues = new ContentValues();
|
||||
leaderboardValues.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
|
||||
leaderboardValues.put(Leaderboard.LEADERBOARD_SERVER_URL, leaderboard.serverUrl);
|
||||
leaderboardValues.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
|
||||
cr.update(Leaderboard.CONTENT_URI, leaderboardValues, Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = ?", new String[] {leaderboard.checkinDigest});
|
||||
List<MarkInfo> currentMarks = getMarks(context, leaderboard.checkinDigest);
|
||||
// Delete marks which where deleted on the server
|
||||
for (MarkInfo currentMark : currentMarks){
|
||||
if (!markList.contains(currentMark)) {
|
||||
deleteMark(context, currentMark);
|
||||
}
|
||||
}
|
||||
// Update marks
|
||||
for (MarkInfo mark : markList) {
|
||||
ContentValues cmv = new ContentValues();
|
||||
cmv.put(Mark.MARK_CHECKIN_DIGEST, mark.getCheckinDigest());
|
||||
cmv.put(Mark.MARK_ID, mark.getId());
|
||||
cmv.put(Mark.MARK_NAME, mark.getName());
|
||||
cmv.put(Mark.MARK_TYPE, mark.getType());
|
||||
cmv.put(Mark.MARK_CLASS_NAME, mark.getClassName());
|
||||
if (!dataBaseContainsMark(context, mark)) {
|
||||
cr.insert(Mark.CONTENT_URI, cmv);
|
||||
} else {
|
||||
cr.update(Mark.CONTENT_URI, cmv, Mark.MARK_ID + " = ?", new String[] { mark.getId() });
|
||||
}
|
||||
}
|
||||
LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(new Intent(context.getString(R.string.database_changed)));
|
||||
}
|
||||
|
||||
private boolean dataBaseContainsMark(Context context, MarkInfo mark) {
|
||||
Cursor contentResolver = context.getContentResolver().query(Mark.CONTENT_URI, null, Mark.MARK_CHECKIN_DIGEST + " = ?" +
|
||||
" AND " + Mark.MARK_ID + " = ? ", new String[] { mark.getCheckinDigest(), mark.getId() }, "");
|
||||
int count = 0;
|
||||
if (contentResolver != null) {
|
||||
count = contentResolver.getCount();
|
||||
|
||||
contentResolver.close();
|
||||
}
|
||||
return count != 0;
|
||||
}
|
||||
|
||||
public void storeMarkPing(Context context, MarkPingInfo markPing) throws GeneralDatabaseHelperException {
|
||||
ContentResolver cr = context.getContentResolver();
|
||||
deletePingsFromDataBase(context, markPing.getMarkId());
|
||||
|
||||
+30
@@ -48,4 +48,34 @@ public class MarkInfo {
|
||||
this.checkinDigest = checkinDigest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null || getClass() != o.getClass())
|
||||
return false;
|
||||
|
||||
MarkInfo info = (MarkInfo) o;
|
||||
|
||||
if (markId != null ? !markId.equals(info.markId) : info.markId != null)
|
||||
return false;
|
||||
if (name != null ? !name.equals(info.name) : info.name != null)
|
||||
return false;
|
||||
if (type != null ? !type.equals(info.type) : info.type != null)
|
||||
return false;
|
||||
if (className != null ? !className.equals(info.className) : info.className != null)
|
||||
return false;
|
||||
return !(checkinDigest != null ? !checkinDigest.equals(info.checkinDigest) : info.checkinDigest != null);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = markId != null ? markId.hashCode() : 0;
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (type != null ? type.hashCode() : 0);
|
||||
result = 31 * result + (className != null ? className.hashCode() : 0);
|
||||
result = 31 * result + (checkinDigest != null ? checkinDigest.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user