1. Julian Brost
  2. volksempfaenger

Commits

Vincent Schüßler  committed 9744242

Handle flattr callback in UI

  • Participants
  • Parent commits 8613488
  • Branches default

Comments (0)

Files changed (4)

File res/layout/flattr_settings.xml

  • Ignore whitespace
-<?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>

File res/layout/flattr_settings_header.xml

View file
  • Ignore whitespace
+<?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>

File res/values/strings.xml

View file
  • Ignore whitespace
     <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>

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

View file
  • Ignore whitespace
 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);
+	}
 }