From 006ee57bbfee7122b6741b6a878cfe466a300c1d Mon Sep 17 00:00:00 2001
From: Ciaran Gultnieks <ciaran@ciarang.com>
Date: Wed, 19 Sep 2012 13:14:36 +0100
Subject: [PATCH] Handle long descriptions properly

---
 res/layout-land/appdetails.xml        | 126 ++++++++++++--------------
 res/layout/appdetails.xml             |  33 +------
 res/layout/appinfo.xml                |  32 +++++++
 src/org/fdroid/fdroid/AppDetails.java |  81 ++++++++++-------
 4 files changed, 139 insertions(+), 133 deletions(-)
 create mode 100644 res/layout/appinfo.xml

diff --git a/res/layout-land/appdetails.xml b/res/layout-land/appdetails.xml
index 5c57ae87b..19ecbfc22 100644
--- a/res/layout-land/appdetails.xml
+++ b/res/layout-land/appdetails.xml
@@ -1,77 +1,69 @@
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              android:layout_width="fill_parent"
-              android:layout_height="fill_parent"
-              android:orientation="horizontal">
-
-  <LinearLayout android:layout_width="0dp"
-                android:layout_height="fill_parent"
-                android:layout_weight="0.5"
-                android:layout_margin="5dp"
-                android:orientation="vertical">
-
-    <RelativeLayout android:id="@+id/header"
-                    android:layout_width="fill_parent"
-                    android:layout_height="wrap_content"
-                    android:layout_marginBottom="4dp"
-                    android:orientation="horizontal">
-
-      <TextView android:id="@+id/title"
-                android:textSize="18sp"
-                android:textStyle="bold"
-                android:singleLine="false"
-                android:layout_marginBottom="4dp"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:layout_alignParentLeft="true" />
-
-      <ImageView android:id="@+id/icon"
-                 android:scaleType="fitCenter"
-                 android:layout_marginRight="5dp"
-                 android:layout_height="42dp"
-                 android:layout_width="42dp"
-                 android:layout_below="@id/title" />
-
-      <TextView android:id="@+id/license"
-                android:textSize="12sp"
-                android:layout_below="@id/title"
-                android:layout_toRightOf="@id/icon"
-                android:layout_height="wrap_content"
-                android:layout_width="wrap_content" />
-
-      <TextView android:id="@+id/status"
-                android:textSize="12sp"
-                android:layout_below="@id/license"
-                android:layout_toRightOf="@id/icon"
-                android:layout_height="wrap_content"
-                android:layout_width="fill_parent" />
-
-    </RelativeLayout>
-
-    <TextView android:id="@+id/signature"
-              android:textSize="12sp"
-              android:visibility="gone"
-              android:layout_marginBottom="4dp"
-              android:layout_height="wrap_content"
-              android:layout_width="fill_parent" />
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    android:orientation="horizontal" >
 
     <ScrollView
-        android:id="@+id/desc_scrollview"
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content">
+        android:layout_width="wrap_content"
+        android:layout_height="fill_parent"
+        android:layout_weight="0.5" >
 
-      <TextView android:id="@+id/description"
-                android:singleLine="false"
+        <LinearLayout
+            android:id="@+id/landleft"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_margin="5dp"
+            android:orientation="vertical" >
+
+            <RelativeLayout
+                android:id="@+id/header"
                 android:layout_width="fill_parent"
-                android:layout_height="wrap_content" />
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="4dp"
+                android:orientation="horizontal" >
 
+                <TextView
+                    android:id="@+id/title"
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_alignParentLeft="true"
+                    android:layout_marginBottom="4dp"
+                    android:singleLine="false"
+                    android:textSize="18sp"
+                    android:textStyle="bold" />
+
+                <ImageView
+                    android:id="@+id/icon"
+                    android:layout_width="42dp"
+                    android:layout_height="42dp"
+                    android:layout_below="@id/title"
+                    android:layout_marginRight="5dp"
+                    android:scaleType="fitCenter" />
+
+                <TextView
+                    android:id="@+id/license"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/title"
+                    android:layout_toRightOf="@id/icon"
+                    android:textSize="12sp" />
+
+                <TextView
+                    android:id="@+id/status"
+                    android:layout_width="fill_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_below="@id/license"
+                    android:layout_toRightOf="@id/icon"
+                    android:textSize="12sp" />
+            </RelativeLayout>
+        </LinearLayout>
     </ScrollView>
 
-  </LinearLayout>
+    <ListView
+        android:id="@android:id/list"
+        android:layout_width="wrap_content"
+        android:layout_height="fill_parent"
+        android:layout_weight="0.5" />
 
-  <ListView android:id="@android:id/list"
-            android:layout_width="0dp"
-            android:layout_height="fill_parent"
-            android:layout_weight="0.5" />
-
-</LinearLayout>
+</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/appdetails.xml b/res/layout/appdetails.xml
index f90b15fa2..45fe822b0 100644
--- a/res/layout/appdetails.xml
+++ b/res/layout/appdetails.xml
@@ -51,40 +51,9 @@
         </RelativeLayout>
     </LinearLayout>
 
-    <LinearLayout
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:orientation="vertical" >
-
-        <TextView
-            android:id="@+id/summary"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:textSize="14sp" />
-
-        <TextView
-            android:id="@+id/appid"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:textSize="12sp" />
-
-        <TextView
-            android:id="@+id/signature"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:textSize="12sp" />
-
-        <TextView
-            android:id="@+id/description"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:singleLine="false" />
-    </LinearLayout>
-
     <ListView
         android:id="@android:id/list"
         android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:minHeight="80dp" />
+        android:layout_height="fill_parent" />
 
 </LinearLayout>
\ No newline at end of file
diff --git a/res/layout/appinfo.xml b/res/layout/appinfo.xml
new file mode 100644
index 000000000..9fbc5ac81
--- /dev/null
+++ b/res/layout/appinfo.xml
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="fill_parent"
+    android:layout_height="wrap_content"
+    android:orientation="vertical" >
+
+    <TextView
+        android:id="@+id/summary"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:textSize="14sp"
+        android:textStyle="bold" />
+
+    <TextView
+        android:id="@+id/appid"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:textSize="12sp" />
+
+    <TextView
+        android:id="@+id/signature"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:textSize="12sp" />
+
+    <TextView
+        android:id="@+id/description"
+        android:layout_width="fill_parent"
+        android:layout_height="wrap_content"
+        android:singleLine="false" />
+
+</LinearLayout>
diff --git a/src/org/fdroid/fdroid/AppDetails.java b/src/org/fdroid/fdroid/AppDetails.java
index 58a02ae50..787d6966c 100644
--- a/src/org/fdroid/fdroid/AppDetails.java
+++ b/src/org/fdroid/fdroid/AppDetails.java
@@ -36,6 +36,7 @@ import android.os.Handler;
 import android.os.Message;
 import android.preference.PreferenceManager;
 import android.widget.ImageView;
+import android.widget.LinearLayout;
 import android.widget.ListView;
 import android.widget.TextView;
 import android.widget.Toast;
@@ -168,6 +169,7 @@ public class AppDetails extends ListActivity {
 
     private Context mctx = this;
 
+
     @Override
     protected void onCreate(Bundle savedInstanceState) {
 
@@ -192,7 +194,7 @@ public class AppDetails extends ListActivity {
 
     private boolean pref_cacheDownloaded;
     private boolean pref_expert;
-    private boolean viewResetRequired;
+    private boolean resetRequired;
 
     // The signature of the installed version.
     private Signature mInstalledSignature;
@@ -211,19 +213,18 @@ public class AppDetails extends ListActivity {
         if (old != null) {
             copyState(old);
         } else {
-            viewResetRequired = true;
+            resetRequired = true;
         }
     }
 
     @Override
     protected void onResume() {
         super.onResume();
-        if (viewResetRequired) {
+        if (resetRequired) {
             reset();
-            viewResetRequired = false;
-        } else {
-            resetViews();
+            resetRequired = false;
         }
+        resetViews();
         if (downloadHandler != null) {
             downloadHandler.startUpdates();
         }
@@ -323,16 +324,33 @@ public class AppDetails extends ListActivity {
             }
         }
 
+    }
+
+    private void resetViews() {
+
+        // Clear the listadapter, because we can't mess with the listview's
+        // header view while it's set.
+        setListAdapter(null);
+        
+        // Insert the 'infoView' (which contains the summary, various odds and
+        // ends, and the description) into the appropriate place, if we're in
+        // landscape mode. In portrait mode, we put it in the listview's
+        // header..
+        View infoView = View.inflate(this, R.layout.appinfo, null);
+        LinearLayout landparent = (LinearLayout) findViewById(R.id.landleft);
+        ListView lv = (ListView) findViewById(android.R.id.list);
+        if (landparent != null) {
+            landparent.addView(infoView);
+        } else {
+            lv.addHeaderView(infoView);
+        }
+
         // Set up the list...
         ApkListAdapter la = new ApkListAdapter(this, null);
         for (DB.Apk apk : app.apks)
             la.addItem(apk);
         setListAdapter(la);
 
-        resetViews();
-    }
-
-    private void resetViews() {
         // Set the icon...
         ImageView iv = (ImageView) findViewById(R.id.icon);
         File icon = new File(DB.getIconsPath(), app.icon);
@@ -353,9 +371,9 @@ public class AppDetails extends ListActivity {
         else
             tv.setText(String.format(getString(R.string.details_installed),
                     app.installedVersion));
-        tv = (TextView) findViewById(R.id.description);
-        tv.setMovementMethod(LinkMovementMethod.getInstance());
 
+        tv = (TextView) infoView.findViewById(R.id.description);
+        tv.setMovementMethod(LinkMovementMethod.getInstance());
         // Need this to add the unimplemented support for ordered and unordered
         // lists to Html.fromHtml().
         class HtmlTagHandler implements TagHandler {
@@ -386,30 +404,25 @@ public class AppDetails extends ListActivity {
         tv.setText(Html.fromHtml(app.detail_description, null,
                 new HtmlTagHandler()));
 
-        tv = (TextView) findViewById(R.id.summary);
-        if (tv != null) {
-            tv.setText(app.summary);
+        tv = (TextView) infoView.findViewById(R.id.summary);
+        tv.setText(app.summary);
+
+        tv = (TextView) infoView.findViewById(R.id.appid);
+        if (pref_expert) {
+            tv.setVisibility(View.VISIBLE);
+            tv.setText(app.id);
+        } else {
+            tv.setVisibility(View.GONE);
         }
 
-        if (tv != null) {
-            tv = (TextView) findViewById(R.id.appid);
-            if (pref_expert) {
-                tv.setVisibility(View.VISIBLE);
-                tv.setText(app.id);
-            } else {
-                tv.setVisibility(View.INVISIBLE);
-            }
+        tv = (TextView) infoView.findViewById(R.id.signature);
+        if (pref_expert && mInstalledSignature != null) {
+            tv.setVisibility(View.VISIBLE);
+            tv.setText("Signed: " + mInstalledSigID);
+        } else {
+            tv.setVisibility(View.GONE);
         }
 
-        tv = (TextView) findViewById(R.id.signature);
-        if (tv != null) {
-            if (pref_expert && mInstalledSignature != null) {
-                tv.setVisibility(View.VISIBLE);
-                tv.setText("Signed: " + mInstalledSigID);
-            } else {
-                tv.setVisibility(View.INVISIBLE);
-            }
-        }
     }
 
     @Override
@@ -700,10 +713,10 @@ public class AppDetails extends ListActivity {
                 downloadHandler.cleanUp();
                 downloadHandler = null;
             }
-            viewResetRequired = true;
+            resetRequired = true;
             break;
         case REQUEST_UNINSTALL:
-            viewResetRequired = true;
+            resetRequired = true;
             break;
         }
     }