Resolve google play services errors

pull/437/head
Alex Baker 8 years ago
parent 6f2cd36dff
commit 4a59565cc1

@ -0,0 +1,28 @@
package org.tasks.gtasks;
import com.todoroo.astrid.activity.TaskListFragment;
import javax.inject.Inject;
public class SyncAdapterHelper {
@Inject
public SyncAdapterHelper() {
}
public boolean shouldShowBackgroundSyncWarning() {
return false;
}
public void checkPlayServices(TaskListFragment taskListFragment) {
}
public boolean initiateManualSync() {
return false;
}
public boolean isEnabled() {
return false;
}
}

@ -0,0 +1,28 @@
package org.tasks.gtasks;
import com.todoroo.astrid.activity.TaskListFragment;
import javax.inject.Inject;
public class SyncAdapterHelper {
@Inject
public SyncAdapterHelper() {
}
public boolean shouldShowBackgroundSyncWarning() {
return false;
}
public void checkPlayServices(TaskListFragment taskListFragment) {
}
public boolean initiateManualSync() {
return false;
}
public boolean isEnabled() {
return false;
}
}

@ -13,8 +13,6 @@ import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity;
@ -24,6 +22,7 @@ import org.tasks.activities.NativeGoogleTaskListPicker;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.gtasks.GoogleTaskListSelectionHandler;
import org.tasks.gtasks.PlayServicesAvailability;
import org.tasks.gtasks.SyncAdapterHelper;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.InjectingPreferenceActivity;
@ -45,6 +44,7 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go
@Inject Tracker tracker;
@Inject SyncAdapterHelper syncAdapterHelper;
@Inject Activity activity;
@Inject PlayServicesAvailability playServicesAvailability;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -58,14 +58,8 @@ public class GtasksPreferences extends InjectingPreferenceActivity implements Go
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((boolean) newValue) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int result = googleApiAvailability.isGooglePlayServicesAvailable(activity);
if (result != ConnectionResult.SUCCESS) {
if (googleApiAvailability.isUserResolvableError(result)) {
googleApiAvailability.getErrorDialog(activity, result, REQUEST_LOGIN).show();
} else {
Toast.makeText(activity, R.string.common_google_play_services_notification_ticker, Toast.LENGTH_LONG).show();
}
if (!playServicesAvailability.refreshAndCheck()) {
playServicesAvailability.resolve(activity);
} else if (permissionRequestor.requestAccountPermissions()) {
requestLogin();
}

@ -2,10 +2,10 @@ package org.tasks;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.GtasksTaskListUpdater;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import org.tasks.billing.InventoryHelper;
import org.tasks.billing.PurchaseHelper;
import org.tasks.gtasks.PlayServicesAvailability;
import org.tasks.gtasks.SyncAdapterHelper;
import org.tasks.preferences.Preferences;
import org.tasks.receivers.TeslaUnreadReceiver;
@ -20,6 +20,7 @@ public class FlavorSetup {
private final TeslaUnreadReceiver teslaUnreadReceiver;
private final InventoryHelper inventoryHelper;
private final SyncAdapterHelper syncAdapterHelper;
private final PlayServicesAvailability playServicesAvailability;
@Inject
public FlavorSetup(Preferences preferences, GtasksPreferenceService gtasksPreferenceService,
@ -27,12 +28,13 @@ public class FlavorSetup {
@SuppressWarnings("UnusedParameters") PurchaseHelper purchaseHelper,
@SuppressWarnings("UnusedParameters") SyncExecutor syncExecutor,
TeslaUnreadReceiver teslaUnreadReceiver, InventoryHelper inventoryHelper,
SyncAdapterHelper syncAdapterHelper) {
SyncAdapterHelper syncAdapterHelper, PlayServicesAvailability playServicesAvailability) {
this.preferences = preferences;
this.gtasksPreferenceService = gtasksPreferenceService;
this.teslaUnreadReceiver = teslaUnreadReceiver;
this.inventoryHelper = inventoryHelper;
this.syncAdapterHelper = syncAdapterHelper;
this.playServicesAvailability = playServicesAvailability;
}
public void setup() {
@ -40,5 +42,6 @@ public class FlavorSetup {
teslaUnreadReceiver.setEnabled(preferences.getBoolean(R.string.p_tesla_unread_enabled, false));
gtasksPreferenceService.stopOngoing(); // if sync ongoing flag was set, clear it
syncAdapterHelper.enableSynchronization(syncAdapterHelper.isEnabled());
playServicesAvailability.refresh();
}
}

@ -0,0 +1,67 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.content.Context;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import org.tasks.R;
import org.tasks.injection.ForApplication;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
import timber.log.Timber;
public class PlayServicesAvailability {
private static final int REQUEST_RESOLUTION = 10000;
private final Context context;
private final Preferences preferences;
@Inject
public PlayServicesAvailability(@ForApplication Context context, Preferences preferences) {
this.context = context;
this.preferences = preferences;
}
public boolean refreshAndCheck() {
refresh();
return isPlayServicesAvailable();
}
public boolean isPlayServicesAvailable() {
return getResult() == ConnectionResult.SUCCESS;
}
public void refresh() {
GoogleApiAvailability instance = GoogleApiAvailability.getInstance();
int googlePlayServicesAvailable = instance.isGooglePlayServicesAvailable(context);
preferences.setInt(R.string.play_services_available, googlePlayServicesAvailable);
if (googlePlayServicesAvailable == ConnectionResult.SUCCESS) {
preferences.setBoolean(R.string.warned_play_services, false);
}
Timber.d(getStatus());
}
public void resolve(Activity activity) {
GoogleApiAvailability googleApiAvailability = GoogleApiAvailability.getInstance();
int error = preferences.getInt(R.string.play_services_available, -1);
if (googleApiAvailability.isUserResolvableError(error)) {
googleApiAvailability.getErrorDialog(activity, error, REQUEST_RESOLUTION).show();
} else {
Toast.makeText(activity, R.string.common_google_play_services_notification_ticker, Toast.LENGTH_LONG).show();
}
}
public String getStatus() {
return GoogleApiAvailability.getInstance().getErrorString(getResult());
}
private int getResult() {
return preferences.getInt(R.string.play_services_available, -1);
}
}

@ -4,10 +4,13 @@ import android.accounts.Account;
import android.content.ContentResolver;
import android.os.Bundle;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import org.tasks.AccountManager;
import org.tasks.R;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.preferences.Preferences;
import javax.inject.Inject;
@ -21,13 +24,18 @@ public class SyncAdapterHelper {
private final AccountManager accountManager;
private final Preferences preferences;
private final GtasksPreferenceService gtasksPreferenceService;
private final PlayServicesAvailability playServicesAvailability;
private final Tracker tracker;
@Inject
public SyncAdapterHelper(AccountManager accountManager, Preferences preferences,
GtasksPreferenceService gtasksPreferenceService) {
GtasksPreferenceService gtasksPreferenceService,
PlayServicesAvailability playServicesAvailability, Tracker tracker) {
this.accountManager = accountManager;
this.preferences = preferences;
this.gtasksPreferenceService = gtasksPreferenceService;
this.playServicesAvailability = playServicesAvailability;
this.tracker = tracker;
}
/**
@ -63,7 +71,9 @@ public class SyncAdapterHelper {
}
public boolean isEnabled() {
return preferences.getBoolean(R.string.sync_gtasks, false) && getAccount() != null;
return preferences.getBoolean(R.string.sync_gtasks, false) &&
playServicesAvailability.isPlayServicesAvailable() &&
getAccount() != null;
}
public boolean masterSyncEnabled() {
@ -104,4 +114,15 @@ public class SyncAdapterHelper {
public boolean shouldShowBackgroundSyncWarning() {
return isEnabled() && !masterSyncEnabled() && !ContentResolver.getPeriodicSyncs(getAccount(), AUTHORITY).isEmpty();
}
public void checkPlayServices(TaskListFragment taskListFragment) {
if (taskListFragment != null &&
preferences.getBoolean(R.string.sync_gtasks, false) &&
!playServicesAvailability.refreshAndCheck() &&
!preferences.getBoolean(R.string.warned_play_services, false)) {
preferences.setBoolean(R.string.warned_play_services, true);
playServicesAvailability.resolve(taskListFragment.getActivity());
tracker.reportEvent(Tracking.Events.PLAY_SERVICES_WARNING, playServicesAvailability.getStatus());
}
}
}

@ -7,4 +7,6 @@
<string name="sku_themes">themes</string>
<string name="p_dashclock_filter">dashclock_filter</string>
<string name="tasker_message">If you purchased the stand-alone Tasker plugin please send your Google Play Store transaction ID to support@tasks.org and you will receive a promo code for this in-app purchase. You can find the transaction ID in your Google Play Store order confirmation e-mail or by visiting wallet.google.com</string>
<string name="play_services_available">play_services_available</string>
<string name="warned_play_services">warned_play_services</string>
</resources>

@ -221,8 +221,8 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
repeatConfirmationReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_TASK_REPEATED));
TaskListFragment taskListFragment = getTaskListFragment();
if (syncAdapterHelper.shouldShowBackgroundSyncWarning() && !preferences.getBoolean(R.string.p_sync_warning_shown, false)) {
TaskListFragment taskListFragment = getTaskListFragment();
if (taskListFragment != null) {
taskListFragment.makeSnackbar(R.string.master_sync_warning)
.setAction(R.string.TLA_menu_settings, new View.OnClickListener() {
@ -242,6 +242,8 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
.show();
}
}
syncAdapterHelper.checkPlayServices(taskListFragment);
}
public void restart() {

@ -20,7 +20,8 @@ public class Tracking {
UPGRADE(R.string.tracking_category_event, R.string.tracking_event_upgrade),
LEGACY_TASKER_TRIGGER(R.string.tracking_category_event, R.string.tracking_event_legacy_tasker_trigger),
NIGHT_MODE_MISMATCH(R.string.tracking_category_event, R.string.tracking_event_night_mode_mismatch),
SET_PREFERENCE(R.string.tracking_category_preferences, 0);
SET_PREFERENCE(R.string.tracking_category_preferences, 0),
PLAY_SERVICES_WARNING(R.string.tracking_category_event, R.string.tracking_event_play_services_error);
public final int category;
public final int action;

@ -293,6 +293,7 @@
<string name="tracking_action_off">Off</string>
<string name="tracking_action_clear">Clear</string>
<string name="tracking_event_night_mode_mismatch">Night Mismatch</string>
<string name="tracking_event_play_services_error">Play Services Error</string>
<string name="tracking_event_upgrade">Upgrade</string>
<string name="tracking_event_legacy_tasker_trigger">Legacy Tasker</string>
<string name="p_tesla_unread_enabled">tesla_unread_enabled</string>

Loading…
Cancel
Save