Silently update security provider

gtask_related_email
Alex Baker 5 years ago
parent 8a94c15ebe
commit f76d046b11

@ -1,6 +1,7 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.content.Context;
import com.todoroo.astrid.activity.MainActivity;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
@ -28,4 +29,6 @@ public class PlayServices {
public Disposable check(MainActivity mainActivity) {
return Disposables.empty();
}
public void updateSecurityProvider(Context context) {}
}

@ -1,6 +1,7 @@
package org.tasks.gtasks;
import android.app.Activity;
import android.content.Context;
import com.todoroo.astrid.activity.MainActivity;
import io.reactivex.disposables.Disposable;
import io.reactivex.disposables.Disposables;
@ -28,4 +29,6 @@ public class PlayServices {
public Disposable check(MainActivity mainActivity) {
return Disposables.empty();
}
public void updateSecurityProvider(Context context) {}
}

@ -7,6 +7,9 @@ import android.content.Context;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
import com.google.android.gms.security.ProviderInstaller;
import io.reactivex.Single;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
@ -95,4 +98,11 @@ public class PlayServices {
return preferences.getInt(R.string.play_services_available, -1);
}
public void updateSecurityProvider(Context context) {
try {
ProviderInstaller.installIfNeeded(context);
} catch (GooglePlayServicesRepairableException | GooglePlayServicesNotAvailableException e) {
Timber.e(e);
}
}
}

@ -1,10 +1,22 @@
package org.tasks.activities;
import android.content.Context;
import org.tasks.caldav.CaldavClient;
import org.tasks.gtasks.PlayServices;
import org.tasks.ui.CompletableViewModel;
public class AddCaldavAccountViewModel extends CompletableViewModel<String> {
public void addAccount(CaldavClient client, String url, String username, String password) {
run(() -> client.forUrl(url, username, password).getHomeSet());
public void addAccount(
PlayServices playServices,
Context context,
CaldavClient client,
String url,
String username,
String password) {
run(
() -> {
playServices.updateSecurityProvider(context);
return client.forUrl(url, username, password).getHomeSet();
});
}
}

@ -19,6 +19,7 @@ import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnFocusChange;
import butterknife.OnTextChanged;
import com.google.android.gms.security.ProviderInstaller;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
@ -38,6 +39,7 @@ import org.tasks.analytics.Tracking.Events;
import org.tasks.data.CaldavAccount;
import org.tasks.data.CaldavDao;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.gtasks.PlayServices;
import org.tasks.injection.ActivityComponent;
import org.tasks.injection.ForApplication;
import org.tasks.injection.ThemedInjectingAppCompatActivity;
@ -62,6 +64,7 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
@Inject TaskDeleter taskDeleter;
@Inject Encryption encryption;
@Inject CaldavClient client;
@Inject PlayServices playServices;
@BindView(R.id.root_layout)
LinearLayout root;
@ -304,7 +307,7 @@ public class CaldavAccountSettingsActivity extends ThemedInjectingAppCompatActiv
if (caldavAccount == null) {
showProgressIndicator();
addCaldavAccountViewModel.addAccount(client, url, username, password);
addCaldavAccountViewModel.addAccount(playServices, context, client, url, username, password);
} else if (needsValidation()) {
showProgressIndicator();
updateCaldavAccountViewModel.updateCaldavAccount(client, url, username, password);

Loading…
Cancel
Save