Commits

Juha Kuitunen  committed 23590bc

fetch comments of current issue from API

  • Participants
  • Parent commits 5b3df8c

Comments (0)

Files changed (2)

File res/layout/issue.xml

             <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_content" android:text="@string/nothing" android:textSize="18dip" 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>

File src/com/saibotd/bitbeaker/IssueActivity.java

 package com.saibotd.bitbeaker;
 
+import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.app.ProgressDialog;
 import android.os.Bundle;
 import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
 import android.widget.TextView;
 
 public class IssueActivity extends MyActivity {
 		JSONObject jsonObject;
 		TextView status = (TextView) findViewById(R.id.issue_status);
 		TextView content = (TextView) findViewById(R.id.issue_content);
+		TextView comments_count = (TextView) findViewById(R.id.issue_comments_count);
+		comments_count.setOnClickListener(loadCommentsListener);
 		try {
 			jsonObject = new JSONObject(result);
 			status.setText("Status: " + jsonObject.getString("status"));
 			content.setText(jsonObject.getString("content"));
+			comments_count.setText("Comments: " + jsonObject.getString("comment_count") + " (click to open)");
 			Log.d("TEST", jsonObject.toString());
 		} catch (JSONException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
 	}
-	
-	
+
+	private OnClickListener loadCommentsListener = new OnClickListener() {
+		public void onClick(View v) {
+			progressDialog = ProgressDialog.show(IssueActivity.this, "", "Loading comments...", true);
+			AsyncCommentsLoader asyncCommentsLoader = new AsyncCommentsLoader();
+			asyncCommentsLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + id + "/comments/");
+		}
+	};
+
+	protected class AsyncCommentsLoader extends AsyncLoader {
+		@Override
+		protected void onPostExecute(String result) {
+			AsyncCommentsLoaderDone(result);
+		}
+	}
+
+	protected void AsyncCommentsLoaderDone(String result) {
+		super.AsyncLoaderDone(result);
+		JSONArray jsonArray;
+		try {
+			jsonArray = new JSONArray(result);
+			Log.d("ISSUE_COMMENTS", jsonArray.toString());
+		} catch (JSONException e) {
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
 }