Skip to content

Commit ad29908

Browse files
author
Chris Bellew
committed
Moved client selection completely into cast icon. Fixed hiding and showing of cast icon when network state toggles. Don't show notification when the client is the local device.
1 parent a26b848 commit ad29908

File tree

6 files changed

+63
-17
lines changed

6 files changed

+63
-17
lines changed

Voice Control For Plex/src/main/java/com/atomjack/vcfp/LocalScan.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class LocalScan {
2424
private Dialog searchDialog;
2525
private Dialog deviceSelectDialog = null;
2626
private ScanHandler scanHandler;
27+
private boolean cancelScan = false;
28+
public boolean isScanning = false;
2729

2830
public LocalScan(Context ctx, Class cls, ScanHandler handler) {
2931
context = ctx;
@@ -37,6 +39,7 @@ public void searchForPlexServers() {
3739

3840
public void searchForPlexServers(boolean silent) {
3941
Logger.d("searchForPlexServers()");
42+
isScanning = true;
4043
if(!VoiceControlForPlexApplication.isWifiConnected(context)) {
4144
VoiceControlForPlexApplication.showNoWifiDialog(context);
4245
return;
@@ -74,6 +77,11 @@ public void showPlexServers() {
7477
}
7578

7679
public void showPlexServers(ConcurrentHashMap<String, PlexServer> servers) {
80+
isScanning = false;
81+
if(cancelScan) {
82+
cancelScan = false;
83+
return;
84+
}
7785
if(searchDialog != null)
7886
searchDialog.dismiss();
7987
if(deviceSelectDialog == null) {
@@ -101,24 +109,36 @@ public void onItemClick(AdapterView<?> parentAdapter, View view, int position, l
101109
});
102110
}
103111

112+
public void cancelScan() {
113+
Logger.d("[LocalScan] canceling scan");
114+
cancelScan = true;
115+
}
116+
104117
public void searchForPlexClients() {
105-
searchForPlexClients(false);
118+
searchForPlexClients(false, true);
106119
}
107120

108121
public void searchForPlexClients(boolean connectToClient) {
122+
searchForPlexClients(connectToClient, true);
123+
}
124+
125+
public void searchForPlexClients(boolean connectToClient, boolean showSearchDialog) {
109126
Logger.d("[LocalScan] searchForPlexClients()");
127+
isScanning = true;
110128
if(!VoiceControlForPlexApplication.isWifiConnected(context)) {
111129
VoiceControlForPlexApplication.showNoWifiDialog(context);
112130
return;
113131
}
114132

115-
searchDialog = new Dialog(context);
133+
if(showSearchDialog) {
134+
searchDialog = new Dialog(context);
116135

117-
searchDialog.setContentView(R.layout.search_popup);
118-
searchDialog.setTitle(context.getResources().getString(R.string.searching_for_plex_clients));
119-
searchDialog.setOnCancelListener(searchDialogCancel);
136+
searchDialog.setContentView(R.layout.search_popup);
137+
searchDialog.setTitle(context.getResources().getString(R.string.searching_for_plex_clients));
138+
searchDialog.setOnCancelListener(searchDialogCancel);
120139

121-
searchDialog.show();
140+
searchDialog.show();
141+
}
122142

123143
Intent mServiceIntent = new Intent(context, GDMService.class);
124144
mServiceIntent.putExtra(GDMService.PORT, 32412); // Port for clients
@@ -155,6 +175,11 @@ public boolean isDeviceDialogShowing() {
155175
}
156176

157177
public void showPlexClients(boolean showResume, final ScanHandler onFinish) {
178+
isScanning = false;
179+
if(cancelScan) {
180+
cancelScan = false;
181+
return;
182+
}
158183
if (searchDialog != null)
159184
searchDialog.dismiss();
160185
if (deviceSelectDialog == null) {

Voice Control For Plex/src/main/java/com/atomjack/vcfp/NetworkMonitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public void onReceive(Context context, Intent intent) {
4545
VoiceControlForPlexApplication.getInstance().onNetworkDisconnected();
4646
}
4747
} else {
48-
connected = true;
4948
int type = activeNetwork.getType();
50-
if (type != currentState) {
49+
if (type != currentState || !connected) {
5150
currentState = type;
5251
VoiceControlForPlexApplication.getInstance().onNetworkConnected(currentState);
5352
}
53+
connected = true;
5454
}
5555

5656
/*

Voice Control For Plex/src/main/java/com/atomjack/vcfp/VoiceControlForPlexApplication.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,10 +360,6 @@ public static String generateRandomString() {
360360
return new BigInteger(130, random).toString(32).substring(0, 12);
361361
}
362362

363-
public void setNotification(final PlexClient client, final PlayerState currentState, final PlexMedia media) {
364-
setNotification(client, currentState, media, false);
365-
}
366-
367363
private Bitmap getCachedBitmap(String key) {
368364
if(key == null)
369365
return null;
@@ -414,7 +410,14 @@ protected Object doInBackground(Object[] objects) {
414410
}.execute();
415411
}
416412

413+
public void setNotification(final PlexClient client, final PlayerState currentState, final PlexMedia media) {
414+
setNotification(client, currentState, media, false);
415+
}
416+
417417
public void setNotification(final PlexClient client, final PlayerState currentState, final PlexMedia media, boolean skipThumb) {
418+
419+
if(client.isLocalDevice())
420+
return;
418421
Logger.d("Setting notification, client: %s, media: %s", client, media);
419422
if(client == null) {
420423
Logger.d("Client is null for some reason");

Voice Control For Plex/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ private void initMainWithServer() {
268268
clientName = getString(R.string.this_device);
269269
MainSetting setting_data[] = new MainSetting[] {
270270
new MainSetting(MainListAdapter.SettingHolder.TAG_SERVER, getResources().getString(R.string.stream_video_from_server), server.owned ? server.name : server.sourceTitle),
271-
new MainSetting(MainListAdapter.SettingHolder.TAG_CLIENT, getResources().getString(R.string.to_the_client), clientName),
271+
// new MainSetting(MainListAdapter.SettingHolder.TAG_CLIENT, getResources().getString(R.string.to_the_client), clientName),
272272
new MainSetting(MainListAdapter.SettingHolder.TAG_FEEDBACK, getResources().getString(R.string.feedback), VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.FEEDBACK, FEEDBACK_TOAST) == FEEDBACK_VOICE ? getResources().getString(R.string.voice) : getResources().getString(R.string.toast)),
273273
new MainSetting(MainListAdapter.SettingHolder.TAG_ERRORS, getResources().getString(R.string.errors), VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.ERRORS, FEEDBACK_TOAST) == FEEDBACK_VOICE ? getResources().getString(R.string.voice) : getResources().getString(R.string.toast))
274274
};
@@ -333,6 +333,7 @@ public void onFailure(int statusCode) {
333333
} else
334334
localScan.searchForPlexServers();
335335
}
336+
/*
336337
} else if (holder.tag.equals(holder.TAG_CLIENT)) {
337338
if(!currentNetworkState.equals(NetworkState.WIFI)) {
338339
if(currentNetworkState.equals(NetworkState.MOBILE)) {
@@ -345,6 +346,7 @@ public void onFailure(int statusCode) {
345346
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
346347
localScan.searchForPlexClients();
347348
}
349+
*/
348350
} else if (holder.tag.equals(holder.TAG_FEEDBACK)) {
349351
selectFeedback();
350352
} else if (holder.tag.equals(holder.TAG_ERRORS)) {
@@ -835,6 +837,8 @@ protected void setServer(PlexServer _server) {
835837

836838
@Override
837839
protected void setClient(PlexClient _client) {
840+
super.setClient(_client);
841+
Logger.d("[MainActivity] setClient");
838842
if(!VoiceControlForPlexApplication.getInstance().hasChromecast() && _client.isCastClient) {
839843
showChromecastPurchase(_client, new Runnable() {
840844
@Override

Voice Control For Plex/src/main/java/com/atomjack/vcfp/activities/VCFPActivity.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.atomjack.vcfp.PlayerState;
3232
import com.atomjack.vcfp.PlexHeaders;
3333
import com.atomjack.vcfp.PlexSubscription;
34+
import com.atomjack.vcfp.Preferences;
3435
import com.atomjack.vcfp.R;
3536
import com.atomjack.vcfp.ScanHandler;
3637
import com.atomjack.vcfp.ServerFindHandler;
@@ -63,7 +64,6 @@
6364

6465
public abstract class VCFPActivity extends ActionBarActivity implements PlexSubscription.PlexListener, CastPlayerManager.CastListener, VoiceControlForPlexApplication.NetworkChangeListener {
6566
protected PlexMedia nowPlayingMedia;
66-
protected boolean subscribed = false;
6767
protected boolean subscribing = false;
6868
protected PlexClient mClient;
6969

@@ -229,8 +229,11 @@ public boolean onOptionsItemSelected(MenuItem item) {
229229
subscribing = true;
230230
if(VoiceControlForPlexApplication.clients.size() == 0 && !VoiceControlForPlexApplication.hasDoneClientScan) {
231231
localScan.searchForPlexClients(true);
232-
} else
233-
localScan.showPlexClients(false, onClientChosen);
232+
} else {
233+
localScan.showPlexClients(false, onClientChosen);
234+
// Kick off a client scan in the background
235+
localScan.searchForPlexClients(true, false);
236+
}
234237
} else if(!subscribing) {
235238
// For some reason we sometimes lost mClient here, even though we're subscribed. If we do, let's try to get the client from the subscription manager
236239
if(mClient == null) {
@@ -275,11 +278,15 @@ public void onClick(DialogInterface dialogInterface, int i) {
275278
protected ScanHandler onClientChosen = new ScanHandler() {
276279
@Override
277280
public void onDeviceSelected(PlexDevice device, boolean resume) {
281+
if(localScan.isScanning)
282+
localScan.cancelScan();
278283
subscribing = false;
279284
if(device != null) {
280285
Logger.d("[VCFPActivity] onClientChosen: %s", device.name);
281286
PlexClient clientSelected = (PlexClient) device;
282287

288+
setClient(clientSelected);
289+
283290
// Start animating the action bar icon
284291
final MenuItem castIcon = menu.findItem(R.id.action_cast);
285292
castIcon.setIcon(R.drawable.mr_ic_media_route_connecting_holo_dark);
@@ -707,5 +714,7 @@ protected void setServer(PlexServer _server) {
707714
}
708715

709716
protected void setClient(PlexClient _client) {
717+
Logger.d("[VCFPActivity] setClient");
718+
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.CLIENT, gsonWrite.toJson(_client));
710719
}
711720
}

Voice Control For Plex/src/main/java/com/atomjack/vcfp/model/PlexClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.os.Parcel;
44
import android.os.Parcelable;
55

6+
import com.atomjack.vcfp.Utils;
67
import com.atomjack.vcfp.net.PlexHttpClient;
78
import com.atomjack.vcfp.net.PlexHttpResponseHandler;
89
import com.google.android.gms.cast.CastDevice;
@@ -108,7 +109,6 @@ private void adjustPlayback(String which, PlexHttpResponseHandler responseHandle
108109

109110
public PlexResponse pause() {
110111
return adjustPlayback("pause");
111-
// adjustPlayback("pause", responseHandler);
112112
}
113113

114114
public PlexResponse stop() {
@@ -134,4 +134,9 @@ private PlexResponse adjustPlayback(String which) {
134134
}
135135
return null;
136136
}
137+
138+
public boolean isLocalDevice() {
139+
String localip = Utils.getIPAddress(true);
140+
return localip.equals(address);
141+
}
137142
}

0 commit comments

Comments
 (0)