Commits

Ville Saalo committed f46f52d

Shortened the code by some 30 lines by changing the switch-case statements into a TwoWayMap.

  • Participants
  • Parent commits 3015d57

Comments (0)

Files changed (1)

src/com/saibotd/bitbeaker/IssuesActivity.java

 
 public class IssuesActivity extends MyActivity {
 
-	private static final String FILTER_STATUS_NEW_OPEN = "status=new&status=open";
+	private static final String FILTER_STATUS_NEW_OPEN = "new&status=open";
 	private SpinnerAdapter mSpinnerAdapter;
 	private String slug;
 	private String owner;
 	ActionBar actionBar;
 	static final int NEW_ISSUE = 0;
 
+	private static final TwoWayMap<String,Integer> filterPositions;
+	static {
+		filterPositions = new TwoWayMap<String,Integer>(FILTER_STATUS_NEW_OPEN, -1);
+		filterPositions.put("", 0);
+		filterPositions.put(FILTER_STATUS_NEW_OPEN, 1);
+		filterPositions.put("resolved", 2);
+		filterPositions.put("on hold", 3);
+		filterPositions.put("invalid", 4);
+		filterPositions.put("duplicate", 5);
+		filterPositions.put("wontfix", 6);		
+	}
+	
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 		} else if (status.length==0){
 			pos=0;
 			filter="";
-		}
-		else {
-			filter = "status="+TextUtils.join("&status=", status);
+		} else {
+			filter = TextUtils.join("&status=", status);
 			pos = getPositionFromFilter(status);
 		}
 		setContentView(R.layout.issues);
 			break;
 		case 1:
 			String status = statusValues[0];
-			if ("resolved".equals(status)) {
-				return 2;
-			}
-			if ("on hold".equals(status)) {
-				return 3;
-			}
-			if ("invalid".equals(status)) {
-				return 4;
-			}
-			if ("duplicate".equals(status)) {
-				return 5;
-			}
-			if ("wontfix".equals(status)) {
-				return 6;
-			}
-			break;
+			return filterPositions.getByKey(status);
 		case 0:
 			return 0;
 		}
 		String url = API_BASE_URL + "/repositories/" + owner
 				+ "/" + slug + "/issues/";
 		if (!TextUtils.isEmpty(filter)) {
-			url += "?" + filter;
+			url += "?status=" + filter;
 		}
 		bitbeaker.delKV(url);
 		executeAsyncLoader(url);
 			loadIssuesByFilter();
 		}
 	}
-
+	
 	private OnNavigationListener mNavigationCallback = new OnNavigationListener() {
 
 		@Override
 				spinnerFirstTime = false;
 				return false;
 			}
-			/* This function is heavily linked with getpositionFromFilter() */
-			switch (pos) { 
-			    // These comparisons (this and the one that is repeated the other way around in the getPositionFromFilter 
-			    // method) should, in my opinion, be replaced with a TwoWayMap once it has been implemented. 
-			case 0:
-				filter = "";
-				break;
-			case 1:
-				filter = FILTER_STATUS_NEW_OPEN;
-				break;
-			case 2:
-				filter = "status=resolved";
-				break;
-			case 3:
-				filter = "status=on%20hold";
-				break;
-			case 4:
-				filter = "status=invalid";
-				break;
-			case 5:
-				filter = "status=duplicate";
-				break;
-			case 6:
-				filter = "status=wontfix";
-				break;
-			default:
-				filter = FILTER_STATUS_NEW_OPEN;
-			}
+			/* This function is heavily linked with getPositionFromFilter() */
+			String newFilter = filterPositions.getByValue(pos).replace(" ", "%20");
+			filter = newFilter;
 			loadIssuesByFilter();
 			return true;
 		}
     			String comments = res.getQuantityString(R.plurals.comments, num_comments, num_comments);
     			subtitle.setText(status + " - " + Helper.dateFormat(this.getItem(position).getString("utc_created_on")) + " - " + comments);
     			if(type.equals("bug")) icon.setImageResource(R.drawable.bug);
-    			if(type.equals("enhancement")) icon.setImageResource(R.drawable.enhancement);
-    			if(type.equals("proposal")) icon.setImageResource(R.drawable.proposal);
-    			if(type.equals("task")) icon.setImageResource(R.drawable.task);
+    			else if(type.equals("enhancement")) icon.setImageResource(R.drawable.enhancement);
+    			else if(type.equals("proposal")) icon.setImageResource(R.drawable.proposal);
+    			else if(type.equals("task")) icon.setImageResource(R.drawable.task);
     			//if(status.equals("resolved")) title.getBackground().setAlpha(45);
     		} catch (JSONException e) {
     			// TODO Auto-generated catch block