Cleaner handling of first start
This commit is contained in:
@ -93,6 +93,7 @@ class MainActivity : AppCompatActivity() {
|
||||
private var resumeUap = ""
|
||||
private var resumeCall: Call? = null
|
||||
private var resumeAction = ""
|
||||
private var firstRun = false
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -624,17 +625,15 @@ class MainActivity : AppCompatActivity() {
|
||||
else
|
||||
if (!BaresipService.isServiceRunning)
|
||||
if (File(filesDir.absolutePath + "/accounts").exists()) {
|
||||
val accounts = String(Utils.getFileContents(filesDir.absolutePath + "/accounts")!!,
|
||||
Charsets.UTF_8).lines().toMutableList()
|
||||
val accounts = String(
|
||||
Utils.getFileContents(filesDir.absolutePath + "/accounts")!!,
|
||||
Charsets.UTF_8
|
||||
).lines().toMutableList()
|
||||
askPasswords(accounts)
|
||||
} else {
|
||||
// Baresip is started for the first time
|
||||
if (!Utils.checkPermission(this, Manifest.permission.RECORD_AUDIO))
|
||||
Utils.requestPermission(this, Manifest.permission.RECORD_AUDIO,
|
||||
RECORD_PERMISSION_REQUEST_CODE)
|
||||
else
|
||||
// Some old devices have granted Mic permission without a need to ask
|
||||
startBaresip()
|
||||
firstRun = true
|
||||
startBaresip()
|
||||
}
|
||||
|
||||
intent.removeExtra("action")
|
||||
@ -649,6 +648,16 @@ class MainActivity : AppCompatActivity() {
|
||||
else
|
||||
volumeControlStream = AudioManager.STREAM_VOICE_CALL
|
||||
|
||||
window.decorView.post {
|
||||
if (firstRun) {
|
||||
if (!Utils.checkPermission(this, Manifest.permission.RECORD_AUDIO))
|
||||
Utils.requestPermission(
|
||||
this, Manifest.permission.RECORD_AUDIO, RECORD_PERMISSION_REQUEST_CODE
|
||||
)
|
||||
firstRun = false
|
||||
}
|
||||
}
|
||||
|
||||
} // OnCreate
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
@ -1233,13 +1242,10 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
when (requestCode) {
|
||||
|
||||
RECORD_PERMISSION_REQUEST_CODE -> {
|
||||
RECORD_PERMISSION_REQUEST_CODE ->
|
||||
if ((grantResults.isNotEmpty()) && (grantResults[0] != PackageManager.PERMISSION_GRANTED))
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
getString(R.string.no_calls), ::startBaresip)
|
||||
else
|
||||
startBaresip()
|
||||
}
|
||||
getString(R.string.no_calls))
|
||||
|
||||
BACKUP_PERMISSION_REQUEST_CODE ->
|
||||
if ((grantResults.isNotEmpty()) && (grantResults[0] == PackageManager.PERMISSION_GRANTED))
|
||||
|
||||
Reference in New Issue
Block a user