mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
Getting rid of the authentication refresher (we can now reference AuthManager)
This commit is contained in:
@@ -2,7 +2,6 @@ package com.google.android.apps.mytracks.io;
|
||||
|
||||
import com.google.android.apps.mytracks.io.gdata.GDataClientFactory;
|
||||
import com.google.android.apps.mytracks.io.mymaps.MapsFacade;
|
||||
import com.google.android.apps.mytracks.io.mymaps.MapsFacade.AuthenticationRefresher;
|
||||
import com.google.android.apps.mytracks.io.mymaps.MapsService;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -24,13 +23,7 @@ public class MyMapsFactory {
|
||||
public static MapsFacade newMapsClient(Activity context, final AuthManager auth) {
|
||||
MapsFacade client = MapsService.newClient(context,
|
||||
GDataClientFactory.getGDataClient(context),
|
||||
auth.getAuthToken());
|
||||
client.setAuthenticationRefresher(new AuthenticationRefresher() {
|
||||
@Override
|
||||
public void invalidateAndRefresh(Runnable done) {
|
||||
auth.invalidateAndRefresh(done);
|
||||
}
|
||||
});
|
||||
auth);
|
||||
return client;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,15 +12,6 @@ import java.util.Collection;
|
||||
*/
|
||||
public interface MapsFacade {
|
||||
|
||||
/** Interface used for refreshing authentication credentials. */
|
||||
public interface AuthenticationRefresher {
|
||||
/** Refreshes authentication credentials, then calls done. */
|
||||
void invalidateAndRefresh(Runnable done);
|
||||
}
|
||||
|
||||
/** Sets the authentication refresher to use. */
|
||||
void setAuthenticationRefresher(AuthenticationRefresher refresher);
|
||||
|
||||
/**
|
||||
* Interface for receiving data back from getMapsList.
|
||||
* All calls to the interface will happen before getMapsList returns.
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
package com.google.android.apps.mytracks.io.mymaps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.maps.GeoPoint;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import com.google.wireless.gdata.client.GDataClient;
|
||||
@@ -36,11 +37,11 @@ class MapsFacadeImpl implements MapsFacade {
|
||||
private final String authToken;
|
||||
|
||||
public MapsFacadeImpl(Context context, GDataClient gdataClient,
|
||||
String authToken) {
|
||||
AuthManager auth) {
|
||||
this.context = context;
|
||||
this.authToken = authToken;
|
||||
this.authToken = auth.getAuthToken();
|
||||
|
||||
wrapper = new MyMapsGDataWrapper(context, gdataClient);
|
||||
wrapper = new MyMapsGDataWrapper(context, gdataClient, auth);
|
||||
wrapper.setRetryOnAuthFailure(true);
|
||||
|
||||
try {
|
||||
@@ -50,11 +51,6 @@ class MapsFacadeImpl implements MapsFacade {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthenticationRefresher(AuthenticationRefresher refresher) {
|
||||
wrapper.setAuthenticationRefresher(refresher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getMapsList(final MapsListCallback callback) {
|
||||
return wrapper.runQuery(new MyMapsGDataWrapper.QueryFunction() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2011 Google Inc. All Rights Reserved.
|
||||
package com.google.android.apps.mytracks.io.mymaps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.wireless.gdata.client.GDataClient;
|
||||
|
||||
import android.app.Activity;
|
||||
@@ -25,8 +26,8 @@ public class MapsService {
|
||||
public static MapsFacade newClient(
|
||||
Activity context,
|
||||
GDataClient gDataClient,
|
||||
String authToken) {
|
||||
return new MapsFacadeImpl(context, gDataClient, authToken);
|
||||
AuthManager auth) {
|
||||
return new MapsFacadeImpl(context, gDataClient, auth);
|
||||
}
|
||||
|
||||
/** Returns the service name to authenticate to for providing the authentication token above. */
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2010 Google Inc. All Rights Reserved.
|
||||
package com.google.android.apps.mytracks.io.mymaps;
|
||||
|
||||
import com.google.android.apps.mytracks.io.mymaps.MapsFacade.AuthenticationRefresher;
|
||||
import com.google.android.apps.mytracks.io.AuthManager;
|
||||
import com.google.android.common.gdata.AndroidXmlParserFactory;
|
||||
import com.google.wireless.gdata.client.GDataClient;
|
||||
import com.google.wireless.gdata.client.HttpException;
|
||||
@@ -56,6 +56,7 @@ class MyMapsGDataWrapper {
|
||||
public static final int ERROR_UNKNOWN = 100;
|
||||
|
||||
private final GDataClient androidGdataClient;
|
||||
private final AuthManager auth;
|
||||
private final MapsClient client;
|
||||
|
||||
private String errorMessage;
|
||||
@@ -63,10 +64,10 @@ class MyMapsGDataWrapper {
|
||||
private boolean retryOnAuthFailure;
|
||||
private int retriesPending;
|
||||
private boolean cleanupCalled;
|
||||
private AuthenticationRefresher authenticationRefresher;
|
||||
|
||||
public MyMapsGDataWrapper(Context context, GDataClient gdataClient) {
|
||||
public MyMapsGDataWrapper(Context context, GDataClient gdataClient, AuthManager auth) {
|
||||
androidGdataClient = gdataClient;
|
||||
this.auth = auth;
|
||||
client =
|
||||
new MapsClient(androidGdataClient, new XmlMapsGDataParserFactory(
|
||||
new AndroidXmlParserFactory()));
|
||||
@@ -123,7 +124,7 @@ class MyMapsGDataWrapper {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Log.d(MyMapsConstants.TAG, "GData error encountered: " + errorMessage);
|
||||
if (errorType == ERROR_AUTH && authenticationRefresher != null) {
|
||||
if (errorType == ERROR_AUTH && auth != null) {
|
||||
Runnable whenFinished = null;
|
||||
if (retryOnAuthFailure) {
|
||||
retriesPending++;
|
||||
@@ -138,7 +139,7 @@ class MyMapsGDataWrapper {
|
||||
}
|
||||
};
|
||||
}
|
||||
authenticationRefresher.invalidateAndRefresh(whenFinished);
|
||||
auth.invalidateAndRefresh(whenFinished);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -161,10 +162,6 @@ class MyMapsGDataWrapper {
|
||||
cleanupCalled = true;
|
||||
}
|
||||
|
||||
public void setAuthenticationRefresher(AuthenticationRefresher refresher) {
|
||||
this.authenticationRefresher = refresher;
|
||||
}
|
||||
|
||||
public void setRetryOnAuthFailure(boolean retry) {
|
||||
retryOnAuthFailure = retry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user