{"action":"created","comment":{"url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/comments/40595848","id":40595848,"diff_hunk":"@@ -0,0 +1,179 @@\n+package com.example.edwinmperazaduran.gridimagesearch.activities;\n+\n+import android.content.Context;\n+import android.content.Intent;\n+import android.net.ConnectivityManager;\n+import android.net.NetworkInfo;\n+import android.os.Bundle;\n+import android.support.v4.app.FragmentManager;\n+import android.support.v7.app.AppCompatActivity;\n+import android.view.Menu;\n+import android.view.MenuItem;\n+import android.view.View;\n+import android.view.inputmethod.InputMethodManager;\n+import android.widget.AdapterView;\n+import android.widget.Button;\n+import android.widget.EditText;\n+import android.widget.GridView;\n+import android.widget.Toast;\n+\n+import com.example.edwinmperazaduran.gridimagesearch.Dialogs.ImageFilterDialog;\n+import com.example.edwinmperazaduran.gridimagesearch.R;\n+import com.example.edwinmperazaduran.gridimagesearch.adapters.ImageResultArrayAdapter;\n+import com.example.edwinmperazaduran.gridimagesearch.helpers.EndlessScrollListener;\n+import com.example.edwinmperazaduran.gridimagesearch.models.ImageFilter;\n+import com.example.edwinmperazaduran.gridimagesearch.models.ImageResult;\n+import com.example.edwinmperazaduran.gridimagesearch.net.SearchClient;\n+import com.loopj.android.http.JsonHttpResponseHandler;\n+\n+import org.json.JSONArray;\n+import org.json.JSONException;\n+import org.json.JSONObject;\n+\n+import java.util.ArrayList;\n+\n+import cz.msebera.android.httpclient.Header;\n+\n+public class SearchActivity extends AppCompatActivity implements\n+        ImageFilterDialog.ImageFilterDialogListener{\n+\n+    private static int MAX_PAGE = 8;\n+    EditText etQuery;\n+    GridView gvResults;\n+    Button btnSearch;\n+    ArrayList<ImageResult> imageResults;\n+    ImageResultArrayAdapter imageAdapter;\n+    SearchClient client;\n+    int startPage = 0;\n+    String query;\n+    ImageFilter imageFilter = new ImageFilter();\n+\n+    @Override\n+    protected void onCreate(Bundle savedInstanceState) {\n+        super.onCreate(savedInstanceState);\n+        setContentView(R.layout.activity_search);\n+        setupViews();\n+    }\n+\n+    public void setupViews(){\n+        etQuery = (EditText) findViewById(R.id.etQuery);\n+        gvResults = (GridView) findViewById(R.id.gvResults);\n+        btnSearch = (Button) findViewById(R.id.btnSearch);\n+\n+        btnSearch.setOnClickListener(new View.OnClickListener() {\n+            @Override\n+            public void onClick(View v) {\n+                hideSoftKeyboard(v);\n+                onImageSearch(0);\n+            }\n+        });\n+\n+        gvResults.setOnItemClickListener(new AdapterView.OnItemClickListener() {\n+            @Override\n+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {\n+                Intent i = new Intent(getApplicationContext(), ImageDisplayActivity.class);\n+                ImageResult imageResult = imageResults.get(position);\n+                i.putExtra(\"result\", imageResult);\n+                startActivity(i);\n+            }\n+        });\n+\n+        gvResults.setOnScrollListener(new EndlessScrollListener() {\n+            @Override\n+            public void onLoadMore(int page, int totalItemsCount) {\n+                if (page < MAX_PAGE) {\n+                    onImageSearch(page - 1);\n+                }\n+            }\n+        });\n+\n+        imageResults = new ArrayList<>();\n+        imageAdapter = new ImageResultArrayAdapter(this, imageResults);\n+        gvResults.setAdapter(imageAdapter);\n+    }\n+\n+    @Override\n+    public boolean onCreateOptionsMenu(Menu menu) {\n+        // Inflate the menu; this adds items to the action bar if it is present.\n+        getMenuInflater().inflate(R.menu.menu_search, menu);\n+        return true;\n+    }\n+\n+    @Override\n+    public boolean onOptionsItemSelected(MenuItem item) {\n+        // Handle action bar item clicks here. The action bar will\n+        // automatically handle clicks on the Home/Up button, so long\n+        // as you specify a parent activity in AndroidManifest.xml.\n+        int id = item.getItemId();\n+\n+        //noinspection SimplifiableIfStatement\n+        if (id == R.id.miAdvancedSearch) {\n+            FragmentManager fm = getSupportFragmentManager();\n+            ImageFilterDialog imageFilterDialog= ImageFilterDialog.newInstance(\"Prueba\", imageFilter);\n+            imageFilterDialog.show(fm, \"fragment_image_filter\");\n+            return true;\n+        }\n+\n+        return super.onOptionsItemSelected(item);\n+    }\n+\n+    public void onImageSearch(int start) {\n+\n+        if (isNetworkAvailable()) {\n+            client = new SearchClient();\n+            query = etQuery.getText().toString();\n+            startPage = start;\n+            if (startPage == 0)\n+                imageAdapter.clear();\n+\n+            if (!query.equals(\"\"))\n+                client.getSearch(query, startPage, imageFilter, this, new JsonHttpResponseHandler() {\n+                            @Override\n+                            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {\n+                                try {\n+                                    JSONArray imageJsonResults;\n+                                    if (response != null) {\n+                                        imageJsonResults = response.getJSONObject(\"responseData\").getJSONArray(\"results\");\n+                                        imageAdapter.addAll(ImageResult.fromJSONArray(imageJsonResults));\n+                                    }\n+                                } catch (JSONException e) {\n+                                    Toast.makeText(getApplicationContext(), \"Invalid data received\", Toast.LENGTH_SHORT).show();\n+                                    e.printStackTrace();\n+                                }\n+                            }\n+\n+                            @Override\n+                            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {\n+                                super.onFailure(statusCode, headers, responseString, throwable);","path":"app/src/main/java/com/example/edwinmperazaduran/gridimagesearch/activities/SearchActivity.java","position":147,"original_position":147,"commit_id":"d5534c68de358d22079925be4471322e833ebe24","original_commit_id":"d5534c68de358d22079925be4471322e833ebe24","user":{"login":"josemontesdeoca","id":762541,"avatar_url":"https://avatars.githubusercontent.com/u/762541?v=3","gravatar_id":"","url":"https://api.github.com/users/josemontesdeoca","html_url":"https://github.com/josemontesdeoca","followers_url":"https://api.github.com/users/josemontesdeoca/followers","following_url":"https://api.github.com/users/josemontesdeoca/following{/other_user}","gists_url":"https://api.github.com/users/josemontesdeoca/gists{/gist_id}","starred_url":"https://api.github.com/users/josemontesdeoca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/josemontesdeoca/subscriptions","organizations_url":"https://api.github.com/users/josemontesdeoca/orgs","repos_url":"https://api.github.com/users/josemontesdeoca/repos","events_url":"https://api.github.com/users/josemontesdeoca/events{/privacy}","received_events_url":"https://api.github.com/users/josemontesdeoca/received_events","type":"User","site_admin":false},"body":"@edwinperaza you should handle the `onFailure` of the API call and give the user some visual queue of what happened","created_at":"2015-09-28T19:43:24Z","updated_at":"2015-09-28T19:43:24Z","html_url":"https://github.com/edwinperaza/GridImageSearch/pull/1#discussion_r40595848","pull_request_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/comments/40595848"},"html":{"href":"https://github.com/edwinperaza/GridImageSearch/pull/1#discussion_r40595848"},"pull_request":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1","id":46123077,"html_url":"https://github.com/edwinperaza/GridImageSearch/pull/1","diff_url":"https://github.com/edwinperaza/GridImageSearch/pull/1.diff","patch_url":"https://github.com/edwinperaza/GridImageSearch/pull/1.patch","issue_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/1","number":1,"state":"open","locked":false,"title":"Pull Request - Edwin Branch","user":{"login":"edwinperaza","id":10181100,"avatar_url":"https://avatars.githubusercontent.com/u/10181100?v=3","gravatar_id":"","url":"https://api.github.com/users/edwinperaza","html_url":"https://github.com/edwinperaza","followers_url":"https://api.github.com/users/edwinperaza/followers","following_url":"https://api.github.com/users/edwinperaza/following{/other_user}","gists_url":"https://api.github.com/users/edwinperaza/gists{/gist_id}","starred_url":"https://api.github.com/users/edwinperaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edwinperaza/subscriptions","organizations_url":"https://api.github.com/users/edwinperaza/orgs","repos_url":"https://api.github.com/users/edwinperaza/repos","events_url":"https://api.github.com/users/edwinperaza/events{/privacy}","received_events_url":"https://api.github.com/users/edwinperaza/received_events","type":"User","site_admin":false},"body":"Please @josemontesdeoca check this program.","created_at":"2015-09-28T06:12:38Z","updated_at":"2015-09-28T19:43:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"78a4c6857eb2bb4b6d1bd052a9de2a1794f4ed9b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1/commits","review_comments_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1/comments","review_comment_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/1/comments","statuses_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/statuses/d5534c68de358d22079925be4471322e833ebe24","head":{"label":"edwinperaza:edwin-branch","ref":"edwin-branch","sha":"d5534c68de358d22079925be4471322e833ebe24","user":{"login":"edwinperaza","id":10181100,"avatar_url":"https://avatars.githubusercontent.com/u/10181100?v=3","gravatar_id":"","url":"https://api.github.com/users/edwinperaza","html_url":"https://github.com/edwinperaza","followers_url":"https://api.github.com/users/edwinperaza/followers","following_url":"https://api.github.com/users/edwinperaza/following{/other_user}","gists_url":"https://api.github.com/users/edwinperaza/gists{/gist_id}","starred_url":"https://api.github.com/users/edwinperaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edwinperaza/subscriptions","organizations_url":"https://api.github.com/users/edwinperaza/orgs","repos_url":"https://api.github.com/users/edwinperaza/repos","events_url":"https://api.github.com/users/edwinperaza/events{/privacy}","received_events_url":"https://api.github.com/users/edwinperaza/received_events","type":"User","site_admin":false},"repo":{"id":43225871,"name":"GridImageSearch","full_name":"edwinperaza/GridImageSearch","owner":{"login":"edwinperaza","id":10181100,"avatar_url":"https://avatars.githubusercontent.com/u/10181100?v=3","gravatar_id":"","url":"https://api.github.com/users/edwinperaza","html_url":"https://github.com/edwinperaza","followers_url":"https://api.github.com/users/edwinperaza/followers","following_url":"https://api.github.com/users/edwinperaza/following{/other_user}","gists_url":"https://api.github.com/users/edwinperaza/gists{/gist_id}","starred_url":"https://api.github.com/users/edwinperaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edwinperaza/subscriptions","organizations_url":"https://api.github.com/users/edwinperaza/orgs","repos_url":"https://api.github.com/users/edwinperaza/repos","events_url":"https://api.github.com/users/edwinperaza/events{/privacy}","received_events_url":"https://api.github.com/users/edwinperaza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edwinperaza/GridImageSearch","description":"","fork":false,"url":"https://api.github.com/repos/edwinperaza/GridImageSearch","forks_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/forks","keys_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/teams","hooks_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/hooks","issue_events_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/events{/number}","events_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/events","assignees_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/assignees{/user}","branches_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/branches{/branch}","tags_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/tags","blobs_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/statuses/{sha}","languages_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/languages","stargazers_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/stargazers","contributors_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/contributors","subscribers_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/subscribers","subscription_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/subscription","commits_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/contents/{+path}","compare_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/merges","archive_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/downloads","issues_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues{/number}","pulls_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls{/number}","milestones_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/milestones{/number}","notifications_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/labels{/name}","releases_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/releases{/id}","created_at":"2015-09-26T22:42:43Z","updated_at":"2015-09-26T22:42:43Z","pushed_at":"2015-09-28T06:12:38Z","git_url":"git://github.com/edwinperaza/GridImageSearch.git","ssh_url":"git@github.com:edwinperaza/GridImageSearch.git","clone_url":"https://github.com/edwinperaza/GridImageSearch.git","svn_url":"https://github.com/edwinperaza/GridImageSearch","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"edwinperaza:master","ref":"master","sha":"83a040f6061ed2c4ee84c0125801b9b74810f623","user":{"login":"edwinperaza","id":10181100,"avatar_url":"https://avatars.githubusercontent.com/u/10181100?v=3","gravatar_id":"","url":"https://api.github.com/users/edwinperaza","html_url":"https://github.com/edwinperaza","followers_url":"https://api.github.com/users/edwinperaza/followers","following_url":"https://api.github.com/users/edwinperaza/following{/other_user}","gists_url":"https://api.github.com/users/edwinperaza/gists{/gist_id}","starred_url":"https://api.github.com/users/edwinperaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edwinperaza/subscriptions","organizations_url":"https://api.github.com/users/edwinperaza/orgs","repos_url":"https://api.github.com/users/edwinperaza/repos","events_url":"https://api.github.com/users/edwinperaza/events{/privacy}","received_events_url":"https://api.github.com/users/edwinperaza/received_events","type":"User","site_admin":false},"repo":{"id":43225871,"name":"GridImageSearch","full_name":"edwinperaza/GridImageSearch","owner":{"login":"edwinperaza","id":10181100,"avatar_url":"https://avatars.githubusercontent.com/u/10181100?v=3","gravatar_id":"","url":"https://api.github.com/users/edwinperaza","html_url":"https://github.com/edwinperaza","followers_url":"https://api.github.com/users/edwinperaza/followers","following_url":"https://api.github.com/users/edwinperaza/following{/other_user}","gists_url":"https://api.github.com/users/edwinperaza/gists{/gist_id}","starred_url":"https://api.github.com/users/edwinperaza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edwinperaza/subscriptions","organizations_url":"https://api.github.com/users/edwinperaza/orgs","repos_url":"https://api.github.com/users/edwinperaza/repos","events_url":"https://api.github.com/users/edwinperaza/events{/privacy}","received_events_url":"https://api.github.com/users/edwinperaza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/edwinperaza/GridImageSearch","description":"","fork":false,"url":"https://api.github.com/repos/edwinperaza/GridImageSearch","forks_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/forks","keys_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/teams","hooks_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/hooks","issue_events_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/events{/number}","events_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/events","assignees_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/assignees{/user}","branches_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/branches{/branch}","tags_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/tags","blobs_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/statuses/{sha}","languages_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/languages","stargazers_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/stargazers","contributors_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/contributors","subscribers_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/subscribers","subscription_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/subscription","commits_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/contents/{+path}","compare_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/merges","archive_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/downloads","issues_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues{/number}","pulls_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls{/number}","milestones_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/milestones{/number}","notifications_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/labels{/name}","releases_url":"https://api.github.com/repos/edwinperaza/GridImageSearch/releases{/id}","created_at":"2015-09-26T22:42:43Z","updated_at":"2015-09-26T22:42:43Z","pushed_at":"2015-09-28T06:12:38Z","git_url":"git://github.com/edwinperaza/GridImageSearch.git","ssh_url":"git@github.com:edwinperaza/GridImageSearch.git","clone_url":"https://github.com/edwinperaza/GridImageSearch.git","svn_url":"https://github.com/edwinperaza/GridImageSearch","homepage":null,"size":0,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1"},"html":{"href":"https://github.com/edwinperaza/GridImageSearch/pull/1"},"issue":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/1"},"comments":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/edwinperaza/GridImageSearch/statuses/d5534c68de358d22079925be4471322e833ebe24"}}}}