From 622e0f5c0f969d718238a67b9570d82874405a59 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Fri, 19 Apr 2019 21:37:22 +0300 Subject: [PATCH] - Fixed placing call from call history - Use singleTask launch mode in order to avoid creating multiple activity stacks - Small call history related edits --- app/src/main/AndroidManifest.xml | 2 +- .../com/tutpro/baresip/BaresipService.kt | 18 ++++++++---------- .../kotlin/com/tutpro/baresip/CallHistory.kt | 10 ++++------ .../kotlin/com/tutpro/baresip/MainActivity.kt | 4 +++- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5b12dd49..1b1aa9ae 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -38,7 +38,7 @@ + android:launchMode="singleTask"> diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 750a4a53..805bdd2b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -24,6 +24,9 @@ import java.io.File import java.nio.charset.StandardCharsets import java.io.InputStream import java.util.* +import android.content.Intent + + class BaresipService: Service() { @@ -170,8 +173,7 @@ class BaresipService: Service() { "Call Show", "Call Answer" -> { val newIntent = Intent(this, MainActivity::class.java) - newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP newIntent.putExtra("action", action.toLowerCase()) newIntent.putExtra("callp", intent!!.getStringExtra("callp")) startActivity(newIntent) @@ -199,8 +201,7 @@ class BaresipService: Service() { Log.w(LOG_TAG, "onStartCommand did not find ua $uap") } else { val newIntent = Intent(this, MainActivity::class.java) - newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP newIntent.putExtra("action", action.toLowerCase()) newIntent.putExtra("callp", intent.getStringExtra("callp")) newIntent.putExtra("uri", intent.getStringExtra("uri")) @@ -221,8 +222,7 @@ class BaresipService: Service() { "Message Show", "Message Reply" -> { val newIntent = Intent(this, MainActivity::class.java) - newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + newIntent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP newIntent.putExtra("action", action.toLowerCase()) newIntent.putExtra("uap", intent!!.getStringExtra("uap")) newIntent.putExtra("time", intent.getStringExtra("time")) @@ -519,8 +519,7 @@ class BaresipService: Service() { return if (newEvent == null) newEvent = event val intent = Intent("service event") - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP intent.putExtra("event", newEvent) intent.putExtra("params", arrayListOf(uap, callp)) LocalBroadcastManager.getInstance(this).sendBroadcast(intent) @@ -590,8 +589,7 @@ class BaresipService: Service() { return } val intent = Intent("service event") - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or - Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP) + intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP intent.putExtra("event", "message show") intent.putExtra("params", arrayListOf(uap, timeStamp)) LocalBroadcastManager.getInstance(this).sendBroadcast(intent) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt index c5b1c2b8..0e520051 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallHistory.kt @@ -17,10 +17,6 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String, return BaresipService.history } - fun historySet(history: ArrayList) { - BaresipService.history = history - } - fun add(history: CallHistory) { BaresipService.history.add(history) if (aorHistorySize(history.aor) > CALL_HISTORY_SIZE) { @@ -49,11 +45,12 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String, } fun save(path: String) { + Log.d("Baresip", "Saving history of size ${BaresipService.history.size}") val file = File(path, "history") try { val fos = FileOutputStream(file) val oos = ObjectOutputStream(fos) - oos.writeObject(history()) + oos.writeObject(BaresipService.history) oos.close() fos.close() } catch (e: IOException) { @@ -68,9 +65,10 @@ class CallHistory(val aor: String, val peerURI: String, val direction: String, try { val fis = FileInputStream(file) val ois = ObjectInputStream(fis) - historySet(ois.readObject() as ArrayList) + BaresipService.history = ois.readObject() as ArrayList ois.close() fis.close() + Log.d("Baresip", "Restored history of size ${BaresipService.history.size}") } catch (e: Exception) { Log.e("Baresip", "InputStream exception: - " + e.toString()) } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 03ddac1a..6c652a87 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -507,8 +507,10 @@ class MainActivity : AppCompatActivity() { } "call reject" -> rejectButton.performClick() - "call" -> + "call" -> { + callUri.setText(resumeUri) callButton.performClick() + } "transfer show", "transfer accept" -> handleServiceEvent("$resumeAction,$resumeUri", arrayListOf(resumeCall!!.ua.uap, resumeCall!!.callp))