{"action":"created","comment":{"url":"https://api.github.com/repos/openhab/openhab-android/pulls/comments/173888823","pull_request_review_id":103144761,"id":173888823,"diff_hunk":"@@ -178,67 +206,95 @@ private Connection getConnectionInternal(int connectionType) {\n             case Connection.TYPE_REMOTE:\n                 return mRemoteConnection;\n             case Connection.TYPE_CLOUD:\n-                // TODO: Need a proper way of finding if the connection supports openHAB cloud\n-                // things, e.g. by checking if the /api/v1/settings/notifications endpoint works,\n-                // but currently does not work for myopenhab.org\n-                return mRemoteConnection;\n+                return mCloudConnection;\n             default:\n                 throw new IllegalArgumentException(\"Invalid Connection type requested.\");\n         }\n     }\n \n     @Override\n     public void onReceive(Context context, Intent intent) {\n+        if (mIgnoreNextConnectivityChange) {\n+            mIgnoreNextConnectivityChange = false;\n+            return;\n+        }\n         if (mListeners.isEmpty()) {\n             // We're running in background. Clear current state and postpone update for next\n             // listener registration.\n             mAvailableConnection = null;\n             mConnectionFailureReason = null;\n             mNeedsUpdate = true;\n         } else {\n-            mUpdateHandler.sendEmptyMessage(MSG_TRIGGER_UPDATE);\n+            triggerConnectionUpdateIfNeeded();\n         }\n     }\n \n     @Override\n     public boolean handleMessage(Message msg) {\n         switch (msg.what) {\n-            case MSG_TRIGGER_UPDATE: // update thread\n-                Message result = mMainHandler.obtainMessage(MSG_UPDATE_DONE);\n+            case MSG_TRIGGER_UPDATE: { // update thread\n                 Connection local, remote;\n                 synchronized (this) {\n                     local = mLocalConnection;\n                     remote = mRemoteConnection;\n                 }\n+                ConnectionUpdateResult result = new ConnectionUpdateResult();\n                 try {\n-                    result.obj = determineAvailableConnection(ctx, local, remote);\n+                    result.available = determineAvailableConnection(ctx, local, remote);\n                 } catch (ConnectionException e) {\n-                    result.obj = e;\n+                    result.availableFailureReason = e;\n                 }\n-                mMainHandler.sendMessage(result);\n-                return true;\n-            case MSG_UPDATE_DONE: // main thread\n-                if (msg.obj instanceof ConnectionException) {\n-                    updateAvailableConnection(null, (ConnectionException) msg.obj);\n+                if (remote != null) {\n+                    mUpdateHandler.obtainMessage(MSG_UPDATE_CLOUD_CONNECTION, result).sendToTarget();\n                 } else {\n-                    // Check whether the passed connection matches a known one. If not, the\n-                    // connections were updated while the thread was processing and we'll get\n-                    // a new callback.\n-                    if (msg.obj == mLocalConnection || msg.obj == mRemoteConnection) {\n-                        updateAvailableConnection((Connection) msg.obj, null);\n-                    }\n+                    mMainHandler.obtainMessage(MSG_UPDATE_DONE, result).sendToTarget();\n+                }\n+                return true;\n+            }\n+            case MSG_UPDATE_CLOUD_CONNECTION: { // update thread\n+                ConnectionUpdateResult result = (ConnectionUpdateResult) msg.obj;\n+                final AbstractConnection remote;\n+                synchronized (this) {\n+                    remote = mRemoteConnection;\n                 }\n+                if (remote != null) {\n+                    final MySyncHttpClient client = remote.getSyncHttpClient();\n+                    client.get(CloudConnection.SETTINGS_ROUTE, new MyHttpClient.TextResponseHandler() {\n+                        @Override\n+                        public void onFailure(Call call, int statusCode, Headers headers, String responseBody, Throwable error) {\n+                            Log.e(TAG, \"Error loading notification settings: \" + error.getMessage());\n+                        }\n+\n+                        @Override\n+                        public void onSuccess(Call call, int statusCode, Headers headers, String responseBody) {\n+                            try {\n+                                JSONObject json = new JSONObject(responseBody);\n+                                String senderId = json.getJSONObject(\"gcm\").getString(\"senderId\");","path":"mobile/src/main/java/org/openhab/habdroid/core/connection/ConnectionFactory.java","position":199,"original_position":199,"commit_id":"088ba7744a87b0a3b103af8eec688628216e6767","original_commit_id":"088ba7744a87b0a3b103af8eec688628216e6767","user":{"login":"FlorianSW","id":4892966,"avatar_url":"https://avatars1.githubusercontent.com/u/4892966?v=4","gravatar_id":"","url":"https://api.github.com/users/FlorianSW","html_url":"https://github.com/FlorianSW","followers_url":"https://api.github.com/users/FlorianSW/followers","following_url":"https://api.github.com/users/FlorianSW/following{/other_user}","gists_url":"https://api.github.com/users/FlorianSW/gists{/gist_id}","starred_url":"https://api.github.com/users/FlorianSW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FlorianSW/subscriptions","organizations_url":"https://api.github.com/users/FlorianSW/orgs","repos_url":"https://api.github.com/users/FlorianSW/repos","events_url":"https://api.github.com/users/FlorianSW/events{/privacy}","received_events_url":"https://api.github.com/users/FlorianSW/received_events","type":"User","site_admin":false},"body":"As already stated somewhere else: I don't think, that this belongs into the Connection object. And if it does, I would argue, that it should be part of the Connection interface, so that no cast is needed.\r\n\r\nOr, when I think about it: If a connection to specific server has special features/parameters, it should probably be it's own type (class or interface). However, it feeld strange to shift the need to cast the connection object to the caller of the COnnectionFactory, though :(","created_at":"2018-03-12T17:50:06Z","updated_at":"2018-03-12T17:56:35Z","html_url":"https://github.com/openhab/openhab-android/pull/775#discussion_r173888823","pull_request_url":"https://api.github.com/repos/openhab/openhab-android/pulls/775","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/comments/173888823"},"html":{"href":"https://github.com/openhab/openhab-android/pull/775#discussion_r173888823"},"pull_request":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/775"}}},"pull_request":{"url":"https://api.github.com/repos/openhab/openhab-android/pulls/775","id":174230494,"html_url":"https://github.com/openhab/openhab-android/pull/775","diff_url":"https://github.com/openhab/openhab-android/pull/775.diff","patch_url":"https://github.com/openhab/openhab-android/pull/775.patch","issue_url":"https://api.github.com/repos/openhab/openhab-android/issues/775","number":775,"state":"open","locked":false,"title":"Refactor GCM implementation","user":{"login":"maniac103","id":781373,"avatar_url":"https://avatars1.githubusercontent.com/u/781373?v=4","gravatar_id":"","url":"https://api.github.com/users/maniac103","html_url":"https://github.com/maniac103","followers_url":"https://api.github.com/users/maniac103/followers","following_url":"https://api.github.com/users/maniac103/following{/other_user}","gists_url":"https://api.github.com/users/maniac103/gists{/gist_id}","starred_url":"https://api.github.com/users/maniac103/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maniac103/subscriptions","organizations_url":"https://api.github.com/users/maniac103/orgs","repos_url":"https://api.github.com/users/maniac103/repos","events_url":"https://api.github.com/users/maniac103/events{/privacy}","received_events_url":"https://api.github.com/users/maniac103/received_events","type":"User","site_admin":false},"body":"Keep notion of 'Google Cloud Messaging' in full flavor code. Also generate cloud connection object only if settings endpoint of server API can be reached.","created_at":"2018-03-11T16:55:40Z","updated_at":"2018-03-12T17:56:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"130df44f268de3a06f1526810b9cc8b66310d441","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":394758269,"url":"https://api.github.com/repos/openhab/openhab-android/labels/code%20enhancement","name":"code enhancement","color":"f9d0c4","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/openhab/openhab-android/pulls/775/commits","review_comments_url":"https://api.github.com/repos/openhab/openhab-android/pulls/775/comments","review_comment_url":"https://api.github.com/repos/openhab/openhab-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openhab/openhab-android/issues/775/comments","statuses_url":"https://api.github.com/repos/openhab/openhab-android/statuses/088ba7744a87b0a3b103af8eec688628216e6767","head":{"label":"maniac103:gcm-refactor","ref":"gcm-refactor","sha":"088ba7744a87b0a3b103af8eec688628216e6767","user":{"login":"maniac103","id":781373,"avatar_url":"https://avatars1.githubusercontent.com/u/781373?v=4","gravatar_id":"","url":"https://api.github.com/users/maniac103","html_url":"https://github.com/maniac103","followers_url":"https://api.github.com/users/maniac103/followers","following_url":"https://api.github.com/users/maniac103/following{/other_user}","gists_url":"https://api.github.com/users/maniac103/gists{/gist_id}","starred_url":"https://api.github.com/users/maniac103/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maniac103/subscriptions","organizations_url":"https://api.github.com/users/maniac103/orgs","repos_url":"https://api.github.com/users/maniac103/repos","events_url":"https://api.github.com/users/maniac103/events{/privacy}","received_events_url":"https://api.github.com/users/maniac103/received_events","type":"User","site_admin":false},"repo":{"id":97915798,"name":"openhab.android","full_name":"maniac103/openhab.android","owner":{"login":"maniac103","id":781373,"avatar_url":"https://avatars1.githubusercontent.com/u/781373?v=4","gravatar_id":"","url":"https://api.github.com/users/maniac103","html_url":"https://github.com/maniac103","followers_url":"https://api.github.com/users/maniac103/followers","following_url":"https://api.github.com/users/maniac103/following{/other_user}","gists_url":"https://api.github.com/users/maniac103/gists{/gist_id}","starred_url":"https://api.github.com/users/maniac103/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maniac103/subscriptions","organizations_url":"https://api.github.com/users/maniac103/orgs","repos_url":"https://api.github.com/users/maniac103/repos","events_url":"https://api.github.com/users/maniac103/events{/privacy}","received_events_url":"https://api.github.com/users/maniac103/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maniac103/openhab.android","description":"openHAB Android app","fork":true,"url":"https://api.github.com/repos/maniac103/openhab.android","forks_url":"https://api.github.com/repos/maniac103/openhab.android/forks","keys_url":"https://api.github.com/repos/maniac103/openhab.android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maniac103/openhab.android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maniac103/openhab.android/teams","hooks_url":"https://api.github.com/repos/maniac103/openhab.android/hooks","issue_events_url":"https://api.github.com/repos/maniac103/openhab.android/issues/events{/number}","events_url":"https://api.github.com/repos/maniac103/openhab.android/events","assignees_url":"https://api.github.com/repos/maniac103/openhab.android/assignees{/user}","branches_url":"https://api.github.com/repos/maniac103/openhab.android/branches{/branch}","tags_url":"https://api.github.com/repos/maniac103/openhab.android/tags","blobs_url":"https://api.github.com/repos/maniac103/openhab.android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maniac103/openhab.android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maniac103/openhab.android/git/refs{/sha}","trees_url":"https://api.github.com/repos/maniac103/openhab.android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maniac103/openhab.android/statuses/{sha}","languages_url":"https://api.github.com/repos/maniac103/openhab.android/languages","stargazers_url":"https://api.github.com/repos/maniac103/openhab.android/stargazers","contributors_url":"https://api.github.com/repos/maniac103/openhab.android/contributors","subscribers_url":"https://api.github.com/repos/maniac103/openhab.android/subscribers","subscription_url":"https://api.github.com/repos/maniac103/openhab.android/subscription","commits_url":"https://api.github.com/repos/maniac103/openhab.android/commits{/sha}","git_commits_url":"https://api.github.com/repos/maniac103/openhab.android/git/commits{/sha}","comments_url":"https://api.github.com/repos/maniac103/openhab.android/comments{/number}","issue_comment_url":"https://api.github.com/repos/maniac103/openhab.android/issues/comments{/number}","contents_url":"https://api.github.com/repos/maniac103/openhab.android/contents/{+path}","compare_url":"https://api.github.com/repos/maniac103/openhab.android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maniac103/openhab.android/merges","archive_url":"https://api.github.com/repos/maniac103/openhab.android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maniac103/openhab.android/downloads","issues_url":"https://api.github.com/repos/maniac103/openhab.android/issues{/number}","pulls_url":"https://api.github.com/repos/maniac103/openhab.android/pulls{/number}","milestones_url":"https://api.github.com/repos/maniac103/openhab.android/milestones{/number}","notifications_url":"https://api.github.com/repos/maniac103/openhab.android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maniac103/openhab.android/labels{/name}","releases_url":"https://api.github.com/repos/maniac103/openhab.android/releases{/id}","deployments_url":"https://api.github.com/repos/maniac103/openhab.android/deployments","created_at":"2017-07-21T06:48:55Z","updated_at":"2017-07-21T06:48:57Z","pushed_at":"2018-03-12T15:47:49Z","git_url":"git://github.com/maniac103/openhab.android.git","ssh_url":"git@github.com:maniac103/openhab.android.git","clone_url":"https://github.com/maniac103/openhab.android.git","svn_url":"https://github.com/maniac103/openhab.android","homepage":null,"size":22316,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"openhab:master","ref":"master","sha":"b2080350148d5f326fcc8b19e431f3651a9c42f5","user":{"login":"openhab","id":1007353,"avatar_url":"https://avatars0.githubusercontent.com/u/1007353?v=4","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"repo":{"id":18703240,"name":"openhab-android","full_name":"openhab/openhab-android","owner":{"login":"openhab","id":1007353,"avatar_url":"https://avatars0.githubusercontent.com/u/1007353?v=4","gravatar_id":"","url":"https://api.github.com/users/openhab","html_url":"https://github.com/openhab","followers_url":"https://api.github.com/users/openhab/followers","following_url":"https://api.github.com/users/openhab/following{/other_user}","gists_url":"https://api.github.com/users/openhab/gists{/gist_id}","starred_url":"https://api.github.com/users/openhab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openhab/subscriptions","organizations_url":"https://api.github.com/users/openhab/orgs","repos_url":"https://api.github.com/users/openhab/repos","events_url":"https://api.github.com/users/openhab/events{/privacy}","received_events_url":"https://api.github.com/users/openhab/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openhab/openhab-android","description":"openHAB Android client","fork":false,"url":"https://api.github.com/repos/openhab/openhab-android","forks_url":"https://api.github.com/repos/openhab/openhab-android/forks","keys_url":"https://api.github.com/repos/openhab/openhab-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openhab/openhab-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openhab/openhab-android/teams","hooks_url":"https://api.github.com/repos/openhab/openhab-android/hooks","issue_events_url":"https://api.github.com/repos/openhab/openhab-android/issues/events{/number}","events_url":"https://api.github.com/repos/openhab/openhab-android/events","assignees_url":"https://api.github.com/repos/openhab/openhab-android/assignees{/user}","branches_url":"https://api.github.com/repos/openhab/openhab-android/branches{/branch}","tags_url":"https://api.github.com/repos/openhab/openhab-android/tags","blobs_url":"https://api.github.com/repos/openhab/openhab-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openhab/openhab-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openhab/openhab-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/openhab/openhab-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openhab/openhab-android/statuses/{sha}","languages_url":"https://api.github.com/repos/openhab/openhab-android/languages","stargazers_url":"https://api.github.com/repos/openhab/openhab-android/stargazers","contributors_url":"https://api.github.com/repos/openhab/openhab-android/contributors","subscribers_url":"https://api.github.com/repos/openhab/openhab-android/subscribers","subscription_url":"https://api.github.com/repos/openhab/openhab-android/subscription","commits_url":"https://api.github.com/repos/openhab/openhab-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/openhab/openhab-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/openhab/openhab-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/openhab/openhab-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/openhab/openhab-android/contents/{+path}","compare_url":"https://api.github.com/repos/openhab/openhab-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openhab/openhab-android/merges","archive_url":"https://api.github.com/repos/openhab/openhab-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openhab/openhab-android/downloads","issues_url":"https://api.github.com/repos/openhab/openhab-android/issues{/number}","pulls_url":"https://api.github.com/repos/openhab/openhab-android/pulls{/number}","milestones_url":"https://api.github.com/repos/openhab/openhab-android/milestones{/number}","notifications_url":"https://api.github.com/repos/openhab/openhab-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openhab/openhab-android/labels{/name}","releases_url":"https://api.github.com/repos/openhab/openhab-android/releases{/id}","deployments_url":"https://api.github.com/repos/openhab/openhab-android/deployments","created_at":"2014-04-12T12:09:03Z","updated_at":"2018-03-12T13:51:40Z","pushed_at":"2018-03-12T16:41:39Z","git_url":"git://github.com/openhab/openhab-android.git","ssh_url":"git@github.com:openhab/openhab-android.git","clone_url":"https://github.com/openhab/openhab-android.git","svn_url":"https://github.com/openhab/openhab-android","homepage":"","size":21816,"stargazers_count":185,"watchers_count":185,"language":"Java","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":183,"mirror_url":null,"archived":false,"open_issues_count":125,"license":{"key":"epl-1.0","name":"Eclipse Public License 1.0","spdx_id":"EPL-1.0","url":"https://api.github.com/licenses/epl-1.0"},"forks":183,"open_issues":125,"watchers":185,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/775"},"html":{"href":"https://github.com/openhab/openhab-android/pull/775"},"issue":{"href":"https://api.github.com/repos/openhab/openhab-android/issues/775"},"comments":{"href":"https://api.github.com/repos/openhab/openhab-android/issues/775/comments"},"review_comments":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/775/comments"},"review_comment":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openhab/openhab-android/pulls/775/commits"},"statuses":{"href":"https://api.github.com/repos/openhab/openhab-android/statuses/088ba7744a87b0a3b103af8eec688628216e6767"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"FlorianSW"}}