Skip to content

Commit 608c50c

Browse files
author
Chris Bellew
committed
Don't save cast clients, just get ones currently available. Use default user icon in case no gravatar icon is found. Fixed layout of initial server & client scan popup.
1 parent 66ac945 commit 608c50c

File tree

3 files changed

+46
-29
lines changed

3 files changed

+46
-29
lines changed

mobile/src/main/java/com/atomjack/vcfp/VoiceControlForPlexApplication.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ public void onCreate() {
210210

211211
// Load saved clients and servers
212212
Type clientType = new TypeToken<HashMap<String, PlexClient>>(){}.getType();
213-
VoiceControlForPlexApplication.castClients = gsonRead.fromJson(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.SAVED_CAST_CLIENTS, "{}"), clientType);
214213
VoiceControlForPlexApplication.clients = gsonRead.fromJson(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.SAVED_CLIENTS, "{}"), clientType);
215214
Type serverType = new TypeToken<ConcurrentHashMap<String, PlexServer>>(){}.getType();
216215
VoiceControlForPlexApplication.servers = gsonRead.fromJson(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.SAVED_SERVERS, "{}"), serverType);
@@ -844,4 +843,11 @@ public int getSecondsSinceLastServerScan() {
844843
Logger.d("lastServerScan: %s", lastServerScan);
845844
return (int)((now.getTime() - lastServerScan.getTime())/1000);
846845
}
846+
847+
public String getUserThumbKey() {
848+
String key = "user_thumb_key";
849+
if(prefs.getString(Preferences.PLEX_USERNAME) != null)
850+
key += prefs.getString(Preferences.PLEX_USERNAME);
851+
return key;
852+
}
847853
}

mobile/src/main/java/com/atomjack/vcfp/activities/MainActivity.java

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ public class MainActivity extends AppCompatActivity
160160

161161
protected static final int REQUEST_WRITE_STORAGE = 112;
162162

163-
public static String USER_THUMB_KEY = "user_thumb_key";
164-
165163
// Whether or not we received device logs from a wear device. This will allow a timer to be run in case wear support has
166164
// been purchased, but no wear device is paired. When this happens, we'll go ahead and email just the mobile device's logs
167165
//
@@ -434,7 +432,7 @@ private void init() {
434432
.addControlCategory(CastMediaControlIntent.categoryForCast(BuildConfig.CHROMECAST_APP_ID))
435433
.build();
436434
mMediaRouterCallback = new MediaRouterCallback();
437-
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);
435+
mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback, MediaRouter.CALLBACK_FLAG_PERFORM_ACTIVE_SCAN);
438436

439437
server = gsonRead.fromJson(prefs.get(Preferences.SERVER, ""), PlexServer.class);
440438
if (server == null)
@@ -699,7 +697,6 @@ private void showFindingPlexClientsAndServers() {
699697
View layout = inflater.inflate(R.layout.search_popup, null);
700698

701699
alertDialog = new AlertDialog.Builder(this)
702-
.setTitle(R.string.finding_plex_clients_and_servers)
703700
.setCancelable(false)
704701
.setView(layout)
705702
.create();
@@ -1188,7 +1185,7 @@ private void setUserThumb() {
11881185
}
11891186

11901187
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());
11921189
if(bitmap == null && !skipThumb) {
11931190
fetchUserThumb();
11941191
} else {
@@ -1197,7 +1194,10 @@ private void setUserThumb(boolean skipThumb) {
11971194
public void run() {
11981195
View navHeader = navigationViewMain.getHeaderView(0);
11991196
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);
12011201
}
12021202
});
12031203
}
@@ -1208,13 +1208,15 @@ private void fetchUserThumb() {
12081208
@Override
12091209
protected Void doInBackground(Void... params) {
12101210
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)));
12121212
Logger.d("url: %s", url);
12131213
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+
}
12181220
setUserThumb(true);
12191221
}
12201222
catch(SocketTimeoutException e) {
@@ -1486,19 +1488,23 @@ private void saveSettings() {
14861488
prefs.put(Preferences.RESUME, prefs.get(Preferences.RESUME, false));
14871489
}
14881490

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+
14891498
private class MediaRouterCallback extends MediaRouter.Callback {
14901499
@Override
14911500
public void onRouteRemoved(MediaRouter router, MediaRouter.RouteInfo route) {
14921501
super.onRouteRemoved(router, route);
14931502
Logger.d("Cast Client %s has gone missing. Removing.", route.getName());
14941503
if(VoiceControlForPlexApplication.castClients.containsKey(route.getName())) {
14951504
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+
}
15021508
}
15031509
}
15041510

@@ -1513,18 +1519,13 @@ public void onRouteAdded(MediaRouter router, MediaRouter.RouteInfo route)
15131519
client.isCastClient = true;
15141520
client.name = route.getName();
15151521
client.product = route.getDescription();
1516-
// client.castRouteInfo = route;
15171522
client.castDevice = CastDevice.getFromBundle(route.getExtras());
15181523
client.machineIdentifier = client.castDevice.getDeviceId();
1519-
// VoiceControlForPlexApplication.castRoutes.put(client.machineIdentifier, route);
15201524
VoiceControlForPlexApplication.castClients.put(client.name, client);
15211525
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+
}
15281529
}
15291530

15301531
@Override

mobile/src/main/res/layout/search_popup.xml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:layout_width="match_parent"
4-
android:layout_height="match_parent"
5-
android:orientation="vertical" >
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:background="@color/settings_popup_background"
7+
android:padding="20dp">
8+
9+
<TextView
10+
android:layout_width="wrap_content"
11+
android:layout_height="wrap_content"
12+
android:textAppearance="?android:attr/textAppearanceMedium"
13+
android:text="@string/finding_plex_clients_and_servers"
14+
android:id="@+id/textView22"
15+
android:textColor="@color/white"/>
616

717
<ProgressBar
818
android:id="@+id/progressBar1"

0 commit comments

Comments
 (0)