Merge branch 'master' into bug3529

This commit is contained in:
Steffen Schaefer committed 2016-12-12 10:54:07 +01:00
commit 1cede03f28
35 files changed
+547 -784

No files matched your search

@@ -37,6 +37,12 @@ public class SimpleRaceMetadataDTO implements DTO, Comparable<SimpleRaceMetadata
return StringMessages.INSTANCE.raceIsFinished();
}
},
FINISHING { // the blue flag has gone up but has not gone down yet
@Override
public String getLabel() {
return StringMessages.INSTANCE.raceIsFinishing();
}
},
POSTPONED { // the start has been postponed
@Override
public String getLabel() {
@@ -159,12 +165,21 @@ public class SimpleRaceMetadataDTO implements DTO, Comparable<SimpleRaceMetadata
/**
* Convenience method to check if this {@link SimpleRaceMetadataDTO race} is currently running.
*
* @return <code>true</code> if the {@link #getViewState() view state} is {@link RaceViewState#RUNNING},
* <code>false</code> otherwise
* @return <code>true</code> if the {@link #getViewState() view state} is {@link RaceViewState#RUNNING} or
* {@link RaceViewState#FINISHING}, <code>false</code> otherwise
*/
public boolean isRunning() {
return getViewState() == RaceViewState.RUNNING;
return getViewState() == RaceViewState.RUNNING || getViewState() == RaceViewState.FINISHING;
}
/**
* Convenience method to check if this {@link SimpleRaceMetadataDTO race} is scheduled.
*
* @return <code>true</code> if the {@link #getViewState() view state} is {@link RaceViewState#SCHEDULED},
* <code>false</code> otherwise
*/
public boolean isScheduled() {
return getViewState() == RaceViewState.SCHEDULED;
}
}
@@ -591,6 +591,11 @@ public class RaceContext {
if (startTime != null && now.before(startTime)) {
return RaceViewState.SCHEDULED;
}
if (state != null && state.getStatus() == RaceLogRaceStatus.FINISHING) {
// someone pulled up the blue flag; it's pretty likely that we'll also see the blue flag down
// event for the transition into the FINISHED state, so we can report FINISHING for now:
return RaceViewState.FINISHING;
}
if (finishTime != null && now.after(finishTime)) {
return RaceViewState.FINISHED;
}
@@ -17,7 +17,6 @@ import com.google.gwt.user.client.ui.Widget;
import com.sap.sailing.gwt.common.client.DateUtil;
import com.sap.sailing.gwt.home.communication.race.SimpleRaceMetadataDTO;
import com.sap.sailing.gwt.home.communication.race.SimpleRaceMetadataDTO.RaceTrackingState;
import com.sap.sailing.gwt.home.communication.race.SimpleRaceMetadataDTO.RaceViewState;
import com.sap.sailing.gwt.home.desktop.partials.raceviewerlaunchpad.RaceviewerLaunchPad;
import com.sap.sailing.gwt.home.shared.partials.regattacompetition.RegattaCompetitionView.RegattaCompetitionRaceView;
import com.sap.sailing.gwt.ui.client.StringMessages;
@@ -36,7 +35,7 @@ public abstract class AbstractRegattaCompetitionFleetRace extends Widget impleme
this.race = race;
this.presenter = presenter;
this.mainElement = getMainUiElement();
setupRaceState(race.getTrackingState(), race.getViewState());
setupRaceState(race);
getRaceNameUiElement().setInnerText(race.getRaceName());
setupRaceStart(race.getStart());
setElement(mainElement);
@@ -82,17 +81,20 @@ public abstract class AbstractRegattaCompetitionFleetRace extends Widget impleme
});
}
private void setupRaceState(RaceTrackingState trackingState, RaceViewState viewState) {
boolean isUntrackedRace = trackingState != RaceTrackingState.TRACKED_VALID_DATA;
if (viewState == RaceViewState.RUNNING) {
private void setupRaceState(SimpleRaceMetadataDTO race) {
boolean isUntrackedRace = race.getTrackingState() != RaceTrackingState.TRACKED_VALID_DATA;
if (race.isRunning()) {
mainElement.addClassName(getRaceLiveStyleName());
getRaceStateUiElement().setInnerText(isUntrackedRace ? I18N.live() : I18N.actionWatch());
} else if (viewState == RaceViewState.FINISHED) {
} else if (race.isFinished()) {
getRaceStateUiElement().setInnerText(isUntrackedRace ? I18N.raceIsFinished() : I18N.actionAnalyze());
} else {
mainElement.addClassName(getRacePlannedStyleName());
if (viewState == RaceViewState.SCHEDULED) getRaceStateUiElement().setInnerText(I18N.raceIsPlanned());
else getRaceStateUiElement().setInnerText(viewState.getLabel());
if (race.isScheduled()) {
getRaceStateUiElement().setInnerText(I18N.raceIsPlanned());
} else {
getRaceStateUiElement().setInnerText(race.getViewState().getLabel());
}
}
setStyleName(mainElement, getRaceUntrackedStyleName(), isUntrackedRace);
}
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/toolbar_height"
android:theme="@style/AppTheme.Toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="middle"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="16sp" />
<TextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="middle"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="12sp" />
</LinearLayout>
</com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar>
@@ -3,43 +3,9 @@
android:layout_height="match_parent"
android:orientation="vertical">
<com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar
<include
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/toolbar_height"
android:theme="@style/AppTheme.Toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="middle"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="16sp" />
<TextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:ellipsize="middle"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="12sp" />
</LinearLayout>
</com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar>
layout="@layout/custom_toolbar" />
<View
android:id="@+id/toolbar_separator"
@@ -3,6 +3,10 @@ package com.sap.sailing.android.shared.data;
public class LeaderboardInfo {
public String name;
/**
* the leaderboard's display name if one has been explicitly provided, otherwise the same as {@link #name}
*/
public String displayName;
public String checkinDigest;
public int rowId;
public String serverUrl;
@@ -1,48 +1,18 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fiori_main_background">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fiori_main_background">
<com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar
<include
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.Toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="0dp">
<com.sap.sailing.android.shared.ui.customviews.OpenSansTextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="16sp"/>
<com.sap.sailing.android.shared.ui.customviews.OpenSansTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:lines="1"
android:singleLine="true"
android:textColor="@color/toolbar_text_color"
android:textSize="12sp"/>
</LinearLayout>
</com.sap.sailing.android.shared.ui.customviews.OpenSansToolbar>
layout="@layout/custom_toolbar" />
<View
android:id="@+id/toolbar_separator"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_separator_height"
android:layout_below="@id/toolbar"
android:background="@color/separator_color"/>
android:background="@color/separator_color" />
<LinearLayout
android:layout_width="match_parent"
@@ -56,13 +26,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="0dp"/>
android:padding="0dp" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
android:layout_weight="1" />
</LinearLayout>
<Button
@@ -77,13 +47,13 @@
android:background="@drawable/stop_tracking_button"
android:padding="0dp"
android:text="@string/stop_tracking"
android:textSize="@dimen/highlight_text_size"/>
android:textSize="@dimen/highlight_text_size" />
<com.viewpagerindicator.CirclePageIndicator
android:id="@+id/title_page_indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="10dp"/>
android:layout_marginBottom="10dp" />
</RelativeLayout>
@@ -21,7 +21,7 @@ public class RegattaAdapter extends AbstractRegattaAdapter {
public void bindView(View view, Context context, Cursor cursor) {
TextView regattaName = ViewHelper.get(view,R.id.regattaName);
if (regattaName != null) {
String regatteNameText = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_NAME));
String regatteNameText = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_DISPLAY_NAME));
regattaName.setText(regatteNameText);
}
TextView regattaEvent = ViewHelper.get(view, R.id.regatta_event);
@@ -4,6 +4,8 @@ import android.content.ContentResolver;
import android.net.Uri;
import android.provider.BaseColumns;
import com.sap.sailing.android.tracking.app.provider.AnalyticsDatabase.Tables;
public class AnalyticsContract {
interface CompetitorColumns {
@@ -17,6 +19,7 @@ public class AnalyticsContract {
interface LeaderboardColumns {
String LEADERBOARD_NAME = "leaderboard_name";
String LEADERBOARD_DISPLAY_NAME = "leaderboard_display_name";
String LEADERBOARD_CHECKIN_DIGEST = "leaderboard_checkin_digest";
}
@@ -46,12 +49,6 @@ public class AnalyticsContract {
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
public static final String PATH_COMPETITOR = "competitors";
public static final String PATH_EVENT = "events";
public static final String PATH_LEADERBOARD = "leaderboards";
public static final String PATH_CHECKIN = "checkin_uris";
public static final String PATH_MARK = "marks";
public static class LeaderboardsEventsCompetitorsMarksJoined {
public final static Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath("leaderboards_events_competitors_marks_joined")
.build();
@@ -68,100 +65,47 @@ public class AnalyticsContract {
}
public static class Competitor implements CompetitorColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_COMPETITOR).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.COMPETITORS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics.competitor";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics.competitor";
public static final String DEFAULT_SORT = CompetitorColumns.COMPETITOR_ID + " COLLATE NOCASE ASC";
public static Uri buildCompetitorUri(String competitorId) {
return CONTENT_URI.buildUpon().appendPath(competitorId).build();
}
public static Uri buildEventsDirUri(String competitorId) {
return CONTENT_URI.buildUpon().appendPath(competitorId).appendPath(PATH_EVENT).build();
}
public static String getCompetitorId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class Event implements EventColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_EVENT).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.EVENTS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics.event";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics.event";
public static final String DEFAULT_SORT = EventColumns.EVENT_NAME + " COLLATE NOCASE ASC ";
public static Uri buildEventUri(String eventId) {
return CONTENT_URI.buildUpon().appendPath(eventId).build();
}
public static Uri buildCompetitorsDirUri(String evevntId) {
return CONTENT_URI.buildUpon().appendPath(evevntId).appendPath(PATH_COMPETITOR).build();
}
public static String getEventId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class Leaderboard implements LeaderboardColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_LEADERBOARD).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.LEADERBOARDS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics.leaderboard";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics.leaderboard";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri buildLeaderboardUri(String leaderboardId) {
return CONTENT_URI.buildUpon().appendPath(leaderboardId).build();
}
public static String getLeaderboardId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class Checkin implements CheckinColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_CHECKIN).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.CHECKIN_URIS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics.uri";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics.uri";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri builCheckInUri(String checkinUriId) {
return CONTENT_URI.buildUpon().appendPath(checkinUriId).build();
}
public static String getCheckinUriId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class Mark implements markColums, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_MARK).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.MARKS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics.Mark";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics.Mark";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri buildMarkUri(String leaderboardId) {
return CONTENT_URI.buildUpon().appendPath(leaderboardId).build();
}
public static String getMarkId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
private AnalyticsContract() {
@@ -6,6 +6,7 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Checkin;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Competitor;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.CompetitorColumns;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Event;
@@ -20,8 +21,7 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "sap_sailing_analytics.db";
private static final int VER_2016_RELEASE_1 = 2;
private static final int CUR_DATABASE_VERSION = VER_2016_RELEASE_1;
private static final int DATABASE_VERSION = 3;
private static final String createMarkTable = "CREATE TABLE " + Tables.MARKS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + AnalyticsContract.Mark.MARK_ID + " TEXT, "
@@ -33,15 +33,16 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
public interface Tables {
String COMPETITORS = "competitors";
String EVENTS = "events";
String EVENTS_COMPETITORS = "events_competitors";
String LEADERBOARDS = "leaderboards";
String CHECKIN_URIS = "checkin_uris";
String MARKS = "marks";
String EVENTS_JOIN_LEADERBOARDS_JOIN_MARKS = Tables.LEADERBOARDS + " INNER JOIN " + Tables.EVENTS
+ " ON (" + Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.EVENTS
+ "." + Event.EVENT_CHECKIN_DIGEST + ") " + " INNER JOIN " + Tables.MARKS + " ON ("
+ Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.MARKS + "."
+ AnalyticsContract.Mark.MARK_CHECKIN_DIGEST + ") ";
String EVENTS_JOIN_LEADERBOARDS_JOIN_COMPETITORS = Tables.LEADERBOARDS + " INNER JOIN " + Tables.EVENTS
+ " ON (" + Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.EVENTS
+ "." + Event.EVENT_CHECKIN_DIGEST + ") " + " INNER JOIN " + Tables.COMPETITORS + " ON ("
@@ -52,7 +53,7 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
+ " ON (" + Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.EVENTS
+ "." + Event.EVENT_CHECKIN_DIGEST + ") " + " INNER JOIN " + Tables.CHECKIN_URIS + " ON ("
+ Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.CHECKIN_URIS + "."
+ AnalyticsContract.Checkin.CHECKIN_URI_CHECKIN_DIGEST + ") "
+ Checkin.CHECKIN_URI_CHECKIN_DIGEST + ") "
+ " LEFT OUTER JOIN " + Tables.COMPETITORS + " ON ("
+ Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = " + Tables.COMPETITORS + "."
+ Competitor.COMPETITOR_CHECKIN_DIGEST + ") "
@@ -62,7 +63,7 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
}
public AnalyticsDatabase(Context context) {
super(context, DATABASE_NAME, null, CUR_DATABASE_VERSION);
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mContext = context;
}
@@ -70,7 +71,8 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + Tables.LEADERBOARDS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + LeaderboardColumns.LEADERBOARD_CHECKIN_DIGEST + " TEXT, "
+ LeaderboardColumns.LEADERBOARD_NAME + " TEXT );");
+ LeaderboardColumns.LEADERBOARD_NAME + " TEXT, "
+ LeaderboardColumns.LEADERBOARD_DISPLAY_NAME + " TEXT);");
db.execSQL("CREATE TABLE " + Tables.CHECKIN_URIS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + CheckinColumns.CHECKIN_URI_CHECKIN_DIGEST + " TEXT, "
@@ -96,9 +98,13 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
ExLog.i(mContext, TAG, "onUpgrade() from " + oldVersion + " to " + newVersion);
if (oldVersion == 1 && newVersion == 2) {
if (oldVersion < 2) {
db.execSQL(createMarkTable);
db.execSQL("ALTER TABLE " + Tables.CHECKIN_URIS + " ADD COLUMN " + AnalyticsContract.Checkin.CHECKIN_TYPE + " INTEGER DEFAULT 0");
db.execSQL("ALTER TABLE " + Tables.CHECKIN_URIS + " ADD COLUMN " + Checkin.CHECKIN_TYPE + " INTEGER DEFAULT 0");
}
if (oldVersion < 3) {
db.execSQL("ALTER TABLE " + Tables.LEADERBOARDS + " ADD COLUMN " + Leaderboard.LEADERBOARD_DISPLAY_NAME + " TEXT");
db.execSQL("UPDATE " + Tables.LEADERBOARDS + " SET " + Leaderboard.LEADERBOARD_DISPLAY_NAME + " = " + Leaderboard.LEADERBOARD_NAME);
}
}
@@ -3,6 +3,7 @@ package com.sap.sailing.android.tracking.app.provider;
import java.util.Arrays;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
@@ -20,7 +21,6 @@ import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Competito
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Event;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Leaderboard;
import com.sap.sailing.android.tracking.app.provider.AnalyticsDatabase.Tables;
import com.sap.sailing.android.tracking.app.utils.AppPreferences;
public class AnalyticsProvider extends ContentProvider {
@@ -39,9 +39,6 @@ public class AnalyticsProvider extends ContentProvider {
private static final int LEADERBOARD = 300;
private static final int LEADERBOARD_ID = 301;
private static final int MESSAGE = 400;
private static final int MESSAGE_ID = 401;
private static final int CHECKIN_URI = 500;
private static final int CHECKIN_URI_ID = 501;
@@ -59,20 +56,17 @@ public class AnalyticsProvider extends ContentProvider {
final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
final String authority = AnalyticsContract.CONTENT_AUTHORITY;
matcher.addURI(authority, "competitors", COMPETITOR);
matcher.addURI(authority, "competitors/*", COMPETITOR_ID);
matcher.addURI(authority, Tables.COMPETITORS, COMPETITOR);
matcher.addURI(authority, Tables.COMPETITORS + "/*", COMPETITOR_ID);
matcher.addURI(authority, "leaderboards", LEADERBOARD);
matcher.addURI(authority, "leaderboards/*", LEADERBOARD_ID);
matcher.addURI(authority, Tables.LEADERBOARDS, LEADERBOARD);
matcher.addURI(authority, Tables.LEADERBOARDS + "/*", LEADERBOARD_ID);
matcher.addURI(authority, "checkin_uris", CHECKIN_URI);
matcher.addURI(authority, "checkin_uris/*", CHECKIN_URI_ID);
matcher.addURI(authority, Tables.CHECKIN_URIS, CHECKIN_URI);
matcher.addURI(authority, Tables.CHECKIN_URIS + "/*", CHECKIN_URI_ID);
matcher.addURI(authority, "events", EVENT);
matcher.addURI(authority, "events/*", EVENT_ID);
matcher.addURI(authority, "messages", MESSAGE);
matcher.addURI(authority, "messages/#", MESSAGE_ID);
matcher.addURI(authority, Tables.EVENTS, EVENT);
matcher.addURI(authority, Tables.EVENTS + "/*", EVENT_ID);
matcher.addURI(authority, "event_leaderboard_competitor_joined", EVENT_LEADERBOARD_COMPETITOR_JOINED);
matcher.addURI(authority, "event_leaderboard_mark_joined", EVENT_LEADERBOARD_MARK_JOINED);
@@ -81,8 +75,8 @@ public class AnalyticsProvider extends ContentProvider {
matcher.addURI(authority, "leaderboards_events_competitors_marks_joined", LEADERBOARDS_EVENTS_COMPETITORS_MARKS_JOINED);
matcher.addURI(authority, "marks", MARK);
matcher.addURI(authority, "marks/*", MARK_ID);
matcher.addURI(authority, Tables.MARKS, MARK);
matcher.addURI(authority, Tables.MARKS + "/*", MARK_ID);
return matcher;
}
@@ -93,56 +87,48 @@ public class AnalyticsProvider extends ContentProvider {
return true;
}
// private void deleteDatabase() {
// Context context = getContext();
// mOpenHelper.close();
// AnalyticsDatabase.deleteDatabase(context);
// mOpenHelper = new AnalyticsDatabase(context);
// }
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "query: uri=" + uri + " projection=" + Arrays.toString(projection) + " selection=[" + selection + "] args=" + Arrays
.toString(selectionArgs) + " order=[" + sortOrder + "]";
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG,
"query() called with: uri = [" + uri + "], projection = [" + Arrays.toString(projection) + "], selection = ["
+ selection + "], selectionArgs = [" + Arrays.toString(selectionArgs) + "], sortOrder = [" + sortOrder + "]");
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Cursor cursor;
final SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
String table = null;
switch (sUriMatcher.match(uri)) {
case EVENT_LEADERBOARD_MARK_JOINED:
SQLiteQueryBuilder mqb = new SQLiteQueryBuilder();
mqb.setTables(Tables.EVENTS_JOIN_LEADERBOARDS_JOIN_MARKS);
cursor = mqb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return cursor;
table = Tables.EVENTS_JOIN_LEADERBOARDS_JOIN_MARKS;
break;
case EVENT_LEADERBOARD_COMPETITOR_JOINED:
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(Tables.EVENTS_JOIN_LEADERBOARDS_JOIN_COMPETITORS);
cursor = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return cursor;
table = Tables.EVENTS_JOIN_LEADERBOARDS_JOIN_COMPETITORS;
break;
case LEADERBOARDS_EVENTS_COMPETITORS_MARKS_JOINED:
SQLiteQueryBuilder el = new SQLiteQueryBuilder();
el.setTables(Tables.LEADERBOARDS_JOIN_EVENTS_JOIN_COMPETITORS_JOIN_MARKS);
cursor = el.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return cursor;
table = Tables.LEADERBOARDS_JOIN_EVENTS_JOIN_COMPETITORS_JOIN_MARKS;
break;
default:
final SelectionBuilder builder = buildExpandedSelection(uri);
cursor = builder.where(selection, selectionArgs).query(db, false, projection, sortOrder, null);
Context context = getContext();
if (context != null) {
cursor.setNotificationUri(context.getContentResolver(), uri);
}
return cursor;
// np-op
}
Cursor cursor;
if (table != null) {
builder.setTables(table);
cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
} else {
final SelectionBuilder selectionBuilder = buildExpandedSelection(uri);
cursor = selectionBuilder.where(selection, selectionArgs).query(db, false, projection, sortOrder, null);
}
Context context = getContext();
if (context != null) {
cursor.setNotificationUri(context.getContentResolver(), uri);
}
return cursor;
}
@Override
@@ -165,14 +151,19 @@ public class AnalyticsProvider extends ContentProvider {
case LEADERBOARD_ID:
return Leaderboard.CONTENT_ITEM_TYPE;
case CHECKIN_URI:
return Checkin.CONTENT_TYPE;
case CHECKIN_URI_ID:
return Checkin.CONTENT_ITEM_TYPE;
case MARK:
return AnalyticsContract.Mark.CONTENT_TYPE;
case MARK_ID:
return AnalyticsContract.Mark.CONTENT_ITEM_TYPE;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
@@ -180,93 +171,92 @@ public class AnalyticsProvider extends ContentProvider {
@Override
public Uri insert(Uri uri, ContentValues values) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
if (BuildConfig.DEBUG) {
String message = "insert: uri=" + uri + " values=[" + values.toString() + "]";
ExLog.i(getContext(), TAG, message);
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String table;
switch (sUriMatcher.match(uri)) {
case COMPETITOR:
long competitorId = db.insertOrThrow(Tables.COMPETITORS, null, values);
notifyChange(uri);
return Competitor.buildCompetitorUri(String.valueOf(competitorId));
table = Tables.COMPETITORS;
break;
case EVENT:
long eventId = db.insertOrThrow(Tables.EVENTS, null, values);
notifyChange(uri);
return Event.buildEventUri(String.valueOf(eventId));
table = Tables.EVENTS;
break;
case LEADERBOARD:
long leaderboardId = db.insertOrThrow(Tables.LEADERBOARDS, null, values);
notifyChange(uri);
return Leaderboard.buildLeaderboardUri(String.valueOf(leaderboardId));
table = Tables.LEADERBOARDS;
break;
case CHECKIN_URI:
long checkinUriID = db.insertOrThrow(Tables.CHECKIN_URIS, null, values);
notifyChange(uri);
return Checkin.builCheckInUri(String.valueOf(checkinUriID));
table = Tables.CHECKIN_URIS;
break;
case MARK:
long markUriID = db.insertOrThrow(Tables.MARKS, null, values);
notifyChange(uri);
return AnalyticsContract.Mark.buildMarkUri(String.valueOf(markUriID));
table = Tables.MARKS;
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
long id = db.insertOrThrow(table, null, values);
notifyChange(AnalyticsContract.LeaderboardsEventsCompetitorsMarksJoined.CONTENT_URI);
notifyChange(uri);
return uri.buildUpon().appendPath(String.valueOf(id)).build();
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "delete: uri=" + uri + " selection=[" + selection + "] args=" + Arrays.toString(selectionArgs);
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG, "delete() called with: uri = [" + uri + "], selection = [" + selection
+ "], selectionArgs = [" + Arrays.toString(selectionArgs) + "]");
}
String table;
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
switch (sUriMatcher.match(uri)) {
case COMPETITOR:
int numCompetitorRowsDeleted = db.delete(Tables.COMPETITORS, selection, selectionArgs);
notifyChange(uri);
return numCompetitorRowsDeleted;
table = Tables.COMPETITORS;
break;
case EVENT:
int numEventRowsDeleted = db.delete(Tables.EVENTS, selection, selectionArgs);
notifyChange(uri);
return numEventRowsDeleted;
table = Tables.EVENTS;
break;
case LEADERBOARD:
int numLeaderboardRowsDeleted = db.delete(Tables.LEADERBOARDS, selection, selectionArgs);
notifyChange(uri);
return numLeaderboardRowsDeleted;
table = Tables.LEADERBOARDS;
break;
case CHECKIN_URI:
int numCheckinUriRowsDeleted = db.delete(Tables.CHECKIN_URIS, selection, selectionArgs);
notifyChange(uri);
return numCheckinUriRowsDeleted;
table = Tables.CHECKIN_URIS;
break;
case MARK:
int numMarkRowsDeleted = db.delete(Tables.MARKS, selection, selectionArgs);
notifyChange(uri);
return numMarkRowsDeleted;
table = Tables.MARKS;
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
int rowsDeleted = db.delete(table, selection, selectionArgs);
notifyChange(AnalyticsContract.LeaderboardsEventsCompetitorsMarksJoined.CONTENT_URI);
notifyChange(uri);
return rowsDeleted;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "update: uri=" + uri + " values=[" + values == null ?
"null" :
values.toString() + "] selection=[" + selection + "]" + " args=" + Arrays.toString(selectionArgs);
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG, "update() called with: uri = [" + uri + "], values = [" + values + "], selection = [" + selection + "], selectionArgs = ["
+ Arrays.toString(selectionArgs) + "]");
}
// final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
switch (sUriMatcher.match(uri)) {
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
@@ -274,7 +264,10 @@ public class AnalyticsProvider extends ContentProvider {
}
private void notifyChange(Uri uri) {
getContext().getContentResolver().notifyChange(uri, null);
ContentResolver cr = getContext().getContentResolver();
if (cr != null) {
cr.notifyChange(uri, null);
}
}
private SelectionBuilder buildExpandedSelection(Uri uri) {
@@ -285,32 +278,31 @@ public class AnalyticsProvider extends ContentProvider {
return builder.table(Tables.COMPETITORS);
case COMPETITOR_ID:
final String competitor_id = Competitor.getCompetitorId(uri);
return builder.table(Tables.COMPETITORS).where(Competitor.COMPETITOR_ID + " = ?", competitor_id);
return builder.table(Tables.COMPETITORS).where(Competitor.COMPETITOR_ID + " = ?", uri.getLastPathSegment());
case LEADERBOARD:
return builder.table(Tables.LEADERBOARDS);
case LEADERBOARD_ID:
final String leaderboard_id = Leaderboard.getLeaderboardId(uri);
return builder.table(Tables.LEADERBOARDS).where(BaseColumns._ID + " = ?", leaderboard_id);
return builder.table(Tables.LEADERBOARDS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
case EVENT:
return builder.table(Tables.EVENTS);
case EVENT_ID:
final String event_id = Event.getEventId(uri);
return builder.table(Tables.EVENTS).where(Event.EVENT_ID + " = ?", event_id);
return builder.table(Tables.EVENTS).where(Event.EVENT_ID + " = ?", uri.getLastPathSegment());
case CHECKIN_URI:
return builder.table(Tables.CHECKIN_URIS);
case CHECKIN_URI_ID:
final String checkinUriId = Checkin.getCheckinUriId(uri);
return builder.table(Tables.CHECKIN_URIS).where(BaseColumns._ID + " = ?", checkinUriId);
return builder.table(Tables.CHECKIN_URIS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
case MARK:
return builder.table(Tables.MARKS);
case MARK_ID:
final String mark_id = AnalyticsContract.Mark.getMarkId(uri);
return builder.table(Tables.MARKS).where(BaseColumns._ID + " = ?", mark_id);
return builder.table(Tables.MARKS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
@@ -58,7 +58,7 @@ public class BuoyActivity extends AbstractBaseActivity {
toolbar.setNavigationIcon(R.drawable.sap_logo_64dp);
int sidePadding = (int) getResources().getDimension(R.dimen.toolbar_left_padding);
toolbar.setPadding(sidePadding, 0, 0, 0);
getSupportActionBar().setTitle(leaderboard.name);
getSupportActionBar().setTitle(leaderboard.displayName);
getSupportActionBar().setSubtitle(event.name);
ColorDrawable backgroundDrawable = new ColorDrawable(getResources().getColor(R.color.toolbar_background));
getSupportActionBar().setBackgroundDrawable(backgroundDrawable);
@@ -113,7 +113,7 @@ public class RegattaActivity extends AbstractRegattaActivity<CheckinData>
toolbar.setNavigationIcon(R.drawable.sap_logo_64dp);
int sidePadding = (int) getResources().getDimension(R.dimen.toolbar_left_padding);
toolbar.setPadding(sidePadding, 0, 0, 0);
getSupportActionBar().setTitle(leaderboard.name);
getSupportActionBar().setTitle(leaderboard.displayName);
getSupportActionBar().setSubtitle(event.name);
ColorDrawable backgroundDrawable = new ColorDrawable(getResources().getColor(R.color.toolbar_background));
getSupportActionBar().setBackgroundDrawable(backgroundDrawable);
@@ -105,7 +105,7 @@ public class TrackingActivity extends BaseActivity implements GPSQualityListener
LeaderboardInfo leaderboardInfo = DatabaseHelper.getInstance().getLeaderboard(this, checkinDigest);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle(leaderboardInfo.name);
getSupportActionBar().setTitle(leaderboardInfo.displayName);
getSupportActionBar().setSubtitle(getString(R.string.tracking_colon) + " " + eventInfo.name);
ColorDrawable backgroundDrawable = new ColorDrawable(getResources().getColor(R.color.toolbar_background));
getSupportActionBar().setBackgroundDrawable(backgroundDrawable);
@@ -62,6 +62,7 @@ public class AboutFragment extends com.sap.sailing.android.ui.fragments.BaseFrag
notices.addNotice(licenseHelper.getDialogNotice(getActivity()));
LicensesDialog.Builder builder = new LicensesDialog.Builder(getActivity());
builder.setTitle(getString(R.string.license_information));
builder.setThemeResourceId(R.style.AppTheme_AlertDialog);
builder.setNotices(notices);
builder.build().show();
}
@@ -44,6 +44,7 @@ import com.sap.sailing.android.tracking.app.BuildConfig;
import com.sap.sailing.android.tracking.app.R;
import com.sap.sailing.android.tracking.app.adapter.RegattaAdapter;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract;
import com.sap.sailing.android.tracking.app.provider.AnalyticsDatabase;
import com.sap.sailing.android.tracking.app.ui.activities.BuoyActivity;
import com.sap.sailing.android.tracking.app.ui.activities.RegattaActivity;
import com.sap.sailing.android.tracking.app.ui.activities.StartActivity;
@@ -268,14 +269,14 @@ public class HomeFragment extends AbstractHomeFragment implements LoaderCallback
public Loader<Cursor> onCreateLoader(int loaderId, Bundle bundle) {
switch (loaderId) {
case REGATTA_LOADER:
String[] projection = new String[] { AnalyticsContract.PATH_EVENT + "." + AnalyticsContract.Event.EVENT_CHECKIN_DIGEST,
AnalyticsContract.PATH_EVENT + "." + AnalyticsContract.Event._ID,
AnalyticsContract.PATH_EVENT + "." + AnalyticsContract.Event.EVENT_NAME,
AnalyticsContract.PATH_EVENT + "." + AnalyticsContract.Event.EVENT_SERVER,
AnalyticsContract.PATH_LEADERBOARD + "." + AnalyticsContract.Leaderboard.LEADERBOARD_NAME,
AnalyticsContract.PATH_COMPETITOR + "." + AnalyticsContract.Competitor.COMPETITOR_DISPLAY_NAME,
AnalyticsContract.PATH_MARK + "." + AnalyticsContract.Mark.MARK_NAME,
AnalyticsContract.PATH_CHECKIN + "." + AnalyticsContract.Checkin.CHECKIN_TYPE};
String[] projection = new String[] { AnalyticsDatabase.Tables.EVENTS + "." + AnalyticsContract.Event.EVENT_CHECKIN_DIGEST,
AnalyticsDatabase.Tables.EVENTS + "." + AnalyticsContract.Event._ID,
AnalyticsDatabase.Tables.EVENTS + "." + AnalyticsContract.Event.EVENT_NAME,
AnalyticsDatabase.Tables.EVENTS + "." + AnalyticsContract.Event.EVENT_SERVER,
AnalyticsDatabase.Tables.LEADERBOARDS + "." + AnalyticsContract.Leaderboard.LEADERBOARD_DISPLAY_NAME,
AnalyticsDatabase.Tables.COMPETITORS + "." + AnalyticsContract.Competitor.COMPETITOR_DISPLAY_NAME,
AnalyticsDatabase.Tables.MARKS + "." + AnalyticsContract.Mark.MARK_NAME,
AnalyticsDatabase.Tables.CHECKIN_URIS + "." + AnalyticsContract.Checkin.CHECKIN_TYPE};
return new CursorLoader(getActivity(), AnalyticsContract.LeaderboardsEventsCompetitorsMarksJoined.CONTENT_URI, projection, null, null, null);
default:
@@ -143,10 +143,6 @@ public class AppPreferences extends BaseAppPreferences {
return preferences.getString(context.getString(R.string.preference_tracker_is_tracking_checkin_digest), null);
}
public static boolean getPrintDatabaseOperationDebugMessages() {
return false;
}
public void setMessageResendIntervalInMillis(int intervalInMillis) {
preferences.edit().putInt(context.getString(R.string.preference_messageResendIntervalMillis_key), intervalInMillis).commit();
}
@@ -55,6 +55,7 @@ public class CheckinManager {
private CheckinData checkinData;
private CheckinDataActivity<CheckinData> activity;
private AppPreferences prefs;
private UrlData urlData;
private String url;
private boolean update;
@@ -69,7 +70,7 @@ public class CheckinManager {
Uri uri = Uri.parse(url);
String scheme = uri.getScheme();
final UrlData urlData = extractRequestParametersFromUri(uri, scheme);
urlData = extractRequestParametersFromUri(uri, scheme);
if (urlData == null) {
setCheckinData(null);
return;
@@ -79,7 +80,7 @@ public class CheckinManager {
try {
HttpGetRequest getLeaderboardRequest = new HttpGetRequest(new URL(urlData.leaderboardUrl), activity);
getLeaderBoardFromServer(urlData, getLeaderboardRequest);
getLeaderBoardFromServer(getLeaderboardRequest);
} catch (MalformedURLException e) {
ExLog.e(activity, TAG, "Error: Failed to perform checking due to a MalformedURLException: " + e.getMessage());
@@ -110,13 +111,15 @@ public class CheckinManager {
ExLog.e(activity, TAG, "Neither mark nor competitor checkin");
exception = new Exception();
}
urlData.uriStr = uri.toString();
urlData.checkinURLStr = urlData.hostWithPort + prefs.getServerCheckinPath().replace("{leaderboard-name}", leaderboardNameFromQR);
urlData.eventId = uri.getQueryParameter(DeviceMappingConstants.URL_EVENT_ID);
urlData.leaderboardName = leaderboardNameFromQR;
urlData.deviceUuid = new SmartphoneUUIDIdentifierImpl(UUID.fromString(UniqueDeviceUuid.getUniqueId(activity)));
urlData.eventUrl = urlData.hostWithPort + prefs.getServerEventPath(urlData.eventId);
urlData.leaderboardUrl = urlData.hostWithPort + prefs.getServerLeaderboardPath(urlData.leaderboardName);
if (urlData != null) {
urlData.uriStr = uri.toString();
urlData.checkinURLStr = urlData.hostWithPort + prefs.getServerCheckinPath().replace("{leaderboard-name}", leaderboardNameFromQR);
urlData.eventId = uri.getQueryParameter(DeviceMappingConstants.URL_EVENT_ID);
urlData.leaderboardName = leaderboardNameFromQR;
urlData.deviceUuid = new SmartphoneUUIDIdentifierImpl(UUID.fromString(UniqueDeviceUuid.getUniqueId(activity)));
urlData.eventUrl = urlData.hostWithPort + prefs.getServerEventPath(urlData.eventId);
urlData.leaderboardUrl = urlData.hostWithPort + prefs.getServerLeaderboardPath(urlData.leaderboardName);
}
} catch (UnsupportedEncodingException e) {
ExLog.e(activity, TAG, "Failed to encode leaderboard name: " + e.getMessage());
@@ -133,32 +136,22 @@ public class CheckinManager {
return urlData;
}
private void getLeaderBoardFromServer(final UrlData urlData, HttpGetRequest getLeaderboardRequest) {
private void getLeaderBoardFromServer(HttpGetRequest getLeaderboardRequest) {
NetworkHelper.getInstance(activity)
.executeHttpJsonRequestAsync(getLeaderboardRequest, new NetworkHelper.NetworkHelperSuccessListener() {
@Override
public void performAction(JSONObject response) {
try {
// Check if call to leaderboard returned valid response
response.getString("name");
} catch (JSONException e) {
ExLog.e(activity, TAG, "Error getting data from call on URL: " + urlData.leaderboardUrl + ", Error: " + e.getMessage());
handleApiError();
return;
}
final String leaderboardDisplayName = response.optString("displayName", urlData.leaderboardName);
HttpGetRequest getEventRequest;
try {
getEventRequest = new HttpGetRequest(new URL(urlData.eventUrl), activity);
getEventFromServer(getEventRequest, urlData);
getEventFromServer(getEventRequest, leaderboardDisplayName);
} catch (MalformedURLException e1) {
ExLog.e(activity, TAG, "Error: Failed to perform checking due to a MalformedURLException: " + e1.getMessage());
handleApiError();
}
}
}, new NetworkHelper.NetworkHelperFailureListener() {
@Override
public void performAction(NetworkHelper.NetworkHelperError e) {
ExLog.e(activity, TAG, "Failed to get event from API: " + e.getMessage());
@@ -167,9 +160,8 @@ public class CheckinManager {
});
}
private void getEventFromServer(HttpGetRequest getEventRequest, final UrlData urlData) {
private void getEventFromServer(HttpGetRequest getEventRequest, final String leaderboardDisplayName) {
NetworkHelper.getInstance(activity).executeHttpJsonRequestAsync(getEventRequest, new NetworkHelper.NetworkHelperSuccessListener() {
@Override
public void performAction(JSONObject response) {
EventBaseJsonDeserializer deserializer = new EventBaseJsonDeserializer(
@@ -201,8 +193,7 @@ public class CheckinManager {
CompetitorUrlData competitorUrlData = (CompetitorUrlData) urlData;
try {
HttpGetRequest getCompetitorRequest = new HttpGetRequest(new URL(competitorUrlData.competitorUrl), activity);
getCompetitorFromServer(getCompetitorRequest, competitorUrlData);
getCompetitorFromServer(getCompetitorRequest, competitorUrlData, leaderboardDisplayName);
} catch (MalformedURLException e2) {
ExLog.e(activity, TAG, "Error: Failed to perform checking due to a MalformedURLException: " + e2.getMessage());
handleApiError();
@@ -211,7 +202,7 @@ public class CheckinManager {
MarkUrlData markUrlData = (MarkUrlData) urlData;
try {
HttpGetRequest getMarkRequest = new HttpGetRequest(new URL(markUrlData.getMarkUrl()), activity);
getMarkFromServer(getMarkRequest, markUrlData);
getMarkFromServer(getMarkRequest, markUrlData, leaderboardDisplayName);
} catch (MalformedURLException exception) {
ExLog.e(activity, TAG, "Error: Failed to perform checking due to a MalformedURLException: " + exception.getMessage());
handleApiError();
@@ -229,7 +220,7 @@ public class CheckinManager {
});
}
private void getCompetitorFromServer(HttpGetRequest getCompetitorRequest, final CompetitorUrlData urlData) {
private void getCompetitorFromServer(HttpGetRequest getCompetitorRequest, final CompetitorUrlData urlData, final String leaderboardDisplayName) {
NetworkHelper.getInstance(activity)
.executeHttpJsonRequestAsync(getCompetitorRequest, new NetworkHelper.NetworkHelperSuccessListener() {
@Override
@@ -247,7 +238,7 @@ public class CheckinManager {
handleApiError();
return;
}
saveCheckinDataAndNotifyListeners(urlData);
saveCheckinDataAndNotifyListeners(urlData, leaderboardDisplayName);
}
}, new NetworkHelper.NetworkHelperFailureListener() {
@Override
@@ -258,7 +249,7 @@ public class CheckinManager {
});
}
private void getMarkFromServer(HttpGetRequest getMarkRequest, final MarkUrlData urlData) {
private void getMarkFromServer(HttpGetRequest getMarkRequest, final MarkUrlData urlData, final String leaderboardDisplayName) {
NetworkHelper.getInstance(activity)
.executeHttpJsonRequestAsync(getMarkRequest, new NetworkHelper.NetworkHelperSuccessListener() {
@Override
@@ -277,7 +268,7 @@ public class CheckinManager {
}
return;
}
saveCheckinDataAndNotifyListeners(urlData);
saveCheckinDataAndNotifyListeners(urlData, leaderboardDisplayName);
}
}, new NetworkHelper.NetworkHelperFailureListener() {
@Override
@@ -291,14 +282,14 @@ public class CheckinManager {
});
}
private void saveCheckinDataAndNotifyListeners(UrlData urlData) {
private void saveCheckinDataAndNotifyListeners(UrlData urlData, String leaderboardDisplayName) {
CheckinData data;
if (urlData instanceof CompetitorUrlData) {
CompetitorUrlData competitorUrlData = (CompetitorUrlData) urlData;
data = new CompetitorCheckinData(competitorUrlData);
data = new CompetitorCheckinData(competitorUrlData, leaderboardDisplayName);
} else {
MarkUrlData markUrlData = (MarkUrlData) urlData;
data = new MarkCheckinData(markUrlData);
data = new MarkCheckinData(markUrlData, leaderboardDisplayName);
}
data.setUpdate(update);
try {
@@ -20,7 +20,6 @@ import com.sap.sailing.android.tracking.app.provider.AnalyticsContract;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Checkin;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Competitor;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Event;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.EventLeaderboardCompetitorJoined;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Leaderboard;
import com.sap.sailing.android.tracking.app.provider.AnalyticsDatabase;
import com.sap.sailing.android.tracking.app.valueobjects.CompetitorInfo;
@@ -60,45 +59,6 @@ public class DatabaseHelper {
return checkinUrls;
}
public long getEventRowIdForCheckinDigest(Context context, String checkinDigest) {
int result = 0;
ContentResolver cr = context.getContentResolver();
Cursor cursor = cr.query(Event.CONTENT_URI, null, Event.EVENT_CHECKIN_DIGEST + " = ?",
new String[] { checkinDigest }, null);
if (cursor != null) {
cursor.moveToFirst();
result = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID));
cursor.close();
}
return result;
}
public EventInfo getEventInfoWithLeaderboardAndCompetitor(Context context, String checkinDigest) {
EventInfo result = new EventInfo();
ContentResolver cr = context.getContentResolver();
String projectionStr = AnalyticsDatabase.Tables.EVENTS + "." + Event._ID + ","
+ AnalyticsDatabase.Tables.LEADERBOARDS + "." + Leaderboard.LEADERBOARD_NAME + ","
+ AnalyticsDatabase.Tables.EVENTS + "." + Event.EVENT_ID + ","
+ AnalyticsDatabase.Tables.EVENTS + "." + Event.EVENT_NAME + ","
+ AnalyticsDatabase.Tables.COMPETITORS + "." + Competitor.COMPETITOR_ID;
String[] projection = projectionStr.split(",");
Cursor cursor = cr.query(EventLeaderboardCompetitorJoined.CONTENT_URI, projection,
AnalyticsDatabase.Tables.EVENTS + "." + Event.EVENT_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
result.name = cursor.getString(cursor.getColumnIndex(Event.EVENT_NAME));
result.leaderboardName = cursor.getString(cursor.getColumnIndex(Leaderboard.LEADERBOARD_NAME));
result.competitorId = cursor.getString(cursor.getColumnIndex(Competitor.COMPETITOR_ID));
result.id = cursor.getString(cursor.getColumnIndex(Event.EVENT_ID));
}
cursor.close();
}
return result;
}
public EventInfo getEventInfo(Context context, String checkinDigest) {
EventInfo event = new EventInfo();
event.checkinDigest = checkinDigest;
@@ -145,15 +105,16 @@ public class DatabaseHelper {
LeaderboardInfo leaderboard = new LeaderboardInfo();
leaderboard.checkinDigest = checkinDigest;
Cursor lc = context.getContentResolver().query(Leaderboard.CONTENT_URI, null,
Cursor cursor = context.getContentResolver().query(Leaderboard.CONTENT_URI, null,
Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
if (lc != null) {
if (lc.moveToFirst()) {
leaderboard.rowId = lc.getInt(lc.getColumnIndex(BaseColumns._ID));
leaderboard.name = lc.getString(lc.getColumnIndex(Leaderboard.LEADERBOARD_NAME));
if (cursor != null) {
if (cursor.moveToFirst()) {
leaderboard.rowId = cursor.getInt(cursor.getColumnIndex(BaseColumns._ID));
leaderboard.name = cursor.getString(cursor.getColumnIndex(Leaderboard.LEADERBOARD_NAME));
leaderboard.displayName = cursor.getString(cursor.getColumnIndex(Leaderboard.LEADERBOARD_DISPLAY_NAME));
}
lc.close();
cursor.close();
}
return leaderboard;
@@ -229,17 +190,15 @@ public class DatabaseHelper {
ArrayList<ContentProviderOperation> opList = new ArrayList<>();
// competitor
ContentValues cv = new ContentValues();
cv.put(Competitor.COMPETITOR_COUNTRY_CODE, competitor.countryCode);
cv.put(Competitor.COMPETITOR_DISPLAY_NAME, competitor.name);
cv.put(Competitor.COMPETITOR_ID, competitor.id);
cv.put(Competitor.COMPETITOR_NATIONALITY, competitor.nationality);
cv.put(Competitor.COMPETITOR_SAIL_ID, competitor.sailId);
cv.put(Competitor.COMPETITOR_CHECKIN_DIGEST, competitor.checkinDigest);
ContentValues ccv = new ContentValues();
ccv.put(Competitor.COMPETITOR_COUNTRY_CODE, competitor.countryCode);
ccv.put(Competitor.COMPETITOR_DISPLAY_NAME, competitor.name);
ccv.put(Competitor.COMPETITOR_ID, competitor.id);
ccv.put(Competitor.COMPETITOR_NATIONALITY, competitor.nationality);
ccv.put(Competitor.COMPETITOR_SAIL_ID, competitor.sailId);
ccv.put(Competitor.COMPETITOR_CHECKIN_DIGEST, competitor.checkinDigest);
opList.add(ContentProviderOperation.newInsert(Competitor.CONTENT_URI).withValues(ccv).build());
opList.add(ContentProviderOperation.newInsert(Competitor.CONTENT_URI).withValues(cv).build());
storeBasicInformation(leaderboard, event, checkinURL, opList, contentResolver);
try {
@@ -255,11 +214,11 @@ public class DatabaseHelper {
// Store Mark information
ContentResolver contentResolver = context.getContentResolver();
ArrayList<ContentProviderOperation> opList = new ArrayList<>();
ContentValues markValues = new ContentValues();
markValues.put(AnalyticsContract.Mark.MARK_ID, mark.getId().toString());
markValues.put(AnalyticsContract.Mark.MARK_NAME, mark.getName());
markValues.put(AnalyticsContract.Mark.MARK_CHECKIN_DIGEST, checkinURL.checkinDigest);
opList.add(ContentProviderOperation.newInsert(AnalyticsContract.Mark.CONTENT_URI).withValues(markValues).build());
ContentValues cv = new ContentValues();
cv.put(AnalyticsContract.Mark.MARK_ID, mark.getId().toString());
cv.put(AnalyticsContract.Mark.MARK_NAME, mark.getName());
cv.put(AnalyticsContract.Mark.MARK_CHECKIN_DIGEST, checkinURL.checkinDigest);
opList.add(ContentProviderOperation.newInsert(AnalyticsContract.Mark.CONTENT_URI).withValues(cv).build());
storeBasicInformation(leaderboard, event, checkinURL, opList, contentResolver);
@@ -274,34 +233,31 @@ public class DatabaseHelper {
ArrayList<ContentProviderOperation> opList, ContentResolver contentResolver) {
// inserting leaderboard first
ContentValues clv = new ContentValues();
clv.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
clv.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
contentResolver.insert(Leaderboard.CONTENT_URI, clv);
ContentValues cv = new ContentValues();
cv.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
cv.put(Leaderboard.LEADERBOARD_DISPLAY_NAME, leaderboard.displayName);
cv.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
contentResolver.insert(Leaderboard.CONTENT_URI, cv);
// now insert event
cv.clear();
cv.put(Event.EVENT_ID, event.id);
cv.put(Event.EVENT_NAME, event.name);
cv.put(Event.EVENT_DATE_START, event.startMillis);
cv.put(Event.EVENT_DATE_END, event.endMillis);
cv.put(Event.EVENT_SERVER, event.server);
cv.put(Event.EVENT_IMAGE_URL, event.imageUrl);
cv.put(Event.EVENT_CHECKIN_DIGEST, event.checkinDigest);
ContentValues cev = new ContentValues();
cev.put(Event.EVENT_ID, event.id);
cev.put(Event.EVENT_NAME, event.name);
cev.put(Event.EVENT_DATE_START, event.startMillis);
cev.put(Event.EVENT_DATE_END, event.endMillis);
cev.put(Event.EVENT_SERVER, event.server);
cev.put(Event.EVENT_IMAGE_URL, event.imageUrl);
cev.put(Event.EVENT_CHECKIN_DIGEST, event.checkinDigest);
opList.add(ContentProviderOperation.newInsert(Event.CONTENT_URI).withValues(cev).build());
opList.add(ContentProviderOperation.newInsert(Event.CONTENT_URI).withValues(cv).build());
// checkin url
cv.clear();
cv.put(Checkin.CHECKIN_URI_VALUE, checkinURL.urlString);
cv.put(Checkin.CHECKIN_URI_CHECKIN_DIGEST, checkinURL.checkinDigest);
cv.put(Checkin.CHECKIN_TYPE, checkinURL.type);
ContentValues ccuv = new ContentValues();
ccuv.put(Checkin.CHECKIN_URI_VALUE, checkinURL.urlString);
ccuv.put(Checkin.CHECKIN_URI_CHECKIN_DIGEST, checkinURL.checkinDigest);
ccuv.put(Checkin.CHECKIN_TYPE, checkinURL.type);
opList.add(ContentProviderOperation.newInsert(Checkin.CONTENT_URI).withValues(ccuv).build());
opList.add(ContentProviderOperation.newInsert(Checkin.CONTENT_URI).withValues(cv).build());
}
/**
@@ -1,75 +0,0 @@
package com.sap.sailing.android.tracking.app.utils;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.provider.BaseColumns;
import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Competitor;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Event;
import com.sap.sailing.android.tracking.app.provider.AnalyticsContract.Leaderboard;
public class SqlDebugHelper {
static final public String TAG = SqlDebugHelper.class.getName();
public static void dumpAllTablesToConsole(Context context) {
ExLog.w(context, TAG, "--- PRINT ALL SQL");
ExLog.w(context, TAG, "+++ LEADERBOARDS +++");
ContentResolver cr = context.getContentResolver();
Cursor c1 = cr.query(Leaderboard.CONTENT_URI, null, null, null, null);
while (c1.moveToNext()) {
StringBuffer sb = new StringBuffer();
sb.append("_ID: " + c1.getString(c1.getColumnIndex(BaseColumns._ID)) + ", ");
sb.append("NAME: " + c1.getString(c1.getColumnIndex(Leaderboard.LEADERBOARD_NAME)) + "\n");
sb.append("DIGEST: " + c1.getString(c1.getColumnIndex(Leaderboard.LEADERBOARD_CHECKIN_DIGEST)) + "\n");
ExLog.w(context, TAG, "Leaderboard: " + sb.toString());
}
ExLog.w(context, TAG, "+++ EVENTS +++");
c1.close();
Cursor c2 = cr.query(Event.CONTENT_URI, null, null, null, null);
while (c2.moveToNext()) {
StringBuffer sb = new StringBuffer();
sb.append("_ID: " + c2.getString(c2.getColumnIndex(BaseColumns._ID)) + ", ");
sb.append("ID: " + c2.getString(c2.getColumnIndex(Event.EVENT_ID)) + ", ");
sb.append("NAME: " + c2.getString(c2.getColumnIndex(Event.EVENT_NAME)) + ", ");
sb.append("DATE START: " + c2.getString(c2.getColumnIndex(Event.EVENT_DATE_START)) + ", ");
sb.append("DATE END: " + c2.getString(c2.getColumnIndex(Event.EVENT_DATE_END)) + ", ");
sb.append("IMAGE-URL: " + c2.getString(c2.getColumnIndex(Event.EVENT_IMAGE_URL)) + ", ");
sb.append("SERVER: " + c2.getString(c2.getColumnIndex(Event.EVENT_SERVER)) + "\n");
sb.append("DIGEST: " + c2.getString(c2.getColumnIndex(Event.EVENT_CHECKIN_DIGEST)) + "\n");
ExLog.w(context, TAG, "Event: " + sb.toString());
}
ExLog.w(context, TAG, "+++ COMPETITORS +++");
c2.close();
Cursor c3 = cr.query(Competitor.CONTENT_URI, null, null, null, null);
while (c3.moveToNext()) {
StringBuffer sb = new StringBuffer();
sb.append("_ID: " + c3.getString(c3.getColumnIndex(BaseColumns._ID)) + ", ");
sb.append("ID: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_ID)) + ", ");
sb.append("DISPLAY NAME: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_DISPLAY_NAME)) + ", ");
sb.append("NATIONALITY: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_NATIONALITY)) + ", ");
sb.append("COUNTRY CODE: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_COUNTRY_CODE)) + ", ");
sb.append("SAIL-ID: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_SAIL_ID)) + "\n");
sb.append("DIGEST: " + c3.getString(c3.getColumnIndex(Competitor.COMPETITOR_CHECKIN_DIGEST)) + "\n");
ExLog.w(context, TAG, "Competitor: " + sb.toString());
}
c3.close();
ExLog.w(context, TAG, "--- END OF SQL PRINTOUT");
}
}
@@ -12,6 +12,7 @@ import android.net.Uri;
public abstract class CheckinData extends BaseCheckinData {
private String leaderboardName;
private String leaderboardDisplayName;
private String eventId;
private String eventName;
private String eventStartDateStr;
@@ -24,8 +25,9 @@ public abstract class CheckinData extends BaseCheckinData {
public String checkinDigest;
private boolean update;
public CheckinData(UrlData data) {
public CheckinData(UrlData data, String leaderboardDisplayName) {
leaderboardName = Uri.decode(data.leaderboardName);
this.leaderboardDisplayName = leaderboardDisplayName;
deviceUid = data.deviceUuid.getStringRepresentation();
eventId = data.eventId;
eventName = data.eventName;
@@ -64,6 +66,7 @@ public abstract class CheckinData extends BaseCheckinData {
public LeaderboardInfo getLeaderboard() {
LeaderboardInfo leaderboard = new LeaderboardInfo();
leaderboard.name = leaderboardName;
leaderboard.displayName = leaderboardDisplayName;
leaderboard.checkinDigest = checkinDigest;
return leaderboard;
}
@@ -12,8 +12,8 @@ public class CompetitorCheckinData extends CheckinData {
public String competitorNationality;
public String competitorCountryCode;
public CompetitorCheckinData(CompetitorUrlData urlData) {
super(urlData);
public CompetitorCheckinData(CompetitorUrlData urlData, String leaderboardDisplayName) {
super(urlData, leaderboardDisplayName);
competitorName = urlData.competitorName;
competitorId = urlData.competitorId;
competitorUrl = urlData.competitorUrl;
@@ -1,8 +0,0 @@
package com.sap.sailing.android.tracking.app.valueobjects;
public class LeaderboardInfo {
public String name;
public String checkinDigest;
public int rowId;
}
@@ -7,8 +7,8 @@ public class MarkCheckinData extends CheckinData {
public Mark mark;
public MarkCheckinData(MarkUrlData markUrlData) {
super(markUrlData);
public MarkCheckinData(MarkUrlData markUrlData, String leaderboardDisplayName) {
super(markUrlData, leaderboardDisplayName);
mark = markUrlData.getMark();
}
@@ -19,7 +19,7 @@ public class RegattaAdapter extends AbstractRegattaAdapter {
public void bindView(View view, Context context, Cursor cursor) {
TextView name = (TextView) view.findViewById(R.id.regattaName);
if (name != null) {
String text = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_NAME));
String text = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_DISPLAY_NAME));
name.setText(text);
}
}
@@ -4,10 +4,19 @@ import android.content.ContentResolver;
import android.net.Uri;
import android.provider.BaseColumns;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsDatabase.Tables;
public class AnalyticsContract {
interface LeaderboardColumns {
String LEADERBOARD_NAME = "leaderboard_name";
/**
* The values in this column either equal those of the {@link #LEADERBOARD_NAME} column in case no explicit
* display name has been provided for the leaderboard, or they hold the explicit display name. Note that this
* makes it impossible to tell whether the display name was inferred from the regular name or has been
* explicitly provided.
*/
String LEADERBOARD_DISPLAY_NAME = "leaderboard_display_name";
String LEADERBOARD_SERVER_URL = "leaderboard_server_url";
String LEADERBOARD_CHECKIN_DIGEST = "leaderboard_checkin_digest";
}
@@ -37,81 +46,40 @@ public class AnalyticsContract {
public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
public static final String PATH_LEADERBOARD = AnalyticsDatabase.Tables.LEADERBOARDS;
public static final String PATH_CHECKIN_URI = AnalyticsDatabase.Tables.CHECKIN_URIS;
public static final String PATH_MARK = AnalyticsDatabase.Tables.MARKS;
public static final String PATH_MARK_PING = AnalyticsDatabase.Tables.MARK_PINGS;
public static class Leaderboard implements LeaderboardColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_LEADERBOARD).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.LEADERBOARDS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.leaderboard";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.leaderboard";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri buildLeaderboardUri(String leaderboardId) {
return CONTENT_URI.buildUpon().appendPath(leaderboardId).build();
}
public static String getLeaderboardId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class CheckinUri implements CheckinUriColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_CHECKIN_URI).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.CHECKIN_URIS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.uri";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.uri";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri builCheckInUri(String checkinUriId) {
return CONTENT_URI.buildUpon().appendPath(checkinUriId).build();
}
public static String getCheckinUriId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class Mark implements MarkColums, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_MARK).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.MARKS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.mark";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.mark";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri builMarkUri(String markId) {
return CONTENT_URI.buildUpon().appendPath(markId).build();
}
public static String getMarkId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class MarkPing implements MarkPingColumns, BaseColumns {
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(PATH_MARK_PING).build();
public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon().appendPath(Tables.MARK_PINGS).build();
public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.mark.ping";
public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ "/vnd.sap_sailing_analytics_buoy.mark.ping";
public static final String DEFAULT_SORT = BaseColumns._ID + " ASC ";
public static Uri builMarkPingUri(String markId) {
return CONTENT_URI.buildUpon().appendPath(markId).build();
}
public static String getMarkPingId(Uri uri) {
return uri.getPathSegments().get(1);
}
}
public static class LeaderboardsMarksJoined {
@@ -5,12 +5,10 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.CheckinUriColumns;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.CheckinUri;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.Leaderboard;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.LeaderboardColumns;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.Mark;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.MarkColums;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.MarkPingColumns;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.MarkPing;
import com.sap.sailing.android.shared.logging.ExLog;
public class AnalyticsDatabase extends SQLiteOpenHelper {
@@ -19,8 +17,7 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "sap_sailing_analytics_buoy.db";
private static final int VER_2015_RELEASE_1 = 1;
private static final int CUR_DATABASE_VERSION = VER_2015_RELEASE_1;
private static final int DATABASE_VERSION = 2;
private final Context mContext;
@@ -40,51 +37,38 @@ public class AnalyticsDatabase extends SQLiteOpenHelper {
}
public AnalyticsDatabase(Context context) {
super(context, DATABASE_NAME, null, CUR_DATABASE_VERSION);
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + Tables.LEADERBOARDS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + LeaderboardColumns.LEADERBOARD_CHECKIN_DIGEST + " TEXT, "
+ LeaderboardColumns.LEADERBOARD_SERVER_URL + " TEXT, " + LeaderboardColumns.LEADERBOARD_NAME
+ " TEXT );");
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " TEXT, "
+ Leaderboard.LEADERBOARD_SERVER_URL + " TEXT, " + Leaderboard.LEADERBOARD_NAME
+ " TEXT, " + Leaderboard.LEADERBOARD_DISPLAY_NAME + " TEXT );");
db.execSQL("CREATE TABLE " + Tables.CHECKIN_URIS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + CheckinUriColumns.CHECKIN_URI_CHECKIN_DIGEST + " TEXT, "
+ CheckinUriColumns.CHECKIN_URI_VALUE + " TEXT );");
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + CheckinUri.CHECKIN_URI_CHECKIN_DIGEST + " TEXT, "
+ CheckinUri.CHECKIN_URI_VALUE + " TEXT );");
db.execSQL("CREATE TABLE " + Tables.MARKS + " (" + BaseColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ MarkColums.MARK_CHECKIN_DIGEST + " TEXT," + MarkColums.MARK_ID + " INTEGER," + MarkColums.MARK_NAME
+ " TEXT," + MarkColums.MARK_TYPE + " TEXT," + MarkColums.MARK_CLASS_NAME + " TEXT );");
+ Mark.MARK_CHECKIN_DIGEST + " TEXT," + Mark.MARK_ID + " INTEGER," + Mark.MARK_NAME
+ " TEXT," + Mark.MARK_TYPE + " TEXT," + Mark.MARK_CLASS_NAME + " TEXT );");
db.execSQL("CREATE TABLE " + Tables.MARK_PINGS + " (" + BaseColumns._ID
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + MarkPingColumns.MARK_ID + " INTEGER,"
+ MarkPingColumns.MARK_PING_TIMESTAMP + " TEXT," + MarkPingColumns.MARK_PING_LATITUDE + " TEXT,"
+ MarkPingColumns.MARK_PING_LONGITUDE + " TEXT," + MarkPingColumns.MARK_PING_ACCURACY + " REAL );");
+ " INTEGER PRIMARY KEY AUTOINCREMENT, " + MarkPing.MARK_ID + " INTEGER,"
+ MarkPing.MARK_PING_TIMESTAMP + " TEXT," + MarkPing.MARK_PING_LATITUDE + " TEXT,"
+ MarkPing.MARK_PING_LONGITUDE + " TEXT," + MarkPing.MARK_PING_ACCURACY + " REAL );");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
ExLog.i(mContext, TAG, "onUpgrade() from " + oldVersion + " to " + newVersion);
ExLog.i(mContext, TAG, "onUpgrade() called with: db = [" + db + "], oldVersion = [" + oldVersion + "], newVersion = [" + newVersion + "]");
int version = oldVersion;
if (version != CUR_DATABASE_VERSION) {
ExLog.i(mContext, TAG, "Upgrade unsuccessful - destroying old data during upgrade");
db.execSQL("DROP TABLE IF EXISTS " + Tables.LEADERBOARDS);
db.execSQL("DROP TABLE IF EXISTS " + Tables.CHECKIN_URIS);
db.execSQL("DROP TABLE IF EXISTS " + Tables.MARKS);
db.execSQL("DROP TABLE IF EXISTS " + Tables.MARK_PINGS);
onCreate(db);
version = CUR_DATABASE_VERSION;
if (oldVersion < 2) {
db.execSQL("ALTER TABLE " + Tables.LEADERBOARDS + " ADD COLUMN " + Leaderboard.LEADERBOARD_DISPLAY_NAME + " TEXT");
db.execSQL("UPDATE " + Tables.LEADERBOARDS + " SET " + Leaderboard.LEADERBOARD_DISPLAY_NAME + " = " + Leaderboard.LEADERBOARD_NAME);
}
}
public static void deleteDatabase(Context context) {
context.deleteDatabase(DATABASE_NAME);
}
}
@@ -1,6 +1,9 @@
package com.sap.sailing.android.buoy.positioning.app.provider;
import java.util.Arrays;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
@@ -9,18 +12,16 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.provider.BaseColumns;
import com.sap.sailing.android.buoy.positioning.app.BuildConfig;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.CheckinUri;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.Leaderboard;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.Mark;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract.MarkPing;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsDatabase.Tables;
import com.sap.sailing.android.buoy.positioning.app.util.AppPreferences;
import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.android.shared.util.SelectionBuilder;
import java.util.Arrays;
public class AnalyticsProvider extends ContentProvider {
private static final String TAG = AnalyticsProvider.class.getName();
@@ -38,9 +39,6 @@ public class AnalyticsProvider extends ContentProvider {
private static final int MARK_PING = 300;
private static final int MARK_PING_ID = 301;
private static final int MESSAGE = 400;
private static final int MESSAGE_ID = 401;
private static final int CHECKIN_URI = 500;
private static final int CHECKIN_URI_ID = 501;
@@ -52,20 +50,17 @@ public class AnalyticsProvider extends ContentProvider {
final UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
final String authority = AnalyticsContract.CONTENT_AUTHORITY;
matcher.addURI(authority, "leaderboards", LEADERBOARD);
matcher.addURI(authority, "leaderboards/*", LEADERBOARD_ID);
matcher.addURI(authority, Tables.LEADERBOARDS, LEADERBOARD);
matcher.addURI(authority, Tables.LEADERBOARDS + "/*", LEADERBOARD_ID);
matcher.addURI(authority, "checkin_uris", CHECKIN_URI);
matcher.addURI(authority, "checkin_uris/*", CHECKIN_URI_ID);
matcher.addURI(authority, Tables.CHECKIN_URIS, CHECKIN_URI);
matcher.addURI(authority, Tables.CHECKIN_URIS + "/*", CHECKIN_URI_ID);
matcher.addURI(authority, "marks", MARK);
matcher.addURI(authority, "marks/*", MARK_ID);
matcher.addURI(authority, Tables.MARKS, MARK);
matcher.addURI(authority, Tables.MARKS + "/*", MARK_ID);
matcher.addURI(authority, "mark_pings", MARK_PING);
matcher.addURI(authority, "mark_pings/*", MARK_PING_ID);
matcher.addURI(authority, "messages", MESSAGE);
matcher.addURI(authority, "messages/#", MESSAGE_ID);
matcher.addURI(authority, Tables.MARK_PINGS, MARK_PING);
matcher.addURI(authority, Tables.MARK_PINGS + "/*", MARK_PING_ID);
matcher.addURI(authority, "leaderboards_marks_joined", LEADERBOARDS_MARKS_JOINED);
@@ -82,192 +77,217 @@ public class AnalyticsProvider extends ContentProvider {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "query: uri=" + uri + " projection=" + Arrays.toString(projection) + " selection=["
+ selection + "] args=" + Arrays.toString(selectionArgs) + " order=[" + sortOrder + "]";
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG,
"query() called with: uri = [" + uri + "], projection = [" + Arrays.toString(projection) + "], selection = [" + selection
+ "], selectionArgs = [" + Arrays.toString(selectionArgs) + "], sortOrder = [" + sortOrder + "]");
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
Cursor cursor;
String table = null;
SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
switch (sUriMatcher.match(uri)) {
case LEADERBOARDS_MARKS_JOINED:
table = Tables.LEADERBOARDS_MARKS_JOINED;
break;
case LEADERBOARDS_MARKS_JOINED:
SQLiteQueryBuilder el = new SQLiteQueryBuilder();
el.setTables(Tables.LEADERBOARDS_MARKS_JOINED);
cursor = el.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return cursor;
case MARKS_LEADERBOARDS_JOINED:
table = Tables.MARKS_LEADERBOARDS_JOINED;
break;
case MARKS_LEADERBOARDS_JOINED:
SQLiteQueryBuilder el2 = new SQLiteQueryBuilder();
el2.setTables(Tables.MARKS_LEADERBOARDS_JOINED);
cursor = el2.query(db, projection, selection, selectionArgs, null, null, sortOrder);
return cursor;
default:
break;
}
default:
final SelectionBuilder builder = buildExpandedSelection(uri);
if (table != null) {
builder.setTables(table);
cursor = builder.query(db, projection, selection, selectionArgs, null, null, sortOrder);
} else {
final SelectionBuilder selectionBuilder = buildExpandedSelection(uri);
cursor = builder.where(selection, selectionArgs).query(db, false, projection, sortOrder, null);
cursor = selectionBuilder.where(selection, selectionArgs).query(db, false, projection, sortOrder, null);
Context context = getContext();
if (context != null) {
cursor.setNotificationUri(context.getContentResolver(), uri);
}
return cursor;
}
return cursor;
}
@Override
public String getType(Uri uri) {
switch (sUriMatcher.match(uri)) {
case LEADERBOARD:
return Leaderboard.CONTENT_TYPE;
case LEADERBOARD:
return Leaderboard.CONTENT_TYPE;
case LEADERBOARD_ID:
return Leaderboard.CONTENT_ITEM_TYPE;
case CHECKIN_URI:
return CheckinUri.CONTENT_TYPE;
case CHECKIN_URI_ID:
return CheckinUri.CONTENT_ITEM_TYPE;
case MARK:
return Mark.CONTENT_TYPE;
case MARK_ID:
return Mark.CONTENT_ITEM_TYPE;
case MARK_PING:
return MarkPing.CONTENT_TYPE;
case MARK_PING_ID:
return MarkPing.CONTENT_ITEM_TYPE;
case LEADERBOARD_ID:
return Leaderboard.CONTENT_ITEM_TYPE;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
case CHECKIN_URI:
return CheckinUri.CONTENT_TYPE;
case CHECKIN_URI_ID:
return CheckinUri.CONTENT_ITEM_TYPE;
case MARK:
return Mark.CONTENT_TYPE;
case MARK_ID:
return Mark.CONTENT_ITEM_TYPE;
case MARK_PING:
return MarkPing.CONTENT_TYPE;
case MARK_PING_ID:
return MarkPing.CONTENT_ITEM_TYPE;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "insert: uri=" + uri + " values=[" + values.toString() + "]";
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG, "insert() called with: uri = [" + uri + "], values = [" + values + "]");
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String table;
switch (sUriMatcher.match(uri)) {
case LEADERBOARD:
table = Tables.LEADERBOARDS;
break;
case LEADERBOARD:
long leaderboardId = db.insertOrThrow(Tables.LEADERBOARDS, null, values);
notifyChange(uri);
return Leaderboard.buildLeaderboardUri(String.valueOf(leaderboardId));
case CHECKIN_URI:
long checkinUriID = db.insertOrThrow(Tables.CHECKIN_URIS, null, values);
notifyChange(uri);
return CheckinUri.builCheckInUri(String.valueOf(checkinUriID));
case MARK:
long markID = db.insertOrThrow(Tables.MARKS, null, values);
notifyChange(uri);
return Mark.builMarkUri(String.valueOf(markID));
case MARK_PING:
long markPingId = db.insertOrThrow(Tables.MARK_PINGS, null, values);
notifyChange(uri);
return Mark.builMarkUri(String.valueOf(markPingId));
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
case CHECKIN_URI:
table = Tables.CHECKIN_URIS;
break;
case MARK:
table = Tables.MARKS;
break;
case MARK_PING:
table = Tables.MARK_PINGS;
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
long id = db.insertOrThrow(table, null, values);
notifyChange(uri);
return uri.buildUpon().appendPath(String.valueOf(id)).build();
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "delete: uri=" + uri + " selection=[" + selection + "] args="
+ Arrays.toString(selectionArgs);
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG,
"delete() called with: uri = [" + uri + "], selection = [" + selection + "], selectionArgs = ["
+ Arrays.toString(selectionArgs) + "]");
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String table;
switch (sUriMatcher.match(uri)) {
case LEADERBOARD:
table = Tables.LEADERBOARDS;
break;
case LEADERBOARD:
int numLeaderboardRowsDeleted = db.delete(Tables.LEADERBOARDS, selection, selectionArgs);
notifyChange(uri);
return numLeaderboardRowsDeleted;
case CHECKIN_URI:
int numCheckinUriRowsDeleted = db.delete(Tables.CHECKIN_URIS, selection, selectionArgs);
notifyChange(uri);
return numCheckinUriRowsDeleted;
case MARK:
int numMarkRowsDeleted = db.delete(Tables.MARKS, selection, selectionArgs);
notifyChange(uri);
return numMarkRowsDeleted;
case MARK_PING:
int numMarkPingRowsDeleted = db.delete(Tables.MARK_PINGS, selection, selectionArgs);
notifyChange(uri);
return numMarkPingRowsDeleted;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
case CHECKIN_URI:
table = Tables.CHECKIN_URIS;
break;
case MARK:
table = Tables.MARKS;
break;
case MARK_PING:
table = Tables.MARK_PINGS;
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
int rowsDeleted = db.delete(table, selection, selectionArgs);
notifyChange(uri);
return rowsDeleted;
}
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
if (BuildConfig.DEBUG && AppPreferences.getPrintDatabaseOperationDebugMessages()) {
String message = "update: uri=" + uri + " values=[" + values == null ? "null" : values.toString()
+ "] selection=[" + selection + "]" + " args=" + Arrays.toString(selectionArgs);
ExLog.i(getContext(), TAG, message);
if (BuildConfig.DEBUG) {
ExLog.i(getContext(), TAG,
"update() called with: uri = [" + uri + "], values = [" + values + "], selection = [" + selection + "], selectionArgs = [" + Arrays
.toString(selectionArgs) + "]");
}
final SQLiteDatabase db = mOpenHelper.getWritableDatabase();
String table;
switch (sUriMatcher.match(uri)) {
case LEADERBOARD:
int numLeaderboardRowsUpdated = db.update(Tables.LEADERBOARDS, values, selection, selectionArgs);
notifyChange(uri);
return numLeaderboardRowsUpdated;
table = Tables.LEADERBOARDS;
break;
case MARK:
int numMarkRowsUpdated = db.update(Tables.MARKS, values, selection, selectionArgs);
notifyChange(uri);
return numMarkRowsUpdated;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
table = Tables.MARKS;
break;
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
int rowsUpdated = db.update(table, values, selection, selectionArgs);
notifyChange(uri);
return rowsUpdated;
}
private void notifyChange(Uri uri) {
getContext().getContentResolver().notifyChange(uri, null);
ContentResolver cr = getContext().getContentResolver();
if (cr != null) {
cr.notifyChange(uri, null);
}
}
private SelectionBuilder buildExpandedSelection(Uri uri) {
final SelectionBuilder builder = new SelectionBuilder(getContext());
switch (sUriMatcher.match(uri)) {
case LEADERBOARD:
return builder.table(Tables.LEADERBOARDS);
case LEADERBOARD:
return builder.table(Tables.LEADERBOARDS);
case LEADERBOARD_ID:
return builder.table(Tables.LEADERBOARDS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
case LEADERBOARD_ID:
final String leaderboard_id = Leaderboard.getLeaderboardId(uri);
return builder.table(Tables.LEADERBOARDS).where(BaseColumns._ID + " = ?", leaderboard_id);
case CHECKIN_URI:
return builder.table(Tables.CHECKIN_URIS);
case CHECKIN_URI:
return builder.table(Tables.CHECKIN_URIS);
case CHECKIN_URI_ID:
final String checkinUriId = AnalyticsContract.CheckinUri.getCheckinUriId(uri);
return builder.table(Tables.CHECKIN_URIS).where(BaseColumns._ID + " = ?", checkinUriId);
case MARK:
return builder.table(Tables.MARKS);
case MARK_ID:
final String mark_id = Mark.getMarkId(uri);
return builder.table(Tables.MARKS).where(BaseColumns._ID + " = ?", mark_id);
case MARK_PING:
return builder.table(Tables.MARK_PINGS);
case MARK_PING_ID:
final String mark_ping_id = MarkPing.getMarkPingId(uri);
return builder.table(Tables.MARK_PINGS).where(BaseColumns._ID + " = ?", mark_ping_id);
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
case CHECKIN_URI_ID:
return builder.table(Tables.CHECKIN_URIS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
case MARK:
return builder.table(Tables.MARKS);
case MARK_ID:
return builder.table(Tables.MARKS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
case MARK_PING:
return builder.table(Tables.MARK_PINGS);
case MARK_PING_ID:
return builder.table(Tables.MARK_PINGS).where(BaseColumns._ID + " = ?", uri.getLastPathSegment());
default:
throw new UnsupportedOperationException("Unknown uri: " + uri);
}
}
}
@@ -55,6 +55,7 @@ public class AboutFragment extends BaseFragment {
notices.addNotice(licenseHelper.getDialogNotice(getActivity()));
LicensesDialog.Builder builder = new LicensesDialog.Builder(getActivity());
builder.setTitle(getString(R.string.license_information));
builder.setThemeResourceId(R.style.AppTheme_AlertDialog);
builder.setNotices(notices);
builder.build().show();
}
@@ -69,7 +69,6 @@ public class HomeFragment extends AbstractHomeFragment implements LoaderCallback
public void displayUserConfirmationScreen(BaseCheckinData data) {
CheckinData chData = (CheckinData) data;
checkinWithApiAndStartRegattaActivity(chData);
}
private void checkinWithApiAndStartRegattaActivity(CheckinData checkinData) {
@@ -89,7 +88,7 @@ public class HomeFragment extends AbstractHomeFragment implements LoaderCallback
if (BuildConfig.DEBUG) {
ExLog.i(getActivity(), TAG, "Batch-insert of checkinData completed.");
}
startRegatta(checkinData.leaderboardName, checkinData.checkinDigest);
startRegatta(checkinData.leaderboardDisplayName, checkinData.checkinDigest);
}
@Override
@@ -160,9 +159,8 @@ public class HomeFragment extends AbstractHomeFragment implements LoaderCallback
// -1, because there's a header row
Cursor cursor = (Cursor) adapter.getItem(position - 1);
String checkinDigest = cursor.getString(cursor.getColumnIndex("leaderboard_checkin_digest"));
String leaderboardName = cursor.getString(cursor.getColumnIndex("leaderboard_name"));
String checkinDigest = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_CHECKIN_DIGEST));
String leaderboardName = cursor.getString(cursor.getColumnIndex(AnalyticsContract.Leaderboard.LEADERBOARD_DISPLAY_NAME));
startRegatta(leaderboardName, checkinDigest);
}
}
@@ -1,6 +1,7 @@
package com.sap.sailing.android.buoy.positioning.app.util;
import android.content.Context;
import com.sap.sailing.android.buoy.positioning.app.R;
import com.sap.sailing.android.shared.util.BaseAppPreferences;
@@ -37,8 +38,4 @@ public class AppPreferences extends BaseAppPreferences {
return preferences.getLong(context.getString(R.string.preference_data_refresh_interval_seconds_key),
context.getResources().getInteger(R.integer.preference_data_refresh_interval_seconds_default));
}
public static boolean getPrintDatabaseOperationDebugMessages() {
return false;
}
}
@@ -115,10 +115,7 @@ public class CheckinManager {
}
if (urlData != null) {
urlData.leaderboardName = leaderboardNameFromQR;
urlData.deviceUuid = new SmartphoneUUIDIdentifierImpl(UUID.fromString(UniqueDeviceUuid
.getUniqueId(mContext)));
urlData.deviceUuid = new SmartphoneUUIDIdentifierImpl(UUID.fromString(UniqueDeviceUuid.getUniqueId(mContext)));
urlData.getLeaderboardUrl = urlData.hostWithPort + prefs.getServerLeaderboardPath(urlData.leaderboardName);
}
return urlData;
@@ -142,11 +139,11 @@ public class CheckinManager {
}
return;
}
final String leaderboardDisplayName = response.optString("displayName", leaderboardName);
HttpGetRequest getMarksRequest;
try {
getMarksRequest = new HttpGetRequest(new URL(urlData.getMarkUrl), mContext);
getMarksFromServer(leaderboardName, getMarksRequest, urlData);
getMarksFromServer(leaderboardName, leaderboardDisplayName, getMarksRequest, urlData);
} catch (MalformedURLException e1) {
ExLog.e(mContext, TAG, "Error: Failed to perform checking due to a MalformedURLException: " + e1.getMessage());
}
@@ -163,7 +160,12 @@ public class CheckinManager {
});
}
private void getMarksFromServer(final String leaderboardName, HttpGetRequest getMarksRequest, final URLData urlData) {
/**
* @param leaderboardDisplayName
* the leaderboard's display name if one has been explicitly provided, otherwise the same as
* {@code leaderboardName}
*/
private void getMarksFromServer(final String leaderboardName, final String leaderboardDisplayName, HttpGetRequest getMarksRequest, final URLData urlData) {
NetworkHelper.getInstance(mContext).executeHttpJsonRequestAsync(getMarksRequest,
new NetworkHelperSuccessListener() {
@@ -204,7 +206,7 @@ public class CheckinManager {
}
urlData.marks = marks;
urlData.pings = pings;
saveCheckinDataAndNotifyListeners(urlData, leaderboardName);
saveCheckinDataAndNotifyListeners(urlData, leaderboardName, leaderboardDisplayName);
} catch (JSONException | ParseException | JsonDeserializationException e) {
ExLog.e(mContext, TAG, "Error getting data from call on URL: " + urlData.getMarkUrl
@@ -230,10 +232,16 @@ public class CheckinManager {
});
}
private void saveCheckinDataAndNotifyListeners(URLData urlData, String leaderboardName) {
/**
* @param leaderboardDisplayName
* the leaderboard's display name if one has been explicitly provided, otherwise the same as
* {@code leaderboardName}
*/
private void saveCheckinDataAndNotifyListeners(URLData urlData, String leaderboardName, String leaderboardDisplayName) {
CheckinData data = new CheckinData();
data.serverWithPort = urlData.hostWithPort;
data.leaderboardName = leaderboardName;
data.leaderboardDisplayName = leaderboardDisplayName;
data.marks = urlData.marks;
data.pings = urlData.pings;
data.deviceUid = urlData.deviceUuid.getStringRepresentation();
@@ -326,9 +334,5 @@ public class CheckinManager {
public DeviceIdentifier deviceUuid;
public String getMarkUrl;
public String getLeaderboardUrl;
public URLData() {
}
}
}
@@ -4,6 +4,17 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.provider.BaseColumns;
import android.support.v4.content.LocalBroadcastManager;
import com.sap.sailing.android.buoy.positioning.app.BuildConfig;
import com.sap.sailing.android.buoy.positioning.app.R;
import com.sap.sailing.android.buoy.positioning.app.provider.AnalyticsContract;
@@ -20,17 +31,6 @@ import com.sap.sailing.android.shared.logging.ExLog;
import com.sap.sailing.domain.common.tracking.impl.GPSFixImpl;
import com.sap.sailing.server.gateway.deserialization.impl.Helpers;
import android.content.ContentProviderOperation;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.OperationApplicationException;
import android.database.Cursor;
import android.os.RemoteException;
import android.provider.BaseColumns;
import android.support.v4.content.LocalBroadcastManager;
public class DatabaseHelper {
private final static String TAG = DatabaseHelper.class.getName();
@@ -41,14 +41,12 @@ public class DatabaseHelper {
if (mInstance == null) {
mInstance = new DatabaseHelper();
}
return mInstance;
}
public LeaderboardInfo getLeaderboard(Context context, String checkinDigest) {
LeaderboardInfo leaderboard = new LeaderboardInfo();
leaderboard.checkinDigest = checkinDigest;
Cursor lc = context.getContentResolver().query(Leaderboard.CONTENT_URI, null,
Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
if (lc != null) {
@@ -57,17 +55,14 @@ public class DatabaseHelper {
leaderboard.name = lc.getString(lc.getColumnIndex(Leaderboard.LEADERBOARD_NAME));
leaderboard.serverUrl = lc.getString(lc.getColumnIndex(Leaderboard.LEADERBOARD_SERVER_URL));
}
lc.close();
}
return leaderboard;
}
public CheckinUrlInfo getCheckinUrl(Context context, String checkinDigest) {
CheckinUrlInfo checkinUrlInfo = new CheckinUrlInfo();
checkinUrlInfo.checkinDigest = checkinDigest;
Cursor uc = context.getContentResolver().query(CheckinUri.CONTENT_URI, null,
CheckinUri.CHECKIN_URI_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
if (uc != null) {
@@ -75,10 +70,8 @@ public class DatabaseHelper {
checkinUrlInfo.rowId = uc.getInt(uc.getColumnIndex(BaseColumns._ID));
checkinUrlInfo.urlString = uc.getString(uc.getColumnIndex(CheckinUri.CHECKIN_URI_VALUE));
}
uc.close();
}
return checkinUrlInfo;
}
@@ -126,7 +119,6 @@ public class DatabaseHelper {
public void deletePingsFromDataBase(Context context, String markIdAsString) {
ContentResolver cr = context.getContentResolver();
int d1 = cr.delete(MarkPing.CONTENT_URI, MarkPing.MARK_ID + " = ?", new String[] { markIdAsString });
if (BuildConfig.DEBUG) {
ExLog.i(context, TAG, "Checkout, number of markpings for mark: " + markIdAsString + " deleted: " + d1);
}
@@ -134,17 +126,13 @@ public class DatabaseHelper {
public void deleteRegattaFromDatabase(Context context, String checkinDigest) {
ContentResolver cr = context.getContentResolver();
List<MarkInfo> marks = getMarks(context, checkinDigest);
for (MarkInfo mark : marks) {
deletePingsFromDataBase(context, mark.getId().toString());
}
int d2 = cr.delete(Leaderboard.CONTENT_URI, Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest });
int d3 = cr.delete(Mark.CONTENT_URI, Mark.MARK_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest });
int d4 = cr.delete(CheckinUri.CONTENT_URI, CheckinUri.CHECKIN_URI_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest });
if (BuildConfig.DEBUG) {
ExLog.i(context, TAG, "Checkout, number of leaderbards deleted: " + d2);
ExLog.i(context, TAG, "Checkout, number of marks deleted: " + d3);
@@ -169,46 +157,38 @@ public class DatabaseHelper {
}
// inserting leaderboard first
ContentResolver cr = context.getContentResolver();
ContentValues clv = new ContentValues();
clv.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
clv.put(Leaderboard.LEADERBOARD_SERVER_URL, leaderboard.serverUrl);
clv.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
cr.insert(Leaderboard.CONTENT_URI, clv);
ContentValues cv = new ContentValues();
cv.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
cv.put(Leaderboard.LEADERBOARD_DISPLAY_NAME, leaderboard.displayName);
cv.put(Leaderboard.LEADERBOARD_SERVER_URL, leaderboard.serverUrl);
cv.put(Leaderboard.LEADERBOARD_CHECKIN_DIGEST, leaderboard.checkinDigest);
cr.insert(Leaderboard.CONTENT_URI, cv);
// now insert marks
ArrayList<ContentProviderOperation> opList = new ArrayList<>();
// marks
for (MarkInfo mark : markList) {
ContentValues cmv = new ContentValues();
cmv.put(Mark.MARK_CHECKIN_DIGEST, mark.getCheckinDigest());
cmv.put(Mark.MARK_ID, mark.getId().toString());
cmv.put(Mark.MARK_NAME, mark.getName());
cmv.put(Mark.MARK_TYPE, mark.getType().toString());
cmv.put(Mark.MARK_CLASS_NAME, mark.getClassName());
cv.clear();
cv.put(Mark.MARK_CHECKIN_DIGEST, mark.getCheckinDigest());
cv.put(Mark.MARK_ID, mark.getId().toString());
cv.put(Mark.MARK_NAME, mark.getName());
cv.put(Mark.MARK_TYPE, mark.getType().toString());
cv.put(Mark.MARK_CLASS_NAME, mark.getClassName());
opList.add(ContentProviderOperation.newInsert(Mark.CONTENT_URI).withValues(cmv).build());
opList.add(ContentProviderOperation.newInsert(Mark.CONTENT_URI).withValues(cv).build());
}
for (MarkPingInfo ping : pings) {
storeMarkPing(context, ping);
}
// checkin url
ContentValues ccuv = new ContentValues();
ccuv.put(CheckinUri.CHECKIN_URI_VALUE, checkinURL.urlString);
ccuv.put(CheckinUri.CHECKIN_URI_CHECKIN_DIGEST, checkinURL.checkinDigest);
cr.insert(CheckinUri.CONTENT_URI, ccuv);
opList.add(ContentProviderOperation.newInsert(CheckinUri.CONTENT_URI).withValues(ccuv).build());
cv.clear();
cv.put(CheckinUri.CHECKIN_URI_VALUE, checkinURL.urlString);
cv.put(CheckinUri.CHECKIN_URI_CHECKIN_DIGEST, checkinURL.checkinDigest);
cr.insert(CheckinUri.CONTENT_URI, cv);
opList.add(ContentProviderOperation.newInsert(CheckinUri.CONTENT_URI).withValues(cv).build());
try {
cr.applyBatch(AnalyticsContract.CONTENT_AUTHORITY, opList);
LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(new Intent(context.getString(R.string.database_changed)));
} catch (RemoteException e) {
throw new GeneralDatabaseHelperException(e.getMessage());
} catch (OperationApplicationException e) {
@@ -219,7 +199,6 @@ 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().toString() });
if (BuildConfig.DEBUG) {
ExLog.i(context, TAG, "Deleted mark with id: " + markInfo.getId());
}
@@ -232,6 +211,7 @@ public class DatabaseHelper {
LeaderboardInfo leaderboard = data.getLeaderboard();
ContentValues leaderboardValues = new ContentValues();
leaderboardValues.put(Leaderboard.LEADERBOARD_NAME, leaderboard.name);
leaderboardValues.put(Leaderboard.LEADERBOARD_DISPLAY_NAME, leaderboard.displayName);
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});
@@ -263,13 +243,13 @@ public class DatabaseHelper {
ContentResolver cr = context.getContentResolver();
deletePingsFromDataBase(context, markPing.getMarkId().toString());
ArrayList<ContentProviderOperation> opList = new ArrayList<>();
ContentValues mpcv = new ContentValues();
mpcv.put(MarkPing.MARK_ID, markPing.getMarkId().toString());
mpcv.put(MarkPing.MARK_PING_LATITUDE, markPing.getLatitude());
mpcv.put(MarkPing.MARK_PING_LONGITUDE, markPing.getLongitude());
mpcv.put(MarkPing.MARK_PING_ACCURACY, markPing.getAccuracy());
mpcv.put(MarkPing.MARK_PING_TIMESTAMP, markPing.getTimestamp());
opList.add(ContentProviderOperation.newInsert(MarkPing.CONTENT_URI).withValues(mpcv).build());
ContentValues cv = new ContentValues();
cv.put(MarkPing.MARK_ID, markPing.getMarkId().toString());
cv.put(MarkPing.MARK_PING_LATITUDE, markPing.getLatitude());
cv.put(MarkPing.MARK_PING_LONGITUDE, markPing.getLongitude());
cv.put(MarkPing.MARK_PING_ACCURACY, markPing.getAccuracy());
cv.put(MarkPing.MARK_PING_TIMESTAMP, markPing.getTimestamp());
opList.add(ContentProviderOperation.newInsert(MarkPing.CONTENT_URI).withValues(cv).build());
try {
cr.applyBatch(AnalyticsContract.CONTENT_AUTHORITY, opList);
@@ -282,13 +262,11 @@ public class DatabaseHelper {
}
public boolean markLeaderboardCombinationAvailable(Context context, String checkinDigest) {
Cursor lc = context.getContentResolver().query(Leaderboard.CONTENT_URI, null,
Leaderboard.LEADERBOARD_CHECKIN_DIGEST + " = ?", new String[] { checkinDigest }, null);
int count = 0;
if (lc != null) {
count = lc.getCount();
lc.close();
}
return count == 0;
@@ -1,16 +1,20 @@
package com.sap.sailing.android.buoy.positioning.app.valueobjects;
import com.sap.sailing.android.shared.data.BaseCheckinData;
import com.sap.sailing.android.shared.data.CheckinUrlInfo;
import com.sap.sailing.android.shared.data.LeaderboardInfo;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import com.sap.sailing.android.shared.data.BaseCheckinData;
import com.sap.sailing.android.shared.data.CheckinUrlInfo;
import com.sap.sailing.android.shared.data.LeaderboardInfo;
public class CheckinData extends BaseCheckinData {
public String leaderboardName;
/**
* the leaderboard's display name if one has been explicitly provided, otherwise the same as {@link #leaderboardName}
*/
public String leaderboardDisplayName;
public String deviceUid;
public String uriString;
public String checkinDigest;
@@ -33,6 +37,7 @@ public class CheckinData extends BaseCheckinData {
public LeaderboardInfo getLeaderboard() {
LeaderboardInfo leaderboard = new LeaderboardInfo();
leaderboard.name = leaderboardName;
leaderboard.displayName = leaderboardDisplayName;
leaderboard.checkinDigest = checkinDigest;
leaderboard.serverUrl = serverWithPort;
return leaderboard;
@@ -133,6 +133,7 @@ public class SystemInformationActivityHelper {
notices.addNotice(licenseHelper.getDialogNotice(activity));
LicensesDialog.Builder builder = new LicensesDialog.Builder(activity);
builder.setTitle(activity.getString(R.string.license_information));
builder.setThemeResourceId(R.style.AppTheme_AlertDialog);
builder.setNotices(notices);
builder.build().show();
}