mirror of https://github.com/tasks/tasks
Replace play services auth library
Google Tasks and Drive support for F-Droid and Amazon buildspull/820/head
parent
569f5e57f1
commit
f6505cf985
@ -1,24 +0,0 @@
|
||||
package org.tasks.gtasks;
|
||||
|
||||
import android.accounts.Account;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GoogleAccountManager {
|
||||
|
||||
@Inject
|
||||
public GoogleAccountManager() {}
|
||||
|
||||
public List<String> getAccounts() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private List<Account> getAccountList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Account getAccount(final String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import com.todoroo.astrid.dao.Database;
|
||||
import com.todoroo.astrid.dao.MetadataDaoTests;
|
||||
import com.todoroo.astrid.dao.TaskDaoTests;
|
||||
import com.todoroo.astrid.model.TaskTest;
|
||||
import com.todoroo.astrid.provider.Astrid3ProviderTests;
|
||||
import com.todoroo.astrid.reminders.NotificationTests;
|
||||
import com.todoroo.astrid.reminders.ReminderServiceTest;
|
||||
import com.todoroo.astrid.repeats.NewRepeatTests;
|
||||
import com.todoroo.astrid.service.QuickAddMarkupTest;
|
||||
import com.todoroo.astrid.service.TitleParserTest;
|
||||
import com.todoroo.astrid.subtasks.SubtasksHelperTest;
|
||||
import com.todoroo.astrid.subtasks.SubtasksTestCase;
|
||||
import com.todoroo.astrid.sync.NewSyncTestCase;
|
||||
import dagger.Component;
|
||||
import org.tasks.jobs.BackupServiceTests;
|
||||
|
||||
@ApplicationScope
|
||||
@Component(modules = TestModule.class)
|
||||
public interface TestComponent {
|
||||
|
||||
Database getDatabase();
|
||||
|
||||
void inject(ReminderServiceTest reminderServiceTest);
|
||||
|
||||
void inject(TaskTest taskTest);
|
||||
|
||||
void inject(TaskDaoTests taskDaoTests);
|
||||
|
||||
void inject(MetadataDaoTests metadataDaoTests);
|
||||
|
||||
void inject(Astrid3ProviderTests astrid3ProviderTests);
|
||||
|
||||
void inject(NewSyncTestCase newSyncTestCase);
|
||||
|
||||
void inject(SubtasksTestCase subtasksTestCase);
|
||||
|
||||
void inject(SubtasksHelperTest subtasksHelperTest);
|
||||
|
||||
void inject(QuickAddMarkupTest quickAddMarkupTest);
|
||||
|
||||
void inject(TitleParserTest titleParserTest);
|
||||
|
||||
void inject(NewRepeatTests newRepeatTests);
|
||||
|
||||
void inject(BackupServiceTests backupServiceTests);
|
||||
|
||||
NotificationTests.NotificationTestsComponent plus(
|
||||
NotificationTests.NotificationTestsModule notificationTestsModule);
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
package org.tasks.injection;
|
||||
|
||||
import com.todoroo.astrid.dao.Database;
|
||||
import com.todoroo.astrid.dao.MetadataDaoTests;
|
||||
import com.todoroo.astrid.dao.TaskDaoTests;
|
||||
import com.todoroo.astrid.model.TaskTest;
|
||||
import com.todoroo.astrid.provider.Astrid3ProviderTests;
|
||||
import com.todoroo.astrid.reminders.NotificationTests;
|
||||
import com.todoroo.astrid.reminders.ReminderServiceTest;
|
||||
import com.todoroo.astrid.repeats.NewRepeatTests;
|
||||
import com.todoroo.astrid.service.QuickAddMarkupTest;
|
||||
import com.todoroo.astrid.service.TitleParserTest;
|
||||
import com.todoroo.astrid.subtasks.SubtasksHelperTest;
|
||||
import com.todoroo.astrid.subtasks.SubtasksTestCase;
|
||||
import com.todoroo.astrid.sync.NewSyncTestCase;
|
||||
import dagger.Component;
|
||||
import org.tasks.jobs.BackupServiceTests;
|
||||
|
||||
@ApplicationScope
|
||||
@Component(modules = TestModule.class)
|
||||
public interface TestComponent {
|
||||
|
||||
Database getDatabase();
|
||||
|
||||
void inject(ReminderServiceTest reminderServiceTest);
|
||||
|
||||
void inject(TaskTest taskTest);
|
||||
|
||||
void inject(TaskDaoTests taskDaoTests);
|
||||
|
||||
void inject(MetadataDaoTests metadataDaoTests);
|
||||
|
||||
void inject(Astrid3ProviderTests astrid3ProviderTests);
|
||||
|
||||
void inject(NewSyncTestCase newSyncTestCase);
|
||||
|
||||
void inject(SubtasksTestCase subtasksTestCase);
|
||||
|
||||
void inject(SubtasksHelperTest subtasksHelperTest);
|
||||
|
||||
void inject(QuickAddMarkupTest quickAddMarkupTest);
|
||||
|
||||
void inject(TitleParserTest titleParserTest);
|
||||
|
||||
void inject(NewRepeatTests newRepeatTests);
|
||||
|
||||
void inject(BackupServiceTests backupServiceTests);
|
||||
|
||||
NotificationTests.NotificationTestsComponent plus(
|
||||
NotificationTests.NotificationTestsModule notificationTestsModule);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package org.tasks.gtasks;
|
||||
|
||||
import android.accounts.Account;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class GoogleAccountManager {
|
||||
|
||||
@Inject
|
||||
public GoogleAccountManager() {}
|
||||
|
||||
public List<String> getAccounts() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private List<Account> getAccountList() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public Account getAccount(final String name) {
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package org.tasks.gtasks;
|
||||
|
||||
import static com.google.common.collect.Iterables.tryFind;
|
||||
import static com.google.common.collect.Lists.transform;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import com.google.common.base.Strings;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.injection.ForApplication;
|
||||
import org.tasks.preferences.PermissionChecker;
|
||||
|
||||
public class GoogleAccountManager {
|
||||
|
||||
private final PermissionChecker permissionChecker;
|
||||
private final android.accounts.AccountManager accountManager;
|
||||
|
||||
@Inject
|
||||
public GoogleAccountManager(
|
||||
@ForApplication Context context, PermissionChecker permissionChecker) {
|
||||
this.permissionChecker = permissionChecker;
|
||||
|
||||
accountManager = android.accounts.AccountManager.get(context);
|
||||
}
|
||||
|
||||
public List<String> getAccounts() {
|
||||
return transform(getAccountList(), account -> account.name);
|
||||
}
|
||||
|
||||
private List<Account> getAccountList() {
|
||||
return permissionChecker.canAccessAccounts()
|
||||
? asList(accountManager.getAccountsByType("com.google"))
|
||||
: Collections.emptyList();
|
||||
}
|
||||
|
||||
public Account getAccount(final String name) {
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return tryFind(getAccountList(), account -> name.equalsIgnoreCase(account.name)).orNull();
|
||||
}
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
package org.tasks.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.api.services.tasks.model.TaskList;
|
||||
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
|
||||
import org.tasks.gtasks.GoogleAccountManager;
|
||||
import org.tasks.ui.CompletableViewModel;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class CreateListViewModel extends CompletableViewModel<TaskList> {
|
||||
void createList(Context context, String account, String name) {
|
||||
run(() -> new GtasksInvoker(context, account).createGtaskList(name));
|
||||
void createList(GoogleAccountManager googleAccountManager, String account, String name) {
|
||||
run(() -> new GtasksInvoker(account, googleAccountManager).createGtaskList(name));
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package org.tasks.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
|
||||
import org.tasks.data.GoogleTaskList;
|
||||
import org.tasks.gtasks.GoogleAccountManager;
|
||||
import org.tasks.ui.ActionViewModel;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class DeleteListViewModel extends ActionViewModel {
|
||||
void deleteList(Context context, GoogleTaskList list) {
|
||||
run(() -> new GtasksInvoker(context, list.getAccount()).deleteGtaskList(list.getRemoteId()));
|
||||
void deleteList(GoogleAccountManager googleAccountManager, GoogleTaskList list) {
|
||||
run(() -> new GtasksInvoker(list.getAccount(), googleAccountManager).deleteGtaskList(list.getRemoteId()));
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,17 @@
|
||||
package org.tasks.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import com.google.api.services.tasks.model.TaskList;
|
||||
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
|
||||
import org.tasks.data.GoogleTaskList;
|
||||
import org.tasks.gtasks.GoogleAccountManager;
|
||||
import org.tasks.ui.CompletableViewModel;
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class RenameListViewModel extends CompletableViewModel<TaskList> {
|
||||
void renameList(Context context, GoogleTaskList list, String name) {
|
||||
void renameList(GoogleAccountManager googleAccountManager, GoogleTaskList list, String name) {
|
||||
run(
|
||||
() ->
|
||||
new GtasksInvoker(context, list.getAccount())
|
||||
new GtasksInvoker(list.getAccount(), googleAccountManager)
|
||||
.renameGtaskList(list.getRemoteId(), name));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,124 @@
|
||||
package org.tasks.gtasks;
|
||||
|
||||
import static com.google.common.collect.Iterables.tryFind;
|
||||
import static com.google.common.collect.Lists.transform;
|
||||
import static com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread;
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import com.google.api.services.drive.DriveScopes;
|
||||
import com.google.api.services.tasks.TasksScopes;
|
||||
import com.google.common.base.Strings;
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.R;
|
||||
import org.tasks.injection.ForApplication;
|
||||
import org.tasks.play.AuthResultHandler;
|
||||
import org.tasks.preferences.PermissionChecker;
|
||||
import timber.log.Timber;
|
||||
|
||||
public class GoogleAccountManager {
|
||||
|
||||
private final PermissionChecker permissionChecker;
|
||||
private final android.accounts.AccountManager accountManager;
|
||||
|
||||
@Inject
|
||||
public GoogleAccountManager(
|
||||
@ForApplication Context context, PermissionChecker permissionChecker) {
|
||||
this.permissionChecker = permissionChecker;
|
||||
accountManager = android.accounts.AccountManager.get(context);
|
||||
}
|
||||
|
||||
public List<String> getAccounts() {
|
||||
return transform(getAccountList(), account -> account.name);
|
||||
}
|
||||
|
||||
private List<Account> getAccountList() {
|
||||
return permissionChecker.canAccessAccounts()
|
||||
? asList(accountManager.getAccountsByType("com.google"))
|
||||
: Collections.emptyList();
|
||||
}
|
||||
|
||||
public Account getAccount(String name) {
|
||||
if (Strings.isNullOrEmpty(name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return tryFind(getAccountList(), account -> name.equalsIgnoreCase(account.name)).orNull();
|
||||
}
|
||||
|
||||
public Bundle getAccessToken(String name, String scope) {
|
||||
assertNotMainThread();
|
||||
|
||||
Account account = getAccount(name);
|
||||
if (account == null) {
|
||||
Timber.e("Cannot find account %s", name);
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return accountManager
|
||||
.getAuthToken(account, "oauth2:" + scope, new Bundle(), true, null, null)
|
||||
.getResult();
|
||||
} catch (AuthenticatorException | IOException | OperationCanceledException e) {
|
||||
Timber.e(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Disposable getTasksAuthToken(
|
||||
final Activity activity, final String accountName, final AuthResultHandler handler) {
|
||||
return getToken(TasksScopes.TASKS, activity, accountName, handler);
|
||||
}
|
||||
|
||||
public Disposable getDriveAuthToken(
|
||||
final Activity activity, final String accountName, final AuthResultHandler handler) {
|
||||
return getToken(DriveScopes.DRIVE_FILE, activity, accountName, handler);
|
||||
}
|
||||
|
||||
private Disposable getToken(
|
||||
String scope, Activity activity, String accountName, AuthResultHandler handler) {
|
||||
final Account account = getAccount(accountName);
|
||||
return Single.fromCallable(
|
||||
() -> {
|
||||
if (account == null) {
|
||||
throw new RuntimeException(
|
||||
activity.getString(R.string.gtasks_error_accountNotFound, accountName));
|
||||
}
|
||||
assertNotMainThread();
|
||||
|
||||
return accountManager
|
||||
.getAuthToken(account, "oauth2:" + scope, new Bundle(), activity, null, null)
|
||||
.getResult();
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
bundle -> {
|
||||
Intent intent = (Intent) bundle.get(AccountManager.KEY_INTENT);
|
||||
if (intent != null) {
|
||||
activity.startActivity(intent);
|
||||
} else {
|
||||
handler.authenticationSuccessful(accountName);
|
||||
}
|
||||
},
|
||||
e -> handler.authenticationFailed(e.getMessage()));
|
||||
}
|
||||
|
||||
public void invalidateToken(String token) {
|
||||
accountManager.invalidateAuthToken("com.google", token);
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
** Copyright (c) 2012 Todoroo Inc
|
||||
**
|
||||
** See the file "LICENSE" for the full license governing this code.
|
||||
-->
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="@string/gtasks_GPr_header"
|
||||
android:title="@string/gtasks_GPr_header"/>
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue