Skip to content

Commit 23fd2b9

Browse files
author
Chris Bellew
committed
Don't dismiss login dialog until logged in; On older versions, setting background on Now Playing screen wouldn't work; Version bump and change log addition.
1 parent de86cec commit 23fd2b9

File tree

6 files changed

+63
-45
lines changed

6 files changed

+63
-45
lines changed

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

Lines changed: 3 additions & 3 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="11"
5-
android:versionName="1.7.1" >
4+
android:versionCode="14"
5+
android:versionName="1.8" >
66

77
<uses-permission android:name="com.mohammadag.googlesearchapi.permission.ACCESS_GGOGLE_SEARCH_API" />
88
<uses-permission android:name="android.permission.INTERNET" />
@@ -31,7 +31,7 @@
3131
<action android:name="com.twofortyfouram.locale.intent.action.EDIT_SETTING" />
3232
</intent-filter>
3333
</activity>
34-
<service android:name=".PlexSearch"
34+
<service android:name=".PlexSearchService"
3535
android:label="Plex Search">
3636
</service>
3737
<activity

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

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.view.View;
3333
import android.view.ViewGroup;
3434
import android.widget.AdapterView;
35+
import android.widget.Button;
3536
import android.widget.CheckBox;
3637
import android.widget.EditText;
3738
import android.widget.ListAdapter;
@@ -444,38 +445,11 @@ public void showLogin() {
444445
final EditText usernameInput = (EditText) promptView.findViewById(R.id.usernameInput);
445446
final EditText passwordInput = (EditText) promptView.findViewById(R.id.passwordInput);
446447
alertDialogBuilder
447-
.setCancelable(false)
448-
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
449-
public void onClick(DialogInterface dialog, int id) {
450-
// get user input and set it to result
451-
Header[] headers = {
452-
new BasicHeader(PlexHeaders.XPlexClientPlatform, "Android"),
453-
new BasicHeader(PlexHeaders.XPlexClientIdentifier, getUUID()),
454-
new BasicHeader("Accept", "text/xml")
455-
};
456-
PlexHttpClient.signin(MainActivity.this, usernameInput.getText().toString(), passwordInput.getText().toString(), headers, "application/xml;charset=\"utf-8\"", new PlexHttpUserHandler() {
457-
@Override
458-
public void onSuccess(PlexUser user) {
459-
mPrefsEditor.putString(VoiceControlForPlexApplication.Pref.AUTHENTICATION_TOKEN, user.authenticationToken);
460-
remoteScan.authenticationToken = user.authenticationToken;
461-
mPrefsEditor.commit();
462-
feedback.m(R.string.logged_in);
463-
MenuItem loginItem = menu.findItem(R.id.menu_login);
464-
loginItem.setVisible(false);
465-
MenuItem logoutItem = menu.findItem(R.id.menu_logout);
466-
logoutItem.setVisible(true);
467-
loggedIn = true;
468-
}
469-
470-
@Override
471-
public void onFailure(int statusCode, PlexError error) {
472-
Logger.e("Failure logging in");
473-
String err = getString(R.string.login_error);
474-
if(error.errors != null && error.errors.size() > 0)
475-
err = error.errors.get(0);
476-
feedback.e(err);
477-
}
478-
});
448+
.setCancelable(true)
449+
.setNeutralButton("OK", new DialogInterface.OnClickListener() {
450+
@Override
451+
public void onClick(final DialogInterface dialog, int id) {
452+
479453

480454
}
481455
})
@@ -487,11 +461,48 @@ public void onClick(DialogInterface dialog, int id) {
487461
}
488462
);
489463

464+
490465
// create an alert dialog
491-
AlertDialog alertD = alertDialogBuilder.create();
466+
final AlertDialog alertD = alertDialogBuilder.create();
492467

493468
alertD.show();
494469

470+
Button b = alertD.getButton(DialogInterface.BUTTON_NEUTRAL);
471+
b.setOnClickListener(new View.OnClickListener() {
472+
@Override
473+
public void onClick(View view) {
474+
Header[] headers = {
475+
new BasicHeader(PlexHeaders.XPlexClientPlatform, "Android"),
476+
new BasicHeader(PlexHeaders.XPlexClientIdentifier, getUUID()),
477+
new BasicHeader("Accept", "text/xml")
478+
};
479+
PlexHttpClient.signin(MainActivity.this, usernameInput.getText().toString(), passwordInput.getText().toString(), headers, "application/xml;charset=\"utf-8\"", new PlexHttpUserHandler() {
480+
@Override
481+
public void onSuccess(PlexUser user) {
482+
mPrefsEditor.putString(VoiceControlForPlexApplication.Pref.AUTHENTICATION_TOKEN, user.authenticationToken);
483+
remoteScan.authenticationToken = user.authenticationToken;
484+
mPrefsEditor.commit();
485+
feedback.m(R.string.logged_in);
486+
MenuItem loginItem = menu.findItem(R.id.menu_login);
487+
loginItem.setVisible(false);
488+
MenuItem logoutItem = menu.findItem(R.id.menu_logout);
489+
logoutItem.setVisible(true);
490+
loggedIn = true;
491+
alertD.cancel();
492+
}
493+
494+
@Override
495+
public void onFailure(int statusCode, PlexError error) {
496+
Logger.e("Failure logging in");
497+
String err = getString(R.string.login_error);
498+
if (error.errors != null && error.errors.size() > 0)
499+
err = error.errors.get(0);
500+
feedback.e(err);
501+
}
502+
503+
});
504+
}
505+
});
495506

496507
}
497508

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import android.app.Activity;
44
import android.content.Intent;
5-
import android.content.SharedPreferences;
65
import android.os.Bundle;
7-
import android.speech.RecognizerIntent;
86
import android.widget.ImageView;
97
import android.widget.ScrollView;
108
import android.widget.TextView;
@@ -18,8 +16,6 @@
1816
import org.codechimp.apprater.AppRater;
1917

2018
public class NowPlayingActivity extends Activity {
21-
public final static String PREFS = MainActivity.PREFS;
22-
private SharedPreferences mPrefs;
2319
private PlexVideo playingVideo; // The video currently playing
2420
private PlexTrack playingTrack; // The track currently playing
2521
private PlexClient client = null;
@@ -32,8 +28,6 @@ protected void onCreate(Bundle savedInstanceState) {
3228

3329
BugSenseHandler.initAndStartSession(NowPlayingActivity.this, MainActivity.BUGSENSE_APIKEY);
3430

35-
mPrefs = getSharedPreferences(PREFS, MODE_PRIVATE);
36-
3731
setContentView(R.layout.play_media);
3832

3933
AppRater.app_launched(this);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {
102102
// Received spoken query from the RecognizerIntent
103103
ArrayList<String> voiceResults = intent.getExtras().getStringArrayList(RecognizerIntent.EXTRA_RESULTS);
104104
for(String q : voiceResults) {
105-
Logger.d("q: %s", q);
106105
if(q.matches(getString(R.string.pattern_recognition))) {
107106
queryText = q;
108107
break;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import android.content.Context;
44
import android.content.res.Resources;
55
import android.graphics.drawable.Drawable;
6+
import android.os.Build;
67
import android.widget.ImageView;
78
import android.widget.ScrollView;
89

@@ -91,7 +92,7 @@ public static void signin(Context context, String username, String password, Hea
9192
client.post(context, "https://plex.tv/users/sign_in.xml", headers, new RequestParams(), contentType, new AsyncHttpResponseHandler() {
9293
@Override
9394
public void onSuccess(int statusCode, org.apache.http.Header[] headers, byte[] responseBody) {
94-
Logger.d("GET SUCCESS: %d", statusCode);
95+
Logger.d("signin success: %d", statusCode);
9596
PlexUser u = new PlexUser();
9697
try {
9798
u = serial.read(PlexUser.class, new String(responseBody, "UTF-8"));
@@ -145,6 +146,7 @@ public void onSuccess(byte[] imageData) {
145146
}
146147
}
147148

149+
@SuppressWarnings("deprecation")
148150
public static void setThumb(PlexVideo video, final ScrollView layout) {
149151
if(!video.thumb.equals("")) {
150152
try {
@@ -164,7 +166,10 @@ public void onSuccess(byte[] imageData) {
164166
}
165167
Drawable d = Drawable.createFromStream(is, "thumb");
166168
d.setAlpha(80);
167-
layout.setBackground(d);
169+
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
170+
layout.setBackground(d);
171+
else
172+
layout.setBackgroundDrawable(d);
168173
}
169174
});
170175
} catch(Exception e) {

Voice Control For Plex/src/main/res/xml/changelog.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<changelog>
3+
<release version="1.8" versioncode="14">
4+
<change>Added Plex login, including support for shared libraries.</change>
5+
<change>Added ability to hardcode server and client into a homescreen shortcut.</change>
6+
<change>Don't ignore Plex clients &lt; 1.0.7 unless they are a desktop client (was hiding Rasplex).</change>
7+
<change>Increased support for localization.</change>
8+
<change>Added French localization (Gostron).</change>
9+
<change>Fixed Scan All functionality.</change>
10+
<change>Various bug fixes and enhancements</change>
11+
</release>
312
<release version="1.7.1" versioncode="11">
413
<change>Fixed bug that prevented Install Tasker Project action from being shown in the menu unless you have both utter! and AutoVoice installed - it should show if you have either installed.</change>
514
<change>Fixed hardcoded value in strings.xml</change>

0 commit comments

Comments
 (0)