@@ -160,8 +160,6 @@ public class MainActivity extends AppCompatActivity
160
160
161
161
protected static final int REQUEST_WRITE_STORAGE = 112 ;
162
162
163
- public static String USER_THUMB_KEY = "user_thumb_key" ;
164
-
165
163
// Whether or not we received device logs from a wear device. This will allow a timer to be run in case wear support has
166
164
// been purchased, but no wear device is paired. When this happens, we'll go ahead and email just the mobile device's logs
167
165
//
@@ -434,7 +432,7 @@ private void init() {
434
432
.addControlCategory (CastMediaControlIntent .categoryForCast (BuildConfig .CHROMECAST_APP_ID ))
435
433
.build ();
436
434
mMediaRouterCallback = new MediaRouterCallback ();
437
- mMediaRouter .addCallback (mMediaRouteSelector , mMediaRouterCallback , MediaRouter .CALLBACK_FLAG_REQUEST_DISCOVERY );
435
+ mMediaRouter .addCallback (mMediaRouteSelector , mMediaRouterCallback , MediaRouter .CALLBACK_FLAG_PERFORM_ACTIVE_SCAN );
438
436
439
437
server = gsonRead .fromJson (prefs .get (Preferences .SERVER , "" ), PlexServer .class );
440
438
if (server == null )
@@ -699,7 +697,6 @@ private void showFindingPlexClientsAndServers() {
699
697
View layout = inflater .inflate (R .layout .search_popup , null );
700
698
701
699
alertDialog = new AlertDialog .Builder (this )
702
- .setTitle (R .string .finding_plex_clients_and_servers )
703
700
.setCancelable (false )
704
701
.setView (layout )
705
702
.create ();
@@ -1188,7 +1185,7 @@ private void setUserThumb() {
1188
1185
}
1189
1186
1190
1187
private void setUserThumb (boolean skipThumb ) {
1191
- final Bitmap bitmap = VoiceControlForPlexApplication .getInstance ().getCachedBitmap (USER_THUMB_KEY );
1188
+ final Bitmap bitmap = VoiceControlForPlexApplication .getInstance ().getCachedBitmap (VoiceControlForPlexApplication . getInstance (). getUserThumbKey () );
1192
1189
if (bitmap == null && !skipThumb ) {
1193
1190
fetchUserThumb ();
1194
1191
} else {
@@ -1197,7 +1194,10 @@ private void setUserThumb(boolean skipThumb) {
1197
1194
public void run () {
1198
1195
View navHeader = navigationViewMain .getHeaderView (0 );
1199
1196
ImageView imageView = (ImageView ) navHeader .findViewById (R .id .navHeaderUserIcon );
1200
- imageView .setImageBitmap (bitmap );
1197
+ if (bitmap == null )
1198
+ imageView .setImageResource (R .drawable .nav_default_user );
1199
+ else
1200
+ imageView .setImageBitmap (bitmap );
1201
1201
}
1202
1202
});
1203
1203
}
@@ -1208,13 +1208,15 @@ private void fetchUserThumb() {
1208
1208
@ Override
1209
1209
protected Void doInBackground (Void ... params ) {
1210
1210
try {
1211
- String url = String .format ("http://www.gravatar.com/avatar/%s?s=60" , Utils .md5 (prefs .getString (Preferences .PLEX_EMAIL )));
1211
+ String url = String .format ("http://www.gravatar.com/avatar/%s?s=60&d=404 " , Utils .md5 (prefs .getString (Preferences .PLEX_EMAIL )));
1212
1212
Logger .d ("url: %s" , url );
1213
1213
byte [] imageData = PlexHttpClient .getSyncBytes (url );
1214
- Logger .d ("got %d bytes" , imageData .length );
1215
- InputStream is = new ByteArrayInputStream (imageData );
1216
- is .reset ();
1217
- VoiceControlForPlexApplication .getInstance ().mSimpleDiskCache .put (USER_THUMB_KEY , is );
1214
+ if (imageData != null ) {
1215
+ Logger .d ("got %d bytes" , imageData .length );
1216
+ InputStream is = new ByteArrayInputStream (imageData );
1217
+ is .reset ();
1218
+ VoiceControlForPlexApplication .getInstance ().mSimpleDiskCache .put (VoiceControlForPlexApplication .getInstance ().getUserThumbKey (), is );
1219
+ }
1218
1220
setUserThumb (true );
1219
1221
}
1220
1222
catch (SocketTimeoutException e ) {
@@ -1486,19 +1488,23 @@ private void saveSettings() {
1486
1488
prefs .put (Preferences .RESUME , prefs .get (Preferences .RESUME , false ));
1487
1489
}
1488
1490
1491
+ public void deviceSelectDialogRefresh () {
1492
+ ListView serverListView = (ListView ) deviceSelectDialog .findViewById (R .id .serverListView );
1493
+ PlexListAdapter adapter = (PlexListAdapter )serverListView .getAdapter ();
1494
+ adapter .setClients (VoiceControlForPlexApplication .getAllClients ());
1495
+ adapter .notifyDataSetChanged ();
1496
+ }
1497
+
1489
1498
private class MediaRouterCallback extends MediaRouter .Callback {
1490
1499
@ Override
1491
1500
public void onRouteRemoved (MediaRouter router , MediaRouter .RouteInfo route ) {
1492
1501
super .onRouteRemoved (router , route );
1493
1502
Logger .d ("Cast Client %s has gone missing. Removing." , route .getName ());
1494
1503
if (VoiceControlForPlexApplication .castClients .containsKey (route .getName ())) {
1495
1504
VoiceControlForPlexApplication .castClients .remove (route .getName ());
1496
- prefs .put (Preferences .SAVED_CAST_CLIENTS , gsonWrite .toJson (VoiceControlForPlexApplication .castClients ));
1497
- // If the "select a plex client" dialog is showing, refresh the list of clients
1498
- // TODO: Refresh device dialog if needed
1499
- // if(localScan.isDeviceDialogShowing()) {
1500
- // localScan.deviceSelectDialogRefresh();
1501
- // }
1505
+ if (deviceSelectDialog != null && deviceSelectDialog .isShowing ()) {
1506
+ deviceSelectDialogRefresh ();
1507
+ }
1502
1508
}
1503
1509
}
1504
1510
@@ -1513,18 +1519,13 @@ public void onRouteAdded(MediaRouter router, MediaRouter.RouteInfo route)
1513
1519
client .isCastClient = true ;
1514
1520
client .name = route .getName ();
1515
1521
client .product = route .getDescription ();
1516
- // client.castRouteInfo = route;
1517
1522
client .castDevice = CastDevice .getFromBundle (route .getExtras ());
1518
1523
client .machineIdentifier = client .castDevice .getDeviceId ();
1519
- // VoiceControlForPlexApplication.castRoutes.put(client.machineIdentifier, route);
1520
1524
VoiceControlForPlexApplication .castClients .put (client .name , client );
1521
1525
Logger .d ("Added cast client %s (%s)" , client .name , client .machineIdentifier );
1522
- prefs .put (Preferences .SAVED_CAST_CLIENTS , gsonWrite .toJson (VoiceControlForPlexApplication .castClients ));
1523
- // If the "select a plex client" dialog is showing, refresh the list of clients
1524
- // TODO: implement this?
1525
- // if(deviceSelectDialog != null && deviceSelectDialog.isShowing()) {
1526
- // deviceSelectDialogRefresh();
1527
- // }
1526
+ if (deviceSelectDialog != null && deviceSelectDialog .isShowing ()) {
1527
+ deviceSelectDialogRefresh ();
1528
+ }
1528
1529
}
1529
1530
1530
1531
@ Override
0 commit comments