Commits

Juha Kuitunen committed d16ad77

tried to improve comment layout in issues

Comments (0)

Files changed (3)

res/layout/issue.xml

   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">
   <include layout="@layout/header"  android:layout_width="match_parent" android:layout_height="wrap_content"/>
-    <ScrollView android:layout_height="match_parent" android:layout_width="match_parent" android:layout_margin="4dip">
+    <ScrollView android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_margin="4dip">
         <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issue_layout" android:orientation="vertical">
             <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issue_title" android:textSize="18dip" android:text="@string/nothing"></TextView>
             <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issue_status" android:text="@string/nothing" android:paddingTop="4dip"></TextView>
             <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issue_comments_count" android:text="@string/nothing" android:paddingTop="4dip"></TextView>
         </LinearLayout>
     </ScrollView>
-</LinearLayout>
+    <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issue_comments_list" android:layout_margin="4dip"></ListView>
+</LinearLayout>

res/layout/listitem_issue_comment.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="wrap_content"
+    android:orientation="vertical" >
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/issue_comment_header"
+        android:textStyle="bold" >
+    </TextView>
+
+    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:id="@+id/issue_comment_content" >
+    </TextView>
+
+</LinearLayout>

src/com/saibotd/bitbeaker/IssueActivity.java

 import org.json.JSONObject;
 
 import android.app.ProgressDialog;
+import android.content.Context;
 import android.os.Bundle;
 import android.util.Log;
 import android.view.View;
 import android.view.View.OnClickListener;
-import android.widget.LinearLayout;
+import android.view.ViewGroup;
+import android.widget.ListView;
 import android.widget.TextView;
 
 public class IssueActivity extends MyActivity {
 
 	protected void AsyncCommentsLoaderDone(String result) {
 		super.AsyncLoaderDone(result);
+
+		ListView listView = (ListView) findViewById(R.id.issue_comments_list);
 		JSONArray jsonArray;
 		try {
 			jsonArray = new JSONArray(result);
 			Log.d("ISSUE_COMMENTS", jsonArray.toString());
-
-			LinearLayout issue_layout = (LinearLayout) findViewById(R.id.issue_layout);
-			for (int i = jsonArray.length()-1; i >= 0; i--) {
-
-				// TODO: Use something smarter for creating layout. :)
-
-				TextView tv = new TextView(this);
-				JSONObject row = jsonArray.getJSONObject(i);
-				String content = row.getString("content")=="null" ? "Updated content. Further info not available via API" : row.getString("content");
-				tv.setPadding(0, 15, 0, 0);
-				tv.setText(
-						"Author:\t" + row.getJSONObject("author_info").getString("username") + "\n" +
-						"Posted (UTC):\t" + row.getString("utc_created_on") + "\n" +
-						"\n" +
-						content
-				);
-				issue_layout.addView(tv);
-			}
-
+			listView.setAdapter(new IssueCommentsAdapter(this, reverse(jsonArray)));
 		} catch (JSONException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
+
 	}
+
+	private JSONArray reverse(JSONArray array) throws JSONException{
+		JSONArray tmp = new JSONArray();
+		for(int i = array.length()-1; i >= 0; i--){
+			tmp.put(array.getJSONObject(i));
+		}
+		return tmp;
+	}
+
+	protected class IssueCommentsAdapter extends MyAdapter {
+
+		public IssueCommentsAdapter(Context context, JSONArray jsonArray) {
+			super(context, jsonArray);
+		}
+
+		public View getView(int position, View convertView, ViewGroup parent) {
+			View view;
+			if (convertView == null) {
+				view = mFactory.inflate(R.layout.listitem_issue_comment, null);
+			} else {
+				view = (View) convertView;
+			}
+			view.setId(position);
+			TextView header = (TextView) view.findViewById(R.id.issue_comment_header);
+			TextView content = (TextView) view.findViewById(R.id.issue_comment_content);
+
+			try {
+				String contents = this.getItem(position).getString("content")=="null" ? "Contents updated: details not available via API" : this.getItem(position).getString("content");
+				header.setText(
+					this.getItem(position).getJSONObject("author_info").getString("username") + " - " +
+					this.getItem(position).getString("utc_created_on")
+				);
+				content.setText(contents);
+			} catch (JSONException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+
+			return view;
+		}
+
+	}
+
 }
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.