{"action":"created","comment":{"url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/comments/76845163","id":76845163,"diff_hunk":"@@ -0,0 +1,92 @@\n+package com.shamilov.weatherapp.mvp.weaterlist;\n+\n+import android.content.res.Resources;\n+\n+import com.shamilov.weatherapp.App;\n+import com.shamilov.weatherapp.Constants;\n+import com.shamilov.weatherapp.R;\n+import com.shamilov.weatherapp.data.Database;\n+import com.shamilov.weatherapp.model.mapper.WeatherMapper;\n+import com.shamilov.weatherapp.utils.RxUtils;\n+import com.shamilov.weatherapp.web.ConnectivityUtils;\n+import com.shamilov.weatherapp.web.api.WeatherApi;\n+\n+import javax.inject.Inject;\n+\n+import rx.Subscription;\n+import rx.android.schedulers.AndroidSchedulers;\n+import rx.schedulers.Schedulers;\n+import rx.subscriptions.CompositeSubscription;\n+\n+/**\n+ * @author Stanislav Shamilov\n+ */\n+\n+public class WeatherCitiesPresenter {\n+\n+    @Inject\n+    WeatherApi mApi;\n+\n+    @Inject\n+    Database mDatabase;\n+\n+    @Inject\n+    App mApp;\n+\n+    @Inject\n+    Resources mResources;\n+\n+    private final WeatherCitiesView mView;\n+\n+    private final CompositeSubscription mCompositeSubscription = new CompositeSubscription();\n+\n+    public WeatherCitiesPresenter(WeatherCitiesView view) {\n+        App.getComponent().inject(this);\n+        mView = view;\n+        mDatabase.open();\n+    }\n+\n+    public void loadWeathers() {\n+        final Subscription subscription = mDatabase.getWeathers()\n+                .compose(RxUtils.applySchedulers())\n+                .subscribe(mView::showWeather);\n+        mCompositeSubscription.add(subscription);\n+    }\n+\n+    public void findWeatherByCity(String cityName) {\n+        final Subscription subscription =\n+                ConnectivityUtils\n+                        .getConnectivityObservable(mApp.getApplicationContext())\n+                        .doOnNext(isNetwork -> throwExceptionIfNot(isNetwork, mResources.getString(R.string.error_network)))\n+                        .flatMap(isNetwork -> mApi.getWeatherByCityName(cityName))\n+                        .doOnNext(\n+                                weatherResponse -> throwExceptionIfNot(\n+                                        weatherResponse.getCode() == Constants.CODE_RESPONSE_SUCCESS,\n+                                        mResources.getString(R.string.error_unable_to_find))\n+                        )\n+                        .map(new WeatherMapper())\n+                        .doOnNext(mDatabase::saveWeather)\n+                        .subscribeOn(Schedulers.io())\n+                        .observeOn(AndroidSchedulers.mainThread())\n+                        .subscribe(\n+                                mView::addWeather,\n+                                error -> mView.showError(error.getMessage())\n+                        );\n+        mCompositeSubscription.add(subscription);\n+    }\n+\n+    public void onDestroy() {\n+        mDatabase.close();\n+        if (mCompositeSubscription != null && !mCompositeSubscription.isUnsubscribed()) {\n+            mCompositeSubscription.unsubscribe();\n+        }\n+    }\n+\n+\n+\n+    private void throwExceptionIfNot(boolean condition, String errorMessage) {","path":"app/src/main/java/com/shamilov/weatherapp/mvp/weaterlist/WeatherCitiesPresenter.java","position":87,"original_position":87,"commit_id":"76f6a87f42609c0f0fc6f3c631c8ec0c171b4a12","original_commit_id":"76f6a87f42609c0f0fc6f3c631c8ec0c171b4a12","user":{"login":"mikhailmikhaylov","id":8265843,"avatar_url":"https://avatars.githubusercontent.com/u/8265843?v=3","gravatar_id":"","url":"https://api.github.com/users/mikhailmikhaylov","html_url":"https://github.com/mikhailmikhaylov","followers_url":"https://api.github.com/users/mikhailmikhaylov/followers","following_url":"https://api.github.com/users/mikhailmikhaylov/following{/other_user}","gists_url":"https://api.github.com/users/mikhailmikhaylov/gists{/gist_id}","starred_url":"https://api.github.com/users/mikhailmikhaylov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikhailmikhaylov/subscriptions","organizations_url":"https://api.github.com/users/mikhailmikhaylov/orgs","repos_url":"https://api.github.com/users/mikhailmikhaylov/repos","events_url":"https://api.github.com/users/mikhailmikhaylov/events{/privacy}","received_events_url":"https://api.github.com/users/mikhailmikhaylov/received_events","type":"User","site_admin":false},"body":"Logic also seems a bit strange","created_at":"2016-08-30T17:51:34Z","updated_at":"2016-08-30T17:51:34Z","html_url":"https://github.com/ShamilovSV/WeatherClient/pull/6#discussion_r76845163","pull_request_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/comments/76845163"},"html":{"href":"https://github.com/ShamilovSV/WeatherClient/pull/6#discussion_r76845163"},"pull_request":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6","id":83130980,"html_url":"https://github.com/ShamilovSV/WeatherClient/pull/6","diff_url":"https://github.com/ShamilovSV/WeatherClient/pull/6.diff","patch_url":"https://github.com/ShamilovSV/WeatherClient/pull/6.patch","issue_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/6","number":6,"state":"open","locked":false,"title":"Feature/architecture","user":{"login":"ShamilovSV","id":13655535,"avatar_url":"https://avatars.githubusercontent.com/u/13655535?v=3","gravatar_id":"","url":"https://api.github.com/users/ShamilovSV","html_url":"https://github.com/ShamilovSV","followers_url":"https://api.github.com/users/ShamilovSV/followers","following_url":"https://api.github.com/users/ShamilovSV/following{/other_user}","gists_url":"https://api.github.com/users/ShamilovSV/gists{/gist_id}","starred_url":"https://api.github.com/users/ShamilovSV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShamilovSV/subscriptions","organizations_url":"https://api.github.com/users/ShamilovSV/orgs","repos_url":"https://api.github.com/users/ShamilovSV/repos","events_url":"https://api.github.com/users/ShamilovSV/events{/privacy}","received_events_url":"https://api.github.com/users/ShamilovSV/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-08-29T16:57:15Z","updated_at":"2016-08-30T17:51:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0571459f3f7cc5e8381678cdf34df0e0cacde987","assignee":{"login":"mikhailmikhaylov","id":8265843,"avatar_url":"https://avatars.githubusercontent.com/u/8265843?v=3","gravatar_id":"","url":"https://api.github.com/users/mikhailmikhaylov","html_url":"https://github.com/mikhailmikhaylov","followers_url":"https://api.github.com/users/mikhailmikhaylov/followers","following_url":"https://api.github.com/users/mikhailmikhaylov/following{/other_user}","gists_url":"https://api.github.com/users/mikhailmikhaylov/gists{/gist_id}","starred_url":"https://api.github.com/users/mikhailmikhaylov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikhailmikhaylov/subscriptions","organizations_url":"https://api.github.com/users/mikhailmikhaylov/orgs","repos_url":"https://api.github.com/users/mikhailmikhaylov/repos","events_url":"https://api.github.com/users/mikhailmikhaylov/events{/privacy}","received_events_url":"https://api.github.com/users/mikhailmikhaylov/received_events","type":"User","site_admin":false},"assignees":[{"login":"mikhailmikhaylov","id":8265843,"avatar_url":"https://avatars.githubusercontent.com/u/8265843?v=3","gravatar_id":"","url":"https://api.github.com/users/mikhailmikhaylov","html_url":"https://github.com/mikhailmikhaylov","followers_url":"https://api.github.com/users/mikhailmikhaylov/followers","following_url":"https://api.github.com/users/mikhailmikhaylov/following{/other_user}","gists_url":"https://api.github.com/users/mikhailmikhaylov/gists{/gist_id}","starred_url":"https://api.github.com/users/mikhailmikhaylov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mikhailmikhaylov/subscriptions","organizations_url":"https://api.github.com/users/mikhailmikhaylov/orgs","repos_url":"https://api.github.com/users/mikhailmikhaylov/repos","events_url":"https://api.github.com/users/mikhailmikhaylov/events{/privacy}","received_events_url":"https://api.github.com/users/mikhailmikhaylov/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6/commits","review_comments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6/comments","review_comment_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/6/comments","statuses_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/statuses/76f6a87f42609c0f0fc6f3c631c8ec0c171b4a12","head":{"label":"ShamilovSV:feature/architecture","ref":"feature/architecture","sha":"76f6a87f42609c0f0fc6f3c631c8ec0c171b4a12","user":{"login":"ShamilovSV","id":13655535,"avatar_url":"https://avatars.githubusercontent.com/u/13655535?v=3","gravatar_id":"","url":"https://api.github.com/users/ShamilovSV","html_url":"https://github.com/ShamilovSV","followers_url":"https://api.github.com/users/ShamilovSV/followers","following_url":"https://api.github.com/users/ShamilovSV/following{/other_user}","gists_url":"https://api.github.com/users/ShamilovSV/gists{/gist_id}","starred_url":"https://api.github.com/users/ShamilovSV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShamilovSV/subscriptions","organizations_url":"https://api.github.com/users/ShamilovSV/orgs","repos_url":"https://api.github.com/users/ShamilovSV/repos","events_url":"https://api.github.com/users/ShamilovSV/events{/privacy}","received_events_url":"https://api.github.com/users/ShamilovSV/received_events","type":"User","site_admin":false},"repo":{"id":66140002,"name":"WeatherClient","full_name":"ShamilovSV/WeatherClient","owner":{"login":"ShamilovSV","id":13655535,"avatar_url":"https://avatars.githubusercontent.com/u/13655535?v=3","gravatar_id":"","url":"https://api.github.com/users/ShamilovSV","html_url":"https://github.com/ShamilovSV","followers_url":"https://api.github.com/users/ShamilovSV/followers","following_url":"https://api.github.com/users/ShamilovSV/following{/other_user}","gists_url":"https://api.github.com/users/ShamilovSV/gists{/gist_id}","starred_url":"https://api.github.com/users/ShamilovSV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShamilovSV/subscriptions","organizations_url":"https://api.github.com/users/ShamilovSV/orgs","repos_url":"https://api.github.com/users/ShamilovSV/repos","events_url":"https://api.github.com/users/ShamilovSV/events{/privacy}","received_events_url":"https://api.github.com/users/ShamilovSV/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ShamilovSV/WeatherClient","description":"Openweathermap.com mobile client","fork":false,"url":"https://api.github.com/repos/ShamilovSV/WeatherClient","forks_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/forks","keys_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/teams","hooks_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/hooks","issue_events_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/events{/number}","events_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/events","assignees_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/assignees{/user}","branches_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/branches{/branch}","tags_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/tags","blobs_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/refs{/sha}","trees_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/statuses/{sha}","languages_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/languages","stargazers_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/stargazers","contributors_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/contributors","subscribers_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/subscribers","subscription_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/subscription","commits_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/commits{/sha}","git_commits_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/commits{/sha}","comments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/comments{/number}","issue_comment_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/comments{/number}","contents_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/contents/{+path}","compare_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/merges","archive_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/downloads","issues_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues{/number}","pulls_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls{/number}","milestones_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/milestones{/number}","notifications_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/labels{/name}","releases_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/releases{/id}","deployments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/deployments","created_at":"2016-08-20T09:54:53Z","updated_at":"2016-08-20T10:52:02Z","pushed_at":"2016-08-30T15:14:26Z","git_url":"git://github.com/ShamilovSV/WeatherClient.git","ssh_url":"git@github.com:ShamilovSV/WeatherClient.git","clone_url":"https://github.com/ShamilovSV/WeatherClient.git","svn_url":"https://github.com/ShamilovSV/WeatherClient","homepage":null,"size":129,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"base":{"label":"ShamilovSV:develop","ref":"develop","sha":"f09e672796c2d7c0fd841730d9c290a7a1d5d230","user":{"login":"ShamilovSV","id":13655535,"avatar_url":"https://avatars.githubusercontent.com/u/13655535?v=3","gravatar_id":"","url":"https://api.github.com/users/ShamilovSV","html_url":"https://github.com/ShamilovSV","followers_url":"https://api.github.com/users/ShamilovSV/followers","following_url":"https://api.github.com/users/ShamilovSV/following{/other_user}","gists_url":"https://api.github.com/users/ShamilovSV/gists{/gist_id}","starred_url":"https://api.github.com/users/ShamilovSV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShamilovSV/subscriptions","organizations_url":"https://api.github.com/users/ShamilovSV/orgs","repos_url":"https://api.github.com/users/ShamilovSV/repos","events_url":"https://api.github.com/users/ShamilovSV/events{/privacy}","received_events_url":"https://api.github.com/users/ShamilovSV/received_events","type":"User","site_admin":false},"repo":{"id":66140002,"name":"WeatherClient","full_name":"ShamilovSV/WeatherClient","owner":{"login":"ShamilovSV","id":13655535,"avatar_url":"https://avatars.githubusercontent.com/u/13655535?v=3","gravatar_id":"","url":"https://api.github.com/users/ShamilovSV","html_url":"https://github.com/ShamilovSV","followers_url":"https://api.github.com/users/ShamilovSV/followers","following_url":"https://api.github.com/users/ShamilovSV/following{/other_user}","gists_url":"https://api.github.com/users/ShamilovSV/gists{/gist_id}","starred_url":"https://api.github.com/users/ShamilovSV/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShamilovSV/subscriptions","organizations_url":"https://api.github.com/users/ShamilovSV/orgs","repos_url":"https://api.github.com/users/ShamilovSV/repos","events_url":"https://api.github.com/users/ShamilovSV/events{/privacy}","received_events_url":"https://api.github.com/users/ShamilovSV/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ShamilovSV/WeatherClient","description":"Openweathermap.com mobile client","fork":false,"url":"https://api.github.com/repos/ShamilovSV/WeatherClient","forks_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/forks","keys_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/teams","hooks_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/hooks","issue_events_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/events{/number}","events_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/events","assignees_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/assignees{/user}","branches_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/branches{/branch}","tags_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/tags","blobs_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/refs{/sha}","trees_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/statuses/{sha}","languages_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/languages","stargazers_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/stargazers","contributors_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/contributors","subscribers_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/subscribers","subscription_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/subscription","commits_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/commits{/sha}","git_commits_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/git/commits{/sha}","comments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/comments{/number}","issue_comment_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/comments{/number}","contents_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/contents/{+path}","compare_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/merges","archive_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/downloads","issues_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues{/number}","pulls_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls{/number}","milestones_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/milestones{/number}","notifications_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/labels{/name}","releases_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/releases{/id}","deployments_url":"https://api.github.com/repos/ShamilovSV/WeatherClient/deployments","created_at":"2016-08-20T09:54:53Z","updated_at":"2016-08-20T10:52:02Z","pushed_at":"2016-08-30T15:14:26Z","git_url":"git://github.com/ShamilovSV/WeatherClient.git","ssh_url":"git@github.com:ShamilovSV/WeatherClient.git","clone_url":"https://github.com/ShamilovSV/WeatherClient.git","svn_url":"https://github.com/ShamilovSV/WeatherClient","homepage":null,"size":129,"stargazers_count":1,"watchers_count":1,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":4,"forks":0,"open_issues":4,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6"},"html":{"href":"https://github.com/ShamilovSV/WeatherClient/pull/6"},"issue":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/6"},"comments":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/ShamilovSV/WeatherClient/statuses/76f6a87f42609c0f0fc6f3c631c8ec0c171b4a12"}}}}
{"actor":{"display_login":"mikhailmikhaylov"}}