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

Fixed account and sync which I broke ;)

parent 8641c806
......@@ -21,16 +21,11 @@
package nz.net.catalyst.MaharaDroid;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.syncadapter.ThreadedSyncAdapter;
import android.accounts.Account;
import android.app.Notification;
import android.app.NotificationManager;
......@@ -42,8 +37,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
......@@ -301,7 +294,7 @@ public class Utils {
cursor = myProvider.query(uri, new String[] { "ID", "VALUE" }, null, null, null);
} catch (RemoteException e) {
// TODO Auto-generated catch block
Log.e(TAG, "Failed to aquire content provider for query - is ther an active sync running?");
Log.e(TAG, "Failed to aquire content provider for query - is there an active sync running?");
e.printStackTrace();
}
......
......@@ -17,7 +17,6 @@
package nz.net.catalyst.MaharaDroid.authenticator;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import nz.net.catalyst.MaharaDroid.syncadapter.ThreadedSyncAdapter;
import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
......@@ -73,9 +72,9 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
// Just pick the first one .. support multiple accounts can come later.
mUsername = mAccounts[0].name;
}
mRequestNewAccount = mUsername == null;
mRequestNewAccount = ( mUsername == null );
if ( DEBUG ) Log.d(TAG, "AuthenticatorActivity request new: " + mRequestNewAccount);
if ( DEBUG ) Log.d(TAG, "AuthenticatorActivity/onCreate request new: " + mRequestNewAccount);
MaharaAuthHandler.attemptAuth(mUsername, mHandler, AuthenticatorActivity.this);
finish();
......@@ -86,16 +85,21 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity {
*/
public void onAuthenticationResult(String username, String authToken) {
// If we have an auth token create the account
if ( DEBUG ) Log.d(TAG, "AuthenticatorActivity/onAuthenticationResult request new: " + mRequestNewAccount);
if (authToken != null) {
final Account account = new Account(username, GlobalResources.ACCOUNT_TYPE);
if (mRequestNewAccount) {
mAccountManager.addAccountExplicitly(account, null, null);
Boolean newAccountCreated = mAccountManager.addAccountExplicitly(account, null, null);
if ( DEBUG ) Log.d(TAG, "onAuthenticationResult new account created: " + newAccountCreated);
// Set contacts sync for this account.
ContentResolver.setSyncAutomatically(account, GlobalResources.SYNC_AUTHORITY, true);
ContentResolver.setIsSyncable(account, GlobalResources.SYNC_AUTHORITY, 1);
ContentResolver.requestSync(account, GlobalResources.SYNC_AUTHORITY, null);
// ContentResolver.requestSync(account, GlobalResources.SYNC_AUTHORITY, null);
Utils.setPeriodicSync(account, getApplicationContext());
}
......
......@@ -102,6 +102,7 @@ public class MaharaAuthHandler {
}
handler.post(new Runnable() {
public void run() {
((AuthenticatorActivity) context).onAuthenticationResult(username, authToken);
}
});
}
......
......@@ -22,15 +22,11 @@
package nz.net.catalyst.MaharaDroid.data;
import java.io.File;
import java.util.List;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.ui.ArtefactExpandableListAdapterActivity;
import nz.net.catalyst.MaharaDroid.ui.ArtifactSettingsActivity;
import nz.net.catalyst.MaharaDroid.upload.TransferService;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
......
......@@ -22,7 +22,6 @@
package nz.net.catalyst.MaharaDroid.data;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
......@@ -40,7 +39,7 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
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 final int DATABASE_VERSION = 2;
private static Context mContext;
// Table name
......@@ -61,9 +60,9 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
public ArtefactDataSQLHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
mContext = context;
// SQLiteDatabase db = this.getReadableDatabase();
SQLiteDatabase db = this.getReadableDatabase();
//db.execSQL("DROP TABLE " + TABLE + "; ");
// db.execSQL("DROP TABLE " + TABLE + "; ");
// this.onCreate(db);
// String sql = "alter table " + TABLE + " ADD COLUMN " + IS_DRAFT + " boolean; ";
......@@ -81,8 +80,8 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
+ DESCRIPTION + " text, "
+ TAGS + " text, "
+ SAVED_ID + " integer, "
+ JOURNAL_ID + " text "
+ IS_DRAFT + " boolean "
+ JOURNAL_ID + " text, "
+ IS_DRAFT + " boolean, "
+ ALLOW_COMMENTS + " boolean "
+ ");";
if ( DEBUG ) Log.d("LogData", "onCreate: " + sql);
......@@ -95,8 +94,8 @@ public class ArtefactDataSQLHelper extends SQLiteOpenHelper {
return;
String sql = null;
// Version 7 is the first version with SQL
if (oldVersion < 10) {
// Version 1 is the first version with SQL
if (oldVersion < 2) {
db.execSQL("DROP TABLE " + TABLE + "; ");
this.onCreate(db);
Log.d("EventsData", "onUpgrade : " + sql);
......
package nz.net.catalyst.MaharaDroid.syncadapter;
import java.util.Date;
import java.util.List;
import org.json.JSONObject;
......@@ -11,14 +9,12 @@ 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;
import android.content.ContentProviderClient;
import android.content.ContentResolver;
import android.content.Context;
import android.content.PeriodicSync;
import android.content.SharedPreferences;
import android.content.SyncResult;
import android.os.Bundle;
......
......@@ -101,15 +101,15 @@ public class ArtefactExpandableListAdapterActivity extends Activity implements O
public void onResume() {
super.onResume();
// if ( DEBUG ) Log.d(TAG, "onResume() calls loadSavedArtefacts");
//
// loadSavedArtefacts();
if ( DEBUG ) Log.d(TAG, "onResume() calls loadSavedArtefacts");
loadSavedArtefacts();
}
public void onStart() {
super.onStart();
if ( DEBUG ) Log.d(TAG, "onStart() calls loadSavedArtefacts");
loadSavedArtefacts();
// if ( DEBUG ) Log.d(TAG, "onStart() calls loadSavedArtefacts");
//
// loadSavedArtefacts();
}
@Override
......
......@@ -44,7 +44,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
......@@ -63,7 +62,6 @@ import nz.net.catalyst.MaharaDroid.GlobalResources;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.R;
import nz.net.catalyst.MaharaDroid.authenticator.AuthenticatorActivity;
import nz.net.catalyst.MaharaDroid.syncadapter.ThreadedSyncAdapter;
import android.accounts.Account;
import android.accounts.AccountManager;
......
......@@ -45,7 +45,6 @@ import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
public class TransferService extends Service {
static final String TAG = LogConfig.getLogTag(TransferService.class);
......
......@@ -33,7 +33,6 @@ import org.apache.http.entity.mime.MultipartEntity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
/*
* The MultipartEntityMonitored class is taken from the MultipartEntityMonitored class
......
......@@ -38,7 +38,6 @@ import java.util.TreeMap;
import java.util.Vector;
import nz.net.catalyst.MaharaDroid.LogConfig;
import nz.net.catalyst.MaharaDroid.Utils;
import nz.net.catalyst.MaharaDroid.upload.http.MultipartEntityMonitored;
import org.apache.http.HttpEntity;
......
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