Improved implementation of calls activity

Increased call history size to 256
This commit is contained in:
Juha Heinanen
2025-04-08 12:44:59 +03:00
parent a64ea0b69d
commit 1daeed7018
2 changed files with 3 additions and 76 deletions
@@ -19,7 +19,7 @@ class CallHistoryNew(val aor: String, val peerUri: String, val direction: String
companion object { companion object {
private const val serialVersionUID: Long = 3 private const val serialVersionUID: Long = 3
private const val CALL_HISTORY_SIZE = 128 private const val CALL_HISTORY_SIZE = 256
fun add(history: CallHistoryNew) { fun add(history: CallHistoryNew) {
BaresipService.callHistory.add(history) BaresipService.callHistory.add(history)
@@ -7,8 +7,6 @@ import android.content.Intent
import android.graphics.BitmapFactory import android.graphics.BitmapFactory
import android.os.Bundle import android.os.Bundle
import android.os.SystemClock import android.os.SystemClock
import android.view.Menu
import android.view.MenuItem
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
@@ -175,10 +173,7 @@ class CallsActivity : ComponentActivity() {
when (selectedItem) { when (selectedItem) {
delete -> delete ->
with( with(
MaterialAlertDialogBuilder( MaterialAlertDialogBuilder(this@CallsActivity, R.style.AlertDialogTheme)
this@CallsActivity,
R.style.AlertDialogTheme
)
) { ) {
setTitle(R.string.confirmation) setTitle(R.string.confirmation)
setMessage( setMessage(
@@ -190,8 +185,7 @@ class CallsActivity : ComponentActivity() {
setPositiveButton(delete) { dialog, _ -> setPositiveButton(delete) { dialog, _ ->
CallHistoryNew.clear(aor) CallHistoryNew.clear(aor)
CallHistoryNew.save() CallHistoryNew.save()
aorGenerateHistory(aor) uaHistory.value = emptyList()
//clAdapter.notifyDataSetChanged()
dialog.dismiss() dialog.dismiss()
} }
setNeutralButton(getText(R.string.cancel)) { dialog, _ -> setNeutralButton(getText(R.string.cancel)) { dialog, _ ->
@@ -425,7 +419,6 @@ class CallsActivity : ComponentActivity() {
DialogInterface.BUTTON_POSITIVE -> { DialogInterface.BUTTON_POSITIVE -> {
removeFromHistory(callRow) removeFromHistory(callRow)
CallHistoryNew.save() CallHistoryNew.save()
/// clAdapter.notifyDataSetChanged()
} }
DialogInterface.BUTTON_NEUTRAL -> { DialogInterface.BUTTON_NEUTRAL -> {
} }
@@ -483,49 +476,6 @@ class CallsActivity : ComponentActivity() {
} }
} }
override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (BaresipService.activities.indexOf("calls,$aor") == -1)
return true
when (item.itemId) {
R.id.delete_history -> {
with (MaterialAlertDialogBuilder(this@CallsActivity, R.style.AlertDialogTheme)) {
setTitle(R.string.confirmation)
setMessage(String.format(getString(R.string.delete_history_alert),
aor.substringAfter(":")))
setPositiveButton(getText(R.string.delete)) { dialog, _ ->
CallHistoryNew.clear(aor)
CallHistoryNew.save()
aorGenerateHistory(aor)
// clAdapter.notifyDataSetChanged()
dialog.dismiss()
}
setNeutralButton(getText(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
show()
}
return true
}
R.id.history_on_off -> {
account.callHistory = !account.callHistory
invalidateOptionsMenu()
AccountsActivity.saveAccounts()
return true
}
android.R.id.home -> {
goBack()
return true
}
}
return super.onOptionsItemSelected(item)
}
private fun goBack() { private fun goBack() {
BaresipService.activities.remove("calls,$aor") BaresipService.activities.remove("calls,$aor")
returnResult() returnResult()
@@ -541,21 +491,6 @@ class CallsActivity : ComponentActivity() {
finish() finish()
} }
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
if (account.callHistory)
menu.findItem(R.id.history_on_off).title = getString(R.string.disable_history)
else
menu.findItem(R.id.history_on_off).title = getString(R.string.enable_history)
return super.onPrepareOptionsMenu(menu)
}
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.calls_menu, menu)
return true
}
private fun aorGenerateHistory(aor: String) { private fun aorGenerateHistory(aor: String) {
uaHistory.value = emptyList() uaHistory.value = emptyList()
for (i in BaresipService.callHistory.indices.reversed()) { for (i in BaresipService.callHistory.indices.reversed()) {
@@ -603,7 +538,6 @@ class CallsActivity : ComponentActivity() {
} }
CallHistoryNew.deleteRecording(callRow.recording) CallHistoryNew.deleteRecording(callRow.recording)
deleteFromUaHistory(callRow) deleteFromUaHistory(callRow)
updateUaHistory()
} }
private fun addToUaHistory(callRow: CallRow) { private fun addToUaHistory(callRow: CallRow) {
@@ -618,13 +552,6 @@ class CallsActivity : ComponentActivity() {
uaHistory.value = updatedList uaHistory.value = updatedList
} }
private fun updateUaHistory() {
val updatedList: MutableList<CallRow> = mutableListOf()
for (h in uaHistory.value)
updatedList.add(h)
uaHistory.value = updatedList
}
@SuppressLint("MutableCollectionMutableState") @SuppressLint("MutableCollectionMutableState")
companion object { companion object {
val uaHistory = mutableStateOf(emptyList<CallRow>()) val uaHistory = mutableStateOf(emptyList<CallRow>())