Skip to content

Commit e76ec8c

Browse files
author
Chris Bellew
committed
Make sure there's a viewOffset before trying to set it when playing a video or track; Show message when no clients found; Use access token if one exists when testing servers for connections; Fixed bug in server connection test.
1 parent 19f0abd commit e76ec8c

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ private void startup() {
184184
shows = new ArrayList<PlexDirectory>();
185185

186186
Gson gson = new Gson();
187-
Logger.d("default server json: %s", mPrefs.getString("Server", ""));
188187
final PlexServer defaultServer = gson.fromJson(mPrefs.getString("Server", ""), PlexServer.class);
189188
if(specifiedServer != null && client != null && !specifiedServer.name.equals(getResources().getString(R.string.scan_all))) {
190189
// got a specified server and client from a shortcut
@@ -799,7 +798,7 @@ private void playVideo(final PlexVideo video, String transientToken) {
799798
qs.add("address", video.server.activeConnection.address);
800799
Logger.d("address: %s", video.server.activeConnection.address);
801800

802-
if(mPrefs.getBoolean("resume", false) || resumePlayback)
801+
if((mPrefs.getBoolean("resume", false) || resumePlayback) && video.viewOffset != null)
803802
qs.add("viewOffset", video.viewOffset);
804803
if(transientToken != null)
805804
qs.add("token", transientToken);
@@ -1529,7 +1528,7 @@ private void playTrack(final PlexTrack track, final PlexDirectory album) {
15291528
qs.add("address", track.server.activeConnection.address);
15301529
if(album != null)
15311530
qs.add("containerKey", album.key);
1532-
if(mPrefs.getBoolean("resume", false) || resumePlayback)
1531+
if((mPrefs.getBoolean("resume", false) || resumePlayback) && track.viewOffset != null)
15331532
qs.add("viewOffset", track.viewOffset);
15341533
qs.add(PlexHeaders.XPlexTargetClientIdentifier, client.machineIdentifier);
15351534
String url = String.format("http://%s:%s/player/playback/playMedia?%s", client.address, client.port, qs);

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -793,13 +793,28 @@ public void onClick(DialogInterface dialog, int id) {
793793
}
794794
} else if(intent.getStringExtra(VoiceControlForPlexApplication.Intent.SCAN_TYPE).equals("client")) {
795795
ArrayList<PlexClient> clients = intent.getParcelableArrayListExtra(VoiceControlForPlexApplication.Intent.EXTRA_CLIENTS);
796-
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
797-
for(PlexClient c : clients) {
798-
VoiceControlForPlexApplication.clients.put(c.name, c);
796+
if(clients != null) {
797+
VoiceControlForPlexApplication.clients = new HashMap<String, PlexClient>();
798+
for (PlexClient c : clients) {
799+
VoiceControlForPlexApplication.clients.put(c.name, c);
800+
}
801+
mPrefsEditor.putString(Preferences.SAVED_CLIENTS, gson.toJson(VoiceControlForPlexApplication.clients));
802+
mPrefsEditor.commit();
803+
localScan.showPlexClients(VoiceControlForPlexApplication.clients);
804+
} else {
805+
if (searchDialog != null)
806+
searchDialog.hide();
807+
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
808+
builder.setTitle(R.string.no_clients_found);
809+
builder.setCancelable(false)
810+
.setNeutralButton(R.string.ok, new DialogInterface.OnClickListener() {
811+
public void onClick(DialogInterface dialog, int id) {
812+
dialog.cancel();
813+
}
814+
});
815+
AlertDialog d = builder.create();
816+
d.show();
799817
}
800-
mPrefsEditor.putString(Preferences.SAVED_CLIENTS, gson.toJson(VoiceControlForPlexApplication.clients));
801-
mPrefsEditor.commit();
802-
localScan.showPlexClients(VoiceControlForPlexApplication.clients);
803818
}
804819
} else if(origin.equals("ScanForClients")) {
805820
// No default server specified, so we need to search all servers for all clients

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

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

66
import com.atomjack.vcfp.Logger;
7+
import com.atomjack.vcfp.PlexHeaders;
78
import com.atomjack.vcfp.ServerFindHandler;
89
import com.atomjack.vcfp.ServerTestHandler;
910
import com.loopj.android.http.AsyncHttpClient;
@@ -13,6 +14,7 @@
1314
import java.util.List;
1415

1516
import org.apache.http.Header;
17+
import org.apache.http.message.BasicHeader;
1618
import org.simpleframework.xml.Root;
1719

1820
@Root(strict=false)
@@ -162,7 +164,7 @@ public void onFinish(boolean available) {
162164
} else {
163165
int newConnectionIndex = connectionIndex + 1;
164166
// TODO: Fix this
165-
if(connections.size() < newConnectionIndex)
167+
if(connections.size() <= newConnectionIndex)
166168
handler.onFailure();
167169
else
168170
findServerConnection(newConnectionIndex, handler);
@@ -176,6 +178,8 @@ private void testServerConnection(final Connection connection, final ServerTestH
176178
Logger.d("testServerConnection: fetching %s", connection.uri);
177179
// Set timeout to 2 seconds, we don't want this to take too long
178180
httpClient.setTimeout(2000);
181+
if(accessToken != null)
182+
httpClient.addHeader(PlexHeaders.XPlexToken, accessToken);
179183
httpClient.get(connection.uri, new AsyncHttpResponseHandler() {
180184
@Override
181185
public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) {

Voice Control For Plex/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@
9696
<string name="searching_for_plex_clients">Searching for Plex Clients</string>
9797
<string name="select_plex_client">Select a Plex Client</string>
9898
<string name="no_servers_found">No Plex Servers Found</string>
99+
<string name="no_clients_found">No Plex Clients Found</string>
99100
</resources>

0 commit comments

Comments
 (0)