Commits

Vincent Schüßler committed 19d6076

Start implementing Flattr authorization (see #30)

Comments (0)

Files changed (6)

AndroidManifest.xml

                 android:name="android.support.PARENT_ACTIVITY"
                 android:value=".ui.AddSubscriptionActivity" />
         </activity>
+        <activity android:name=".ui.SettingsActivity$FlattrCallbackProxyActivity" >
+            <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:scheme="net.x4a42.volksempfaenger" />
+                <data android:host="callback.oauth.flattr" />
+            </intent-filter>
+        </activity>
 
         <service android:name=".service.CleanCacheService" />
         <service android:name=".service.DownloadService" />

res/values/strings.xml

     <string name="button_retry">Retry</string>
     <string name="message_error_loading">Loading failed</string>
     <string name="unknown_error_occured">An unknown error occured.</string>
+    <string name="settings_summary_flattr">Flattr settings</string>
+    <string name="settings_flattr">Flattr</string>
+    <string name="button_flattr_auth">Connect to Flattr</string>
 
 </resources>

res/xml/preference_flattr.xml

+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+    android:summary="@string/settings_flattr"
+    android:title="@string/settings_summary_flattr" >
+    <Preference />
+
+</PreferenceScreen>

res/xml/preference_headers.xml

         android:summary="@string/settings_summary_storage"
         android:title="@string/settings_storage" />
     <header
+        android:fragment="net.x4a42.volksempfaenger.ui.FlattrSettingsFragment"
+        android:icon="@drawable/icon"
+        android:summary="@string/settings_summary_flattr"
+        android:title="@string/settings_flattr" />
+    <header
         android:fragment="net.x4a42.volksempfaenger.ui.SettingsActivity$AboutFragment"
         android:icon="@drawable/icon"
         android:summary="@string/settings_summary_about"

src/net/x4a42/volksempfaenger/ui/FlattrSettingsFragment.java

+package net.x4a42.volksempfaenger.ui;
+
+import net.x4a42.volksempfaenger.Constants;
+import net.x4a42.volksempfaenger.Log;
+import net.x4a42.volksempfaenger.R;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.PreferenceFragment;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+public class FlattrSettingsFragment extends PreferenceFragment implements
+		OnClickListener {
+	@Override
+	public void onCreate(Bundle savedInstanceState) {
+		super.onCreate(savedInstanceState);
+		addPreferencesFromResource(R.xml.preference_flattr);
+	}
+
+	@Override
+	public void onStart() {
+		super.onStart();
+		Bundle bundle = getArguments();
+		if (bundle != null) {
+			String code = bundle.getString("code");
+			if (code != null) {
+				Log.e(this, code);
+			}
+		}
+	}
+
+	@Override
+	public View onCreateView(LayoutInflater inflater, ViewGroup container,
+			Bundle savedInstanceState) {
+		View v = inflater.inflate(R.layout.flattr_settings, container, false);
+		Button authButton = (Button) v.findViewById(R.id.button_flattr_auth);
+		authButton.setOnClickListener(this);
+		return v;
+	}
+
+	@Override
+	public void onClick(View v) {
+		String authorizeUrl = "https://flattr.com/oauth/authorize?response_type=code&scope=flattr&client_id="
+				+ Constants.FLATTR_OAUTH_TOKEN;
+		Intent i = new Intent(Intent.ACTION_VIEW);
+		i.setData(Uri.parse(authorizeUrl));
+		startActivity(i);
+	}
+}

src/net/x4a42/volksempfaenger/ui/SettingsActivity.java

 import java.util.List;
 
 import net.x4a42.volksempfaenger.R;
-
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
 import android.preference.PreferenceFragment;
 
 	}
 
+	public static class FlattrCallbackProxyActivity extends Activity {
+		@Override
+		public void onStart() {
+			super.onStart();
+			Uri uri = getIntent().getData();
+			if (uri != null) {
+				Intent intent = new Intent(this, SettingsActivity.class);
+				intent.putExtra(EXTRA_SHOW_FRAGMENT,
+						FlattrSettingsFragment.class.getName());
+				Bundle bundle = new Bundle();
+				bundle.putString("code", uri.getQueryParameter("code"));
+				intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, bundle);
+				startActivity(intent);
+			}
+		}
+	}
+
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.