@ -3,9 +3,11 @@ using Android.App;
using Android.OS ;
using Android.OS ;
using Android.Views ;
using Android.Views ;
using Android.Widget ;
using Android.Widget ;
using Android.Content ;
using Android.Support.V7.App ;
using Android.Support.V7.App ;
using Toolbar = Android . Support . V7 . Widget . Toolbar ;
using Toolbar = Android . Support . V7 . Widget . Toolbar ;
using GridLayoutManager = Android . Support . V7 . Widget . GridLayoutManager ;
using GridLayoutManager = Android . Support . V7 . Widget . GridLayoutManager ;
using Android.Runtime ;
namespace QuickPlay
namespace QuickPlay
{
{
@ -25,15 +27,6 @@ namespace QuickPlay
appConfig = AppConfiguration . loadConfiguration ( ) ;
appConfig = AppConfiguration . loadConfiguration ( ) ;
var playerConfig = await appConfig . GetPlayerConfig ( ) ;
var playerConfig = await appConfig . GetPlayerConfig ( ) ;
currentPlayer = playerConfig . GetPlayer ( ) ;
currentPlayer = playerConfig . GetPlayer ( ) ;
try
{
await currentPlayer . ConnectAsync ( ) ;
} catch ( CannotConnectException e )
{
//TODO: View a toast with details and change some colors?
var t = Toast . MakeText ( this , e . Message + ": " + e . InnerException . Message ? ? "" , ToastLength . Long ) ;
t . Show ( ) ;
}
// UI initialization
// UI initialization
SetContentView ( Resource . Layout . activity_main ) ;
SetContentView ( Resource . Layout . activity_main ) ;
@ -51,8 +44,7 @@ namespace QuickPlay
// Since this is rather complicated, it is in a separate method
// Since this is rather complicated, it is in a separate method
InitializeRecyclerView ( ) ;
InitializeRecyclerView ( ) ;
// FIXME: This should be in OnResume...
// I don't know why, but this needs to be here in order to show correct colors and player name.
// Refresh player info
OnPlayerUpdate ( ) ;
OnPlayerUpdate ( ) ;
}
}
@ -77,9 +69,33 @@ namespace QuickPlay
{
{
if ( item . ItemId = = Resource . Id . action_settings )
if ( item . ItemId = = Resource . Id . action_settings )
{
{
// Show the play bar
// Set player config URL
var bar = FindViewById ( Resource . Id . currentSongBar ) ;
var b = new Android . Support . V7 . App . AlertDialog . Builder ( this ) ;
bar . Visibility = ViewStates . Visible ;
b . SetTitle ( "Player config URL" ) ;
var input = new EditText ( this ) ;
input . Text = appConfig . playerConfigUrl ;
b . SetView ( input ) ;
b . SetPositiveButton ( "Set" , delegate
{
string text = input . Text ;
appConfig . playerConfigUrl = text ;
appConfig . saveConfiguration ( ) ;
Toast . MakeText ( this , "Configuration saved, reloading" , ToastLength . Short ) . Show ( ) ;
var i = new Intent ( this , typeof ( MainActivity ) ) ;
StartActivity ( i ) ;
} ) ;
b . SetNegativeButton ( "Scan QR" , delegate {
try
{
var i = new Intent ( "com.google.zxing.client.android.SCAN" ) ;
StartActivityForResult ( i , 0 ) ;
} catch ( ActivityNotFoundException ) {
Toast . MakeText ( this , "You need ZXing Barcode scanner for this" , ToastLength . Long ) . Show ( ) ;
}
} ) ;
b . SetCancelable ( true ) ;
b . Show ( ) ;
}
}
if ( item . ItemId = = Resource . Id . action_edit )
if ( item . ItemId = = Resource . Id . action_edit )
@ -135,5 +151,51 @@ namespace QuickPlay
{
{
await currentPlayer . Play ( song ) ;
await currentPlayer . Play ( song ) ;
}
}
protected new async void OnResume ( )
{
base . OnResume ( ) ;
// Reconnect the player
try
{
await currentPlayer . ConnectAsync ( ) ;
} catch ( CannotConnectException e )
{
//TODO: View a toast with details and change some colors?
var t = Toast . MakeText ( this , e . Message + ": " + e . InnerException . Message ? ? "" , ToastLength . Long ) ;
t . Show ( ) ;
}
// Refresh player info
OnPlayerUpdate ( ) ;
}
protected new void OnDestroy ( )
{
base . OnDestroy ( ) ;
this . appConfig . saveConfiguration ( ) ;
}
protected override void OnActivityResult ( int requestCode , [ GeneratedEnum ] Result resultCode , Intent data )
{
base . OnActivityResult ( requestCode , resultCode , data ) ;
if ( requestCode = = 0 )
{
if ( resultCode = = Result . Ok )
{
string url = data . GetStringExtra ( "SCAN_RESULT" ) ;
var cfg = new AppConfiguration { playerConfigUrl = url } ;
cfg . saveConfiguration ( ) ;
Toast . MakeText ( this , "Configuration saved, reloading" , ToastLength . Short ) . Show ( ) ;
var i = new Intent ( this , typeof ( MainActivity ) ) ;
StartActivity ( i ) ;
}
else if ( resultCode = = Result . Canceled )
{
Toast . MakeText ( this , "Could not load QR code" , ToastLength . Short ) . Show ( ) ;
}
}
}
}
}
}
}