Flattring things now works

This commit is contained in:
daniel oeh 2012-07-12 15:41:56 +02:00
parent 85ee1272bf
commit 0e8909807d
3 changed files with 62 additions and 24 deletions

View File

@ -52,9 +52,13 @@
android:enabled="true" > android:enabled="true" >
</service> </service>
<activity android:name=".activity.PreferenceActivity" android:label="@string/settings_label"> <activity
android:name=".activity.PreferenceActivity"
android:label="@string/settings_label" >
</activity> </activity>
<activity android:name=".activity.DownloadLogActivity" android:label="@string/download_log_label"> <activity
android:name=".activity.DownloadLogActivity"
android:label="@string/download_log_label" >
</activity> </activity>
<receiver android:name=".receiver.MediaButtonReceiver" > <receiver android:name=".receiver.MediaButtonReceiver" >
@ -62,7 +66,7 @@
<action android:name="android.intent.action.MEDIA_BUTTON" /> <action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="de.podfetcher.NOTIFY_BUTTON_RECEIVER"/> <action android:name="de.podfetcher.NOTIFY_BUTTON_RECEIVER" />
</intent-filter> </intent-filter>
</receiver> </receiver>
@ -74,25 +78,44 @@
android:enabled="true" android:enabled="true"
android:exported="false" > android:exported="false" >
</service> </service>
<receiver android:name=".receiver.PlayerWidget">
<receiver android:name=".receiver.PlayerWidget" >
<intent-filter> <intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/> <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="de.podfetcher.FORCE_WIDGET_UPDATE"/> <action android:name="de.podfetcher.FORCE_WIDGET_UPDATE" />
</intent-filter> </intent-filter>
<meta-data android:resource="@xml/player_widget_info" android:name="android.appwidget.provider"/>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/player_widget_info" />
</receiver> </receiver>
<receiver android:name=".receiver.FeedUpdateReceiver"> <receiver android:name=".receiver.FeedUpdateReceiver" >
<intent-filter> <intent-filter>
<action android:name="de.podfetcher.feedupdatereceiver.refreshFeeds"/> <action android:name="de.podfetcher.feedupdatereceiver.refreshFeeds" />
</intent-filter> </intent-filter>
</receiver> </receiver>
<activity android:name=".activity.StorageErrorActivity"></activity>
<activity android:name=".activity.FlattrAuthActivity" android:label="@string/flattr_auth_label"> <activity android:name=".activity.StorageErrorActivity" >
</activity>
<activity
android:name=".activity.FlattrAuthActivity"
android:label="@string/flattr_auth_label" >
<intent-filter> <intent-filter>
<action android:name=".activities.FlattrAuthActivity"/> <action android:name=".activities.FlattrAuthActivity" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="de.danoeh.antennapod"
android:scheme="flattr4j" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>

View File

@ -113,5 +113,6 @@
<string name="authenticate_now_label">Authenticate</string> <string name="authenticate_now_label">Authenticate</string>
<string name="action_forbidden_title">Action forbidden</string> <string name="action_forbidden_title">Action forbidden</string>
<string name="action_forbidden_msg">Antennapod has no permission for this action. The reason for this could be that the access token of Antennapod to your account has been revoked. You can either re-reauthenticate or visit the website of the thing instead.</string> <string name="action_forbidden_msg">Antennapod has no permission for this action. The reason for this could be that the access token of Antennapod to your account has been revoked. You can either re-reauthenticate or visit the website of the thing instead.</string>
<string name="flattr_click_success">Successfully flattred this thing!</string>
</resources> </resources>

View File

@ -5,15 +5,10 @@ import java.util.EnumSet;
import org.shredzone.flattr4j.FlattrFactory; import org.shredzone.flattr4j.FlattrFactory;
import org.shredzone.flattr4j.FlattrService; import org.shredzone.flattr4j.FlattrService;
import org.shredzone.flattr4j.exception.FlattrException; import org.shredzone.flattr4j.exception.FlattrException;
import org.shredzone.flattr4j.exception.ForbiddenException;
import org.shredzone.flattr4j.oauth.AccessToken; import org.shredzone.flattr4j.oauth.AccessToken;
import org.shredzone.flattr4j.oauth.AndroidAuthenticator; import org.shredzone.flattr4j.oauth.AndroidAuthenticator;
import org.shredzone.flattr4j.oauth.Scope; import org.shredzone.flattr4j.oauth.Scope;
import de.podfetcher.PodcastApp;
import de.podfetcher.R;
import de.podfetcher.activity.FlattrAuthActivity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -23,14 +18,18 @@ import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import android.widget.Toast;
import de.podfetcher.PodcastApp;
import de.podfetcher.R;
import de.podfetcher.activity.FlattrAuthActivity;
/** Utility methods for doing something with flattr. */ /** Utility methods for doing something with flattr. */
public class FlattrUtils { public class FlattrUtils {
private static final String TAG = "FlattrUtils"; private static final String TAG = "FlattrUtils";
private static final String HOST_NAME = ""; private static final String HOST_NAME = "de.danoeh.antennapod";
private static final String APP_KEY = ""; private static final String APP_KEY = "qBoVa9rhUOSPCrBwYPjzyNytHRbkPul5VzRWz93jNMZf4rCS7LhwpGPWnR73biZW";
private static final String APP_SECRET = ""; private static final String APP_SECRET = "IGJ8FDiif7n9pPSmr0JHwotK5rD7AsU8Yt7uWfC2cQ2svKFNAekXtExpV1mlk7k8";
private static final String PREF_ACCESS_TOKEN = "de.danoeh.antennapod.preference.flattrAccessToken"; private static final String PREF_ACCESS_TOKEN = "de.danoeh.antennapod.preference.flattrAccessToken";
@ -92,11 +91,12 @@ public class FlattrUtils {
FlattrService fs = factory.createFlattrService(retrieveToken()); FlattrService fs = factory.createFlattrService(retrieveToken());
try { try {
fs.click(url); fs.click(url);
} catch (ForbiddenException fe) { Toast toast = Toast.makeText(context.getApplicationContext(),
deleteToken(); R.string.flattr_click_success, Toast.LENGTH_LONG);
showForbiddenDialog(context, url); toast.show();
} catch (FlattrException e) { } catch (FlattrException e) {
e.printStackTrace(); e.printStackTrace();
showErrorDialog(context, e.getMessage());
} }
} else { } else {
showNoTokenDialog(context, url); showNoTokenDialog(context, url);
@ -174,4 +174,18 @@ public class FlattrUtils {
}); });
builder.create().show(); builder.create().show();
} }
private static void showErrorDialog(final Context context, final String msg) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(R.string.error_label);
builder.setMessage(msg);
builder.setNeutralButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
builder.create().show();
}
} }