Skip to content

Commit ed10a38

Browse files
author
Chris Bellew
committed
Added new app icon to wear and shared projects. Adjusted target sdk in grade script so that app icon shows up properly in status bar on Lollipop+. Fixed resume playback functionality from a homescreen shortcut that was defined to use the current settings (instead of hardcoded).
1 parent 0b61895 commit ed10a38

File tree

22 files changed

+105
-97
lines changed

22 files changed

+105
-97
lines changed

mobile/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
apply plugin: 'android'
1+
apply plugin: 'com.android.application'
22

33
android {
44
useLibrary 'org.apache.http.legacy'
@@ -7,7 +7,7 @@ android {
77
defaultConfig {
88
applicationId "com.atomjack.vcfp"
99
minSdkVersion 15
10-
targetSdkVersion 23
10+
targetSdkVersion 19
1111
}
1212
dexOptions {
1313
preDexLibraries = false

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ public void unsubscribe(final Runnable onFinish) {
358358
}
359359

360360
public void unsubscribe(final boolean notify, final Runnable onFinish) {
361-
if(listener == null)
362-
return;
361+
// if(listener == null)
362+
// return;
363363

364364
PlexHttpClient.unsubscribe(mClient, commandId, VoiceControlForPlexApplication.getInstance().prefs.getUUID(), listener.getString(R.string.app_name), new PlexHttpResponseHandler() {
365365
@Override

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.atomjack.vcfp.model.Connection;
4444
import com.atomjack.vcfp.model.MediaContainer;
4545
import com.atomjack.vcfp.model.PlexClient;
46+
import com.atomjack.vcfp.model.PlexDirectory;
4647
import com.atomjack.vcfp.model.PlexMedia;
4748
import com.atomjack.vcfp.model.PlexServer;
4849
import com.atomjack.vcfp.model.PlexTrack;
@@ -107,7 +108,7 @@ public enum NOTIFICATION_STATUS {
107108
initializing
108109
}
109110

110-
public static HashMap<String, String[]> chromecastVideoOptions = new LinkedHashMap<>();
111+
public static HashMap<String, String[]> chromecastVideoOptions = new LinkedHashMap<String, String[]>();
111112

112113
private NotificationManager mNotifyMgr;
113114
private Bitmap notificationBitmap = null;
@@ -262,15 +263,15 @@ public static void addPlexServer(PlexServer addedServer, final Runnable onFinish
262263
@Override
263264
public void onSuccess(Connection connection) {
264265
Logger.d("active connection: %s", connection);
265-
PlexHttpClient.PlexHttpService service = PlexHttpClient.getService(connection);
266+
PlexHttpClient.PlexHttpService service = PlexHttpClient.getService(connection, true);
266267
Call<MediaContainer> call = service.getLibrarySections(server.accessToken);
267268
call.enqueue(new Callback<MediaContainer>() {
268269
@Override
269270
public void onResponse(Response<MediaContainer> response) {
270271
MediaContainer mc = response.body();
271-
server.movieSections = new ArrayList<String>();
272-
server.tvSections = new ArrayList<String>();
273-
server.musicSections = new ArrayList<String>();
272+
server.movieSections = new ArrayList<>();
273+
server.tvSections = new ArrayList<>();
274+
server.musicSections = new ArrayList<>();
274275
for(int i=0;i<mc.directories.size();i++) {
275276
if(mc.directories.get(i).type.equals("movie")) {
276277
server.addMovieSection(mc.directories.get(i).key);
@@ -828,4 +829,33 @@ public static String getUUID() {
828829
}
829830
return uuid;
830831
}
832+
833+
public static QueryString getPlaybackQueryString(PlexMedia media,
834+
MediaContainer mediaContainer, Connection connection,
835+
String transientToken, PlexDirectory album,
836+
boolean resumePlayback) {
837+
QueryString qs = new QueryString("machineIdentifier", media.server.machineIdentifier);
838+
qs.add("key", media.key);
839+
qs.add("containerKey", String.format("/playQueues/%s", mediaContainer.playQueueID));
840+
qs.add("port", connection.port);
841+
qs.add("address", connection.address);
842+
843+
if (resumePlayback && media.viewOffset != null)
844+
qs.add("viewOffset", media.viewOffset);
845+
if (transientToken != null)
846+
qs.add("token", transientToken);
847+
if (media.server.accessToken != null)
848+
qs.add(PlexHeaders.XPlexToken, media.server.accessToken);
849+
850+
if (album != null)
851+
qs.add("containerKey", album.key);
852+
853+
// new for PMP:
854+
qs.add("commandID", "0");
855+
qs.add("type", media.getType().equals("music") ? "music" : "video");
856+
qs.add("protocol", "http");
857+
qs.add("offset", resumePlayback && media.viewOffset != null ? media.viewOffset : "0");
858+
859+
return qs;
860+
}
831861
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.speech.tts.TextToSpeech;
2020
import android.support.v4.app.ActivityCompat;
2121
import android.support.v4.content.ContextCompat;
22+
import android.support.v4.content.FileProvider;
2223
import android.support.v7.media.MediaRouteSelector;
2324
import android.support.v7.media.MediaRouter;
2425
import android.view.LayoutInflater;
@@ -187,14 +188,16 @@ protected Void doInBackground(Void... params) {
187188
Logger.d("Emailing device logs");
188189
Intent emailIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
189190
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Voice Control for Plex Android Logs");
191+
emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
190192

191193
// Build the body of the email
192194
StringBuilder body = new StringBuilder();
193195
body.append(String.format("Manufacturer: %s\n", Build.MANUFACTURER));
194196
body.append(String.format("Device: %s\n", Build.DEVICE));
195197
body.append(String.format("Model: %s\n", Build.MODEL));
196198
body.append(String.format("Product: %s\n", Build.PRODUCT));
197-
body.append(String.format("Version: %s\n\n", Build.VERSION.RELEASE));
199+
body.append(String.format("Version: %s\n", Build.VERSION.RELEASE));
200+
body.append(String.format("App Version: %s\n\n", getPackageManager().getPackageInfo(getPackageName(), 0).versionName));
198201

199202
body.append(String.format("Logged in: %s\n\n", VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.PLEX_USERNAME) != null ? "yes" : "no"));
200203

@@ -229,15 +232,18 @@ protected Void doInBackground(Void... params) {
229232

230233
ArrayList<Uri> uris = new ArrayList<Uri>();
231234
uris.add(Uri.parse("file://" + tempFile.getAbsolutePath()));
235+
// uris.add(FileProvider.getUriForFile(MainActivity.this, "com.atomjack.vcfp.fileprovider", tempFile));
232236

233237
if (!wearLog.equals("")) {
238+
Logger.d("attaching wear log");
234239
tempFile = new File(tempDirectory, "/vcfp-wear-log.txt");
235240
fos = new FileOutputStream(tempFile);
236241
out = new OutputStreamWriter(fos, "UTF-8");
237242
out.write(wearLog);
238243
out.flush();
239244
out.close();
240245
uris.add(Uri.parse("file://" + tempFile.getAbsolutePath()));
246+
// uris.add(FileProvider.getUriForFile(MainActivity.this, "com.atomjack.vcfp.fileprovider", tempFile));
241247
}
242248
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
243249
startActivity(emailIntent);
@@ -329,7 +335,8 @@ private boolean hasValidUtter() {
329335
}
330336

331337
public void resumeChecked(View v) {
332-
VoiceControlForPlexApplication.getInstance().prefs.put("resume", ((CheckBox) v).isChecked());
338+
Logger.d("Setting resume checkbox to %s", ((CheckBox) v).isChecked());
339+
VoiceControlForPlexApplication.getInstance().prefs.put(Preferences.RESUME, ((CheckBox) v).isChecked());
333340
}
334341

335342
@Override

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@
1717
import com.atomjack.shared.WearConstants;
1818
import com.atomjack.vcfp.BuildConfig;
1919
import com.atomjack.shared.Logger;
20+
import com.atomjack.vcfp.PlexHeaders;
21+
import com.atomjack.vcfp.QueryString;
2022
import com.atomjack.vcfp.R;
2123
import com.atomjack.vcfp.VoiceControlForPlexApplication;
24+
import com.atomjack.vcfp.model.Connection;
25+
import com.atomjack.vcfp.model.MediaContainer;
2226
import com.atomjack.vcfp.model.PlexClient;
27+
import com.atomjack.vcfp.model.PlexDirectory;
28+
import com.atomjack.vcfp.model.PlexMedia;
2329
import com.atomjack.vcfp.model.PlexResponse;
2430
import com.atomjack.shared.model.Timeline;
2531
import com.atomjack.vcfp.model.PlexTrack;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
4949
serviceIntent.putExtra(com.atomjack.shared.Intent.EXTRA_SERVER, gsonWrite.toJson(server));
5050
serviceIntent.putExtra(com.atomjack.shared.Intent.EXTRA_CLIENT, getIntent().getStringExtra(com.atomjack.shared.Intent.EXTRA_CLIENT));
5151
serviceIntent.putExtra(com.atomjack.shared.Intent.EXTRA_RESUME, getIntent().getBooleanExtra(com.atomjack.shared.Intent.EXTRA_RESUME, false));
52+
serviceIntent.putExtra(com.atomjack.shared.Intent.USE_CURRENT, getIntent().getBooleanExtra(com.atomjack.shared.Intent.USE_CURRENT, false));
5253

5354
SecureRandom random = new SecureRandom();
5455
serviceIntent.setData(Uri.parse(new BigInteger(130, random).toString(32)));

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,10 @@ private void createShortcut(boolean use_current) {
110110
launchIntent.putExtra(com.atomjack.shared.Intent.EXTRA_RESUME, resume);
111111
String label = server.name.equals(client.name) ? server.name : (server.owned ? server.name : server.sourceTitle) + "/" + client.name;
112112
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
113-
} else
114-
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
113+
} else {
114+
launchIntent.putExtra(com.atomjack.shared.Intent.USE_CURRENT, true);
115+
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
116+
}
115117

116118
sendIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
117119

mobile/src/main/java/com/atomjack/vcfp/model/PlexServer.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ public PlexServer[] newArray(int size) {
162162
};
163163

164164
public void findServerConnection(final ActiveConnectionHandler activeConnectionHandler) {
165-
Logger.d("[PlexServer] finding server connection, current active connection expires %s", activeConnectionExpires);
166-
if(activeConnectionExpires != null && activeConnectionExpires.after(Calendar.getInstance())) {
165+
Logger.d("[PlexServer] finding server connection, current active connection expires %s, number of connections: %d", activeConnectionExpires, connections.size());
166+
if(activeConnectionExpires != null && activeConnectionExpires.before(Calendar.getInstance())) {
167167
activeConnectionHandler.onSuccess(activeConnection);
168168
} else {
169169
findServerConnection(0, activeConnectionHandler);
@@ -175,37 +175,37 @@ private void findServerConnection(final int connectionIndex, final ActiveConnect
175175
testServerConnection(connection, new ServerTestHandler() {
176176
@Override
177177
public void onFinish(int statusCode, boolean available) {
178-
if(statusCode != 200) {
179-
if(activeConnectionHandler != null)
178+
if (available) {
179+
// This connection replied, so let's use it
180+
activeConnection = connections.get(connectionIndex);
181+
activeConnectionExpires = Calendar.getInstance();
182+
activeConnectionExpires.set(Calendar.HOUR, 1);
183+
activeConnectionHandler.onSuccess(activeConnection);
184+
} else {
185+
int newConnectionIndex = connectionIndex + 1;
186+
Logger.d("Not available, new connection index: %d", newConnectionIndex);
187+
if (connections.size() <= newConnectionIndex)
180188
activeConnectionHandler.onFailure(statusCode);
181-
} else {
182-
if (available) {
183-
// This connection replied, so let's use it
184-
activeConnection = connections.get(connectionIndex);
185-
activeConnectionExpires = Calendar.getInstance();
186-
activeConnectionExpires.set(Calendar.HOUR, 1);
187-
activeConnectionHandler.onSuccess(activeConnection);
188-
} else {
189-
int newConnectionIndex = connectionIndex + 1;
190-
if (connections.size() <= newConnectionIndex)
191-
activeConnectionHandler.onFailure(statusCode);
192-
else
193-
findServerConnection(newConnectionIndex, activeConnectionHandler);
194-
}
195-
}
189+
else
190+
findServerConnection(newConnectionIndex, activeConnectionHandler);
191+
}
196192
}
197193
});
198194
}
199195

200196
private void testServerConnection(final Connection connection, final ServerTestHandler handler) {
201-
Logger.d("testServerConnection: fetching %s", connection.uri);
197+
Logger.d("testServerConnection: fetching %s with token %s", connection.uri, accessToken);
202198
PlexHttpClient.PlexHttpService service = PlexHttpClient.getService(connection, 2);
203199
Call<MediaContainer> call = service.getMediaContainer("", accessToken);
204200
call.enqueue(new Callback<MediaContainer>() {
205201
@Override
206202
public void onResponse(Response<MediaContainer> response) {
207-
Logger.d("%s success", connection.uri);
208-
handler.onFinish(response.code(), true);
203+
if(response.code() == 200) {
204+
Logger.d("%s success", connection.uri);
205+
handler.onFinish(response.code(), true);
206+
} else {
207+
handler.onFinish(response.code(), false);
208+
}
209209
}
210210

211211
@Override

mobile/src/main/java/com/atomjack/vcfp/net/PlexHttpClient.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public void onFailure(int statusCode) {
295295
public static void subscribe(PlexClient client, int subscriptionPort, int commandId, String uuid, String deviceName, final PlexHttpResponseHandler responseHandler) {
296296
String url = String.format("http://%s:%s", client.address, client.port);
297297
Logger.d("Subscribing at url %s", url);
298-
PlexHttpService service = getService(url, true);
298+
PlexHttpService service = getService(url);
299299

300300
Call<PlexResponse> call = service.subscribe(uuid, deviceName, subscriptionPort, commandId);
301301
call.enqueue(new Callback<PlexResponse>() {
@@ -380,6 +380,9 @@ public static void createPlayQueue(Connection connection, final PlexMedia media,
380380
qs.put("extrasPrefixCount", Integer.toString(VoiceControlForPlexApplication.getInstance().prefs.get(Preferences.NUM_CINEMA_TRAILERS, 0)));
381381
}
382382

383+
if(hasOffset)
384+
qs.put("viewOffset", media.viewOffset);
385+
383386
String uri = String.format("library://%s/item/%%2flibrary%%2fmetadata%%2f%s", media.server.machineIdentifier, key);
384387
qs.put("uri", uri);
385388
qs.put("window", "50"); // no idea what this is for
@@ -388,8 +391,10 @@ public static void createPlayQueue(Connection connection, final PlexMedia media,
388391
if (media.server.accessToken != null)
389392
qs.put(PlexHeaders.XPlexToken, media.server.accessToken);
390393

391-
Logger.d("Qs: ", qs);
392-
PlexHttpService service = getService(String.format("http://%s:%s", connection.address, connection.port));
394+
for(Object name:qs.keySet()) {
395+
Logger.d("QS %s:%s", name, qs.get(name));
396+
}
397+
PlexHttpService service = getService(String.format("http://%s:%s", connection.address, connection.port), true);
393398
Call<MediaContainer> call = service.createPlayQueue(qs, VoiceControlForPlexApplication.getUUID());
394399
call.enqueue(new Callback<MediaContainer>() {
395400
@Override

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private boolean isLoggedIn() {
103103
}
104104

105105
private void scanForServers() {
106-
VoiceControlForPlexApplication.servers = new ConcurrentHashMap<String, PlexServer>();
106+
VoiceControlForPlexApplication.servers = new ConcurrentHashMap<>();
107107
if(isLoggedIn()) {
108108
refreshResources(VoiceControlForPlexApplication.getInstance().prefs.getString(Preferences.AUTHENTICATION_TOKEN), new RefreshResourcesResponseHandler() {
109109
@Override
@@ -117,7 +117,6 @@ public void onSuccess() {
117117
public void onFailure(int statusCode) {
118118
Logger.d("[PlexScannerService] failure: %d", statusCode);
119119
if (statusCode == 401) { // Unauthorized
120-
// REMOTE_SERVER_SCAN_UNAUTHORIZED
121120
onScanFinished(ACTION_SERVER_SCAN_FINISHED, REMOTE_SERVER_SCAN_UNAUTHORIZED);
122121
}
123122
}

0 commit comments

Comments
 (0)