Commits

Ville Saalo committed d602ed5

Responding to saibotd / bitbeaker issue #56, "Sort search results": the repositories are now sorted primarily by their fork/non-fork status and secondarily by the time of their last update. Added the time of last update into the results, but it's not shown at least yet whether the repositories are forks of other repositories or not.

Also renamed a getString(int) method from MyAdapter, as it was possible to confuse it with the entirely different getString(int) from Context when used within an inner class that extends MyAdapter but resides within another class that extends MyActivity.

Comments (0)

Files changed (3)

src/com/saibotd/bitbeaker/MyAdapter.java

 		return new JSONObject();
 	}
 	
-	public String getString(int position) throws JSONException {
-		return mData.getString(position);
+	public Object getItemObject(int position) throws JSONException {
+		return mData.get(position);
 	}
 
 	@Override

src/com/saibotd/bitbeaker/SearchableActivity.java

 import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;
 import com.actionbarsherlock.view.MenuItem;
+import com.saibotd.bitbeaker.Helper.Sort;
 
 public class SearchableActivity extends MyActivity {
 	
 		try {
 			lastResult = new JSONObject(result).getJSONArray("repositories");
 			if(lastResult.length() == 0) makeToast(R.string.no_repositories_found);
-			listView.setAdapter(new SearchableRepositoriesAdapter(this, lastResult));
+			final String[] sortKeys = {"is_fork", "utc_last_updated"};
+			final Sort[] sortDirs = {Sort.ASCENDING, Sort.DESCENDING};
+			listView.setAdapter(new SearchableRepositoriesAdapter(this, Helper.getSortedJsonObjectArray(lastResult, sortKeys, sortDirs)));
 		} catch (JSONException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
     		TextView title = (TextView) view.findViewById(R.id.title);
     		TextView subtitle = (TextView) view.findViewById(R.id.subtitle);
     		try {
+    			final String lastUpdated = getString(R.string.last_updated) + ": " 
+    			                         + Helper.dateFormat(getItem(position).getString("utc_last_updated"));
+    			final String description = getItem(position).getString("description");
     			title.setText(this.getItem(position).getString("owner") + " / " + this.getItem(position).getString("name"));
-    			subtitle.setText(this.getItem(position).getString("description"));
+    			subtitle.setText(lastUpdated + (Helper.isJsonEmpty(description) ? "" : "\n" + description));
     		} catch (Exception e) {
     			// TODO Auto-generated catch block
     			e.printStackTrace();

src/com/saibotd/bitbeaker/SourceBrowserActivity.java

     	private JSONObject getItemAndAddName(int position) {
     		JSONObject obj = new JSONObject();
     		try {
-    			obj.put("name", super.getString(position));
+    			obj.put("name", (String) getItemObject(position));
     		} catch (JSONException e) {
     			// TODO Auto-generated catch block
     			e.printStackTrace();