Skip to content

Commit

Permalink
Merge pull request #314 from spacecowboy/SyncFix
Browse files Browse the repository at this point in the history
Update api key and fix sync error
  • Loading branch information
spacecowboy committed Oct 25, 2015
2 parents 56eda36 + 2c0251b commit 9c5f80b
Show file tree
Hide file tree
Showing 12 changed files with 531 additions and 1,321 deletions.
6 changes: 4 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ repositories {
// Version number
def versionMajor = 5 // Major UI overhauls
def versionMinor = 7 // Some new functionality
def versionPatch = 0 // Bug fixes
def versionBuild = 1 // Bump for dogfood builds, public betas, etc.
def versionPatch = 1 // Bug fixes
def versionBuild = 2 // Bump for dogfood builds, public betas, etc.

// Version name from git
def getVersionName = { ->
Expand Down Expand Up @@ -144,6 +144,8 @@ dependencies {
compile 'com.nononsenseapps:filepicker:1.2.0'
// OrgParser
compile 'org.cowboyprogrammer:orgparser:1.1'
// For Sync
compile 'com.squareup.retrofit:retrofit:1.6.1'
// Included libraries
compile project(':external:ActionBar-PullToRefresh')
compile project(':external:datetimepicker')
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/nononsenseapps/build/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static Properties getProperties(final Context context) {

public static String getGtasksApiKey(final Context context) {
return getProperties(context).getProperty(KEY_GTASKS_API_KEY,
"AIzaSyCAjRk2GfPARlIU3JsaEiExLMtj_rdN2i4");
"AIzaSyBtUvSWg41WVi9E3W1VaqDMlJ07a3B6JOs");
}

public static String getKeyDropboxAPI(final Context context) {
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/nononsenseapps/helpers/SyncHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public static boolean isGTasksConfigured(final Context context) {
final String accountName = prefs.getString(SyncPrefs.KEY_ACCOUNT, "");
final boolean syncEnabled = prefs.getBoolean(SyncPrefs.KEY_SYNC_ENABLE,
false);
return syncEnabled & accountName != null & !accountName.equals("");
return syncEnabled && !accountName.isEmpty();
}

private static void requestGTaskSyncNow(final Context context) {
Expand All @@ -88,7 +88,7 @@ private static void requestGTaskSyncNow(final Context context) {

final String accountName = prefs.getString(SyncPrefs.KEY_ACCOUNT, "");

if (accountName != null && !"".equals(accountName)) {
if (!accountName.isEmpty()) {
Account account = SyncPrefs.getAccount(AccountManager.get(context),
accountName);
// Don't start a new sync if one is already going
Expand All @@ -98,6 +98,7 @@ private static void requestGTaskSyncNow(final Context context) {
// in accounts manager. Only use it here where the user has
// manually desired a sync to happen NOW.
options.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
options.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
ContentResolver
.requestSync(account, MyContentProvider.AUTHORITY, options);
// Set last sync time to now
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.nononsenseapps.helpers.SyncHelper;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.database.MyContentProvider;
import com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync;
import com.nononsenseapps.notepad.sync.googleapi.GoogleTasksClient;

/**
* A copy of AccountDialog in SyncPrefs, but extending from support library
Expand Down Expand Up @@ -69,13 +69,12 @@ public void onClick(DialogInterface dialog, int which) {
*
* @param account
*/
public void accountSelected(Account account) {
public void accountSelected(final Account account) {
if (account != null) {
Log.d("prefsActivity", "step one");
Log.d("prefsActivityDialog", "step one");
this.account = account;
// Request user's permission
AccountManager.get(activity).getAuthToken(account,
GoogleTaskSync.AUTH_TOKEN_TYPE, null, activity, this, null);
GoogleTasksClient.getAuthTokenAsync(activity, account, this);
// work continues in callback, method run()
}
}
Expand All @@ -87,17 +86,18 @@ public void accountSelected(Account account) {
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Log.d("prefsActivity", "step two");
Log.d("prefsActivityDialog", "step two");
// If the user has authorized
// your application to use the
// tasks API
// a token is available.
String token = future.getResult().getString(
AccountManager.KEY_AUTHTOKEN);
// Now we are authorized by the user.
Log.d("prefsActivityDialog", "step two-b: " + token);

if (token != null && !token.equals("") && account != null) {
Log.d("prefsActivity", "step three: " + account.name);
Log.d("prefsActivityDialog", "step three: " + account.name);
SharedPreferences customSharedPreference = PreferenceManager
.getDefaultSharedPreferences(activity);
customSharedPreference.edit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.accounts.AccountManagerFuture;
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
Expand All @@ -48,7 +49,7 @@
import com.nononsenseapps.notepad.BuildConfig;
import com.nononsenseapps.notepad.R;
import com.nononsenseapps.notepad.database.MyContentProvider;
import com.nononsenseapps.notepad.sync.googleapi.GoogleTaskSync;
import com.nononsenseapps.notepad.sync.googleapi.GoogleTasksClient;
import com.nononsenseapps.notepad.sync.orgsync.DropboxSyncHelper;
import com.nononsenseapps.notepad.sync.orgsync.DropboxSynchronizer;
import com.nononsenseapps.notepad.sync.orgsync.OrgSyncService;
Expand Down Expand Up @@ -441,14 +442,12 @@ public void onClick(DialogInterface dialog, int which) {
*
* @param account
*/
public void accountSelected(Account account) {
public void accountSelected(final Account account) {
if (account != null) {
Log.d("prefsActivity", "step one");
this.account = account;
// Request user's permission
AccountManager.get(activity).getAuthToken(account,
GoogleTaskSync.AUTH_TOKEN_TYPE, null, activity, this,
null);
GoogleTasksClient.getAuthTokenAsync(activity, account, this);
// work continues in callback, method run()
}
}
Expand All @@ -457,6 +456,7 @@ public void accountSelected(Account account) {
* User wants to select an account to sync with. If we get an approval,
* activate sync and set periodicity also.
*/
@SuppressLint("CommitPrefEdits")
@Override
public void run(AccountManagerFuture<Bundle> future) {
try {
Expand All @@ -468,8 +468,9 @@ public void run(AccountManagerFuture<Bundle> future) {
String token = future.getResult().getString(
AccountManager.KEY_AUTHTOKEN);
// Now we are authorized by the user.
Log.d("prefsActivity", "step two-b: " + token);

if (token != null && !token.equals("") && account != null) {
if (token != null && !token.isEmpty() && account != null) {
Log.d("prefsActivity", "step three: " + account.name);
SharedPreferences customSharedPreference = PreferenceManager
.getDefaultSharedPreferences(activity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
*/
public class SyncAdapter extends AbstractThreadedSyncAdapter {

// public static final String AUTH_TOKEN_TYPE =
// "oauth2:https://www.googleapis.com/auth/tasks";

public static final String SYNC_STARTED = "com.nononsenseapps.notepad.sync.SYNC_STARTED";
public static final String SYNC_FINISHED = "com.nononsenseapps.notepad.sync.SYNC_FINISHED";

Expand Down
Loading

0 comments on commit 9c5f80b

Please sign in to comment.