FlattrClickWorker is now showing a progress dialog
This commit is contained in:
parent
605e6c2b61
commit
428075f04e
|
@ -124,5 +124,6 @@
|
|||
<string name="length_prefix">Length:\u0020</string>
|
||||
<string name="size_prefix">Size:\u0020</string>
|
||||
<string name="processing_label">Processing</string>
|
||||
<string name="flattring_label">flattring</string>
|
||||
|
||||
</resources>
|
|
@ -1,9 +1,9 @@
|
|||
package de.danoeh.antennapod.asynctask;
|
||||
|
||||
import org.shredzone.flattr4j.exception.FlattrException;
|
||||
import org.shredzone.flattr4j.oauth.AccessToken;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
@ -18,6 +18,7 @@ public class FlattrClickWorker extends AsyncTask<Void, Void, Void> {
|
|||
protected String url;
|
||||
protected String errorMsg;
|
||||
protected int exitCode;
|
||||
protected ProgressDialog progDialog;
|
||||
|
||||
protected final static int SUCCESS = 0;
|
||||
protected final static int NO_TOKEN = 1;
|
||||
|
@ -50,9 +51,20 @@ public class FlattrClickWorker extends AsyncTask<Void, Void, Void> {
|
|||
toast.show();
|
||||
}
|
||||
|
||||
protected void onSetupProgDialog() {
|
||||
progDialog = new ProgressDialog(context);
|
||||
progDialog.setMessage(context.getString(R.string.flattring_label));
|
||||
progDialog.setIndeterminate(true);
|
||||
progDialog.setCancelable(false);
|
||||
progDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void result) {
|
||||
Log.d(TAG, "Exit code was " + exitCode);
|
||||
if (progDialog != null) {
|
||||
progDialog.dismiss();
|
||||
}
|
||||
switch (exitCode) {
|
||||
case NO_TOKEN:
|
||||
onNoAccessToken();
|
||||
|
@ -66,6 +78,11 @@ public class FlattrClickWorker extends AsyncTask<Void, Void, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
onSetupProgDialog();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
Log.d(TAG, "Starting background work");
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.shredzone.flattr4j.exception.FlattrException;
|
|||
import org.shredzone.flattr4j.oauth.AccessToken;
|
||||
import org.shredzone.flattr4j.oauth.AndroidAuthenticator;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
@ -79,6 +80,7 @@ public class FlattrTokenFetcher extends AsyncTask<Void, Void, AccessToken> {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public void executeAsync() {
|
||||
if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
|
|
@ -10,7 +10,7 @@ import android.util.Log;
|
|||
public class FlattrServiceCreator {
|
||||
public static final String TAG = "FlattrServiceCreator";
|
||||
|
||||
private static FlattrService flattrService;
|
||||
private static volatile FlattrService flattrService;
|
||||
|
||||
public static FlattrService getService(AccessToken token) {
|
||||
if (flattrService == null) {
|
||||
|
@ -20,4 +20,9 @@ public class FlattrServiceCreator {
|
|||
}
|
||||
return flattrService;
|
||||
}
|
||||
|
||||
public static void deleteFlattrService() {
|
||||
Log.d(TAG, "Deleting service instance");
|
||||
flattrService = null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,12 +39,13 @@ public class FlattrUtils {
|
|||
private static final String PREF_ACCESS_TOKEN = "de.danoeh.antennapod.preference.flattrAccessToken";
|
||||
|
||||
/** Flattr URL for this app. */
|
||||
public static final String APP_URL = "http://antennapod.com";
|
||||
public static final String APP_URL = "http://antennapod.com";
|
||||
/** Human-readable flattr-page. */
|
||||
public static final String APP_LINK = "https://flattr.com/thing/745609/";
|
||||
public static final String APP_THING_ID = "745609";
|
||||
|
||||
|
||||
|
||||
private static volatile AccessToken cachedToken;
|
||||
|
||||
private static AndroidAuthenticator createAuthenticator() {
|
||||
return new AndroidAuthenticator(HOST_NAME, APP_KEY, APP_SECRET);
|
||||
}
|
||||
|
@ -61,16 +62,21 @@ public class FlattrUtils {
|
|||
* was saved before.
|
||||
*/
|
||||
private static AccessToken retrieveToken() {
|
||||
Log.d(TAG, "Retrieving access token");
|
||||
String token = PreferenceManager.getDefaultSharedPreferences(
|
||||
PodcastApp.getInstance()).getString(PREF_ACCESS_TOKEN, null);
|
||||
if (token != null) {
|
||||
Log.d(TAG, "Found access token");
|
||||
return new AccessToken(token);
|
||||
} else {
|
||||
Log.d(TAG, "No access token found");
|
||||
return null;
|
||||
if (cachedToken == null) {
|
||||
Log.d(TAG, "Retrieving access token");
|
||||
String token = PreferenceManager.getDefaultSharedPreferences(
|
||||
PodcastApp.getInstance())
|
||||
.getString(PREF_ACCESS_TOKEN, null);
|
||||
if (token != null) {
|
||||
Log.d(TAG, "Found access token. Caching.");
|
||||
cachedToken = new AccessToken(token);
|
||||
} else {
|
||||
Log.d(TAG, "No access token found");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return cachedToken;
|
||||
|
||||
}
|
||||
|
||||
/** Returns true if the application has saved an access token */
|
||||
|
@ -89,13 +95,14 @@ public class FlattrUtils {
|
|||
editor.putString(PREF_ACCESS_TOKEN, null);
|
||||
}
|
||||
editor.commit();
|
||||
cachedToken = null;
|
||||
}
|
||||
|
||||
public static void deleteToken() {
|
||||
Log.d(TAG, "Deleting flattr token");
|
||||
storeToken(null);
|
||||
}
|
||||
|
||||
|
||||
/** Get the thing that represents this app */
|
||||
public static Thing getAppThing(Context context) {
|
||||
FlattrService fs = FlattrServiceCreator.getService(retrieveToken());
|
||||
|
@ -127,6 +134,7 @@ public class FlattrUtils {
|
|||
public static void revokeAccessToken(Context context) {
|
||||
Log.d(TAG, "Revoking access token");
|
||||
deleteToken();
|
||||
FlattrServiceCreator.deleteFlattrService();
|
||||
showRevokeDialog(context);
|
||||
}
|
||||
|
||||
|
@ -146,8 +154,7 @@ public class FlattrUtils {
|
|||
builder.create().show();
|
||||
}
|
||||
|
||||
public static void showNoTokenDialog(final Context context,
|
||||
final String url) {
|
||||
public static void showNoTokenDialog(final Context context, final String url) {
|
||||
Log.d(TAG, "Creating showNoTokenDialog");
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(R.string.no_flattr_token_title);
|
||||
|
@ -218,6 +225,5 @@ public class FlattrUtils {
|
|||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue