Commits

Juha Kuitunen committed 759f9df

Filter issues by status

  • Participants
  • Parent commits c77a742

Comments (0)

Files changed (3)

File res/layout/issues.xml

     android:layout_height="fill_parent"
     >
     <include layout="@layout/header" android:layout_width="match_parent" android:layout_height="wrap_content"/>
+    <Spinner
+        android:id="@+id/issueSpinner"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:entries="@array/status_of_issue"
+        android:prompt="@string/issue_filter_prompt"
+    />
     <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1">
         <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/issues_list"></ListView>
     </LinearLayout>

File res/values/strings.xml

         <item>proposal</item>
         <item >task</item>
     </string-array>
-        <string name="submit_new_issue">Submit new issue</string>
-        <string name="hint">"Note: You don't need to login to use the search function!"</string>
+    <string name="submit_new_issue">Submit new issue</string>
+    <string name="hint">"Note: You don't need to login to use the search function!"</string>
+
+    <string name="issue_filter_prompt">Filter issues</string>
+    <string-array name="status_of_issue">
+        <item>Show all</item>
+        <item>new &amp; open</item>
+        <item>resolved</item>
+        <item>on hold</item>
+        <item>invalid</item>
+        <item>duplicate</item>
+        <item>wontfix</item>
+    </string-array>
+
 </resources>

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

 package com.saibotd.bitbeaker;
 
+import java.net.URLEncoder;
+
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 import android.view.View;
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemSelectedListener;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.ListView;
+import android.widget.Spinner;
 import android.widget.TextView;
 
 public class IssuesActivity extends MyActivity {
-	
+
 	private String slug;
 	private String owner;
-	
+	private Spinner filterSpinner;
+	private String filter = "?status=new&status=open";//default issue filtering
+	private boolean spinnerFirstTime = true;
+
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         slug = b.getString("slug");
         owner = b.getString("owner");
         //setListAdapter(new IssuesAdapter(this, slug, owner));
+
         setContentView(R.layout.issues);
         ((TextView) findViewById(R.id.header_title)).setText(slug);
+
+        filterSpinner = (Spinner) findViewById(R.id.issueSpinner);
+        filterSpinner.setSelection(1);// default open & new instead of show all
+        filterSpinner.setOnItemSelectedListener(new filterListener());
+
         //AsyncLoader asyncLoader = new AsyncLoader();
         //asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/");
         //progressDialog = ProgressDialog.show(this, "", "Loading ...", true);
     }
-    
-    public void onResume(){
-    	super.onResume();
-    	AsyncLoader asyncLoader = new AsyncLoader();
-        asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/");
-        progressDialog = ProgressDialog.show(this, "", "Loading ...", true);
-    }
-    
-    private OnClickListener newIssueClickListener = new OnClickListener() {
+
+	public void onResume(){
+		super.onResume();
+		AsyncLoader asyncLoader = new AsyncLoader();
+		asyncLoader.execute("https://api.bitbucket.org/1.0/repositories/"+ owner +"/"+ slug +"/issues/" + filter);
+		progressDialog = ProgressDialog.show(this, "", "Loading ...", true);
+	}
+
+	private class filterListener implements OnItemSelectedListener {
+		public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
+			String tmp = parent.getItemAtPosition(pos).toString();
+			if (tmp.equals("Show all")) filter = "";
+			else if (tmp.equals("new &amp; open")) filter = "?status=new&status=open";
+			else filter = "?status="+URLEncoder.encode(tmp);
+
+			if (spinnerFirstTime) spinnerFirstTime = false;
+			else onResume();
+		}
+		public void onNothingSelected(AdapterView<?> parent) {
+			// Do nothing.
+		}
+	}
+
+	private OnClickListener newIssueClickListener = new OnClickListener() {
 		public void onClick(View v) {
-	    	Intent intent = new Intent(v.getContext(), NewIssueActivity.class);
+			Intent intent = new Intent(v.getContext(), NewIssueActivity.class);
 			Bundle b = new Bundle();
 			b.putString("slug", slug);
 			b.putString("owner", owner);
 			v.getContext().startActivity(intent);
 		}
 	};
-    
-    protected void AsyncLoaderDone(String result) {
-    	super.AsyncLoaderDone(result);
-    	ListView listView = (ListView) findViewById(R.id.issues_list);
+
+	protected void AsyncLoaderDone(String result) {
+		super.AsyncLoaderDone(result);
+		ListView listView = (ListView) findViewById(R.id.issues_list);
 		try {
 			listView.setAdapter(new IssuesAdapter(this, new JSONObject(result).getJSONArray("issues")));
 		} catch (JSONException e) {
 		Button newIssue = (Button) findViewById(R.id.bt_new_issue);
 		newIssue.setOnClickListener(newIssueClickListener);
 	}
-    
+
     protected class IssuesAdapter extends MyAdapter {
 
-
-    	
     	public IssuesAdapter(Context context, JSONArray jsonArray) {
     		super(context, jsonArray);
     	}
 
     }
 
-    
-    
 }