Don't show Bluetooth visibility dialog so often.

This commit is contained in:
Felix Ableitner 2015-08-22 19:42:28 +02:00
parent 6eed89f8c0
commit ee621a7d78
2 changed files with 19 additions and 4 deletions

View file

@ -76,7 +76,9 @@ class FirstStartActivity extends AppCompatActivity with OnEditorActionListener w
}
def startMainActivity(): Unit = {
startActivity(new Intent(this, classOf[MainActivity]))
val intent = new Intent(this, classOf[MainActivity])
intent.setAction(MainActivity.ActionRequestBluetooth)
startActivity(intent)
finish()
}

View file

@ -12,9 +12,18 @@ import com.nutomic.ensichat.protocol.Address
object MainActivity {
/**
* If this action is set, a dialog will be shown to request the device to be discoverable.
*
* This should only be used when the app is started from a launcher
* (eg from [[FirstStartActivity]]).
*/
val ActionRequestBluetooth = "request_bluetooth"
val ActionOpenChat = "open_chat"
val ExtraAddress = "address"
}
/**
@ -35,9 +44,13 @@ class MainActivity extends EnsichatActivity {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
startActivityForResult(intent, RequestSetDiscoverable)
if (getIntent.getAction == MainActivity.ActionRequestBluetooth) {
val intent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE)
intent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 0)
startActivityForResult(intent, RequestSetDiscoverable)
// Make sure this code isn't executed after screen rotate etc.
getIntent.setAction(null)
}
val fm = getFragmentManager
if (savedInstanceState != null) {