@@ -61,6 +61,7 @@ public void searchForPlexServers() {
61
61
mServiceIntent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
62
62
mServiceIntent .putExtra ("ORIGIN" , theClass .getSimpleName ());
63
63
mServiceIntent .putExtra ("class" , theClass );
64
+ mServiceIntent .putExtra (VoiceControlForPlexApplication .Intent .SCAN_TYPE , "server" );
64
65
context .startService (mServiceIntent );
65
66
}
66
67
@@ -96,102 +97,37 @@ public void onItemClick(AdapterView<?> parentAdapter, View view, int position, l
96
97
});
97
98
}
98
99
99
- public void getClients () {
100
- getClients (new PlexServer ("none" ));
101
- }
102
-
103
- public void getClients (PlexServer _server ) {
100
+ public void searchForPlexClients () {
101
+ Logger .d ("searchForPlexClients()" );
104
102
if (!VoiceControlForPlexApplication .isWifiConnected (context )) {
105
103
VoiceControlForPlexApplication .showNoWifiDialog (context );
106
104
return ;
107
105
}
108
- server = _server ;
109
- if (_server .name .equals ("none" ))
110
- server = gson .fromJson (mPrefs .getString ("Server" , "" ), PlexServer .class );
111
- if (server == null || server .name .equals (context .getResources ().getString (R .string .scan_all ))) {
112
- scanForClients ();
113
- } else {
114
- getClients (new MediaContainer ());
115
- }
116
- }
117
106
118
- public void getClients (MediaContainer mc ) {
119
- PlexServer server = gson .fromJson (mPrefs .getString ("Server" , "" ), PlexServer .class );
120
- if (mc .machineIdentifier != null ) {
121
- server .machineIdentifier = mc .machineIdentifier ;
122
- SharedPreferences .Editor mPrefsEditor = mPrefs .edit ();
123
- mPrefsEditor .putString ("Server" , gson .toJson (server ));
124
- mPrefsEditor .commit ();
125
- }
126
- if (searchDialog == null ) {
127
- searchDialog = new Dialog (context );
128
- }
107
+ searchDialog = new Dialog (context );
129
108
130
109
searchDialog .setContentView (R .layout .search_popup );
131
- searchDialog .setTitle ("Searching for Plex Clients" );
110
+ searchDialog .setTitle (context . getResources (). getString ( R . string . searching_for_plex_clients ) );
132
111
133
112
searchDialog .show ();
134
- PlexHttpClient .get (server , "/clients" , new PlexHttpMediaContainerHandler () {
135
- @ Override
136
- public void onSuccess (MediaContainer clientMC ) {
137
- // Exclude non-Plex Home Theater clients (pre 1.0.7)
138
- Map <String , PlexClient > clients = new HashMap <String , PlexClient >();
139
- for (int i = 0 ; i < clientMC .clients .size (); i ++) {
140
- if (!VoiceControlForPlexApplication .isVersionLessThan (clientMC .clients .get (i ).version , VoiceControlForPlexApplication .MINIMUM_PHT_VERSION ) || !clientMC .clients .get (i ).product .equals ("Plex Home Theater" )) {
141
- clients .put (clientMC .clients .get (i ).name , clientMC .clients .get (i ));
142
- }
143
- }
144
113
145
- searchDialog .dismiss ();
146
- if (clients .size () == 0 ) {
147
- AlertDialog .Builder builder = new AlertDialog .Builder (context );
148
- builder .setTitle ("No Plex Clients Found" );
149
- builder .setCancelable (false )
150
- .setNeutralButton (R .string .ok , new DialogInterface .OnClickListener () {
151
- public void onClick (DialogInterface dialog , int id ) {
152
- dialog .cancel ();
153
- }
154
- });
155
- AlertDialog d = builder .create ();
156
- d .show ();
157
- } else {
158
- Logger .d ("Clients: " + clients .size ());
159
- SharedPreferences .Editor mPrefsEditor = mPrefs .edit ();
160
- mPrefsEditor .putString (Preferences .SAVED_CLIENTS , gson .toJson (clients ));
161
- mPrefsEditor .commit ();
162
- showPlexClients (clients );
163
- }
164
- }
165
-
166
- @ Override
167
- public void onFailure (Throwable error ) {
168
- searchDialog .dismiss ();
169
- feedback .e (context .getResources ().getString (R .string .got_error ), error .getMessage ());
170
- }
171
- });
172
- }
173
-
174
- public void scanForClients () {
175
- if (searchDialog == null ) {
176
- searchDialog = new Dialog (context );
177
- }
178
-
179
- searchDialog .setContentView (R .layout .search_popup );
180
- searchDialog .setTitle ("Searching for Plex Clients" );
181
-
182
- searchDialog .show ();
183
114
Intent mServiceIntent = new Intent (context , GDMService .class );
184
- mServiceIntent .putExtra ("ORIGIN" , "ScanForClients" );
115
+ mServiceIntent .putExtra ("port" , 32412 ); // Port for clients
116
+ mServiceIntent .addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
117
+ mServiceIntent .putExtra ("ORIGIN" , theClass .getSimpleName ());
185
118
mServiceIntent .putExtra ("class" , theClass );
119
+ mServiceIntent .putExtra (VoiceControlForPlexApplication .Intent .SCAN_TYPE , "client" );
186
120
context .startService (mServiceIntent );
187
121
}
188
122
189
123
public void showPlexClients (Map <String , PlexClient > clients ) {
124
+ if (searchDialog != null )
125
+ searchDialog .dismiss ();
190
126
if (serverSelectDialog == null ) {
191
127
serverSelectDialog = new Dialog (context );
192
128
}
193
129
serverSelectDialog .setContentView (R .layout .server_select );
194
- serverSelectDialog .setTitle ("Select a Plex Client" );
130
+ serverSelectDialog .setTitle (R . string . select_plex_client );
195
131
serverSelectDialog .show ();
196
132
197
133
final ListView serverListView = (ListView )serverSelectDialog .findViewById (R .id .serverListView );
0 commit comments