Vincent Schüßler avatar Vincent Schüßler committed 9744242

Handle flattr callback in UI

Comments (0)

Files changed (4)

res/layout/flattr_settings.xml

-<?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:padding="@dimen/padding_medium" >
-
-    <ListView
-        android:id="@android:id/list"
-        android:layout_width="match_parent"
-        android:layout_height="match_parent" />
-
-</LinearLayout>

res/layout/flattr_settings_header.xml

+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/flattrConnectedToGroup"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:padding="@dimen/padding_medium"
+    android:visibility="gone" >
+
+    <TextView
+        android:id="@+id/flattrConnectedTo"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentLeft="true"
+        android:layout_centerVertical="true"
+        android:text="Medium Text"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:visibility="gone" />
+
+    <ProgressBar
+        android:id="@+id/flattrAuthProgressBar"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_alignParentRight="true"
+        android:layout_centerVertical="true"
+        android:visibility="gone" />
+
+</RelativeLayout>

res/values/strings.xml

     <string name="settings_flattr">Flattr</string>
     <string name="button_flattr_auth">Connect to Flattr</string>
     <string name="settings_summary_flattr_auth">Allow %s to flattr episodes</string>
+    <string name="flattr_connected_to">Connected to <b>%s</b></string>
+    <string name="flattr_connecting">Connecting…</string>
 
 </resources>

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.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.ListView;
+import android.widget.ProgressBar;
+import android.widget.TextView;
 
 public class FlattrSettingsFragment extends PreferenceFragment implements
 		OnPreferenceClickListener {
+	private View groupConnectedTo;
+	private TextView textConnectedTo;
+	private ProgressBar progressConnecting;
+	private ListView list;
+
 	@Override
 	public void onCreate(Bundle savedInstanceState) {
 		super.onCreate(savedInstanceState);
 		if (bundle != null) {
 			String callback = bundle.getString("callback");
 			if (callback != null) {
-				Log.e(this, callback);
+				Uri uri = Uri.parse(callback);
+				String code = uri.getQueryParameter("code");
+				if (code != null) {
+					showHeader();
+					progressConnecting.setVisibility(View.VISIBLE);
+					textConnectedTo.setText(R.string.flattr_connecting);
+				} else {
+					// authorization failed TODO
+				}
 			}
 		}
 	}
 	@Override
 	public View onCreateView(LayoutInflater inflater, ViewGroup container,
 			Bundle savedInstanceState) {
-		View v = inflater.inflate(R.layout.flattr_settings, container, false);
+		View v = super.onCreateView(inflater, container, savedInstanceState);
+		list = (ListView) v.findViewById(android.R.id.list);
+		View header = inflater.inflate(R.layout.flattr_settings_header, list,
+				false);
+		list.addHeaderView(header);
+		list.setHeaderDividersEnabled(false);
+		groupConnectedTo = header.findViewById(R.id.flattrConnectedToGroup);
+		textConnectedTo = (TextView) header
+				.findViewById(R.id.flattrConnectedTo);
+		progressConnecting = (ProgressBar) header
+				.findViewById(R.id.flattrAuthProgressBar);
 		return v;
 	}
 
 		startActivity(i);
 		return true;
 	}
+
+	private void showHeader() {
+		groupConnectedTo.setVisibility(View.VISIBLE);
+		textConnectedTo.setVisibility(View.VISIBLE);
+		progressConnecting.setVisibility(View.INVISIBLE);
+		list.setHeaderDividersEnabled(true);
+	}
 }
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.