@@ -400,8 +400,10 @@ private void switchToFragment(Fragment fragment) {
400
400
private void init () {
401
401
handler = new Handler ();
402
402
403
- if (BuildConfig .USE_BUGSENSE )
403
+ if (BuildConfig .USE_BUGSENSE ) {
404
+ Mint .disableNetworkMonitoring ();
404
405
Mint .initAndStartSession (getApplicationContext (), BUGSENSE_APIKEY );
406
+ }
405
407
406
408
// Set a Toolbar to replace the ActionBar.
407
409
toolbar = (Toolbar ) findViewById (R .id .toolbar );
@@ -575,32 +577,32 @@ public void onFailure(Throwable error) {
575
577
576
578
private void showPin (final Pin pin ) {
577
579
AlertDialog .Builder alertDialogBuilder = new AlertDialog .Builder (MainActivity .this );
578
- alertDialogBuilder .setTitle (R .string .pin_title );
579
- alertDialogBuilder .setMessage (String .format (getString (R .string .pin_message ), pin .code ));
580
- alertDialogBuilder
581
- .setCancelable (false )
582
- .setNegativeButton ("Cancel" ,
583
- new DialogInterface .OnClickListener () {
584
- public void onClick (DialogInterface dialog , int id ) {
585
- dialog .cancel ();
586
- fetchPinTask .getFuture ().cancel (false );
587
- }
588
- }
589
- )
590
- .setNeutralButton ("Manual" , new DialogInterface .OnClickListener () {
591
- @ Override
592
- public void onClick (final DialogInterface dialog , int id ) {
593
- dialog .dismiss ();
594
- fetchPinTask .getFuture ().cancel (false );
595
- showManualLogin ();
596
- }
597
- });
598
-
599
-
580
+ View view = getLayoutInflater ().inflate (R .layout .popup_plex_pin , null );
581
+ alertDialogBuilder .setView (view );
600
582
// create and show an alert dialog
601
583
final AlertDialog pinAlert = alertDialogBuilder .create ();
602
584
pinAlert .show ();
603
585
586
+ TextView popupPlexPinMessage = (TextView )view .findViewById (R .id .popupPlexPinMessage );
587
+ popupPlexPinMessage .setText (String .format (getString (R .string .pin_message ), pin .code ));
588
+ Button popupPlexPinManualButton = (Button )view .findViewById (R .id .popupPlexPinManualButton );
589
+ popupPlexPinManualButton .setOnClickListener (new View .OnClickListener () {
590
+ @ Override
591
+ public void onClick (View v ) {
592
+ pinAlert .dismiss ();
593
+ fetchPinTask .getFuture ().cancel (false );
594
+ showManualLogin ();
595
+ }
596
+ });
597
+ Button popupPlexPinCancelButton = (Button )view .findViewById (R .id .popupPlexPinCancelButton );
598
+ popupPlexPinCancelButton .setOnClickListener (new View .OnClickListener () {
599
+ @ Override
600
+ public void onClick (View v ) {
601
+ pinAlert .cancel ();
602
+ fetchPinTask .getFuture ().cancel (false );
603
+ }
604
+ });
605
+
604
606
// Now set up a task to hit the below url (based on the "id" field returned in the above http POST)
605
607
// every second. Once the user has entered the code on the plex website, the xml returned from the
606
608
// below http GET will contain their authentication token. Once that is retrieved, save it, switch
@@ -618,7 +620,6 @@ public void onSuccess(Pin pin) {
618
620
PlexHttpClient .signin (authToken , new PlexHttpUserHandler () {
619
621
@ Override
620
622
public void onSuccess (PlexUser user ) {
621
- Logger .d ("Got user: %s" , user .username );
622
623
prefs .put (Preferences .PLEX_USERNAME , user .username );
623
624
prefs .put (Preferences .PLEX_EMAIL , user .email );
624
625
if (doingFirstTimeSetup ) {
@@ -628,7 +629,6 @@ public void onSuccess(PlexUser user) {
628
629
} else {
629
630
setupNavigationDrawer ();
630
631
refreshServers (null );
631
- refreshServers .run ();
632
632
}
633
633
}
634
634
@@ -679,45 +679,33 @@ private void showFindingPlexClientsAndServers() {
679
679
680
680
private void showManualLogin () {
681
681
LayoutInflater layoutInflater = LayoutInflater .from (MainActivity .this );
682
- View promptView = layoutInflater .inflate (R .layout .login , null );
683
- AlertDialog .Builder alertDialogBuilder = new AlertDialog .Builder (MainActivity .this );
684
- alertDialogBuilder .setView (promptView );
685
- alertDialogBuilder .setTitle (R .string .login_title );
686
- alertDialogBuilder .setMessage (R .string .login_message );
687
- final EditText usernameInput = (EditText ) promptView .findViewById (R .id .usernameInput );
688
- final EditText passwordInput = (EditText ) promptView .findViewById (R .id .passwordInput );
689
- alertDialogBuilder
690
- .setCancelable (true )
691
- .setPositiveButton (R .string .ok , new DialogInterface .OnClickListener () {
692
- @ Override
693
- public void onClick (final DialogInterface dialog , int id ) {
694
- }
695
- })
696
- .setNeutralButton (R .string .button_pin , new DialogInterface .OnClickListener () {
697
- @ Override
698
- public void onClick (final DialogInterface dialog , int id ) {
699
- dialog .dismiss ();
700
- showLogin ();
701
- }
702
- })
703
- .setNegativeButton (R .string .cancel ,
704
- new DialogInterface .OnClickListener () {
705
- public void onClick (DialogInterface dialog , int id ) {
706
- dialog .cancel ();
707
- }
708
- }
709
- );
710
-
682
+ View view = layoutInflater .inflate (R .layout .login , null );
683
+ AlertDialog .Builder builder = new AlertDialog .Builder (MainActivity .this );
684
+ builder .setView (view );
685
+ final EditText usernameInput = (EditText ) view .findViewById (R .id .usernameInput );
686
+ final EditText passwordInput = (EditText ) view .findViewById (R .id .passwordInput );
711
687
712
- // create an alert dialog
713
- final AlertDialog alertD = alertDialogBuilder .create ();
688
+ final AlertDialog alertD = builder .create ();
714
689
715
- alertD .show ();
716
-
717
- Button b = alertD .getButton (DialogInterface .BUTTON_POSITIVE );
718
- b .setOnClickListener (new View .OnClickListener () {
690
+ Button popupManualLoginPinButton = (Button )view .findViewById (R .id .popupManualLoginPinButton );
691
+ popupManualLoginPinButton .setOnClickListener (new View .OnClickListener () {
719
692
@ Override
720
- public void onClick (View view ) {
693
+ public void onClick (View v ) {
694
+ alertD .dismiss ();
695
+ showLogin ();
696
+ }
697
+ });
698
+ Button popupManualLoginCancelButton = (Button )view .findViewById (R .id .popupManualLoginCancelButton );
699
+ popupManualLoginCancelButton .setOnClickListener (new View .OnClickListener () {
700
+ @ Override
701
+ public void onClick (View v ) {
702
+ alertD .cancel ();
703
+ }
704
+ });
705
+ Button popupManualLoginOKButton = (Button )view .findViewById (R .id .popupManualLoginOKButton );
706
+ popupManualLoginOKButton .setOnClickListener (new View .OnClickListener () {
707
+ @ Override
708
+ public void onClick (View v ) {
721
709
PlexHttpClient .signin (usernameInput .getText ().toString (), passwordInput .getText ().toString (), new PlexHttpUserHandler () {
722
710
@ Override
723
711
public void onSuccess (PlexUser user ) {
@@ -730,6 +718,9 @@ public void onSuccess(PlexUser user) {
730
718
showFindingPlexClientsAndServers ();
731
719
refreshServers .run ();
732
720
refreshClients .run ();
721
+ } else {
722
+ setupNavigationDrawer ();
723
+ refreshServers (null );
733
724
}
734
725
alertD .cancel ();
735
726
}
@@ -747,6 +738,9 @@ public void onFailure(int statusCode) {
747
738
});
748
739
}
749
740
});
741
+ builder
742
+ .setCancelable (true );
743
+ alertD .show ();
750
744
}
751
745
752
746
private void setServer (PlexServer s ) {
@@ -973,7 +967,8 @@ else if(castPlayerManager.isSubscribed())
973
967
private void onFirstTimeScanFinished () {
974
968
doingFirstTimeSetup = false ;
975
969
prefs .put (Preferences .FIRST_TIME_SETUP_COMPLETED , true );
976
- alertDialog .dismiss ();
970
+ if (alertDialog != null )
971
+ alertDialog .dismiss ();
977
972
init ();
978
973
drawerToggle .syncState ();
979
974
doAutomaticDeviceScan ();
0 commit comments