Commit d0a21526 authored by Alan McNatty's avatar Alan McNatty
Browse files

Fixed bugs introduced in last commit (thanks to Jon).

Also after some testing have got the periodic sync functionality working again.
parent ec801b93
...@@ -128,7 +128,7 @@ ...@@ -128,7 +128,7 @@
<string name="uploadsaved">Upload saved</string> <string name="uploadsaved">Upload saved</string>
<string name="uploadnotavailable">Sorry you can only uploaded files.</string> <string name="uploadnotavailable">Sorry you can only uploaded files.</string>
<string name="capturefailed">Sorry there was a problem capturing that image.</string> <string name="capturefailed">Sorry there was a problem capturing that image.</string>
<string name="uploadingartifact">Uploading #8230;</string> <string name="uploadingartifact">Uploading &#8230;</string>
<string name="uploading">Uploading</string> <string name="uploading">Uploading</string>
<string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string> <string name="uploadnoconnection">Sorry you don\'t have a working data connection to upload at this time.</string>
<string name="uploadincomplete">Sorry you must enter a title and an entry for journal posts</string> <string name="uploadincomplete">Sorry you must enter a title and an entry for journal posts</string>
...@@ -159,7 +159,7 @@ ...@@ -159,7 +159,7 @@
<string name="load_config_success">Successfully loaded the configuration file.</string> <string name="load_config_success">Successfully loaded the configuration file.</string>
<string name="scan_not_available">Sorry you need to install ZXing Barcode Scanner for this.</string> <string name="scan_not_available">Sorry you need to install ZXing Barcode Scanner for this.</string>
<string name="login_authenticating">Authenticating #8230;</string> <string name="login_authenticating">Authenticating &#8230;</string>
<string name="only_one_account">Currently you may only have at most one account at any one time.</string> <string name="only_one_account">Currently you may only have at most one account at any one time.</string>
<string name="auth_result_no_connection">Server address or port number incorrect</string> <string name="auth_result_no_connection">Server address or port number incorrect</string>
......
<!-- API Version 7 requires the accountType attribute to be hard-coded as a 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" <sync-adapter xmlns:android="http://schemas.android.com/apk/res/android"
android:contentAuthority="nz.net.catalyst.MaharaDroid" android:contentAuthority="nz.net.catalyst.MaharaDroid"
android:accountType="nz.net.catalyst.MaharaDroid.account"/> android:accountType="nz.net.catalyst.MaharaDroid.account"
\ No newline at end of file android:supportsUploading="true"
android:userVisible="true"
/>
\ No newline at end of file
...@@ -52,6 +52,7 @@ import android.os.Bundle; ...@@ -52,6 +52,7 @@ import android.os.Bundle;
import android.os.RemoteException; import android.os.RemoteException;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.provider.SyncStateContract.Constants;
import android.util.Log; import android.util.Log;
public class Utils { public class Utils {
...@@ -347,15 +348,41 @@ public class Utils { ...@@ -347,15 +348,41 @@ public class Utils {
Long periodic_sync = Long.valueOf(mPrefs.getString(context.getResources().getString(R.string.pref_sync_periodic_key), "0")); Long periodic_sync = Long.valueOf(mPrefs.getString(context.getResources().getString(R.string.pref_sync_periodic_key), "0"));
if ( periodic_sync == null || periodic_sync <= 0 ) { if ( periodic_sync == null || periodic_sync <= 0 ) {
// Note - should only ever have 1
List<PeriodicSync> ps = ContentResolver.getPeriodicSyncs(account, GlobalResources.ACCOUNT_TYPE);
while ( ps != null && ! ps.isEmpty() ) {
if ( periodic_sync == 0 || ps.get(0).period != periodic_sync ) {
ContentResolver.removePeriodicSync(account, GlobalResources.ACCOUNT_TYPE, ps.get(0).extras);
if ( VERBOSE ) Log.v(TAG, "setPeriodicSync removing periodic sync '" + ps.get(0).period + "'");
}
ps.remove(0);
}
return; return;
} }
periodic_sync = periodic_sync * 60; // convert to seconds
if ( DEBUG ) Log.v(TAG, "setPeriodicSync of '" + periodic_sync + "' seconds");
Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
bundle.putBoolean(GlobalResources.EXTRAS_SYNC_IS_PERIODIC, true); bundle.putBoolean( ContentResolver.SYNC_EXTRAS_UPLOAD, true );
ContentResolver.addPeriodicSync(account, GlobalResources.SYNC_AUTHORITY, bundle, periodic_sync * 60); ContentResolver.addPeriodicSync(account, GlobalResources.SYNC_AUTHORITY, bundle, periodic_sync);
}
public static Account getAccount(Context context) {
AccountManager mAccountManager = AccountManager.get(context);
Account account = null;
// if ( periodic_sync != null && periodic_sync > 0 ) {
//
// TODO replicated from AuthenticatorActivity
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
if ( mAccounts.length > 0 ) {
// Just pick the first one .. support multiple accounts can come later.
account = mAccounts[0];
}
return account;
} }
public static String[][] getJournals(String nullitem, Context context) { public static String[][] getJournals(String nullitem, Context context) {
return getValues("blog", nullitem, context); return getValues("blog", nullitem, context);
......
...@@ -59,8 +59,7 @@ public class MaharaAuthHandler { ...@@ -59,8 +59,7 @@ public class MaharaAuthHandler {
// application preferences // application preferences
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String authSyncURI = mPrefs.getString(mContext.getResources().getString(R.string.pref_sync_url_key).toString(), String authSyncURI = Utils.getSyncURLPref(mContext);
mContext.getResources().getString(R.string.pref_sync_url_default).toString());
String token = mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_token_key), ""); String token = mPrefs.getString(mContext.getResources().getString(R.string.pref_auth_token_key), "");
......
...@@ -47,8 +47,8 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{ ...@@ -47,8 +47,8 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
ContentProviderClient myProvider, SyncResult syncResult) { ContentProviderClient myProvider, SyncResult syncResult) {
if ( VERBOSE ) Log.v(TAG, "onPerformSync: Sync request issued"); if ( VERBOSE ) Log.v(TAG, "onPerformSync: Sync request issued");
// One way or another, delay follow-up syncs for another 10 minutes. // // TODO not sure we need this (delay follow-up syncs for another 10 minutes.)
syncResult.delayUntil = 600; // syncResult.delayUntil = 600;
Date now = new Date(); Date now = new Date();
if (sLastCompletedSync > 0 && now.getTime() - sLastCompletedSync < 5000) { if (sLastCompletedSync > 0 && now.getTime() - sLastCompletedSync < 5000) {
...@@ -57,17 +57,6 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{ ...@@ -57,17 +57,6 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
return; 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 //sync
// application preferences // application preferences
SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
...@@ -86,11 +75,22 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{ ...@@ -86,11 +75,22 @@ public class ThreadedSyncAdapter extends AbstractThreadedSyncAdapter{
JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, mContext); JSONObject result = RestClient.AuthSync(authSyncURI, token, username, lastsync, mContext);
if ( Utils.updateTokenFromResult(result, mContext) == null ) { if ( Utils.updateTokenFromResult(result, mContext) == null ) {
syncResult.stats.numAuthExceptions++; ++syncResult.stats.numAuthExceptions;
} else if ( result.has("sync") ) { } else if ( result.has("sync") ) {
syncResult.stats.numUpdates = Utils.processSyncResults(result, myProvider, mContext); syncResult.stats.numUpdates = Utils.processSyncResults(result, myProvider, mContext);
// 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();
}
} else { } else {
syncResult.stats.numParseExceptions++; ++syncResult.stats.numParseExceptions;
} }
} }
......
...@@ -313,8 +313,6 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O ...@@ -313,8 +313,6 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
} }
((CheckBox) convertView.findViewById(R.id.txtArtefactIsDraft)).setChecked(art.getIsDraft()); ((CheckBox) convertView.findViewById(R.id.txtArtefactIsDraft)).setChecked(art.getIsDraft());
((CheckBox) convertView.findViewById(R.id.txtArtefactAllowComments)).setChecked(art.getAllowComments()); ((CheckBox) convertView.findViewById(R.id.txtArtefactAllowComments)).setChecked(art.getAllowComments());
if ( DEBUG ) Log.d(TAG, "getChildView draft: " + art.getIsDraft());
if ( DEBUG ) Log.d(TAG, "getChildView allow comments: " + art.getAllowComments());
} }
// TDODO hide layout // TDODO hide layout
l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalLayout); l = (LinearLayout)convertView.findViewById(R.id.ArtefactJournalLayout);
......
...@@ -61,6 +61,7 @@ import com.google.zxing.integration.android.IntentIntegrator; ...@@ -61,6 +61,7 @@ import com.google.zxing.integration.android.IntentIntegrator;
import nz.net.catalyst.MaharaDroid.GlobalResources; import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig; import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R; import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity; import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import android.accounts.Account; import android.accounts.Account;
...@@ -222,44 +223,8 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe ...@@ -222,44 +223,8 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe
} else if ( key == getString(R.string.pref_base_url_key)) { } else if ( key == getString(R.string.pref_base_url_key)) {
authDetailsChanged = true; authDetailsChanged = true;
} else if ( key == getString(R.string.pref_sync_periodic_key)) { } else if ( key == getString(R.string.pref_sync_periodic_key)) {
Account account = Utils.getAccount(this);
AccountManager mAccountManager = AccountManager.get(this); Utils.setPeriodicSync(account, this);
Account account;
// if ( periodic_sync != null && periodic_sync > 0 ) {
//
// TODO replicated from AuthenticatorActivity
Account[] mAccounts = mAccountManager.getAccountsByType(GlobalResources.ACCOUNT_TYPE);
if ( mAccounts.length > 0 ) {
// Just pick the first one .. support multiple accounts can come later.
account = mAccounts[0];
} else {
return;
}
Bundle bundle = new Bundle();
bundle.putBoolean(GlobalResources.EXTRAS_SYNC_IS_PERIODIC, true);
Long periodic_sync = Long.valueOf(sharedPreferences.getString(key, "0"));
if ( periodic_sync == null ) periodic_sync = (long) 0;
boolean exists = false;
// Note - should only ever have 1
List<PeriodicSync> ps = ContentResolver.getPeriodicSyncs(account, GlobalResources.ACCOUNT_TYPE);
while ( ps != null && ! ps.isEmpty() ) {
if ( periodic_sync == 0 || ps.get(0).period != periodic_sync ) {
ContentResolver.removePeriodicSync(account, GlobalResources.ACCOUNT_TYPE, ps.get(0).extras);
if ( VERBOSE ) Log.v(TAG, "Removing periodic sync '" + ps.get(0).period + "'");
} else if ( periodic_sync != null && periodic_sync > 0 && ps.get(0).period != periodic_sync ) {
exists = true;
}
ps.remove(0);
}
if ( ! exists && periodic_sync > 0 ) {
ContentResolver.addPeriodicSync(account, GlobalResources.ACCOUNT_TYPE, bundle, periodic_sync * 60);
if ( VERBOSE ) Log.v(TAG, "Adding periodic sync '" + periodic_sync + "'");
}
} }
} }
......
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