diff --git a/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt index 696bbace..d9b336a1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/HistoryActivity.kt @@ -19,7 +19,6 @@ import java.util.GregorianCalendar class HistoryActivity : AppCompatActivity() { internal var uaHistory = ArrayList() - internal var posAtHistory = ArrayList() internal var aor: String = "" public override fun onCreate(savedInstanceState: Bundle?) { @@ -45,8 +44,7 @@ class HistoryActivity : AppCompatActivity() { val dialogClickListener = DialogInterface.OnClickListener { _, which -> when (which) { DialogInterface.BUTTON_POSITIVE -> { - MainActivity.history.removeAt(posAtHistory[pos]) - aorGenerateHistory(aor) + removeUaHistoryAt(pos) if (uaHistory.size == 0) { val i = Intent() setResult(Activity.RESULT_CANCELED, i) @@ -61,7 +59,7 @@ class HistoryActivity : AppCompatActivity() { val builder = AlertDialog.Builder(this@HistoryActivity, R.style.Theme_AppCompat) builder.setMessage("Do you want to delete " + - MainActivity.history[pos].peerURI + "?") + uaHistory[pos].peerURI + " call history?") .setPositiveButton("Yes", dialogClickListener) .setNegativeButton("No", dialogClickListener).show() true @@ -84,7 +82,6 @@ class HistoryActivity : AppCompatActivity() { private fun aorGenerateHistory(aor: String) { uaHistory.clear() - posAtHistory.clear() for (i in MainActivity.history.indices.reversed()) { val h = MainActivity.history[i] if (h.aor == aor) { @@ -105,6 +102,7 @@ class HistoryActivity : AppCompatActivity() { direction = R.drawable.arrow_up_red if (uaHistory.isNotEmpty() && (uaHistory.last().peerURI == peer_uri)) { uaHistory.last().directions.add(direction) + uaHistory.last().indexes.add(i) } else { val time: String if (isToday(h.time)) { @@ -114,13 +112,18 @@ class HistoryActivity : AppCompatActivity() { val fmt = SimpleDateFormat("dd.MM") time = fmt.format(h.time.time) } - uaHistory.add(HistoryRow(peer_uri, direction, time)) - posAtHistory.add(i) + uaHistory.add(HistoryRow(peer_uri, direction, time, i)) } } } } + private fun removeUaHistoryAt(i: Int) { + for (index in uaHistory[i].indexes) + MainActivity.history.removeAt(index) + uaHistory.removeAt(i) + } + private fun isToday(time: GregorianCalendar): Boolean { val now = GregorianCalendar() return now.get(Calendar.YEAR) == time.get(Calendar.YEAR) && diff --git a/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt b/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt index 2dd52571..7b731646 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/HistoryRow.kt @@ -1,10 +1,12 @@ package com.tutpro.baresip -class HistoryRow(val peerURI: String, val direction: Int, val time: String) { +class HistoryRow(val peerURI: String, val direction: Int, val time: String, val index: Int) { val directions = ArrayList() + val indexes = ArrayList() init { directions.add(direction) + indexes.add(index) } }