improved history implementation

This commit is contained in:
Juha Heinanen
2018-05-30 08:47:49 +03:00
parent a83e75c2b6
commit d6ddbdc771
2 changed files with 13 additions and 8 deletions
@@ -19,7 +19,6 @@ import java.util.GregorianCalendar
class HistoryActivity : AppCompatActivity() { class HistoryActivity : AppCompatActivity() {
internal var uaHistory = ArrayList<HistoryRow>() internal var uaHistory = ArrayList<HistoryRow>()
internal var posAtHistory = ArrayList<Int>()
internal var aor: String = "" internal var aor: String = ""
public override fun onCreate(savedInstanceState: Bundle?) { public override fun onCreate(savedInstanceState: Bundle?) {
@@ -45,8 +44,7 @@ class HistoryActivity : AppCompatActivity() {
val dialogClickListener = DialogInterface.OnClickListener { _, which -> val dialogClickListener = DialogInterface.OnClickListener { _, which ->
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE -> { DialogInterface.BUTTON_POSITIVE -> {
MainActivity.history.removeAt(posAtHistory[pos]) removeUaHistoryAt(pos)
aorGenerateHistory(aor)
if (uaHistory.size == 0) { if (uaHistory.size == 0) {
val i = Intent() val i = Intent()
setResult(Activity.RESULT_CANCELED, i) setResult(Activity.RESULT_CANCELED, i)
@@ -61,7 +59,7 @@ class HistoryActivity : AppCompatActivity() {
val builder = AlertDialog.Builder(this@HistoryActivity, val builder = AlertDialog.Builder(this@HistoryActivity,
R.style.Theme_AppCompat) R.style.Theme_AppCompat)
builder.setMessage("Do you want to delete " + builder.setMessage("Do you want to delete " +
MainActivity.history[pos].peerURI + "?") uaHistory[pos].peerURI + " call history?")
.setPositiveButton("Yes", dialogClickListener) .setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show() .setNegativeButton("No", dialogClickListener).show()
true true
@@ -84,7 +82,6 @@ class HistoryActivity : AppCompatActivity() {
private fun aorGenerateHistory(aor: String) { private fun aorGenerateHistory(aor: String) {
uaHistory.clear() uaHistory.clear()
posAtHistory.clear()
for (i in MainActivity.history.indices.reversed()) { for (i in MainActivity.history.indices.reversed()) {
val h = MainActivity.history[i] val h = MainActivity.history[i]
if (h.aor == aor) { if (h.aor == aor) {
@@ -105,6 +102,7 @@ class HistoryActivity : AppCompatActivity() {
direction = R.drawable.arrow_up_red direction = R.drawable.arrow_up_red
if (uaHistory.isNotEmpty() && (uaHistory.last().peerURI == peer_uri)) { if (uaHistory.isNotEmpty() && (uaHistory.last().peerURI == peer_uri)) {
uaHistory.last().directions.add(direction) uaHistory.last().directions.add(direction)
uaHistory.last().indexes.add(i)
} else { } else {
val time: String val time: String
if (isToday(h.time)) { if (isToday(h.time)) {
@@ -114,13 +112,18 @@ class HistoryActivity : AppCompatActivity() {
val fmt = SimpleDateFormat("dd.MM") val fmt = SimpleDateFormat("dd.MM")
time = fmt.format(h.time.time) time = fmt.format(h.time.time)
} }
uaHistory.add(HistoryRow(peer_uri, direction, time)) uaHistory.add(HistoryRow(peer_uri, direction, time, i))
posAtHistory.add(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 { private fun isToday(time: GregorianCalendar): Boolean {
val now = GregorianCalendar() val now = GregorianCalendar()
return now.get(Calendar.YEAR) == time.get(Calendar.YEAR) && return now.get(Calendar.YEAR) == time.get(Calendar.YEAR) &&
@@ -1,10 +1,12 @@
package com.tutpro.baresip 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<Int>() val directions = ArrayList<Int>()
val indexes = ArrayList<Int>()
init { init {
directions.add(direction) directions.add(direction)
indexes.add(index)
} }
} }