{"action":"created","comment":{"url":"https://api.github.com/repos/luksdlt92/Training/pulls/comments/29599403","id":29599403,"diff_hunk":"@@ -39,53 +59,160 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,\n         return mView;\n     }\n \n+    private void init() {\n+        mNews = new ArrayList<>();\n+        mActualPosition = 0;\n+        mUser = Utils.getUserSaved(getActivity());\n+        setRefreshing(false);\n+        mAdapter = new NewsAdapter(getActivity(), mNews);\n+        mHandler = new Handler();\n+        listEnd = false;\n+    }\n+\n     private void setUi() {\n         mListView = (ListView) mView.findViewById(R.id.lv_news);\n         mListEmptyTv = (TextView) mView.findViewById(R.id.tv_listempty);\n         mFab = (FloatingActionButton) mView.findViewById(R.id.fab);\n+        mImageError = (ImageView) mView.findViewById(R.id.iv_news_error);\n         mSwipeView = (SwipeRefreshLayout) mView.findViewById(R.id.swipe);\n+\n+        mSwipeView.setColorSchemeResources(R.color.bluewolox, R.color.greenwolox,\n+                R.color.orange, R.color.red);\n     }\n \n     private void populate() {\n+        mListView.setAdapter(mAdapter);\n         mFab.attachToListView(mListView);\n \n-        ArrayList<NewsInstance> arrayOfUsers = NewsInstance.getUsers();\n-\n-        if (arrayOfUsers.isEmpty()) {\n-            mListEmptyTv.setVisibility(View.VISIBLE);\n-        } else {\n-            mListEmptyTv.setVisibility(View.GONE);\n-            NewsAdapter adapter = new NewsAdapter(this.getActivity(), arrayOfUsers);\n-            mListView.setAdapter(adapter);\n-        }\n+        doACallback();\n     }\n \n     private void setListeners() {\n+\n+        mImageError.setOnClickListener(new View.OnClickListener() {\n+            @Override\n+            public void onClick(View v) {\n+                refresh();\n+            }\n+        });\n+\n+        mSwipeView.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {\n+\n+            @Override\n+            public void onRefresh() {\n+                refresh();\n+                mHandler.post(refreshing);\n+            }\n+        });\n+\n         mListView.setOnScrollListener(new AbsListView.OnScrollListener() {\n+\n             @Override\n             public void onScrollStateChanged(AbsListView view, int scrollState) {\n \n             }\n \n             @Override\n-            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {\n-                int topRowVerticalPosition =\n-                        (mListView == null || mListView.getChildCount() == 0) ?\n-                                0 : mListView.getChildAt(0).getTop();\n-\n-                if (firstVisibleItem == 0 && topRowVerticalPosition >= 0) {\n-                    mSwipeView.setEnabled(true);\n-\n-                    //TODO: When the callback is implemented, delete this\n-                    // --------------------\n-                    new Handler().postDelayed(new Runnable() {\n-                        @Override public void run() {\n-                            mSwipeView.setRefreshing(false);\n-                        }\n-                    }, 10000);\n-                    // --------------------\n+            public void onScroll(AbsListView view, int firstVisibleItem,\n+                                 int visibleItemCount, int totalItemCount) {\n+\n+                boolean enable = isTheFirstElement();\n+                mSwipeView.setEnabled(enable);\n+\n+                if (!enable) {\n+                    if ((firstVisibleItem + visibleItemCount + sListViewOffset) >= totalItemCount) {\n+                        doACallback();\n+                    }\n+                }\n+            }\n+        });\n+    }\n+\n+    private final Runnable refreshing = new Runnable(){\n+        public void run(){\n+            try {\n+                if (isRefreshing()) {\n+                    mHandler.postDelayed(this, 2000);\n+                }\n+                else {\n+                    mSwipeView.setRefreshing(false);\n+                }\n+            }\n+            catch (Exception e) {\n+                e.printStackTrace();\n+            }\n+        }\n+    };\n+\n+    private void doACallback() {\n+        if (isRefreshing() || listEnd) return;\n+\n+        setRefreshing(true);\n+\n+        NewsService newsTry = RestApiAdapter.\n+                getAdapter().create(NewsService.class);\n+\n+        newsTry.getNews(sSort, mActualPosition, sListViewOffset, new Callback<NewsArrayInstance>() {\n+            @Override\n+            public void success(NewsArrayInstance newsArray, Response response) {\n+                int lengtResult = newsArray.getResults().length;\n+\n+                if (lengtResult == 0) listEnd = true;\n+\n+                mActualPosition = mActualPosition + lengtResult;\n+\n+                for (NewsInstance newInstance : newsArray.getResults()) {\n+                    newInstance.initialize(mUser.getObjectId());\n+                    mNews.add(newInstance);\n+                }\n+\n+                if (mListView.getVisibility() != View.VISIBLE) {","path":"app/src/main/java/ar/com/wolox/lucasdelatorre/training/fragments/News.java","position":187,"original_position":187,"commit_id":"dd446b97e25dbe2b91dd8c433c5e352ffdd15bda","original_commit_id":"dd446b97e25dbe2b91dd8c433c5e352ffdd15bda","user":{"login":"jpdelorenzo","id":5435922,"avatar_url":"https://avatars.githubusercontent.com/u/5435922?v=3","gravatar_id":"","url":"https://api.github.com/users/jpdelorenzo","html_url":"https://github.com/jpdelorenzo","followers_url":"https://api.github.com/users/jpdelorenzo/followers","following_url":"https://api.github.com/users/jpdelorenzo/following{/other_user}","gists_url":"https://api.github.com/users/jpdelorenzo/gists{/gist_id}","starred_url":"https://api.github.com/users/jpdelorenzo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jpdelorenzo/subscriptions","organizations_url":"https://api.github.com/users/jpdelorenzo/orgs","repos_url":"https://api.github.com/users/jpdelorenzo/repos","events_url":"https://api.github.com/users/jpdelorenzo/events{/privacy}","received_events_url":"https://api.github.com/users/jpdelorenzo/received_events","type":"User","site_admin":false},"body":"El manejo de hacer visible o no las views hacelo en un método aparte ","created_at":"2015-05-04T16:35:22Z","updated_at":"2015-05-04T16:35:22Z","html_url":"https://github.com/luksdlt92/Training/pull/12#discussion_r29599403","pull_request_url":"https://api.github.com/repos/luksdlt92/Training/pulls/12","_links":{"self":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/comments/29599403"},"html":{"href":"https://github.com/luksdlt92/Training/pull/12#discussion_r29599403"},"pull_request":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/12"}}},"pull_request":{"url":"https://api.github.com/repos/luksdlt92/Training/pulls/12","id":34644559,"html_url":"https://github.com/luksdlt92/Training/pull/12","diff_url":"https://github.com/luksdlt92/Training/pull/12.diff","patch_url":"https://github.com/luksdlt92/Training/pull/12.patch","issue_url":"https://api.github.com/repos/luksdlt92/Training/issues/12","number":12,"state":"open","locked":false,"title":"News backend implementation","user":{"login":"luksdlt92","id":4108820,"avatar_url":"https://avatars.githubusercontent.com/u/4108820?v=3","gravatar_id":"","url":"https://api.github.com/users/luksdlt92","html_url":"https://github.com/luksdlt92","followers_url":"https://api.github.com/users/luksdlt92/followers","following_url":"https://api.github.com/users/luksdlt92/following{/other_user}","gists_url":"https://api.github.com/users/luksdlt92/gists{/gist_id}","starred_url":"https://api.github.com/users/luksdlt92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luksdlt92/subscriptions","organizations_url":"https://api.github.com/users/luksdlt92/orgs","repos_url":"https://api.github.com/users/luksdlt92/repos","events_url":"https://api.github.com/users/luksdlt92/events{/privacy}","received_events_url":"https://api.github.com/users/luksdlt92/received_events","type":"User","site_admin":false},"body":"## Summary\r\n\r\n'News' backend implemented.\r\n\r\n## Test\r\n\r\n* Login with a Parse user account (for example, username: t@w.com // password: asdf)\r\n* Do a pull down to drop the current list and get a new one\r\n* Do a top pull to load the old news (pagination implemented)\r\n* Disconnect internet when the app is running. You'll see an error icon. Connect again and click on icon to see a new list.\r\n\r\n## Screenshots\r\n\r\n![News](http://i19.servimg.com/u/f19/12/28/53/00/news_b10.jpg)\r\n\r\n![News loading](http://i19.servimg.com/u/f19/12/28/53/00/news_b11.jpg)\r\n\r\n![News error](http://i19.servimg.com/u/f19/12/28/53/00/news_b10.png)\r\n\r\n## Cards\r\n\r\nhttps://trello.com/c/guhxbBlB/23-tech-news","created_at":"2015-05-04T15:02:09Z","updated_at":"2015-05-04T16:35:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7aa1dee5d2d80407b5da5dd33474d6996102e452","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/luksdlt92/Training/pulls/12/commits","review_comments_url":"https://api.github.com/repos/luksdlt92/Training/pulls/12/comments","review_comment_url":"https://api.github.com/repos/luksdlt92/Training/pulls/comments{/number}","comments_url":"https://api.github.com/repos/luksdlt92/Training/issues/12/comments","statuses_url":"https://api.github.com/repos/luksdlt92/Training/statuses/dd446b97e25dbe2b91dd8c433c5e352ffdd15bda","head":{"label":"luksdlt92:news_backend","ref":"news_backend","sha":"dd446b97e25dbe2b91dd8c433c5e352ffdd15bda","user":{"login":"luksdlt92","id":4108820,"avatar_url":"https://avatars.githubusercontent.com/u/4108820?v=3","gravatar_id":"","url":"https://api.github.com/users/luksdlt92","html_url":"https://github.com/luksdlt92","followers_url":"https://api.github.com/users/luksdlt92/followers","following_url":"https://api.github.com/users/luksdlt92/following{/other_user}","gists_url":"https://api.github.com/users/luksdlt92/gists{/gist_id}","starred_url":"https://api.github.com/users/luksdlt92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luksdlt92/subscriptions","organizations_url":"https://api.github.com/users/luksdlt92/orgs","repos_url":"https://api.github.com/users/luksdlt92/repos","events_url":"https://api.github.com/users/luksdlt92/events{/privacy}","received_events_url":"https://api.github.com/users/luksdlt92/received_events","type":"User","site_admin":false},"repo":{"id":33934574,"name":"Training","full_name":"luksdlt92/Training","owner":{"login":"luksdlt92","id":4108820,"avatar_url":"https://avatars.githubusercontent.com/u/4108820?v=3","gravatar_id":"","url":"https://api.github.com/users/luksdlt92","html_url":"https://github.com/luksdlt92","followers_url":"https://api.github.com/users/luksdlt92/followers","following_url":"https://api.github.com/users/luksdlt92/following{/other_user}","gists_url":"https://api.github.com/users/luksdlt92/gists{/gist_id}","starred_url":"https://api.github.com/users/luksdlt92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luksdlt92/subscriptions","organizations_url":"https://api.github.com/users/luksdlt92/orgs","repos_url":"https://api.github.com/users/luksdlt92/repos","events_url":"https://api.github.com/users/luksdlt92/events{/privacy}","received_events_url":"https://api.github.com/users/luksdlt92/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/luksdlt92/Training","description":"","fork":false,"url":"https://api.github.com/repos/luksdlt92/Training","forks_url":"https://api.github.com/repos/luksdlt92/Training/forks","keys_url":"https://api.github.com/repos/luksdlt92/Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/luksdlt92/Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/luksdlt92/Training/teams","hooks_url":"https://api.github.com/repos/luksdlt92/Training/hooks","issue_events_url":"https://api.github.com/repos/luksdlt92/Training/issues/events{/number}","events_url":"https://api.github.com/repos/luksdlt92/Training/events","assignees_url":"https://api.github.com/repos/luksdlt92/Training/assignees{/user}","branches_url":"https://api.github.com/repos/luksdlt92/Training/branches{/branch}","tags_url":"https://api.github.com/repos/luksdlt92/Training/tags","blobs_url":"https://api.github.com/repos/luksdlt92/Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/luksdlt92/Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/luksdlt92/Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/luksdlt92/Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/luksdlt92/Training/statuses/{sha}","languages_url":"https://api.github.com/repos/luksdlt92/Training/languages","stargazers_url":"https://api.github.com/repos/luksdlt92/Training/stargazers","contributors_url":"https://api.github.com/repos/luksdlt92/Training/contributors","subscribers_url":"https://api.github.com/repos/luksdlt92/Training/subscribers","subscription_url":"https://api.github.com/repos/luksdlt92/Training/subscription","commits_url":"https://api.github.com/repos/luksdlt92/Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/luksdlt92/Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/luksdlt92/Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/luksdlt92/Training/issues/comments{/number}","contents_url":"https://api.github.com/repos/luksdlt92/Training/contents/{+path}","compare_url":"https://api.github.com/repos/luksdlt92/Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/luksdlt92/Training/merges","archive_url":"https://api.github.com/repos/luksdlt92/Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/luksdlt92/Training/downloads","issues_url":"https://api.github.com/repos/luksdlt92/Training/issues{/number}","pulls_url":"https://api.github.com/repos/luksdlt92/Training/pulls{/number}","milestones_url":"https://api.github.com/repos/luksdlt92/Training/milestones{/number}","notifications_url":"https://api.github.com/repos/luksdlt92/Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/luksdlt92/Training/labels{/name}","releases_url":"https://api.github.com/repos/luksdlt92/Training/releases{/id}","created_at":"2015-04-14T13:50:51Z","updated_at":"2015-04-14T13:50:51Z","pushed_at":"2015-05-04T15:02:10Z","git_url":"git://github.com/luksdlt92/Training.git","ssh_url":"git@github.com:luksdlt92/Training.git","clone_url":"https://github.com/luksdlt92/Training.git","svn_url":"https://github.com/luksdlt92/Training","homepage":null,"size":5412,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"luksdlt92:develop","ref":"develop","sha":"4586e6f128839d72ba64bdc6db64dc0cb4442cac","user":{"login":"luksdlt92","id":4108820,"avatar_url":"https://avatars.githubusercontent.com/u/4108820?v=3","gravatar_id":"","url":"https://api.github.com/users/luksdlt92","html_url":"https://github.com/luksdlt92","followers_url":"https://api.github.com/users/luksdlt92/followers","following_url":"https://api.github.com/users/luksdlt92/following{/other_user}","gists_url":"https://api.github.com/users/luksdlt92/gists{/gist_id}","starred_url":"https://api.github.com/users/luksdlt92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luksdlt92/subscriptions","organizations_url":"https://api.github.com/users/luksdlt92/orgs","repos_url":"https://api.github.com/users/luksdlt92/repos","events_url":"https://api.github.com/users/luksdlt92/events{/privacy}","received_events_url":"https://api.github.com/users/luksdlt92/received_events","type":"User","site_admin":false},"repo":{"id":33934574,"name":"Training","full_name":"luksdlt92/Training","owner":{"login":"luksdlt92","id":4108820,"avatar_url":"https://avatars.githubusercontent.com/u/4108820?v=3","gravatar_id":"","url":"https://api.github.com/users/luksdlt92","html_url":"https://github.com/luksdlt92","followers_url":"https://api.github.com/users/luksdlt92/followers","following_url":"https://api.github.com/users/luksdlt92/following{/other_user}","gists_url":"https://api.github.com/users/luksdlt92/gists{/gist_id}","starred_url":"https://api.github.com/users/luksdlt92/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luksdlt92/subscriptions","organizations_url":"https://api.github.com/users/luksdlt92/orgs","repos_url":"https://api.github.com/users/luksdlt92/repos","events_url":"https://api.github.com/users/luksdlt92/events{/privacy}","received_events_url":"https://api.github.com/users/luksdlt92/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/luksdlt92/Training","description":"","fork":false,"url":"https://api.github.com/repos/luksdlt92/Training","forks_url":"https://api.github.com/repos/luksdlt92/Training/forks","keys_url":"https://api.github.com/repos/luksdlt92/Training/keys{/key_id}","collaborators_url":"https://api.github.com/repos/luksdlt92/Training/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/luksdlt92/Training/teams","hooks_url":"https://api.github.com/repos/luksdlt92/Training/hooks","issue_events_url":"https://api.github.com/repos/luksdlt92/Training/issues/events{/number}","events_url":"https://api.github.com/repos/luksdlt92/Training/events","assignees_url":"https://api.github.com/repos/luksdlt92/Training/assignees{/user}","branches_url":"https://api.github.com/repos/luksdlt92/Training/branches{/branch}","tags_url":"https://api.github.com/repos/luksdlt92/Training/tags","blobs_url":"https://api.github.com/repos/luksdlt92/Training/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/luksdlt92/Training/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/luksdlt92/Training/git/refs{/sha}","trees_url":"https://api.github.com/repos/luksdlt92/Training/git/trees{/sha}","statuses_url":"https://api.github.com/repos/luksdlt92/Training/statuses/{sha}","languages_url":"https://api.github.com/repos/luksdlt92/Training/languages","stargazers_url":"https://api.github.com/repos/luksdlt92/Training/stargazers","contributors_url":"https://api.github.com/repos/luksdlt92/Training/contributors","subscribers_url":"https://api.github.com/repos/luksdlt92/Training/subscribers","subscription_url":"https://api.github.com/repos/luksdlt92/Training/subscription","commits_url":"https://api.github.com/repos/luksdlt92/Training/commits{/sha}","git_commits_url":"https://api.github.com/repos/luksdlt92/Training/git/commits{/sha}","comments_url":"https://api.github.com/repos/luksdlt92/Training/comments{/number}","issue_comment_url":"https://api.github.com/repos/luksdlt92/Training/issues/comments{/number}","contents_url":"https://api.github.com/repos/luksdlt92/Training/contents/{+path}","compare_url":"https://api.github.com/repos/luksdlt92/Training/compare/{base}...{head}","merges_url":"https://api.github.com/repos/luksdlt92/Training/merges","archive_url":"https://api.github.com/repos/luksdlt92/Training/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/luksdlt92/Training/downloads","issues_url":"https://api.github.com/repos/luksdlt92/Training/issues{/number}","pulls_url":"https://api.github.com/repos/luksdlt92/Training/pulls{/number}","milestones_url":"https://api.github.com/repos/luksdlt92/Training/milestones{/number}","notifications_url":"https://api.github.com/repos/luksdlt92/Training/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/luksdlt92/Training/labels{/name}","releases_url":"https://api.github.com/repos/luksdlt92/Training/releases{/id}","created_at":"2015-04-14T13:50:51Z","updated_at":"2015-04-14T13:50:51Z","pushed_at":"2015-05-04T15:02:10Z","git_url":"git://github.com/luksdlt92/Training.git","ssh_url":"git@github.com:luksdlt92/Training.git","clone_url":"https://github.com/luksdlt92/Training.git","svn_url":"https://github.com/luksdlt92/Training","homepage":null,"size":5412,"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":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/12"},"html":{"href":"https://github.com/luksdlt92/Training/pull/12"},"issue":{"href":"https://api.github.com/repos/luksdlt92/Training/issues/12"},"comments":{"href":"https://api.github.com/repos/luksdlt92/Training/issues/12/comments"},"review_comments":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/12/comments"},"review_comment":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/luksdlt92/Training/pulls/12/commits"},"statuses":{"href":"https://api.github.com/repos/luksdlt92/Training/statuses/dd446b97e25dbe2b91dd8c433c5e352ffdd15bda"}}}}