Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Ignore metadata from IDEA (Android Studio)
*.iml
.idea/
out/
bin/
gen/
*~
63 changes: 39 additions & 24 deletions src/com/BreakingBytes/SifterReader/IssueDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import android.text.util.Linkify;
import android.widget.TextView;

import java.util.HashSet;
import java.util.Set;

public class IssueDetail extends Activity {

public static final String CATEGORY_NAME = "category_name";
Expand Down Expand Up @@ -48,7 +51,7 @@ protected void onCreate(Bundle savedInstanceState) {
return;
try {
JSONObject issue = new JSONObject(extras.getString(IssuesActivity.ISSUE));
if (issue != null && checkFields(issue)) {
if (checkFields(issue)) {
issueNumber.setText(issue.getString(IssuesActivity.NUMBER));
categoryName.setText(issue.getString(CATEGORY_NAME));
priority.setText(issue.getString(IssuesActivity.PRIORITY));
Expand All @@ -69,29 +72,41 @@ protected void onCreate(Bundle savedInstanceState) {
mSifterHelper.onException(e.toString()); // return not needed
}
}


/**
* The point of this method seems to be to make sure that the given JSONObject
* has the fields we require in order to draw an issue. It should return false
* if a required field is absent, but it should not return false just because a
* non-required field is present.
*
* @param category the JSONObject to be inspected
* @return <tt>true</tt> if all the required fields are present
* @throws JSONException if there's a problem accessing the field names in the given object
*/
private boolean checkFields(JSONObject category) throws JSONException {
String API_ISSUES_URL = "api_url";
JSONArray fieldNames = category.names();
int numKeys = fieldNames.length();
for (int j = 0;j < numKeys; j++) {
if (!IssuesActivity.NUMBER.equals(fieldNames.getString(j)) &&
!CATEGORY_NAME.equals(fieldNames.getString(j)) &&
!IssuesActivity.PRIORITY.equals(fieldNames.getString(j)) &&
!IssuesActivity.SUBJECT.equals(fieldNames.getString(j)) &&
!DESCRIPTION.equals(fieldNames.getString(j)) &&
!MILESTONE_NAME.equals(fieldNames.getString(j)) &&
!OPENER_NAME.equals(fieldNames.getString(j)) &&
!ASSIGNEE_NAME.equals(fieldNames.getString(j)) &&
!IssuesActivity.STATUS.equals(fieldNames.getString(j)) &&
!COMMENT_COUNT.equals(fieldNames.getString(j)) &&
!CREATED_AT.equals(fieldNames.getString(j)) &&
!UPDATED_AT.equals(fieldNames.getString(j)) &&
!ISSUE_COMMENTS_URL.equals(fieldNames.getString(j)) &&
!API_ISSUES_URL.equals(fieldNames.getString(j)))
return false;
}
return true;
}
String API_ISSUES_URL = "api_url";
JSONArray fieldNames = category.names();
int numKeys = fieldNames.length();
Set<String> foundNames = new HashSet<String>();
for (int j = 0;j < numKeys; j++) {
String fieldName = fieldNames.getString(j);
foundNames.add(fieldName);
}
boolean allPresent = foundNames.contains(IssuesActivity.NUMBER) &&
foundNames.contains(CATEGORY_NAME) &&
foundNames.contains(IssuesActivity.PRIORITY) &&
foundNames.contains(IssuesActivity.SUBJECT) &&
foundNames.contains(DESCRIPTION) &&
foundNames.contains(MILESTONE_NAME) &&
foundNames.contains(OPENER_NAME) &&
foundNames.contains(ASSIGNEE_NAME) &&
foundNames.contains(IssuesActivity.STATUS) &&
foundNames.contains(COMMENT_COUNT) &&
foundNames.contains(CREATED_AT) &&
foundNames.contains(UPDATED_AT) &&
foundNames.contains(ISSUE_COMMENTS_URL) &&
foundNames.contains(API_ISSUES_URL);

return allPresent; // TODO If we're returning false, we ought to indicate which required fields are missing
}
}