Skip to content

Commit 3fcfbb5

Browse files
author
Chris Bellew
committed
Removed build directory; Save and restore instance state, so query isn't respoken when app is opened after being cleared from device's memory.
1 parent ec7fdd2 commit 3fcfbb5

File tree

105 files changed

+307
-2954
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+307
-2954
lines changed

Voice Control For Plex Library/src/main/AndroidManifest.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,6 @@
77
android:label="@string/app_name"
88
android:theme="@style/AppTheme"
99
android:debuggable="false" >
10-
<activity android:name=".SetupActivity"
11-
android:label="@string/app_name" >
12-
<intent-filter>
13-
</intent-filter>
14-
</activity>
1510
<activity
1611
android:name=".MainActivity"
1712
android:label="@string/app_name" >

Voice Control For Plex Library/src/main/java/com/atomjack/vcfplib/PlayMediaActivity.java

Lines changed: 86 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,35 @@ public class PlayMediaActivity extends Activity implements TextToSpeech.OnInitLi
5959
private List<PlexDirectory> albums = new ArrayList<PlexDirectory>();
6060
private TextToSpeech mTts = null;
6161
private String ttsDelayedFeedback = null;
62+
private PlexVideo playingVideo; // The video currently playing
63+
private PlexTrack playingTrack; // The track currently playing
6264

6365
protected void onCreate(Bundle savedInstanceState) {
6466
Logger.d("on create PlayMediaActivity");
6567
super.onCreate(savedInstanceState);
6668

67-
6869
BugSenseHandler.initAndStartSession(PlayMediaActivity.this, MainActivity.BUGSENSE_APIKEY);
6970

7071
mPrefs = getSharedPreferences(PREFS, MODE_PRIVATE);
7172

7273
setContentView(R.layout.play_media);
73-
Intent intent = getIntent();
74-
this.queryText = intent.getStringExtra("queryText");
75-
startup();
74+
if(savedInstanceState == null) {
75+
playingVideo = null;
76+
playingTrack = null;
77+
client = null;
78+
Intent intent = getIntent();
79+
this.queryText = intent.getStringExtra("queryText");
80+
startup();
81+
} else {
82+
Logger.d("found saved instance state");
83+
playingVideo = savedInstanceState.getParcelable("video");
84+
playingTrack = savedInstanceState.getParcelable("track");
85+
client = savedInstanceState.getParcelable("client");
86+
if(playingVideo != null)
87+
showPlayingVideo();
88+
else if(playingTrack != null)
89+
showPlayingTrack();
90+
}
7691
}
7792

7893
@Override
@@ -1239,7 +1254,7 @@ public void onSuccess(MediaContainer mc)
12391254
track.album = album.title;
12401255
playTrack(track, album);
12411256
} else {
1242-
Logger.d("Didn't find a video");
1257+
Logger.d("Didn't find any tracks");
12431258
feedback(getResources().getString(R.string.couldnt_find_album));
12441259
searchDialog.dismiss();
12451260
finish();
@@ -1281,19 +1296,8 @@ public void onSuccess(PlexResponse r)
12811296
}
12821297
Logger.d("Playback response: %s", r.code);
12831298
if(passed) {
1284-
setContentView(R.layout.now_playing_music);
1285-
1286-
TextView artist = (TextView)findViewById(R.id.nowPlayingArtist);
1287-
artist.setText(track.artist);
1288-
TextView album = (TextView)findViewById(R.id.nowPlayingAlbum);
1289-
album.setText(track.album);
1290-
TextView title = (TextView)findViewById(R.id.nowPlayingTitle);
1291-
title.setText(track.title);
1292-
1293-
TextView nowPlayingOnClient = (TextView)findViewById(R.id.nowPlayingOnClient);
1294-
nowPlayingOnClient.setText(getResources().getString(R.string.now_playing_on) + " " + client.name);
1295-
1296-
PlexHttpClient.setThumb(track, (ImageView)findViewById(R.id.nowPlayingImage));
1299+
playingTrack = track;
1300+
showPlayingTrack();
12971301
} else {
12981302
searchDialog.dismiss();
12991303
feedback(getResources().getString(R.string.http_status_code_error), r.code);
@@ -1310,6 +1314,24 @@ public void onFailure(Throwable error) {
13101314
});
13111315
}
13121316

1317+
private void showPlayingTrack() {
1318+
if(playingTrack == null)
1319+
return;
1320+
setContentView(R.layout.now_playing_music);
1321+
1322+
TextView artist = (TextView)findViewById(R.id.nowPlayingArtist);
1323+
artist.setText(playingTrack.artist);
1324+
TextView album = (TextView)findViewById(R.id.nowPlayingAlbum);
1325+
album.setText(playingTrack.album);
1326+
TextView title = (TextView)findViewById(R.id.nowPlayingTitle);
1327+
title.setText(playingTrack.title);
1328+
1329+
TextView nowPlayingOnClient = (TextView)findViewById(R.id.nowPlayingOnClient);
1330+
nowPlayingOnClient.setText(getResources().getString(R.string.now_playing_on) + " " + client.name);
1331+
1332+
PlexHttpClient.setThumb(playingTrack, (ImageView)findViewById(R.id.nowPlayingImage));
1333+
}
1334+
13131335
private void playVideo(final PlexVideo video) {
13141336
Logger.d("Playing video: %s", video.title);
13151337
try {
@@ -1337,38 +1359,10 @@ public void onSuccess(PlexResponse r)
13371359
}
13381360
Logger.d("Playback response: %s", r.code);
13391361
if(passed) {
1362+
playingVideo = video;
1363+
Logger.d("duration: %s", video.getDuration());
13401364
videoPlayed = true;
1341-
if(video.type.equals("movie")) {
1342-
setContentView(R.layout.now_playing_movie);
1343-
TextView title = (TextView)findViewById(R.id.nowPlayingTitle);
1344-
title.setText(video.title);
1345-
TextView genre = (TextView)findViewById(R.id.nowPlayingGenre);
1346-
genre.setText(video.getGenres());
1347-
TextView year = (TextView)findViewById(R.id.nowPlayingYear);
1348-
year.setText(video.year);
1349-
TextView duration = (TextView)findViewById(R.id.nowPlayingDuration);
1350-
duration.setText(video.getDuration());
1351-
TextView summary = (TextView)findViewById(R.id.nowPlayingSummary);
1352-
summary.setText(video.summary);
1353-
} else {
1354-
setContentView(R.layout.now_playing_show);
1355-
1356-
TextView showTitle = (TextView)findViewById(R.id.nowPlayingShowTitle);
1357-
showTitle.setText(video.showTitle);
1358-
TextView episodeTitle = (TextView)findViewById(R.id.nowPlayingEpisodeTitle);
1359-
episodeTitle.setText(video.title);
1360-
TextView year = (TextView)findViewById(R.id.nowPlayingYear);
1361-
year.setText(video.year);
1362-
TextView duration = (TextView)findViewById(R.id.nowPlayingDuration);
1363-
duration.setText(video.getDuration());
1364-
TextView summary = (TextView)findViewById(R.id.nowPlayingSummary);
1365-
summary.setText(video.summary);
1366-
}
1367-
1368-
TextView nowPlayingOnClient = (TextView)findViewById(R.id.nowPlayingOnClient);
1369-
nowPlayingOnClient.setText(getResources().getString(R.string.now_playing_on) + " " + client.name);
1370-
1371-
PlexHttpClient.setThumb(video, (ScrollView)findViewById(R.id.background));
1365+
showPlayingVideo();
13721366
} else {
13731367
searchDialog.dismiss();
13741368
feedback(getResources().getString(R.string.http_status_code_error), r.code);
@@ -1410,6 +1404,41 @@ protected void onResume() {
14101404
LocalBroadcastManager.getInstance(this).registerReceiver(gdmReceiver, filters);
14111405
}
14121406

1407+
private void showPlayingVideo() {
1408+
if(playingVideo == null)
1409+
return;
1410+
if(playingVideo.type.equals("movie")) {
1411+
setContentView(R.layout.now_playing_movie);
1412+
TextView title = (TextView)findViewById(R.id.nowPlayingTitle);
1413+
title.setText(playingVideo.title);
1414+
TextView genre = (TextView)findViewById(R.id.nowPlayingGenre);
1415+
genre.setText(playingVideo.getGenres());
1416+
TextView year = (TextView)findViewById(R.id.nowPlayingYear);
1417+
year.setText(playingVideo.year);
1418+
TextView duration = (TextView)findViewById(R.id.nowPlayingDuration);
1419+
duration.setText(playingVideo.getDuration());
1420+
TextView summary = (TextView)findViewById(R.id.nowPlayingSummary);
1421+
summary.setText(playingVideo.summary);
1422+
} else {
1423+
setContentView(R.layout.now_playing_show);
1424+
1425+
TextView showTitle = (TextView)findViewById(R.id.nowPlayingShowTitle);
1426+
showTitle.setText(playingVideo.showTitle);
1427+
TextView episodeTitle = (TextView)findViewById(R.id.nowPlayingEpisodeTitle);
1428+
episodeTitle.setText(playingVideo.title);
1429+
TextView year = (TextView)findViewById(R.id.nowPlayingYear);
1430+
year.setText(playingVideo.year);
1431+
TextView duration = (TextView)findViewById(R.id.nowPlayingDuration);
1432+
duration.setText(playingVideo.getDuration());
1433+
TextView summary = (TextView)findViewById(R.id.nowPlayingSummary);
1434+
summary.setText(playingVideo.summary);
1435+
}
1436+
1437+
TextView nowPlayingOnClient = (TextView)findViewById(R.id.nowPlayingOnClient);
1438+
nowPlayingOnClient.setText(getResources().getString(R.string.now_playing_on) + " " + client.name);
1439+
1440+
PlexHttpClient.setThumb(playingVideo, (ScrollView)findViewById(R.id.background));
1441+
}
14131442
private static Boolean compareTitle(String title, String queryTerm) {
14141443
// First, check if the two terms are equal
14151444
if(title.toLowerCase().equals(queryTerm.toLowerCase()))
@@ -1424,4 +1453,12 @@ private static Boolean compareTitle(String title, String queryTerm) {
14241453
}
14251454
return !missing;
14261455
}
1456+
1457+
@Override
1458+
protected void onSaveInstanceState(Bundle outState) {
1459+
super.onSaveInstanceState(outState);
1460+
outState.putParcelable("video", playingVideo);
1461+
outState.putParcelable("client", client);
1462+
outState.putParcelable("track", playingTrack);
1463+
}
14271464
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,45 @@
11
package com.atomjack.vcfplib.model;
22

3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
36
import org.simpleframework.xml.Attribute;
47
import org.simpleframework.xml.Root;
58

69
@Root(name="Server", strict=false)
710
public class PlexClient extends PlexDevice {
811
@Attribute
912
public String host;
13+
14+
@Override
15+
public int describeContents() {
16+
return 0;
17+
}
18+
19+
@Override
20+
public void writeToParcel(Parcel parcel, int i) {
21+
parcel.writeString(name);
22+
parcel.writeString(port);
23+
parcel.writeString(version);
24+
parcel.writeString(product);
25+
parcel.writeString(host);
26+
}
27+
28+
public PlexClient(Parcel in) {
29+
name = in.readString();
30+
port = in.readString();
31+
version = in.readString();
32+
product = in.readString();
33+
host = in.readString();
34+
}
35+
36+
public static final Parcelable.Creator<PlexClient> CREATOR = new Parcelable.Creator<PlexClient>() {
37+
public PlexClient createFromParcel(Parcel in) {
38+
return new PlexClient(in);
39+
}
40+
41+
public PlexClient[] newArray(int size) {
42+
return new PlexClient[size];
43+
}
44+
};
1045
}

Voice Control For Plex Library/src/main/java/com/atomjack/vcfplib/model/PlexDevice.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package com.atomjack.vcfplib.model;
22

3+
import android.os.Parcelable;
4+
35
import org.simpleframework.xml.Attribute;
46

5-
public abstract class PlexDevice {
7+
public abstract class PlexDevice implements Parcelable {
68
@Attribute
79
public String name;
810
@Attribute
@@ -23,17 +25,6 @@ public void setName(String name) {
2325
this.name = name;
2426
}
2527

26-
public void setAddress(String address) {
27-
this.address = address;
28-
}
29-
30-
public String getPort() {
31-
return port;
32-
}
33-
public void setPort(String port) {
34-
this.port = port;
35-
}
36-
3728
public String getVersion() {
3829
return version;
3930
}

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

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.atomjack.vcfplib.model;
22

3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
36
import java.util.ArrayList;
47
import java.util.List;
58

@@ -44,18 +47,50 @@ public void addMusicSection(String key) {
4447
}
4548

4649
public String getClientsURL() {
47-
return "http://" + super.address + ":" + super.getPort() + "/clients";
50+
return "http://" + address + ":" + port + "/clients";
4851
}
4952

5053
public String getBaseURL() {
51-
return "http://" + super.address + ":" + super.getPort() + "/";
54+
return "http://" + address + ":" + port + "/";
5255
}
5356

5457
@Override
5558
public String toString() {
5659
String output = "";
57-
output += "Name: " + super.name + "\n";
58-
output += "IP Address: " + super.address + "\n";
60+
output += "Name: " + name + "\n";
61+
output += "IP Address: " + address + "\n";
5962
return output;
6063
}
64+
65+
@Override
66+
public int describeContents() {
67+
return 0;
68+
}
69+
70+
@Override
71+
public void writeToParcel(Parcel parcel, int i) {
72+
parcel.writeString(name);
73+
parcel.writeString(port);
74+
parcel.writeString(version);
75+
parcel.writeString(product);
76+
parcel.writeString(address);
77+
}
78+
79+
public PlexServer(Parcel in) {
80+
name = in.readString();
81+
port = in.readString();
82+
version = in.readString();
83+
product = in.readString();
84+
address = in.readString();
85+
}
86+
87+
public static final Parcelable.Creator<PlexServer> CREATOR = new Parcelable.Creator<PlexServer>() {
88+
public PlexServer createFromParcel(Parcel in) {
89+
return new PlexServer(in);
90+
}
91+
92+
public PlexServer[] newArray(int size) {
93+
return new PlexServer[size];
94+
}
95+
};
6196
}

0 commit comments

Comments
 (0)