Commit 7c53986b authored by Alan McNatty's avatar Alan McNatty
Browse files

A clean-up push - missed some obvious bugs

parent c283d97e
......@@ -22,12 +22,12 @@
<string name="pref_upload_url_key">upload.uri</string>
<string name="pref_upload_url_title">Upload URI</string>
<string name="pref_upload_url_summary">Enter the URL to post files to Mahara</string>
<string name="pref_upload_url_default">http://master.dev.mahara.org/api/mobile/upload.php</string>
<string name="pref_upload_url_default">http://solent-mahara.catalystdemo.co.uk/api/mobile/upload.php</string>
<string name="pref_sync_url_key">sync.uri</string>
<string name="pref_sync_url_title">Sync URI</string>
<string name="pref_sync_url_summary">Enter the sync URL to Mahara</string>
<string name="pref_sync_url_default">http://master.dev.mahara.org/api/mobile/sync.php</string>
<string name="pref_sync_url_default">http://solent-mahara.catalystdemo.co.uk/api/mobile/sync.php</string>
<string name="pref_auth_username_key">auth.username</string>
<string name="pref_auth_username_title">Username</string>
......
......@@ -214,7 +214,7 @@ public class Utils {
try {
JSONObject syncObj = result.getJSONObject("sync");
//Log.i(TAG, syncObj.toString());
if ( syncObj.has("activity") ) {
if ( syncObj.has("activity") && syncObj.optJSONArray("activity") != null ) {
JSONArray notArr = syncObj.getJSONArray("activity");
for (int i=0; i<notArr.length(); i++) {
Utils.showNotification(Integer.parseInt(notArr.getJSONObject(i).getString("id")),
......@@ -223,15 +223,15 @@ public class Utils {
numUpdates++;
}
}
if ( syncObj.has("tags") ) {
if ( syncObj.has("tags") && syncObj.optJSONArray("tags") != null ) {
long newItems = updateListPreferenceFromJSON(myProvider, syncObj.getJSONArray("tags"), "tag");
numUpdates += newItems;
}
if ( syncObj.has("blogs") ) {
if ( syncObj.has("blogs") && syncObj.optJSONArray("blogs") != null ) {
long newItems = updateListPreferenceFromJSON(myProvider, syncObj.getJSONArray("blogs"), "blog");
numUpdates += newItems;
}
if ( syncObj.has("folders") ) {
if ( syncObj.has("folders") && syncObj.optJSONArray("folders") != null ) {
long newItems = updateListPreferenceFromJSON(myProvider, syncObj.getJSONArray("folders"), "folder");
numUpdates += newItems;
}
......
......@@ -32,7 +32,7 @@ import android.os.Parcelable;
import android.util.Log;
public class Artefact extends Object implements Parcelable {
private Long id;
private long id = 0;
private long time;
private String filename;
private String title;
......@@ -171,6 +171,7 @@ public class Artefact extends Object implements Parcelable {
i.putExtra("artefact", (Parcelable) this);
if ( auto )
i.putExtra("auto", "yes please");
// TODO - needs to be a start service for result or we need to check post upload and delete on success.
mContext.startService(i);
}
public void delete(Context mContext) {
......@@ -191,7 +192,7 @@ public class Artefact extends Object implements Parcelable {
public void save(Context mContext) {
// TODO Auto-generated method stub
ArtefactDataSQLHelper artefactData = new ArtefactDataSQLHelper(mContext);
if ( id != null ) { // update
if ( id != 0 ) { // update
artefactData.update(id, filename, title, description, tags, saved_id, journal_id);
} else { // add
artefactData.add(filename, title, description, tags, journal_id);
......
......@@ -23,7 +23,9 @@ package nz.net.catalyst.MaharaDroid.data;
import org.json.JSONException;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.syncadapter.ThreadedSyncAdapter;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
......@@ -35,6 +37,12 @@ import android.util.Log;
/** Helper to the database, manages versions and creation */
public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
static final String TAG = LogConfig.getLogTag(ThreadedSyncAdapter.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 = 1;
private static Context mContext;
......@@ -107,12 +115,13 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
if ( uploaded == null ) {
uploaded = false;
}
//Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null,
// null, null);
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, SAVED_ID + " = NULL ", null,
null, null, null);
Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, null, null, null,
null, null);
// Cursor cursor = db.query(ArtefactDataSQLHelper.TABLE, null, SAVED_ID + " != 0 ", null,
// null, null, null);
//startManagingCursor(cursor);
if ( VERBOSE ) Log.v(TAG, "uploadAllSavedArtefacts: returned " + cursor.getCount() + " records.");
while (cursor.moveToNext()) {
Long id = cursor.getLong(0);
......@@ -123,7 +132,9 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
String tags = cursor.getString(5);
Long saved_id = cursor.getLong(6);
String journal_id = cursor.getString(7);
if ( VERBOSE ) Log.v(TAG, "uploadAllSavedArtefacts: saved_id = " + saved_id);
if ( filename == null ) {
continue;
}
......
......@@ -5,9 +5,11 @@ import java.util.Date;
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.ui.ArtifactSettingsActivity;
import nz.net.catalyst.MaharaDroid.upload.http.RestClient;
import android.accounts.Account;
import android.content.AbstractThreadedSyncAdapter;
......@@ -28,9 +30,13 @@ import android.util.Log;
*/
public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
static final String TAG = LogConfig.getLogTag(ThreadedSyncAdapter.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 Context mContext;
private static final String TAG = "ThreadedSyncAdapter";
public static final String EXTRAS_SYNC_IS_PERIODIC = "MaharaDroid.periodic";
static final String SYNC_AUTOMATICALLY_PREF = "sync_automatically";
......@@ -49,7 +55,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
@Override
public void onPerformSync(Account account, Bundle extras, String authority,
ContentProviderClient myProvider, SyncResult syncResult) {
Log.e(TAG, "Sync request issued");
if ( VERBOSE ) Log.v(TAG, "onPerformSync: Sync request issued");
// One way or another, delay follow-up syncs for another 10 minutes.
syncResult.delayUntil = 600;
......@@ -69,7 +75,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
Date now = new Date();
if (sLastCompletedSync > 0 && now.getTime() - sLastCompletedSync < 5000) {
// If the last sync completed 10 seconds ago, ignore this request anyway.
Log.e(TAG, "Sync was CANCELLED because a sync completed within the past 5 seconds.");
if ( DEBUG ) Log.d(TAG, "Sync was CANCELLED because a sync completed within the past 5 seconds.");
return;
}
......@@ -86,7 +92,7 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
"");
Long lastsync = mPrefs.getLong("lastsync", 0);
Log.v(TAG, "Synchronizing Mahara account '" + username + "', " + "'" + token + "' and lastsync '" + lastsync + "'");
if ( VERBOSE ) Log.v(TAG, "Synchronizing Mahara account '" + username + "', " + "'" + token + "' and lastsync '" + lastsync + "'");
// Get latest details from sync
JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, mContext);
......@@ -98,6 +104,8 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
// Now push any saved posts as 2nd part of sync
// 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(false);
artefactData.close();
......
......@@ -314,7 +314,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
String journal = journalKeys[(int) ((Spinner) findViewById(R.id.upload_journal_spinner)).getSelectedItemId()];
String filename = null;
if ( id != null ) {
if ( id != null && id.length() > 0 ) {
a.load(mContext, Long.valueOf(id));
a.setTitle(title);
a.setDescription(description);
......@@ -324,7 +324,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
if ( VERBOSE ) Log.v(TAG, "InitiateUpload loading artefact [" + id + "]");
} else {
a = new Artefact(null, null, title, description, tags, null, journal);
a = new Artefact((long) 0, null, title, description, tags, null, journal);
if ( VERBOSE ) Log.v(TAG, "InitiateUpload creating new artefact object");
}
......@@ -342,12 +342,11 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
} else {
for ( int i = 0; i < uris.length; i++ ) {
filename = Utils.getFilePath(this, uris[i]);
filename = ( uris[i] == null ) ? null : Utils.getFilePath(this, uris[i]);
a.setFilename(filename);
if ( VERBOSE ) Log.v(TAG, "InitiateUpload have file, name is '" + filename + "'");
if (filename == null)
continue;
String new_title = title;
if ( isMulti ) {
// add a 1 of X suffix
......@@ -355,7 +354,6 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
if ( VERBOSE ) Log.v(TAG, "InitiateUpload have multi-file post, title is '" + new_title + "'");
}
a.setFilename(filename);
uploader_intent = new Intent(this, TransferService.class);
uploader_intent.putExtra("artefact", a);
if ( VERBOSE ) Log.v(TAG, "InitiateUpload with file [" + i + "] - about to start service");
......@@ -379,7 +377,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
String journal = journalKeys[(int) ((Spinner) findViewById(R.id.upload_journal_spinner)).getSelectedItemId()];
String filename = null;
if ( id != null ) {
if ( id != null && id.length() > 0 ) {
if ( VERBOSE ) Log.v(TAG, "InitiateSave id is not null - loading ... [" + id + "]");
a.load(mContext, Long.valueOf(id));
......@@ -390,7 +388,7 @@ public class ArtifactSettingsActivity extends Activity implements OnClickListene
a.setFilename(filename);
} else {
if ( VERBOSE ) Log.v(TAG, "InitiateSave id is null, creating new artefact object");
a = new Artefact(Long.valueOf(id), null, title, description, tags, null, journal);
a = new Artefact((long) 0, null, title, description, tags, null, journal);
}
if ( uris == null || uris.length == 0 ) {
......
......@@ -95,7 +95,7 @@ public class TransferService extends Service {
//m_uploads.clear();
} else if ( result.has("success") ) {
Utils.updateTokenFromResult(result, mContext);
if ( result.has("id") ) {
// if ( result.has("id") ) {
// try {
// a.setId(result.getLong("id"));
// a.save(mContext);
......@@ -104,7 +104,7 @@ public class TransferService extends Service {
// e.printStackTrace();
// }
a.delete(mContext);
}
// }
publishProgress(new String[]{"finish", id, a.getTitle()});
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment