Commit 268396d3 authored by Alan McNatty's avatar Alan McNatty

A large commit that moves the artefactdatasqlhelper 'stuff' into a content...

A large commit that moves the artefactdatasqlhelper 'stuff' into a content provider so we can set upa content observer and listen for content changes. This is significant in the cleanliness of the artefacts .. an uninstall and reinstall will be required.

Also split the Utils class into Sync and Account Util classes so it's a bit more focused (easier to know where to look etc).
parent 0c1048db
......@@ -94,8 +94,14 @@
<meta-data android:name="android.content.SyncAdapter"
android:resource="@xml/syncadapter" />
</service>
<provider android:name="nz.net.catalyst.MaharaDroid.provider.MaharaProvider"
android:authorities="nz.net.catalyst.MaharaDroid"
<provider android:name=".provider.SyncContentProvider"
android:authorities="nz.net.catalyst.MaharaDroid.Sync"
android:label="MaharaDroid"
android:syncable="true"
android:enabled="true">
</provider>
<provider android:name=".provider.ArtefactContentProvider"
android:authorities="nz.net.catalyst.MaharaDroid.Artefact"
android:label="MaharaDroid"
android:syncable="true"
android:enabled="true">
......
......@@ -50,12 +50,6 @@
style="@android:style/TextAppearance.Small">
</TextView>
</LinearLayout>
<!--
<ImageView android:id="@+id/UploadArtefact"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ImageView>
-->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ArtefactTitleLayout"
......
......@@ -43,7 +43,7 @@
android:layout_below="@+id/artefacts_banner_text"
/>
<TextView android:text="@string/artefacts_help"
<TextView android:id="@+id/artefacts_help"
android:layout_margin="5dp"
android:layout_width="fill_parent"
android:singleLine="false"
......
......@@ -4,8 +4,16 @@
<string name="artefacts_banner_text">Open source ePortfolios</string>
<string name="artefacts_banner_text2">[mah-har-rah;verb]: to think, thinking, thought</string>
<string name="artefacts_help">
<string name="artefacts_help">&lt;p&gt;Thanks for using MaharaDroid!&lt;/p&gt;
&lt;p&gt;To get started touch Menu -&gt; Preferences.&lt;/p&gt;
&lt;p&gt;
Enter your Mahara username on set the initial token. At the same time visit Mahara (Settings) and set the same token value and click update.
Back in MaharaDroid touch your back button, and an authentication attempt will be made.
&lt;/p&gt;
&lt;p&gt;
Once authenticated check the Menu for options on writing Journal posts and uploading files.
Alternatively when taking photos, videos or recording audio look for options to \'share\' these files with MaharaDroid.
&lt;/p&gt;
</string>
<string name="artefacts_no_saved_artefacts">Nothing saved at present.</string>
......
<!-- API Version 7 requires the accountType attribute to be hard-coded as a string -->
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="nz.net.catalyst.MaharaDroid"
android:contentAuthority="nz.net.catalyst.MaharaDroid.Sync"
android:accountType="nz.net.catalyst.MaharaDroid.account"
android:supportsUploading="true"
android:userVisible="true"
......
......@@ -52,12 +52,16 @@ public class GlobalResources {
public static final String ACCOUNT_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String AUTHTOKEN_TYPE = "nz.net.catalyst.MaharaDroid.account";
public static final String CONTENT_URL = "nz.net.catalyst.MaharaDroid";
public static final String SYNC_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Sync";
public static final String ARTEFACT_CONTENT_URL = "nz.net.catalyst.MaharaDroid.Artefact";
public static final String SYNC_AUTHORITY = "nz.net.catalyst.MaharaDroid";
public static final String EXTRAS_SYNC_IS_PERIODIC = "nz.net.catalyst.MaharaDroid.periodic";
public static final String BROADCAST_ACTION = "nz.net.catalyst.MaharaDroid.UPLOAD_COMPLETED";
public static final String[] CONTENT_TABLES = new String[] { "tag", "blog", "folder" };
public static final String[] CONTENT_FIELDS = new String[] { "ID", "VALUE" };
public static final String[] SYNC_CONTENT_TABLES = new String[] { "tag", "blog", "folder" };
public static final String[] SYNC_CONTENT_FIELDS = new String[] { "ID", "VALUE" };
public static final Map<Integer, String> NOTIFICATIONS;
static {
......@@ -76,5 +80,4 @@ public class GlobalResources {
public static final int REQ_RECORD_AUDIO_RETURN = 2;
public static final int REGISTRATION_TIMEOUT = 30 * 1000; // ms
}
\ No newline at end of file
This diff is collapsed.
......@@ -17,6 +17,7 @@
package nz.net.catalyst.MaharaDroid.authenticator;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
......@@ -103,7 +104,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
//TODO confirm but shouldn't have to force this - setSyncAutomatically should kick one off I believe
// ContentResolver.requestSync(account, GlobalResources.SYNC_AUTHORITY, null);
Utils.setPeriodicSync(account, getApplicationContext());
SyncUtils.setPeriodicSync(account, getApplicationContext());
}
final Intent intent = new Intent();
......
......@@ -3,7 +3,8 @@ package nz.net.catalyst.MaharaDroid.authenticator;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.provider.MaharaProvider;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.provider.SyncContentProvider;
import nz.net.catalyst.MaharaDroid.upload.http.RestClient;
import org.json.JSONObject;
......@@ -61,7 +62,7 @@ public class MaharaAuthHandler {
// application preferences
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String authSyncURI = Utils.getSyncURLPref(mContext);
String authSyncURI = SyncUtils.getSyncURLPref(mContext);
String token = mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_token_key), "");
......@@ -74,12 +75,12 @@ public class MaharaAuthHandler {
Utils.showNotification(NOTIFICATION, mContext.getResources().getText(R.string.login_authenticating),
null, null, mContext);
String syncNotifications = Utils.getSyncNotificationsPref(mContext);
String syncNotifications = SyncUtils.getSyncNotificationsPref(mContext);
JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, syncNotifications, mContext);
token = Utils.updateTokenFromResult(result, mContext);
if ( result.has("sync") ) {
Utils.processSyncResults(result, null, mContext, sync_key);
SyncUtils.processSyncResults(result, null, mContext, sync_key);
}
if ( token != null ) {
......
......@@ -241,9 +241,7 @@ public class Artefact extends Object implements Parcelable {
mContext.startService(i);
}
public void delete(Context mContext) {
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
artefactData.deleteSavedArtefact(id);
artefactData.close();
ArtefactUtils.deleteSavedArtefact(mContext, id);
}
public void view(Context mContext) {
try {
......@@ -269,21 +267,29 @@ public class Artefact extends Object implements Parcelable {
mContext.startActivity(i);
}
public void save(Context mContext) {
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
if ( id != 0 ) { // update
Log.d("Artefact", "save: is_draft: " + is_draft);
Log.d("Artefact", "save: allow comments: " + allow_comments);
artefactData.update(id, filename, title, description, tags, saved_id, journal_id, is_draft, allow_comments);
ArtefactUtils.update(mContext, id, filename, title, description, tags, saved_id, journal_id, is_draft, allow_comments);
} else { // add
artefactData.add(filename, title, description, tags, journal_id, is_draft, allow_comments);
ArtefactUtils.add(mContext, filename, title, description, tags, journal_id, is_draft, allow_comments);
}
artefactData.close();
}
public void load(Context mContext, Long id) {
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
artefactData.loadSavedArtefact(id);
artefactData.close();
Artefact ta = ArtefactUtils.loadSavedArtefact(mContext, id);
this.id = ta.getId();
this.time = ta.getTime();
filename = ta.getFilename();
title = ta.getTitle();
description = ta.getDescription();
tags = ta.getTags();
saved_id = ta.saved_id;
journal_id = ta.getJournalId();
is_draft = ta.getIsDraft();
allow_comments = ta.getAllowComments();
}
public String getFilePath(Context context) {
if ( filename == null )
......
/*
* MaharaDroid - Artefact uploader
*
* This file is part of MaharaDroid.
*
* Copyright [2010] [Catalyst IT Limited]
*
* This file is free software: you may copy, redistribute and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package nz.net.catalyst.MaharaDroid.data;
import nz.net.catalyst.MaharaDroid.LogConfig;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.provider.BaseColumns;
import android.util.Log;
import android.widget.Toast;
/** Helper to the database, manages versions and creation */
public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
static final String TAG = LogConfig.getLogTag(ArtefactDataSQLHelper.class);
// whether DEBUG level logging is enabled (whether globally, or explicitly for this log tag)
static final boolean DEBUG = LogConfig.isDebug(TAG);
// whether VERBOSE level logging is enabled
static final boolean VERBOSE = LogConfig.VERBOSE;
private static final String DATABASE_NAME = "maharadroid_upload_log.db";
private static final int DATABASE_VERSION = 2;
private static Context mContext;
// Table name
public static final String TABLE = "upload_log";
// Columns
public static final String TIME = "time";
public static final String FILENAME = "filename";
public static final String URI = "uri";
public static final String TITLE = "title";
public static final String DESCRIPTION = "description";
public static final String TAGS = "tags";
public static final String SAVED_ID = "id";
public static final String JOURNAL_ID = "journal_id";
public static final String IS_DRAFT = "is_draft";
public static final String ALLOW_COMMENTS = "allow_comments";
public ArtefactDataSQLHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mContext = context;
SQLiteDatabase db = this.getReadableDatabase();
// db.execSQL("DROP TABLE " + TABLE + "; ");
// this.onCreate(db);
// String sql = "alter table " + TABLE + " ADD COLUMN " + IS_DRAFT + " boolean; ";
// String sql = "alter table " + TABLE + " ADD COLUMN " + ALLOW_COMMENTS + " boolean; ";
// Log.d("LogData", "onCreate: " + sql);
// db.execSQL(sql);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table " + TABLE + "( " + BaseColumns._ID
+ " integer primary key autoincrement, " + TIME + " integer, "
+ FILENAME + " text, "
+ TITLE + " text not null, "
+ DESCRIPTION + " text, "
+ TAGS + " text, "
+ SAVED_ID + " integer, "
+ JOURNAL_ID + " text, "
+ IS_DRAFT + " boolean, "
+ ALLOW_COMMENTS + " boolean "
+ ");";
if ( DEBUG ) Log.d("LogData", "onCreate: " + sql);
db.execSQL(sql);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion >= newVersion)
return;
String sql = null;
// Version 1 is the first version with SQL
if (oldVersion < 2) {
db.execSQL("DROP TABLE " + TABLE + "; ");
this.onCreate(db);
Log.d("EventsData", "onUpgrade : " + sql);
}
}
public void uploadAllSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (VERBOSE) Log.v(TAG, "uploadAllSavedArtefacts: returned " + cursor.getCount() + " records.");
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
a.upload(true, mContext);
}
} finally {
cursor.close();
}
}
public Artefact loadSavedArtefact(Long id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, BaseColumns._ID + " = ?",
new String[] { id.toString() }, null, null, null);
try {
if (cursor == null)
return null;
cursor.moveToFirst();
return createArtefactFromCursor(cursor);
} finally {
cursor.close();
}
}
public int countSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
int count = 0;
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (cursor == null)
return count;
return cursor.getCount();
} finally {
cursor.close();
}
}
public Artefact[] loadSavedArtefacts() {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null, null, null);
try {
if (cursor == null)
return new Artefact[] {};// TODO why different from above?
Artefact[] a_array = new Artefact[cursor.getCount()];
int items = 0;
while (cursor.moveToNext()) {
Artefact a = createArtefactFromCursor(cursor);
// Only include artefacts with either no attached file or valid
// files (may have been deleted in the background so we check)
if (a.getFilename() == null
|| (a.getFilename() != null && a.getFilePath(mContext) != null)) {
a_array[items++] = a;
} else {
Log.w(TAG, "File '" + a.getTitle() + "' does not exist on the device, deleting from saved artefacts");
Toast.makeText(mContext, "File '" + a.getTitle() + "' does not exist on the device, deleting from saved artefacts", Toast.LENGTH_LONG);
this.deleteSavedArtefact(a.getId());
}
}
return a_array;
} finally {
cursor.close();
}
}
private Artefact createArtefactFromCursor(Cursor cursor) {
if ( VERBOSE ) Log.v(TAG, "createArtefactFromCursor draft: " + cursor.getInt(8));
if ( VERBOSE ) Log.v(TAG, "createArtefactFromCursor allow comments: " + cursor.getInt(9));
return new Artefact( cursor.getLong(0),
cursor.getLong(1),
cursor.getString(2),
cursor.getString(3),
cursor.getString(4),
cursor.getString(5),
cursor.getLong(6),
cursor.getString(7),
cursor.getInt(8)>0,
cursor.getInt(9)>0);
}
//---deletes a particular item---
public int deleteSavedArtefact(Long id) {
SQLiteDatabase db = this.getWritableDatabase();
int numRecords = db.delete(ArtefactDataSQLHelper.TABLE, BaseColumns._ID + " = ?", new String[] { id.toString() });
if ( VERBOSE ) Log.v(TAG, "deleted '" + numRecords + "' records.");
return numRecords;
}
//---deletes all items---
public int deleteAllSavedArtefacts() {
SQLiteDatabase db = this.getWritableDatabase();
int numRecords = db.delete(ArtefactDataSQLHelper.TABLE, null, null);
if ( VERBOSE ) Log.v(TAG, "deleted '" + numRecords + "' records.");
return numRecords;
}
public long add(String filename, String title, String description, String tags, String journal_id, boolean is_draft, boolean allow_comments) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(ArtefactDataSQLHelper.TIME, System.currentTimeMillis());
values.put(ArtefactDataSQLHelper.FILENAME, filename);
values.put(ArtefactDataSQLHelper.TITLE, title);
values.put(ArtefactDataSQLHelper.DESCRIPTION, description);
values.put(ArtefactDataSQLHelper.TAGS, tags);
values.put(ArtefactDataSQLHelper.JOURNAL_ID, journal_id);
values.put(ArtefactDataSQLHelper.IS_DRAFT, is_draft);
values.put(ArtefactDataSQLHelper.ALLOW_COMMENTS, allow_comments);
if ( VERBOSE ) Log.v(TAG, "add draft: " + is_draft);
if ( VERBOSE ) Log.v(TAG, "add allow comments: " + is_draft);
long numRecords = db.insert(ArtefactDataSQLHelper.TABLE, null, values);
if ( VERBOSE ) Log.v(TAG, "inserted '" + numRecords + "' records.");
return numRecords;
}
public int update(Long id, String filename, String title, String description, String tags, Long saved_id, String journal_id, boolean is_draft, boolean allow_comments) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(ArtefactDataSQLHelper.TIME, System.currentTimeMillis());
// if ( filename != null )
values.put(ArtefactDataSQLHelper.FILENAME, filename);
// if ( title != null )
values.put(ArtefactDataSQLHelper.TITLE, title);
// if ( description != null )
values.put(ArtefactDataSQLHelper.DESCRIPTION, description);
// if ( tags != null )
values.put(ArtefactDataSQLHelper.TAGS, tags);
if ( saved_id != null )
values.put(ArtefactDataSQLHelper.SAVED_ID, saved_id);
// if ( journal_id != null )
values.put(ArtefactDataSQLHelper.JOURNAL_ID, journal_id);
values.put(ArtefactDataSQLHelper.IS_DRAFT, is_draft);
values.put(ArtefactDataSQLHelper.ALLOW_COMMENTS, allow_comments);
if ( VERBOSE ) Log.v(TAG, "update draft: " + is_draft);
if ( VERBOSE ) Log.v(TAG, "update allow comments: " + allow_comments);
int numRecords = db.update(ArtefactDataSQLHelper.TABLE, values, BaseColumns._ID + "= ? ", new String[] { id.toString() });
if ( VERBOSE ) Log.v(TAG, "updated '" + numRecords + "' records.");
return numRecords;
}
}
\ No newline at end of file
package nz.net.catalyst.MaharaDroid.provider;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
public class MaharaProvider extends ContentProvider {
private SQLiteDatabase sqlDB;
private DatabaseHelper dbHelper;
private static final String DATABASE_NAME = "maharadroid_sync.db";
private static final int DATABASE_VERSION = 1;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// create table to store user names
for ( int i = 0; i < GlobalResources.CONTENT_TABLES.length; i++ ) {
db.execSQL("Create table "
+ GlobalResources.CONTENT_TABLES[i]
+ "( _id INTEGER PRIMARY KEY AUTOINCREMENT, ID TEXT, VALUE TEXT);");
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
for ( int i = 0; i < GlobalResources.CONTENT_TABLES.length; i++ ) {
db.execSQL("DROP TABLE IF EXISTS " + GlobalResources.CONTENT_TABLES[i]);
}
onCreate(db);
}
}
public MaharaProvider() {
super();
}
public MaharaProvider(Context context) {
super();
this.dbHelper = new DatabaseHelper(context);
// SQLiteDatabase db = this.getReadableDatabase();
// try {
// db.execSQL("ALTER TABLE " + TABLE + " ADD COLUMN " + SAVED_ID + " integer;");
// } catch (SQLException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
}
@Override
public int delete(Uri uri, String s, String[] as) {
sqlDB = dbHelper.getWritableDatabase();
return sqlDB.delete(uri.getLastPathSegment(), s, as);
}
@Override
public String getType(Uri uri) {
return null;
}
public Uri insert(Uri uri, ContentValues contentvalues) {
if ( contentvalues == null )
return null;
// get database to insert records
sqlDB = dbHelper.getWritableDatabase();
// insert record in user table and get the row number of recently inserted record
long rowId = sqlDB.insert(uri.getLastPathSegment(), "", contentvalues);
if (rowId > 0) {
return Uri.withAppendedPath(uri, Long.toString(rowId));
}
throw new SQLException("Failed to insert row into " + uri);
}
@Override
public boolean onCreate() {
dbHelper = new DatabaseHelper(getContext());
return (dbHelper == null) ? false : true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
SQLiteDatabase db = dbHelper.getReadableDatabase();
qb.setTables(uri.getLastPathSegment());
Cursor c = qb.query(db, projection, selection, null, null, null,
sortOrder);
//c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
@Override
public int update(Uri uri, ContentValues contentvalues, String s,
String[] as) {
return 0;
}
}
......@@ -7,7 +7,8 @@ import org.json.JSONObject;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.data.ArtefactDataSQLHelper;
import nz.net.catalyst.MaharaDroid.data.ArtefactUtils;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.upload.http.RestClient;
import android.accounts.Account;
import android.content.AbstractThreadedSyncAdapter;
......@@ -61,7 +62,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
// application preferences
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String authSyncURI = Utils.getSyncURLPref(mContext);
String authSyncURI = SyncUtils.getSyncURLPref(mContext);
String username = mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_username_key).toString(),
"");
......@@ -70,7 +71,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
String sync_key = mContext.getResources().getString(R.string.pref_sync_time_key);
Long lastsync = Long.parseLong(mPrefs.getString(sync_key, "0"));
String syncNotifications = Utils.getSyncNotificationsPref(mContext);
String syncNotifications = SyncUtils.getSyncNotificationsPref(mContext);
if ( VERBOSE ) Log.v(TAG, "Synchronizing Mahara account '" + username + "', " + "'" + token + "' for details as of lastsync '" + lastsync + "'");
......@@ -80,17 +81,14 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
if ( Utils.updateTokenFromResult(result, mContext) == null ) {
++syncResult.stats.numAuthExceptions;
} else if ( result.has("sync") ) {
syncResult.stats.numUpdates = Utils.processSyncResults(result, myProvider, mContext, sync_key);
syncResult.stats.numUpdates += SyncUtils.processSyncResults(result, myProvider, mContext, sync_key);
// OK sync success - now push any uploads
// Check if we have appropriate data access
if ( Utils.canUpload(mContext) ) {
if ( VERBOSE ) Log.v(TAG, "onPerformSync: canUpload so uploadAllSavedArtefacts");
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
artefactData.uploadAllSavedArtefacts();
// syncResult.stats.numUpdates = // gets increased
artefactData.close();
syncResult.stats.numUpdates += ArtefactUtils.uploadAllSavedArtefacts(mContext);
}
} else {
++syncResult.stats.numParseExceptions;
......
......@@ -29,16 +29,22 @@ import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.data.Artefact;
import nz.net.catalyst.MaharaDroid.data.ArtefactDataSQLHelper;
import nz.net.catalyst.MaharaDroid.data.ArtefactUtils;
import nz.net.catalyst.MaharaDroid.data.SyncUtils;
import nz.net.catalyst.MaharaDroid.ui.about.AboutActivity;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;