{"action":"created","comment":{"url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/comments/44897970","id":44897970,"diff_hunk":"@@ -0,0 +1,161 @@\n+/*\n+ * Copyright (C) 2015 Pedro Vicente Gómez Sánchez.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package com.github.pedrovgs.androidwifiadb.adb;\n+\n+import com.intellij.openapi.project.Project;\n+import com.github.pedrovgs.androidwifiadb.view.View;\n+import com.github.pedrovgs.androidwifiadb.model.Device;\n+\n+import java.util.ArrayList;\n+import java.util.List;\n+\n+public class AndroidWiFiADB {\n+\n+  private final ADB adb;\n+  private final View view;\n+  private List<Device> devices;\n+\n+  public AndroidWiFiADB(ADB adb, View view) {\n+    this.adb = adb;\n+    this.view = view;\n+    this.devices = new ArrayList<Device>();\n+  }\n+\n+  public void connectDevices() {\n+    if (!isADBInstalled()) {\n+      view.showADBNotInstalledNotification();\n+      return;\n+    }\n+    devices = adb.getDevicesConnectedByUSB();\n+    if (devices.isEmpty()) {\n+      view.showNoConnectedDevicesNotification();\n+      return;\n+    }\n+\n+    devices = adb.connectDevices(devices);\n+    showConnectionResultNotification(devices);\n+  }\n+\n+  /**\n+   * Find connected devices through USB.\n+   * If there's a new device - we add it to devices list.\n+   * Call <code>getDevices()</code> in order to get updated devices list.\n+   * <br>We should always update devices list,\n+   * because their names might change.\n+   * Unathorized and authorized states produce different device names.\n+   * @return true - refresh required, false - otherwise.\n+   */\n+  public boolean refreshDevicesList() {\n+    if (!isADBInstalled()) {\n+      return false;\n+    }\n+    List<Device> connected = adb.getDevicesConnectedByUSB();\n+    for (Device connectedDevice : connected) {\n+      boolean deviceExists = checkDeviceExistance(connectedDevice);\n+      if (!deviceExists) {\n+        connectedDevice.setIp(adb.getDeviceIp(connectedDevice));\n+        devices.add(connectedDevice);\n+      } else {\n+        updateDeviceInfo(connectedDevice);\n+      }\n+    }\n+    return true;\n+  }\n+\n+  private void updateDeviceInfo(Device updatedDevice) {\n+    for (int i = 0, size = devices.size(); i < size; i++) {\n+      Device device = devices.get(i);\n+      if (updatedDevice.getId().equals(device.getId())) {\n+        devices.remove(i);\n+        device.setName(updatedDevice.getName());\n+        devices.add(i, device);\n+      }\n+    }","path":"src/main/java/com/github/pedrovgs/androidwifiadb/adb/AndroidWiFiADB.java","position":116,"original_position":87,"commit_id":"51702cd005b0439abd4e364151843e9921aca9fa","original_commit_id":"0c31663282acb893c218aee42ed7806f6abf9fc2","user":{"login":"donvigo","id":3036347,"avatar_url":"https://avatars.githubusercontent.com/u/3036347?v=3","gravatar_id":"","url":"https://api.github.com/users/donvigo","html_url":"https://github.com/donvigo","followers_url":"https://api.github.com/users/donvigo/followers","following_url":"https://api.github.com/users/donvigo/following{/other_user}","gists_url":"https://api.github.com/users/donvigo/gists{/gist_id}","starred_url":"https://api.github.com/users/donvigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donvigo/subscriptions","organizations_url":"https://api.github.com/users/donvigo/orgs","repos_url":"https://api.github.com/users/donvigo/repos","events_url":"https://api.github.com/users/donvigo/events{/privacy}","received_events_url":"https://api.github.com/users/donvigo/received_events","type":"User","site_admin":false},"body":"Well, I'll try `LinkedHashSet` and will come to you with the updates ;)","created_at":"2015-11-16T08:31:39Z","updated_at":"2015-11-16T08:31:39Z","html_url":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26#discussion_r44897970","pull_request_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/comments/44897970"},"html":{"href":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26#discussion_r44897970"},"pull_request":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26","id":48867208,"html_url":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26","diff_url":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26.diff","patch_url":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26.patch","issue_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/26","number":26,"state":"open","locked":false,"title":"Devices window","user":{"login":"donvigo","id":3036347,"avatar_url":"https://avatars.githubusercontent.com/u/3036347?v=3","gravatar_id":"","url":"https://api.github.com/users/donvigo","html_url":"https://github.com/donvigo","followers_url":"https://api.github.com/users/donvigo/followers","following_url":"https://api.github.com/users/donvigo/following{/other_user}","gists_url":"https://api.github.com/users/donvigo/gists{/gist_id}","starred_url":"https://api.github.com/users/donvigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donvigo/subscriptions","organizations_url":"https://api.github.com/users/donvigo/orgs","repos_url":"https://api.github.com/users/donvigo/repos","events_url":"https://api.github.com/users/donvigo/events{/privacy}","received_events_url":"https://api.github.com/users/donvigo/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-27T13:03:39Z","updated_at":"2015-11-16T08:31:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dafa01167cc846fbf1632a964faa253e313ced1f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26/commits","review_comments_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26/comments","review_comment_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/26/comments","statuses_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/statuses/51702cd005b0439abd4e364151843e9921aca9fa","head":{"label":"donvigo:devices-window","ref":"devices-window","sha":"51702cd005b0439abd4e364151843e9921aca9fa","user":{"login":"donvigo","id":3036347,"avatar_url":"https://avatars.githubusercontent.com/u/3036347?v=3","gravatar_id":"","url":"https://api.github.com/users/donvigo","html_url":"https://github.com/donvigo","followers_url":"https://api.github.com/users/donvigo/followers","following_url":"https://api.github.com/users/donvigo/following{/other_user}","gists_url":"https://api.github.com/users/donvigo/gists{/gist_id}","starred_url":"https://api.github.com/users/donvigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donvigo/subscriptions","organizations_url":"https://api.github.com/users/donvigo/orgs","repos_url":"https://api.github.com/users/donvigo/repos","events_url":"https://api.github.com/users/donvigo/events{/privacy}","received_events_url":"https://api.github.com/users/donvigo/received_events","type":"User","site_admin":false},"repo":{"id":44801250,"name":"AndroidWiFiADB","full_name":"donvigo/AndroidWiFiADB","owner":{"login":"donvigo","id":3036347,"avatar_url":"https://avatars.githubusercontent.com/u/3036347?v=3","gravatar_id":"","url":"https://api.github.com/users/donvigo","html_url":"https://github.com/donvigo","followers_url":"https://api.github.com/users/donvigo/followers","following_url":"https://api.github.com/users/donvigo/following{/other_user}","gists_url":"https://api.github.com/users/donvigo/gists{/gist_id}","starred_url":"https://api.github.com/users/donvigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/donvigo/subscriptions","organizations_url":"https://api.github.com/users/donvigo/orgs","repos_url":"https://api.github.com/users/donvigo/repos","events_url":"https://api.github.com/users/donvigo/events{/privacy}","received_events_url":"https://api.github.com/users/donvigo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/donvigo/AndroidWiFiADB","description":"IntelliJ/AndroidStudio plugin which provides a button to connect your Android device over WiFi to install, run and debug your applications without a USB connected.","fork":true,"url":"https://api.github.com/repos/donvigo/AndroidWiFiADB","forks_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/forks","keys_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/keys{/key_id}","collaborators_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/teams","hooks_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/hooks","issue_events_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/issues/events{/number}","events_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/events","assignees_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/assignees{/user}","branches_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/branches{/branch}","tags_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/tags","blobs_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/git/refs{/sha}","trees_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/git/trees{/sha}","statuses_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/statuses/{sha}","languages_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/languages","stargazers_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/stargazers","contributors_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/contributors","subscribers_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/subscribers","subscription_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/subscription","commits_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/commits{/sha}","git_commits_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/git/commits{/sha}","comments_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/comments{/number}","issue_comment_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/issues/comments{/number}","contents_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/contents/{+path}","compare_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/compare/{base}...{head}","merges_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/merges","archive_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/downloads","issues_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/issues{/number}","pulls_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/pulls{/number}","milestones_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/milestones{/number}","notifications_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/labels{/name}","releases_url":"https://api.github.com/repos/donvigo/AndroidWiFiADB/releases{/id}","created_at":"2015-10-23T08:42:43Z","updated_at":"2015-10-23T08:42:44Z","pushed_at":"2015-11-15T11:42:44Z","git_url":"git://github.com/donvigo/AndroidWiFiADB.git","ssh_url":"git@github.com:donvigo/AndroidWiFiADB.git","clone_url":"https://github.com/donvigo/AndroidWiFiADB.git","svn_url":"https://github.com/donvigo/AndroidWiFiADB","homepage":null,"size":2984,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"pedrovgs:master","ref":"master","sha":"e67a48c7829e553b87acbf54e0d48f1263ecf79e","user":{"login":"pedrovgs","id":4030704,"avatar_url":"https://avatars.githubusercontent.com/u/4030704?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrovgs","html_url":"https://github.com/pedrovgs","followers_url":"https://api.github.com/users/pedrovgs/followers","following_url":"https://api.github.com/users/pedrovgs/following{/other_user}","gists_url":"https://api.github.com/users/pedrovgs/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrovgs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrovgs/subscriptions","organizations_url":"https://api.github.com/users/pedrovgs/orgs","repos_url":"https://api.github.com/users/pedrovgs/repos","events_url":"https://api.github.com/users/pedrovgs/events{/privacy}","received_events_url":"https://api.github.com/users/pedrovgs/received_events","type":"User","site_admin":false},"repo":{"id":44498352,"name":"AndroidWiFiADB","full_name":"pedrovgs/AndroidWiFiADB","owner":{"login":"pedrovgs","id":4030704,"avatar_url":"https://avatars.githubusercontent.com/u/4030704?v=3","gravatar_id":"","url":"https://api.github.com/users/pedrovgs","html_url":"https://github.com/pedrovgs","followers_url":"https://api.github.com/users/pedrovgs/followers","following_url":"https://api.github.com/users/pedrovgs/following{/other_user}","gists_url":"https://api.github.com/users/pedrovgs/gists{/gist_id}","starred_url":"https://api.github.com/users/pedrovgs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pedrovgs/subscriptions","organizations_url":"https://api.github.com/users/pedrovgs/orgs","repos_url":"https://api.github.com/users/pedrovgs/repos","events_url":"https://api.github.com/users/pedrovgs/events{/privacy}","received_events_url":"https://api.github.com/users/pedrovgs/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pedrovgs/AndroidWiFiADB","description":"IntelliJ/AndroidStudio plugin which provides a button to connect your Android device over WiFi to install, run and debug your applications without a USB connected.","fork":false,"url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB","forks_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/forks","keys_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/teams","hooks_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/hooks","issue_events_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/events{/number}","events_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/events","assignees_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/assignees{/user}","branches_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/branches{/branch}","tags_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/tags","blobs_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/git/refs{/sha}","trees_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/statuses/{sha}","languages_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/languages","stargazers_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/stargazers","contributors_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/contributors","subscribers_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/subscribers","subscription_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/subscription","commits_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/commits{/sha}","git_commits_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/git/commits{/sha}","comments_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/comments{/number}","issue_comment_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/comments{/number}","contents_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/contents/{+path}","compare_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/merges","archive_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/downloads","issues_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues{/number}","pulls_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls{/number}","milestones_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/milestones{/number}","notifications_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/labels{/name}","releases_url":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/releases{/id}","created_at":"2015-10-18T21:58:45Z","updated_at":"2015-11-16T07:17:32Z","pushed_at":"2015-11-15T11:42:44Z","git_url":"git://github.com/pedrovgs/AndroidWiFiADB.git","ssh_url":"git@github.com:pedrovgs/AndroidWiFiADB.git","clone_url":"https://github.com/pedrovgs/AndroidWiFiADB.git","svn_url":"https://github.com/pedrovgs/AndroidWiFiADB","homepage":null,"size":3200,"stargazers_count":1154,"watchers_count":1154,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":8,"forks":99,"open_issues":8,"watchers":1154,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26"},"html":{"href":"https://github.com/pedrovgs/AndroidWiFiADB/pull/26"},"issue":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/26"},"comments":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/pedrovgs/AndroidWiFiADB/statuses/51702cd005b0439abd4e364151843e9921aca9fa"}}}}