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