11package %1$s.%11$s;
22
3+ import com.tractive.android.commons.R;
4+ import com.tractive.android.data.SLog;
5+ import com.tractive.android.util.LibApp;
36%2$s
47import android.content.ContentProvider;
58import android.content.ContentProviderOperation;
@@ -11,12 +14,15 @@ import android.content.OperationApplicationException;
1114import android.content.UriMatcher;
1215import android.database.Cursor;
1316import android.database.sqlite.SQLiteDatabase;
17+ import android.database.sqlite.SQLiteException;
1418import android.database.sqlite.SQLiteOpenHelper;
1519import android.database.sqlite.SQLiteStatement;
1620import android.net.Uri;
1721import android.provider.BaseColumns;
1822import android.util.Log;
1923
24+
25+
2026import java.util.ArrayList;
2127
2228/**
@@ -27,12 +33,13 @@ import java.util.ArrayList;
2733public %14$sclass %3$sProvider extends ContentProvider {
2834
2935 private static final String LOG_TAG = %3$sProvider.class.getSimpleName();
36+ private ContentValuesModifyHook mContentValuesModifyHook;
3037
3138 /* package */ static final boolean ACTIVATE_ALL_LOGS = false;
3239
3340 protected static final String DATABASE_NAME = "%3$sProvider.db";
3441
35- public static final String AUTHORITY = "%4$s.provider.%3$sProvider" ;
42+ public static final String AUTHORITY = LibApp.getContext().getString(R.string.content_authority) ;
3643
3744 static {
3845 Uri.parse("content://" + AUTHORITY + "/integrityCheck");
@@ -94,16 +101,23 @@ public %14$sclass %3$sProvider extends ContentProvider {
94101
95102 private class DatabaseHelper extends SQLiteOpenHelper {
96103
104+ Context mContext;
105+
97106 DatabaseHelper(Context context, String name) {
98107 super(context, name, null, DATABASE_VERSION);
108+ mContext = context;
99109 }
100110
101111 @Override
102112 public void onCreate(SQLiteDatabase db) {
103- Log .d(LOG_TAG, "Creating %3$sProvider database");
113+ SLog .d("Creating %3$sProvider database");
104114
105115 // Create all tables here; each class has its own method
106- %6$s }
116+ %6$s
117+ //copy all data from the old database if it exists.
118+ new TractiveDbUpgradeHelper().copyFromOldDb(db, mContext);
119+
120+ }
107121
108122 @Override
109123 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
@@ -155,6 +169,8 @@ public %14$sclass %3$sProvider extends ContentProvider {
155169
156170 UriType uriType = matchUri(uri);
157171 Context context = getContext();
172+ // Hook for app to modify content values before they are inserted (e.g. for activity_day)
173+ mContentValuesModifyHook.onContentValuesModified(values);
158174
159175 // Pick the correct database for this operation
160176 SQLiteDatabase db = getDatabase(context);
@@ -293,6 +309,9 @@ public %14$sclass %3$sProvider extends ContentProvider {
293309 UriType uriType = matchUri(uri);
294310 Context context = getContext();
295311
312+ // Hook for app to modify content values before they are inserted (e.g. for activity_day)
313+ mContentValuesModifyHook.onContentValuesModified(values);
314+
296315 // Pick the correct database for this operation
297316 SQLiteDatabase db = getDatabase(context);
298317
@@ -317,6 +336,7 @@ public %14$sclass %3$sProvider extends ContentProvider {
317336
318337 @Override
319338 public boolean onCreate() {
339+ mContentValuesModifyHook = LibApp.getInstance().getContentProviderHook();
320340 return true;
321341 }
322342}
0 commit comments