Skip to content

Commit 8d14057

Browse files
author
Chris Bellew
committed
Added notification when a local server that denies access is found.
1 parent 18e4af7 commit 8d14057

File tree

10 files changed

+110
-56
lines changed

10 files changed

+110
-56
lines changed

mobile/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
package="com.atomjack.vcfp"
5-
android:versionCode="55"
6-
android:versionName="2.0.5" >
5+
android:versionCode="57"
6+
android:versionName="2.0.6" >
77

88
<uses-permission android:name="com.mohammadag.googlesearchapi.permission.ACCESS_GGOGLE_SEARCH_API" />
99
<uses-permission android:name="android.permission.INTERNET" />

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import java.util.Arrays;
7272
import java.util.HashMap;
7373
import java.util.LinkedHashMap;
74+
import java.util.List;
7475
import java.util.Locale;
7576
import java.util.Map;
7677
import java.util.UUID;
@@ -101,6 +102,10 @@ public class VoiceControlForPlexApplication extends Application
101102
.registerTypeAdapter(Uri.class, new UriSerializer())
102103
.create();
103104

105+
// When scanning for servers, if a local server is found but is not accessible due to requiring login
106+
// alert the user that one or more servers like this were found.
107+
public List<String> unauthorizedLocalServersFound = new ArrayList<>();
108+
104109
private NOTIFICATION_STATUS notificationStatus = NOTIFICATION_STATUS.off;
105110
public enum NOTIFICATION_STATUS {
106111
off,
@@ -136,7 +141,7 @@ public enum NOTIFICATION_STATUS {
136141
// This is the default value.
137142
private boolean mHasChromecast = !BuildConfig.CHROMECAST_REQUIRES_PURCHASE;
138143
private boolean mHasWear = !BuildConfig.WEAR_REQUIRES_PURCHASE;
139-
// Only the release build will use the actual Chromecast SKU
144+
// Only the release build will use the actual Chromecast/Wear SKU
140145
public static final String SKU_CHROMECAST = BuildConfig.SKU_CHROMECAST;
141146
public static final String SKU_WEAR = BuildConfig.SKU_WEAR;
142147
public static final String SKU_TEST_PURCHASED = "android.test.purchased";
@@ -311,7 +316,10 @@ public void onFailure(Throwable t) {
311316
@Override
312317
public void onFailure(int statusCode) {
313318
Logger.d("Failed to find connection for %s: %d", server.name, statusCode);
314-
if(onFinish != null)
319+
if(statusCode == 401) {
320+
getInstance().unauthorizedLocalServersFound.add(server.machineIdentifier);
321+
}
322+
if (onFinish != null)
315323
onFinish.run();
316324
}
317325
});
@@ -852,4 +860,8 @@ public static QueryString getPlaybackQueryString(PlexMedia media,
852860

853861
return qs;
854862
}
863+
864+
public boolean isLoggedIn() {
865+
return getInstance().prefs.getString(Preferences.AUTHENTICATION_TOKEN) != null;
866+
}
855867
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -846,13 +846,12 @@ protected void onNewIntent(Intent intent) {
846846

847847
if(intent.getAction().equals(PlexScannerService.ACTION_SERVER_SCAN_FINISHED)) {
848848
if(serverScanCanceled) {
849-
Logger.d("Server scan was canceled.");
850849
serverScanCanceled = false;
851850
return;
852851
}
853852
Logger.d("Got " + VoiceControlForPlexApplication.servers.size() + " servers");
854853
if(searchDialog != null)
855-
searchDialog.cancel();
854+
searchDialog.dismiss();
856855
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.SAVED_SERVERS, gsonWrite.toJson(VoiceControlForPlexApplication.servers));
857856

858857
if(intent.getBooleanExtra(com.atomjack.shared.Intent.EXTRA_SILENT, false) == false) {
@@ -890,17 +889,24 @@ public void onClick(DialogInterface dialog, int id) {
890889
} else {
891890
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
892891
builder.setTitle(R.string.no_servers_found);
892+
if(VoiceControlForPlexApplication.getInstance().unauthorizedLocalServersFound.size() > 0) {
893+
if (VoiceControlForPlexApplication.getInstance().isLoggedIn())
894+
builder.setMessage(R.string.unauthorized_local_server_found_logged_in);
895+
else
896+
builder.setMessage(R.string.unauthorized_local_server_found_logged_out);
897+
}
898+
893899
builder.setCancelable(false).setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
894900
public void onClick(DialogInterface dialog, int id) {
895901
dialog.cancel();
896902
}
897903
});
898904
AlertDialog d = builder.create();
905+
899906
d.show();
900907
}
901908
}
902909
}
903-
// TODO: Check this!
904910
} else if(intent.getStringExtra(com.atomjack.shared.Intent.SCAN_TYPE) != null && intent.getStringExtra(com.atomjack.shared.Intent.SCAN_TYPE).equals(com.atomjack.shared.Intent.SCAN_TYPE_CLIENT)) {
905911
Logger.d("clientScanCanceled: %s", clientScanCanceled);
906912
if(clientScanCanceled) {
@@ -909,7 +915,7 @@ public void onClick(DialogInterface dialog, int id) {
909915
}
910916
ArrayList<PlexClient> clients = intent.getParcelableArrayListExtra(com.atomjack.shared.Intent.EXTRA_CLIENTS);
911917
if(clients != null || (VoiceControlForPlexApplication.getInstance().castClients != null && VoiceControlForPlexApplication.getInstance().castClients.size() > 0)) {
912-
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
918+
VoiceControlForPlexApplication.clients = new HashMap<>();
913919
if(clients != null)
914920
for (PlexClient c : clients) {
915921
VoiceControlForPlexApplication.clients.put(c.name, c);

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,12 @@ public void showPlexServers(ConcurrentHashMap<String, PlexServer> servers, final
861861
return;
862862
}
863863

864-
deviceSelectDialog = getDeviceSelectDialog(getResources().getString(R.string.select_plex_server));
864+
deviceSelectDialog = getDeviceSelectDialog(true, getResources().getString(R.string.select_plex_server));
865865
deviceSelectDialog.show();
866866

867-
868867
final ListView serverListView = (ListView) deviceSelectDialog.findViewById(R.id.serverListView);
869868
if(servers == null)
870-
servers = new ConcurrentHashMap<String, PlexServer>(VoiceControlForPlexApplication.servers);
869+
servers = new ConcurrentHashMap<>(VoiceControlForPlexApplication.servers);
871870
final PlexListAdapter adapter = new PlexListAdapter(this, PlexListAdapter.TYPE_SERVER);
872871
adapter.setServers(servers);
873872
serverListView.setAdapter(adapter);
@@ -883,31 +882,39 @@ public void onItemClick(AdapterView<?> parentAdapter, View view, int position, l
883882
});
884883
}
885884

886-
public Dialog getDeviceSelectDialog(String title) {
885+
public Dialog getDeviceSelectDialog(boolean isServer, String title) {
887886
AlertDialog.Builder builder = new AlertDialog.Builder(this);
888887
LayoutInflater inflater = getLayoutInflater();
889-
View layout = inflater.inflate(R.layout.server_select, null);
888+
View layout = inflater.inflate(R.layout.device_select, null);
889+
if(VoiceControlForPlexApplication.getInstance().unauthorizedLocalServersFound.size() > 0 && isServer) {
890+
layout.findViewById(R.id.unauthorizedLocalServerFoundFrameView).setVisibility(View.VISIBLE);
891+
if(VoiceControlForPlexApplication.getInstance().isLoggedIn()) {
892+
layout.findViewById(R.id.unauthorizedLocalServerFoundTextViewLoggedIn).setVisibility(View.VISIBLE);
893+
layout.findViewById(R.id.unauthorizedLocalServerFoundTextViewLoggedOut).setVisibility(View.INVISIBLE);
894+
} else {
895+
layout.findViewById(R.id.unauthorizedLocalServerFoundTextViewLoggedOut).setVisibility(View.VISIBLE);
896+
layout.findViewById(R.id.unauthorizedLocalServerFoundTextViewLoggedIn).setVisibility(View.INVISIBLE);
897+
}
898+
} else {
899+
layout.findViewById(R.id.unauthorizedLocalServerFoundFrameView).setVisibility(View.GONE);
900+
}
890901
builder.setView(layout);
891902
builder.setTitle(title);
892903
return builder.create();
893904
}
894905

895-
public void showPlexClients() {
896-
showPlexClients(false, null);
897-
}
898-
899-
public void showPlexClients(boolean showResume) {
900-
showPlexClients(true, null);
901-
}
902-
903906
public void showPlexClients(boolean showResume, final ScanHandler onFinish) {
904907
isScanning = false;
905908
if(cancelScan) {
906909
cancelScan = false;
907910
return;
908911
}
909-
if(deviceSelectDialog == null)
910-
deviceSelectDialog = getDeviceSelectDialog(getString(R.string.select_plex_client));
912+
if(deviceSelectDialog == null) {
913+
Logger.d("device select dialog is null");
914+
deviceSelectDialog = getDeviceSelectDialog(false, getString(R.string.select_plex_client));
915+
} else
916+
deviceSelectDialog.setTitle(getString(R.string.select_plex_client));
917+
911918

912919
deviceSelectDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
913920
@Override
@@ -918,6 +925,8 @@ public void onCancel(DialogInterface dialogInterface) {
918925
}
919926
});
920927
deviceSelectDialog.show();
928+
if(deviceSelectDialog.findViewById(R.id.unauthorizedLocalServerFoundFrameView) != null)
929+
deviceSelectDialog.findViewById(R.id.unauthorizedLocalServerFoundFrameView).setVisibility(View.GONE);
921930

922931
if (showResume) {
923932
CheckBox resumeCheckbox = (CheckBox) deviceSelectDialog.findViewById(R.id.serverListResume);
@@ -936,9 +945,6 @@ public void onItemClick(AdapterView<?> parentAdapter, View view, int position,
936945
PlexClient s = (PlexClient) parentAdapter.getItemAtPosition(position);
937946
deviceSelectDialog.dismiss();
938947
CheckBox resumeCheckbox = (CheckBox) deviceSelectDialog.findViewById(R.id.serverListResume);
939-
// if (onFinish == null)
940-
// scanHandler.onDeviceSelected(s, resumeCheckbox.isChecked());
941-
// else
942948
if (onFinish != null)
943949
onFinish.onDeviceSelected(s, resumeCheckbox.isChecked());
944950
}

mobile/src/main/java/com/atomjack/vcfp/services/PlexScannerService.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
5858
scanForClients(intent.getBooleanExtra(com.atomjack.shared.Intent.EXTRA_CONNECT_TO_CLIENT, false));
5959
} else if(action.equals(ACTION_SERVER_SCAN_FINISHED)) {
6060
Logger.d("local server scan finished");
61-
Logger.d("is logged in: %s", isLoggedIn());
61+
Logger.d("is logged in: %s", VoiceControlForPlexApplication.getInstance().isLoggedIn());
6262
localServerScanFinished = true;
63-
if(remoteServerScanFinished || !isLoggedIn()) {
63+
if(remoteServerScanFinished || !VoiceControlForPlexApplication.getInstance().isLoggedIn()) {
6464
onServerScanFinished();
6565
}
6666
} else if(action.equals(ACTION_CLIENT_SCAN_FINISHED)) {
@@ -98,13 +98,10 @@ private void onScanFinished(String type, String extra) {
9898
startActivity(intent);
9999
}
100100

101-
private boolean isLoggedIn() {
102-
return VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.AUTHENTICATION_TOKEN) != null;
103-
}
104-
105101
private void scanForServers() {
102+
VoiceControlForPlexApplication.getInstance().unauthorizedLocalServersFound.clear();
106103
VoiceControlForPlexApplication.servers = new ConcurrentHashMap<>();
107-
if(isLoggedIn()) {
104+
if(VoiceControlForPlexApplication.getInstance().isLoggedIn()) {
108105
refreshResources(VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.AUTHENTICATION_TOKEN), new RefreshResourcesResponseHandler() {
109106
@Override
110107
public void onSuccess() {
@@ -213,6 +210,8 @@ public void onResponse(Response<MediaContainer> response) {
213210
PlexServer server = PlexServer.fromDevice(device);
214211
Logger.d("Device %s is a server, has %d connections", server.name, server.connections.size());
215212
servers.add(server);
213+
if(VoiceControlForPlexApplication.getInstance().unauthorizedLocalServersFound.contains(server.machineIdentifier))
214+
VoiceControlForPlexApplication.getInstance().unauthorizedLocalServersFound.remove(server.machineIdentifier);
216215
} else if(device.provides.contains("player")) {
217216
Logger.d("Device %s is a player", device.name);
218217
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:id="@+id/device_select_root"
6+
android:orientation="vertical" >
7+
8+
<ListView
9+
android:id="@+id/serverListView"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content" >
12+
</ListView>
13+
<CheckBox
14+
android:id="@+id/serverListResume"
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:layout_marginBottom="30dp"
18+
android:layout_marginTop="10dp"
19+
android:visibility="gone"
20+
android:text="@string/resume_if_in_progress"
21+
android:textColor="@color/white" />
22+
23+
<FrameLayout
24+
android:layout_width="match_parent"
25+
android:layout_height="wrap_content"
26+
android:visibility="gone"
27+
android:id="@+id/unauthorizedLocalServerFoundFrameView">
28+
29+
<TextView
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:text="@string/unauthorized_local_server_found_logged_out"
33+
android:id="@+id/unauthorizedLocalServerFoundTextViewLoggedOut"
34+
android:visibility="invisible"
35+
android:layout_margin="25dp"/>
36+
37+
<TextView
38+
android:layout_width="wrap_content"
39+
android:layout_height="wrap_content"
40+
android:text="@string/unauthorized_local_server_found_logged_in"
41+
android:id="@+id/unauthorizedLocalServerFoundTextViewLoggedIn"
42+
android:visibility="invisible"
43+
android:layout_margin="25dp"/>
44+
</FrameLayout>
45+
46+
</LinearLayout>

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

Lines changed: 0 additions & 21 deletions
This file was deleted.

mobile/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,6 @@
154154
<string name="video_attempted_on_audio_only_device">Sorry, but video playback is not supported on %s.</string>
155155
<string name="select_plex_server">Select a Plex Server</string>
156156
<string name="couldnt_play_to_client">Sorry, I got an error trying to connect to %s. If this problem persists, recreate the homescreen shortcut after re-scanning for clients.</string>
157+
<string name="unauthorized_local_server_found_logged_out">I found one or more local servers but was denied access. Log in to Plex (via the Menu button) to attempt to access this server.</string>
158+
<string name="unauthorized_local_server_found_logged_in">I found one or more local servers but was denied access. Since you are already logged in to Plex, either log out and back in (in case your access token has changed), or verify your access to this server/servers.</string>
157159
</resources>

mobile/src/main/res/xml/changelog.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<changelog>
3+
<release version="2.0.6" versioncode="57">
4+
<change>Fix crash from using Scan All Servers.</change>
5+
<change>Added notification when a local server that denies access is found.</change>
6+
</release>
37
<release version="2.0.5" versioncode="55">
48
<change>On Now Playing screen, tap to pause and swipe left/right to seek back/forward.</change>
59
<change>Added support for audio-only Chromecast devices.</change>

wear/src/main/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.atomjack.vcfp"
4-
android:versionCode="55"
5-
android:versionName="2.0.5">
4+
android:versionCode="57"
5+
android:versionName="2.0.6">
66

77
<uses-feature android:name="android.hardware.type.watch" />
88

0 commit comments

Comments
 (0)