Commit ec801b93 authored by Alan McNatty's avatar Alan McNatty

Some bug fixes around the default folder (Utils + TransferService), removed...

Some bug fixes around the default folder (Utils + TransferService), removed some null code from the sync adapter and authenticator activity and simplified my stub for forced sync (which may be removed as it might not be needed).
parent 54093a9d
......@@ -76,10 +76,7 @@ public class Utils {
return;
}
Bundle bundle = new Bundle();
// bundle.putBoolean(GlobalResources.EXTRAS_SYNC_IS_PERIODIC, true);
ContentResolver.requestSync(account, GlobalResources.ACCOUNT_TYPE, bundle);
ContentResolver.requestSync(account, GlobalResources.ACCOUNT_TYPE, null);
}
public static boolean canUpload(Context context) {
......@@ -367,6 +364,10 @@ public class Utils {
public static String[][] getTags(String nullitem, Context context) {
return getValues("tag", nullitem, context);
}
public static String[][] getFolders(String nullitem, Context context) {
return getValues("folder", nullitem, context);
}
private static String[][] getValues(String type, String nullitem, Context context) {
Uri uri = Uri.parse("content://" + GlobalResources.CONTENT_URL + "/" + type);
......
......@@ -99,6 +99,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
// Set contacts sync for this account.
ContentResolver.setSyncAutomatically(account, GlobalResources.SYNC_AUTHORITY, true);
ContentResolver.setIsSyncable(account, GlobalResources.SYNC_AUTHORITY, 1);
//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());
......
......@@ -4,7 +4,6 @@ import java.util.Date;
import org.json.JSONObject;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.Utils;
......@@ -13,7 +12,6 @@ import nz.net.catalyst.MaharaDroid.upload.http.RestClient;
import android.accounts.Account;
import android.content.AbstractThreadedSyncAdapter;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SyncResult;
......@@ -37,12 +35,6 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
private Context mContext;
static final String SYNC_AUTOMATICALLY_PREF = "sync_automatically";
static final String SYNC_FREQUENCY_PREF = "sync_frequency";
public static final boolean DEFAULT_SYNC_AUTOMATICALLY = false;
public static final long DEFAULT_SYNC_FREQUENCY = 900; // 15 minutes for testing
private static long sLastCompletedSync = 0;
public ThreadedSyncAdapter(Context context) {
......@@ -58,18 +50,6 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
// One way or another, delay follow-up syncs for another 10 minutes.
syncResult.delayUntil = 600;
boolean manual = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false);
boolean ignoreSettings = extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false);
boolean isPeriodic = extras.getBoolean(GlobalResources.EXTRAS_SYNC_IS_PERIODIC, false);
if (manual || ignoreSettings) {
Log.i(TAG, "Starting a MANUAL sync");
manual = true;
} else if (isPeriodic) {
Log.i(TAG, "Starting a scheduled PERIODIC sync");
} else {
Log.i(TAG, "Starting an AUTOMATIC sync from a network tickle");
}
Date now = new Date();
if (sLastCompletedSync > 0 && now.getTime() - sLastCompletedSync < 5000) {
// If the last sync completed 10 seconds ago, ignore this request anyway.
......@@ -77,12 +57,22 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
return;
}
// Push any saved posts befiore we 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();
// syncResult.stats.numUpdates = // gets increased
artefactData.close();
}
//sync
// application preferences
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String authSyncURI = mPrefs.getString(mContext.getResources().getString(R.string.pref_sync_url_key).toString(),
mContext.getResources().getString(R.string.pref_sync_url_default).toString());
String authSyncURI = Utils.getSyncURLPref(mContext);
String username = mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_username_key).toString(),
"");
......@@ -99,15 +89,6 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
syncResult.stats.numAuthExceptions++;
} else if ( result.has("sync") ) {
syncResult.stats.numUpdates = Utils.processSyncResults(result, myProvider, mContext);
// 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();
artefactData.close();
}
} else {
syncResult.stats.numParseExceptions++;
}
......
......@@ -157,8 +157,17 @@ public class TransferService extends IntentService {
private String getUploadFolderPref() {
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String[][] folderItems = Utils.getFolders(null, mContext);
if ( mPrefs.getBoolean(mContext.getResources().getString(R.string.pref_upload_folder_default_key), false) ) {
return mPrefs.getString(mContext.getResources().getString(R.string.pref_upload_folder_key), "");
String folder_key = mPrefs.getString(mContext.getResources().getString(R.string.pref_upload_folder_key), "");
for (int i=0; i<folderItems[0].length; i++) {
if ( folder_key.equals(folderItems[0][i]) ) {
return folderItems[1][i];
}
}
}
return "";
}
......
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