@@ -273,13 +273,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
273
273
if (btService!! .getState() == = BtService .State .CONNECTED ) {
274
274
// Fetch latest board
275
275
val newBoard = btService!! .getLocalBoard()
276
- if (newBoard != = gs!! .board())
277
- play(Source .Bluetooth , newBoard.lastMove()!! )
276
+ if (newBoard != = gs!! .board()) newBoard.lastMove()?.let { play(Source .Bluetooth , it) }
278
277
279
278
// Update subtitle
280
279
setSubTitle(getString(R .string.connected_to, btService!! .getConnectedDeviceName()))
281
- } else
282
- turnLocal()
280
+ } else turnLocal()
283
281
}
284
282
}
285
283
@@ -337,16 +335,19 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
337
335
}
338
336
339
337
private fun turnLocal () {
340
- if (! gs!! .isAi() && ! gs!! .isHuman())
338
+ if (! gs!! .isAi() && ! gs!! .isHuman()) {
341
339
newGame(GameState .Builder ().boards(gs!! .boards).build())
340
+ NotificationManagerCompat .from(this @MainActivity).cancel(BT_STILL_RUNNING )
341
+ }
342
342
}
343
343
344
344
private fun newLocal () {
345
345
newGame(GameState .Builder ().swapped(false ).build())
346
346
}
347
347
348
348
private inner class GameThread : Thread (), Closeable {
349
- @Volatile private var running: Boolean = false
349
+ @Volatile
350
+ private var running: Boolean = false
350
351
private var timer: Timer ? = null
351
352
352
353
override fun run () {
@@ -506,11 +507,11 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
506
507
if (t) newLocal()
507
508
}
508
509
}, this )
509
- R .id.nav_local_ai -> newAi(object : Callback <GameState >{
510
+ R .id.nav_local_ai -> newAi(object : Callback <GameState > {
510
511
override fun invoke (t : GameState ) {
511
512
newGame(t)
512
513
}
513
- },this )
514
+ }, this )
514
515
R .id.nav_bt_host -> hostBt()
515
516
R .id.nav_bt_join -> joinBt()
516
517
R .id.nav_other_feedback -> feedbackSender(this )
@@ -537,7 +538,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
537
538
val layout = View .inflate(this , R .layout.dialog_bt_host, null )
538
539
(layout.findViewById<View >(R .id.bt_host_desc) as TextView ).text = getString(R .string.host_desc, btService!! .getLocalBluetoothName())
539
540
540
- val onCheckedChangeListener = RadioGroup .OnCheckedChangeListener { _, _ ->
541
+ val onCheckedChangeListener = RadioGroup .OnCheckedChangeListener { _, _ ->
541
542
// Get board type
542
543
val newBoard = (layout.findViewById<View >(R .id.board_new) as RadioButton ).isChecked
543
544
@@ -591,7 +592,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
591
592
if (PackageManager .PERMISSION_GRANTED != ContextCompat .checkSelfPermission(this , android.Manifest .permission.ACCESS_COARSE_LOCATION ))
592
593
ActivityCompat .requestPermissions(this , arrayOf(android.Manifest .permission.ACCESS_COARSE_LOCATION ), REQUEST_COARSE_LOCATION )
593
594
else
594
- btDialog = BtPicker (this , btAdapter!! , object : Callback <String >{
595
+ btDialog = BtPicker (this , btAdapter!! , object : Callback <String > {
595
596
override fun invoke (t : String ) {
596
597
btService?.connect(t)
597
598
}
@@ -618,7 +619,7 @@ class MainActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelecte
618
619
if (askDialog != null && askDialog!! .isShowing)
619
620
askDialog!! .dismiss()
620
621
621
- val dialogClickListener = DialogInterface .OnClickListener { _, which ->
622
+ val dialogClickListener = DialogInterface .OnClickListener { _, which ->
622
623
if (which == DialogInterface .BUTTON_POSITIVE )
623
624
callBack.invoke(true )
624
625
else if (which == DialogInterface .BUTTON_NEGATIVE )
0 commit comments