Set GtasksInvoker username after logging in

pull/384/head
Alex Baker 9 years ago
parent 2113558770
commit 6eeeceef4e

@ -25,6 +25,7 @@ import java.io.IOException;
import java.util.Collections;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Wrapper around the official Google Tasks API to simplify common operations. In the case
@ -32,6 +33,7 @@ import javax.inject.Inject;
*
* @author Sam Bosley
*/
@Singleton
public class GtasksInvoker {
private static final Logger log = LoggerFactory.getLogger(GtasksInvoker.class);
@ -43,13 +45,17 @@ public class GtasksInvoker {
@Inject
public GtasksInvoker(@ForApplication Context context, GtasksPreferenceService preferenceService, AccountManager accountManager) {
this.accountManager = accountManager;
credential = GoogleAccountCredential.usingOAuth2(context, Collections.singletonList(TasksScopes.TASKS))
.setSelectedAccountName(preferenceService.getUserName());
credential = GoogleAccountCredential.usingOAuth2(context, Collections.singletonList(TasksScopes.TASKS));
setUserName(preferenceService.getUserName());
service = new Tasks.Builder(new NetHttpTransport(), new JacksonFactory(), credential)
.setApplicationName(String.format("Tasks/%s", BuildConfig.VERSION_NAME))
.build();
}
public void setUserName(String username) {
credential.setSelectedAccountName(username);
}
//If we get a 401 or 403, try revalidating the auth token before bailing
private synchronized void handleException(IOException e) throws IOException {
log.error(e.getMessage(), e);
@ -118,7 +124,7 @@ public class GtasksInvoker {
.delete(listId, taskId));
}
private <T> T execute(TasksRequest<T> request) throws IOException {
private synchronized <T> T execute(TasksRequest<T> request) throws IOException {
String caller = getCaller();
log.debug("{} request: {}", caller, request);
T response;

@ -13,6 +13,7 @@ import android.widget.Toast;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import org.tasks.AccountManager;
import org.tasks.R;
@ -36,6 +37,7 @@ public class GtasksLoginActivity extends InjectingAppCompatActivity implements A
@Inject GtasksPreferenceService gtasksPreferenceService;
@Inject DialogBuilder dialogBuilder;
@Inject AccountManager accountManager;
@Inject GtasksInvoker gtasksInvoker;
private String accountName;
@ -72,6 +74,7 @@ public class GtasksLoginActivity extends InjectingAppCompatActivity implements A
@Override
public void authenticationSuccessful(String accountName, String authToken) {
gtasksPreferenceService.setUserName(accountName);
gtasksInvoker.setUserName(accountName);
setResult(RESULT_OK);
finish();
DialogUtilities.dismissDialog(GtasksLoginActivity.this, pd);

Loading…
Cancel
Save