- Allow deletion of account's chat history via chats activity menu item.

- Ask confirmation before deleting chat and call history.
- Improved updating of main activity voicemail, chat, and call icons.
- Removed path parameter from saveUaMessage, deleteUaMessage, and
  saveMessages functions.
This commit is contained in:
Juha Heinanen
2019-10-03 20:50:23 +03:00
parent 04cf77a60f
commit 39a0230bd0
10 changed files with 95 additions and 69 deletions
@@ -173,6 +173,7 @@ class BaresipService: Service() {
} }
ContactsActivity.restoreContacts(applicationContext.filesDir, "contacts") ContactsActivity.restoreContacts(applicationContext.filesDir, "contacts")
Message.restoreMessages()
Thread(Runnable { baresipStart(filesPath) }).start() Thread(Runnable { baresipStart(filesPath) }).start()
isServiceRunning = true isServiceRunning = true
@@ -261,8 +262,7 @@ class BaresipService: Service() {
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.saveUaMessage(ua.account.aor, ChatsActivity.saveUaMessage(ua.account.aor,
intent.getStringExtra("time").toLong(), intent.getStringExtra("time").toLong())
applicationContext.filesDir.absolutePath)
nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID) nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID)
} }
@@ -273,8 +273,7 @@ class BaresipService: Service() {
Log.w(LOG_TAG, "onStartCommand did not find UA $uap") Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
else else
ChatsActivity.deleteUaMessage(ua.account.aor, ChatsActivity.deleteUaMessage(ua.account.aor,
intent.getStringExtra("time").toLong(), intent.getStringExtra("time").toLong())
applicationContext.filesDir.absolutePath)
nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID) nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID)
} }
@@ -637,7 +636,7 @@ class BaresipService: Service() {
Log.d(LOG_TAG, "Message event for $uap from $peer at $timeStamp") Log.d(LOG_TAG, "Message event for $uap from $peer at $timeStamp")
Message.add(Message(ua.account.aor, peer, text, timeStamp.toLong(), Message.add(Message(ua.account.aor, peer, text, timeStamp.toLong(),
R.drawable.arrow_down_green, 0, "", true)) R.drawable.arrow_down_green, 0, "", true))
Message.saveMessages(filesPath) Message.saveMessages()
ua.account.unreadMessages = true ua.account.unreadMessages = true
if (!Utils.isVisible()) { if (!Utils.isVisible()) {
val intent = Intent(this, BaresipService::class.java) val intent = Intent(this, BaresipService::class.java)
@@ -20,7 +20,7 @@ import java.util.GregorianCalendar
class CallsActivity : AppCompatActivity() { class CallsActivity : AppCompatActivity() {
internal lateinit var account: Account internal lateinit var account: Account
internal lateinit var adapter: CallListAdapter internal lateinit var clAdapter: CallListAdapter
internal var uaHistory = ArrayList<CallRow>() internal var uaHistory = ArrayList<CallRow>()
internal var aor = "" internal var aor = ""
@@ -41,8 +41,8 @@ class CallsActivity : AppCompatActivity() {
val listView = findViewById(R.id.calls) as ListView val listView = findViewById(R.id.calls) as ListView
aorGenerateHistory(aor) aorGenerateHistory(aor)
adapter = CallListAdapter(this, uaHistory) clAdapter = CallListAdapter(this, uaHistory)
listView.adapter = adapter listView.adapter = clAdapter
listView.isLongClickable = true listView.isLongClickable = true
listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ -> listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
@@ -91,7 +91,7 @@ class CallsActivity : AppCompatActivity() {
} }
DialogInterface.BUTTON_POSITIVE -> { DialogInterface.BUTTON_POSITIVE -> {
removeUaHistoryAt(pos) removeUaHistoryAt(pos)
adapter.notifyDataSetChanged() clAdapter.notifyDataSetChanged()
} }
DialogInterface.BUTTON_NEUTRAL -> { DialogInterface.BUTTON_NEUTRAL -> {
} }
@@ -137,10 +137,20 @@ class CallsActivity : AppCompatActivity() {
when (item.itemId) { when (item.itemId) {
R.id.delete_history -> { R.id.delete_history -> {
CallHistory.clear(aor) val deleteDialog = AlertDialog.Builder(this@CallsActivity)
CallHistory.save(applicationContext.filesDir.absolutePath) deleteDialog.setMessage(String.format(getString(R.string.delete_history_alert),
aorGenerateHistory(aor) aor.substringAfter(":")))
adapter.notifyDataSetChanged() deleteDialog.setPositiveButton(getText(R.string.delete)) { dialog, _ ->
CallHistory.clear(aor)
CallHistory.save(applicationContext.filesDir.absolutePath)
aorGenerateHistory(aor)
clAdapter.notifyDataSetChanged()
dialog.dismiss()
}
deleteDialog.setNegativeButton(getText(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
deleteDialog.create().show()
} }
R.id.history_on_off -> { R.id.history_on_off -> {
@@ -97,7 +97,7 @@ class ChatActivity : AppCompatActivity() {
if (chatMessages.size == 0) { if (chatMessages.size == 0) {
listView.removeFooterView(footerView) listView.removeFooterView(footerView)
} }
Message.saveMessages(applicationContext.filesDir.absolutePath) Message.saveMessages()
} }
DialogInterface.BUTTON_NEUTRAL -> { DialogInterface.BUTTON_NEUTRAL -> {
} }
@@ -224,7 +224,7 @@ class ChatActivity : AppCompatActivity() {
save = true save = true
} }
} }
if (save) Message.saveMessages(applicationContext.filesDir.absolutePath) if (save) Message.saveMessages()
imm.hideSoftInputFromWindow(newMessage.windowToken, 0) imm.hideSoftInputFromWindow(newMessage.windowToken, 0)
BaresipService.activities.removeAt(0) BaresipService.activities.removeAt(0)
val i = Intent() val i = Intent()
@@ -251,7 +251,9 @@ class ChatActivity : AppCompatActivity() {
override fun onBackPressed() { override fun onBackPressed() {
BaresipService.activities.removeAt(0) BaresipService.activities.removeAt(0)
super.onBackPressed() val i = Intent()
setResult(Activity.RESULT_OK, i)
finish()
} }
@@ -5,6 +5,7 @@ import android.content.*
import android.os.Bundle import android.os.Bundle
import android.support.v7.app.AlertDialog import android.support.v7.app.AlertDialog
import android.support.v7.app.AppCompatActivity import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.widget.* import android.widget.*
@@ -26,8 +27,6 @@ class ChatsActivity: AppCompatActivity() {
setContentView(R.layout.activity_chats) setContentView(R.layout.activity_chats)
filesPath = applicationContext.filesDir.absolutePath
listView = findViewById(R.id.chats) as ListView listView = findViewById(R.id.chats) as ListView
plusButton = findViewById(R.id.plusButton) as ImageButton plusButton = findViewById(R.id.plusButton) as ImageButton
@@ -73,7 +72,7 @@ class ChatsActivity: AppCompatActivity() {
clAdapter.remove(m) clAdapter.remove(m)
clAdapter.notifyDataSetChanged() clAdapter.notifyDataSetChanged()
BaresipService.messages = msgs BaresipService.messages = msgs
Message.saveMessages(filesPath) Message.saveMessages()
uaMessages = uaMessages(aor) uaMessages = uaMessages(aor)
} }
DialogInterface.BUTTON_NEUTRAL -> { DialogInterface.BUTTON_NEUTRAL -> {
@@ -143,10 +142,36 @@ class ChatsActivity: AppCompatActivity() {
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.chats_menu, menu)
return true
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.delete_chats -> {
val deleteDialog = AlertDialog.Builder(this@ChatsActivity)
deleteDialog.setMessage(String.format(getString(R.string.delete_chats_alert),
aor.substringAfter(":")))
deleteDialog.setPositiveButton(getText(R.string.delete)) { dialog, _ ->
BaresipService.messages = ArrayList(BaresipService.messages.filter{it.aor != aor})
Message.saveMessages()
uaMessages = ArrayList()
clAdapter = ChatListAdapter(this, uaMessages)
listView.adapter = clAdapter
Account.findUa(aor)!!.account.unreadMessages = false
dialog.dismiss()
}
deleteDialog.setNegativeButton(getText(R.string.cancel)) { dialog, _ ->
dialog.dismiss()
}
deleteDialog.create().show()
}
android.R.id.home -> { android.R.id.home -> {
BaresipService.activities.removeAt(0) BaresipService.activities.removeAt(0)
val i = Intent() val i = Intent()
@@ -198,24 +223,22 @@ class ChatsActivity: AppCompatActivity() {
companion object { companion object {
var filesPath = "" fun saveUaMessage(aor: String, time: Long) {
fun saveUaMessage(aor: String, time: Long, path: String) {
for (i in Message.messages().indices.reversed()) for (i in Message.messages().indices.reversed())
if ((Message.messages()[i].aor == aor) && if ((Message.messages()[i].aor == aor) &&
(Message.messages()[i].timeStamp == time)) { (Message.messages()[i].timeStamp == time)) {
Message.messages()[i].new = false Message.messages()[i].new = false
Message.saveMessages(path) Message.saveMessages()
return return
} }
} }
fun deleteUaMessage(aor: String, time: Long, path: String) { fun deleteUaMessage(aor: String, time: Long) {
for (i in Message.messages().indices.reversed()) for (i in Message.messages().indices.reversed())
if ((Message.messages()[i].aor == aor) && if ((Message.messages()[i].aor == aor) &&
(Message.messages()[i].timeStamp == time)) { (Message.messages()[i].timeStamp == time)) {
Message.messages().removeAt(i) Message.messages().removeAt(i)
Message.saveMessages(path) Message.saveMessages()
return return
} }
} }
@@ -147,15 +147,6 @@ class MainActivity : AppCompatActivity() {
Log.d("Baresip", "Setting $aor current") Log.d("Baresip", "Setting $aor current")
Api.uag_current_set(UserAgent.uas()[position].uap) Api.uag_current_set(UserAgent.uas()[position].uap)
showCall(ua) showCall(ua)
if (acc.vmUri != "") {
if (acc.vmNew > 0)
voicemailButton.setImageResource(R.drawable.voicemail_new)
else
voicemailButton.setImageResource(R.drawable.voicemail)
voicemailButton.visibility = View.VISIBLE
} else {
voicemailButton.visibility = View.INVISIBLE
}
updateIcons(acc) updateIcons(acc)
} }
@@ -403,8 +394,6 @@ class MainActivity : AppCompatActivity() {
startActivityForResult(i, CONTACTS_CODE) startActivityForResult(i, CONTACTS_CODE)
} }
if (intentAction == null)
Message.restoreMessages(applicationContext.filesDir.absolutePath)
messagesButton.setOnClickListener { messagesButton.setOnClickListener {
if (aorSpinner.selectedItemPosition >= 0) { if (aorSpinner.selectedItemPosition >= 0) {
val i = Intent(this@MainActivity, ChatsActivity::class.java) val i = Intent(this@MainActivity, ChatsActivity::class.java)
@@ -579,7 +568,6 @@ class MainActivity : AppCompatActivity() {
aorSpinner.setSelection(currentPosition) aorSpinner.setSelection(currentPosition)
} }
showCall(UserAgent.uas()[aorSpinner.selectedItemPosition]) showCall(UserAgent.uas()[aorSpinner.selectedItemPosition])
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
} }
} }
} }
@@ -840,7 +828,7 @@ class MainActivity : AppCompatActivity() {
b.putString("peer", peer) b.putString("peer", peer)
b.putBoolean("focus", ev[0] == "message reply") b.putBoolean("focus", ev[0] == "message reply")
i.putExtras(b) i.putExtras(b)
startActivity(i) startActivityForResult(i, CHAT_CODE)
} }
"mwi notify" -> { "mwi notify" -> {
val lines = ev[1].split("\n") val lines = ev[1].split("\n")
@@ -949,16 +937,8 @@ class MainActivity : AppCompatActivity() {
if ((aorSpinner.selectedItemPosition == -1) || if ((aorSpinner.selectedItemPosition == -1) ||
(aorSpinner.selectedItemPosition >= UserAgent.uas().size)) (aorSpinner.selectedItemPosition >= UserAgent.uas().size))
aorSpinner.setSelection(0) aorSpinner.setSelection(0)
val acc = UserAgent.uas()[aorSpinner.selectedItemPosition].account else
if (acc.vmUri != "") { updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
if (acc.vmNew > 0)
voicemailButton.setImageResource(R.drawable.voicemail_new)
else
voicemailButton.setImageResource(R.drawable.voicemail)
voicemailButton.visibility = View.VISIBLE
} else {
voicemailButton.visibility = View.INVISIBLE
}
} else { } else {
aorSpinner.setSelection(-1) aorSpinner.setSelection(-1)
} }
@@ -967,16 +947,7 @@ class MainActivity : AppCompatActivity() {
} }
ACCOUNT_CODE -> { ACCOUNT_CODE -> {
val acc = UserAgent.uas()[aorSpinner.selectedItemPosition].account updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
if (acc.vmUri != "") {
if (acc.vmNew > 0)
voicemailButton.setImageResource(R.drawable.voicemail_new)
else
voicemailButton.setImageResource(R.drawable.voicemail)
voicemailButton.visibility = View.VISIBLE
} else {
voicemailButton.visibility = View.INVISIBLE
}
} }
CONTACTS_CODE -> { CONTACTS_CODE -> {
@@ -1001,7 +972,6 @@ class MainActivity : AppCompatActivity() {
} }
} }
if (resultCode == RESULT_CANCELED) { if (resultCode == RESULT_CANCELED) {
Log.d("Baresip", "History canceled")
if (CallHistory.aorHistorySize(acc.aor) == 0) { if (CallHistory.aorHistorySize(acc.aor) == 0) {
holdButton.visibility = View.INVISIBLE holdButton.visibility = View.INVISIBLE
} }
@@ -1009,6 +979,10 @@ class MainActivity : AppCompatActivity() {
callsButton.setImageResource(R.drawable.calls) callsButton.setImageResource(R.drawable.calls)
} }
CHATS_CODE, CHAT_CODE -> {
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
}
ABOUT_CODE -> { ABOUT_CODE -> {
} }
} }
@@ -1029,8 +1003,7 @@ class MainActivity : AppCompatActivity() {
getString(R.string.no_microphone_permission), Toast.LENGTH_SHORT).show() getString(R.string.no_microphone_permission), Toast.LENGTH_SHORT).show()
return false return false
} }
if (ua != UserAgent.uas()[aorSpinner.selectedItemPosition]) if (ua != UserAgent.uas()[aorSpinner.selectedItemPosition]) spinToAor(ua.account.aor)
spinToAor(ua.account.aor)
val callp = Api.ua_connect(ua.uap, uri) val callp = Api.ua_connect(ua.uap, uri)
if (callp != "") { if (callp != "") {
Log.d("Baresip", "Adding outgoing call ${ua.uap}/$callp/$uri") Log.d("Baresip", "Adding outgoing call ${ua.uap}/$callp/$uri")
@@ -1193,6 +1166,15 @@ class MainActivity : AppCompatActivity() {
messagesButton.setImageResource(R.drawable.messages_unread) messagesButton.setImageResource(R.drawable.messages_unread)
else else
messagesButton.setImageResource(R.drawable.messages) messagesButton.setImageResource(R.drawable.messages)
if (acc.vmUri != "") {
if (acc.vmNew > 0)
voicemailButton.setImageResource(R.drawable.voicemail_new)
else
voicemailButton.setImageResource(R.drawable.voicemail)
voicemailButton.visibility = View.VISIBLE
} else {
voicemailButton.visibility = View.INVISIBLE
}
} }
private fun restoreActivities() { private fun restoreActivities() {
@@ -31,8 +31,8 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
BaresipService.messages.removeAt(firstIndex) BaresipService.messages.removeAt(firstIndex)
} }
fun saveMessages(path: String) { fun saveMessages() {
val file = File(path, "messages") val file = File(BaresipService.filesPath, "messages")
try { try {
val fos = FileOutputStream(file) val fos = FileOutputStream(file)
val oos = ObjectOutputStream(fos) val oos = ObjectOutputStream(fos)
@@ -46,8 +46,8 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
} }
} }
fun restoreMessages(path: String) { fun restoreMessages() {
val file = File(path, "messages") val file = File(BaresipService.filesPath, "messages")
if (file.exists()) { if (file.exists()) {
try { try {
val fis = FileInputStream(file) val fis = FileInputStream(file)
@@ -62,6 +62,5 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
} }
} }
} }
} }
+6
View File
@@ -0,0 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/delete_chats"
android:title="@string/delete_chats" />
</menu>
+1
View File
@@ -152,6 +152,7 @@ Verifique Aplicaciones → baresip → Permisos → Almacenamiento y ese archivo
<string name="long_chat_question">¿Quieres eliminar el chat con un compañero? \'%1$s\' o <string name="long_chat_question">¿Quieres eliminar el chat con un compañero? \'%1$s\' o
agregar pares a los contactos?</string> agregar pares a los contactos?</string>
<string name="short_chat_question">¿Quieres eliminar el chat con \'%1$s\'?</string> <string name="short_chat_question">¿Quieres eliminar el chat con \'%1$s\'?</string>
<string name="delete_chats">Eliminar</string>
<!-- Config Activity --> <!-- Config Activity -->
<string name="configuration">Configuración</string> <string name="configuration">Configuración</string>
+4 -3
View File
@@ -147,6 +147,7 @@
<string name="delete_history">Tyhjennä</string> <string name="delete_history">Tyhjennä</string>
<string name="disable_history">Poista käytöstä</string> <string name="disable_history">Poista käytöstä</string>
<string name="enable_history">Ota käyttöön</string> <string name="enable_history">Ota käyttöön</string>
<string name="delete_history_alert">Haluatko tyhjentää tilin \'%1$s\' puheluhistorian?</string>
<!-- Chat Activity --> <!-- Chat Activity -->
<string name="chat">Viestiketju</string> <string name="chat">Viestiketju</string>
<string name="chat_with">Viestiketju %1$s</string> <string name="chat_with">Viestiketju %1$s</string>
@@ -165,9 +166,9 @@
<string name="invalid_chat_peer_uri">Virheellinen SIP URI</string> <string name="invalid_chat_peer_uri">Virheellinen SIP URI</string>
<string name="long_chat_question">Haluatko poistaa viestiketjun tai <string name="long_chat_question">Haluatko poistaa viestiketjun tai
luoda uuden kontaktin \'%1$s\'?</string> luoda uuden kontaktin \'%1$s\'?</string>
<string name="short_chat_question">Haluatko poistaa viestiketjun <string name="short_chat_question">Haluatko poistaa viestiketjun \'%1$s\'?</string>
\'%1$s\'? <string name="delete_chats">Tyhjennä</string>
</string> <string name="delete_chats_alert">Haluatko tyhjentää tilin \'%1$s\' viestihistorian?</string>
<!-- Config Activity --> <!-- Config Activity -->
<string name="configuration">Konfiguraatio</string> <string name="configuration">Konfiguraatio</string>
<string name="start_automatically">Käynnistä automaattisesti</string> <string name="start_automatically">Käynnistä automaattisesti</string>
+3
View File
@@ -132,6 +132,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
<string name="delete_history">Delete</string> <string name="delete_history">Delete</string>
<string name="disable_history">Disable</string> <string name="disable_history">Disable</string>
<string name="enable_history">Enable</string> <string name="enable_history">Enable</string>
<string name="delete_history_alert">Do you want to delete call history of account \'%1$s\'?</string>
<!-- Chat Activity --> <!-- Chat Activity -->
<string name="chat">Chat Messages</string> <string name="chat">Chat Messages</string>
@@ -152,6 +153,8 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
<string name="long_chat_question">Do you want to delete chat with peer \'%1$s\' or <string name="long_chat_question">Do you want to delete chat with peer \'%1$s\' or
add peer to contacts?</string> add peer to contacts?</string>
<string name="short_chat_question">Do you want to delete chat with \'%1$s\'?</string> <string name="short_chat_question">Do you want to delete chat with \'%1$s\'?</string>
<string name="delete_chats">Delete</string>
<string name="delete_chats_alert">Do you want to delete chat history of account \'%1$s\'?</string>
<!-- Config Activity --> <!-- Config Activity -->
<string name="configuration">Configuration</string> <string name="configuration">Configuration</string>