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