- 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:
@ -173,6 +173,7 @@ class BaresipService: Service() {
|
||||
}
|
||||
|
||||
ContactsActivity.restoreContacts(applicationContext.filesDir, "contacts")
|
||||
Message.restoreMessages()
|
||||
|
||||
Thread(Runnable { baresipStart(filesPath) }).start()
|
||||
isServiceRunning = true
|
||||
@ -261,8 +262,7 @@ class BaresipService: Service() {
|
||||
Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
|
||||
else
|
||||
ChatsActivity.saveUaMessage(ua.account.aor,
|
||||
intent.getStringExtra("time").toLong(),
|
||||
applicationContext.filesDir.absolutePath)
|
||||
intent.getStringExtra("time").toLong())
|
||||
nm.cancel(BaresipService.MESSAGE_NOTIFICATION_ID)
|
||||
}
|
||||
|
||||
@ -273,8 +273,7 @@ class BaresipService: Service() {
|
||||
Log.w(LOG_TAG, "onStartCommand did not find UA $uap")
|
||||
else
|
||||
ChatsActivity.deleteUaMessage(ua.account.aor,
|
||||
intent.getStringExtra("time").toLong(),
|
||||
applicationContext.filesDir.absolutePath)
|
||||
intent.getStringExtra("time").toLong())
|
||||
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")
|
||||
Message.add(Message(ua.account.aor, peer, text, timeStamp.toLong(),
|
||||
R.drawable.arrow_down_green, 0, "", true))
|
||||
Message.saveMessages(filesPath)
|
||||
Message.saveMessages()
|
||||
ua.account.unreadMessages = true
|
||||
if (!Utils.isVisible()) {
|
||||
val intent = Intent(this, BaresipService::class.java)
|
||||
|
||||
@ -20,7 +20,7 @@ import java.util.GregorianCalendar
|
||||
class CallsActivity : AppCompatActivity() {
|
||||
|
||||
internal lateinit var account: Account
|
||||
internal lateinit var adapter: CallListAdapter
|
||||
internal lateinit var clAdapter: CallListAdapter
|
||||
|
||||
internal var uaHistory = ArrayList<CallRow>()
|
||||
internal var aor = ""
|
||||
@ -41,8 +41,8 @@ class CallsActivity : AppCompatActivity() {
|
||||
|
||||
val listView = findViewById(R.id.calls) as ListView
|
||||
aorGenerateHistory(aor)
|
||||
adapter = CallListAdapter(this, uaHistory)
|
||||
listView.adapter = adapter
|
||||
clAdapter = CallListAdapter(this, uaHistory)
|
||||
listView.adapter = clAdapter
|
||||
listView.isLongClickable = true
|
||||
|
||||
listView.onItemClickListener = AdapterView.OnItemClickListener { _, _, pos, _ ->
|
||||
@ -91,7 +91,7 @@ class CallsActivity : AppCompatActivity() {
|
||||
}
|
||||
DialogInterface.BUTTON_POSITIVE -> {
|
||||
removeUaHistoryAt(pos)
|
||||
adapter.notifyDataSetChanged()
|
||||
clAdapter.notifyDataSetChanged()
|
||||
}
|
||||
DialogInterface.BUTTON_NEUTRAL -> {
|
||||
}
|
||||
@ -137,10 +137,20 @@ class CallsActivity : AppCompatActivity() {
|
||||
when (item.itemId) {
|
||||
|
||||
R.id.delete_history -> {
|
||||
CallHistory.clear(aor)
|
||||
CallHistory.save(applicationContext.filesDir.absolutePath)
|
||||
aorGenerateHistory(aor)
|
||||
adapter.notifyDataSetChanged()
|
||||
val deleteDialog = AlertDialog.Builder(this@CallsActivity)
|
||||
deleteDialog.setMessage(String.format(getString(R.string.delete_history_alert),
|
||||
aor.substringAfter(":")))
|
||||
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 -> {
|
||||
|
||||
@ -97,7 +97,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
if (chatMessages.size == 0) {
|
||||
listView.removeFooterView(footerView)
|
||||
}
|
||||
Message.saveMessages(applicationContext.filesDir.absolutePath)
|
||||
Message.saveMessages()
|
||||
}
|
||||
DialogInterface.BUTTON_NEUTRAL -> {
|
||||
}
|
||||
@ -224,7 +224,7 @@ class ChatActivity : AppCompatActivity() {
|
||||
save = true
|
||||
}
|
||||
}
|
||||
if (save) Message.saveMessages(applicationContext.filesDir.absolutePath)
|
||||
if (save) Message.saveMessages()
|
||||
imm.hideSoftInputFromWindow(newMessage.windowToken, 0)
|
||||
BaresipService.activities.removeAt(0)
|
||||
val i = Intent()
|
||||
@ -251,7 +251,9 @@ class ChatActivity : AppCompatActivity() {
|
||||
override fun onBackPressed() {
|
||||
|
||||
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.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.*
|
||||
|
||||
@ -26,8 +27,6 @@ class ChatsActivity: AppCompatActivity() {
|
||||
|
||||
setContentView(R.layout.activity_chats)
|
||||
|
||||
filesPath = applicationContext.filesDir.absolutePath
|
||||
|
||||
listView = findViewById(R.id.chats) as ListView
|
||||
plusButton = findViewById(R.id.plusButton) as ImageButton
|
||||
|
||||
@ -73,7 +72,7 @@ class ChatsActivity: AppCompatActivity() {
|
||||
clAdapter.remove(m)
|
||||
clAdapter.notifyDataSetChanged()
|
||||
BaresipService.messages = msgs
|
||||
Message.saveMessages(filesPath)
|
||||
Message.saveMessages()
|
||||
uaMessages = uaMessages(aor)
|
||||
}
|
||||
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 {
|
||||
|
||||
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 -> {
|
||||
BaresipService.activities.removeAt(0)
|
||||
val i = Intent()
|
||||
@ -198,24 +223,22 @@ class ChatsActivity: AppCompatActivity() {
|
||||
|
||||
companion object {
|
||||
|
||||
var filesPath = ""
|
||||
|
||||
fun saveUaMessage(aor: String, time: Long, path: String) {
|
||||
fun saveUaMessage(aor: String, time: Long) {
|
||||
for (i in Message.messages().indices.reversed())
|
||||
if ((Message.messages()[i].aor == aor) &&
|
||||
(Message.messages()[i].timeStamp == time)) {
|
||||
Message.messages()[i].new = false
|
||||
Message.saveMessages(path)
|
||||
Message.saveMessages()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteUaMessage(aor: String, time: Long, path: String) {
|
||||
fun deleteUaMessage(aor: String, time: Long) {
|
||||
for (i in Message.messages().indices.reversed())
|
||||
if ((Message.messages()[i].aor == aor) &&
|
||||
(Message.messages()[i].timeStamp == time)) {
|
||||
Message.messages().removeAt(i)
|
||||
Message.saveMessages(path)
|
||||
Message.saveMessages()
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,15 +147,6 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.d("Baresip", "Setting $aor current")
|
||||
Api.uag_current_set(UserAgent.uas()[position].uap)
|
||||
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)
|
||||
}
|
||||
|
||||
@ -403,8 +394,6 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(i, CONTACTS_CODE)
|
||||
}
|
||||
|
||||
if (intentAction == null)
|
||||
Message.restoreMessages(applicationContext.filesDir.absolutePath)
|
||||
messagesButton.setOnClickListener {
|
||||
if (aorSpinner.selectedItemPosition >= 0) {
|
||||
val i = Intent(this@MainActivity, ChatsActivity::class.java)
|
||||
@ -579,7 +568,6 @@ class MainActivity : AppCompatActivity() {
|
||||
aorSpinner.setSelection(currentPosition)
|
||||
}
|
||||
showCall(UserAgent.uas()[aorSpinner.selectedItemPosition])
|
||||
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -840,7 +828,7 @@ class MainActivity : AppCompatActivity() {
|
||||
b.putString("peer", peer)
|
||||
b.putBoolean("focus", ev[0] == "message reply")
|
||||
i.putExtras(b)
|
||||
startActivity(i)
|
||||
startActivityForResult(i, CHAT_CODE)
|
||||
}
|
||||
"mwi notify" -> {
|
||||
val lines = ev[1].split("\n")
|
||||
@ -949,16 +937,8 @@ class MainActivity : AppCompatActivity() {
|
||||
if ((aorSpinner.selectedItemPosition == -1) ||
|
||||
(aorSpinner.selectedItemPosition >= UserAgent.uas().size))
|
||||
aorSpinner.setSelection(0)
|
||||
val acc = 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
|
||||
}
|
||||
else
|
||||
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
|
||||
} else {
|
||||
aorSpinner.setSelection(-1)
|
||||
}
|
||||
@ -967,16 +947,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
ACCOUNT_CODE -> {
|
||||
val acc = 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
|
||||
}
|
||||
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
|
||||
}
|
||||
|
||||
CONTACTS_CODE -> {
|
||||
@ -1001,7 +972,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
Log.d("Baresip", "History canceled")
|
||||
if (CallHistory.aorHistorySize(acc.aor) == 0) {
|
||||
holdButton.visibility = View.INVISIBLE
|
||||
}
|
||||
@ -1009,6 +979,10 @@ class MainActivity : AppCompatActivity() {
|
||||
callsButton.setImageResource(R.drawable.calls)
|
||||
}
|
||||
|
||||
CHATS_CODE, CHAT_CODE -> {
|
||||
updateIcons(UserAgent.uas()[aorSpinner.selectedItemPosition].account)
|
||||
}
|
||||
|
||||
ABOUT_CODE -> {
|
||||
}
|
||||
}
|
||||
@ -1029,8 +1003,7 @@ class MainActivity : AppCompatActivity() {
|
||||
getString(R.string.no_microphone_permission), Toast.LENGTH_SHORT).show()
|
||||
return false
|
||||
}
|
||||
if (ua != UserAgent.uas()[aorSpinner.selectedItemPosition])
|
||||
spinToAor(ua.account.aor)
|
||||
if (ua != UserAgent.uas()[aorSpinner.selectedItemPosition]) spinToAor(ua.account.aor)
|
||||
val callp = Api.ua_connect(ua.uap, uri)
|
||||
if (callp != "") {
|
||||
Log.d("Baresip", "Adding outgoing call ${ua.uap}/$callp/$uri")
|
||||
@ -1193,6 +1166,15 @@ class MainActivity : AppCompatActivity() {
|
||||
messagesButton.setImageResource(R.drawable.messages_unread)
|
||||
else
|
||||
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() {
|
||||
|
||||
@ -31,8 +31,8 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
|
||||
BaresipService.messages.removeAt(firstIndex)
|
||||
}
|
||||
|
||||
fun saveMessages(path: String) {
|
||||
val file = File(path, "messages")
|
||||
fun saveMessages() {
|
||||
val file = File(BaresipService.filesPath, "messages")
|
||||
try {
|
||||
val fos = FileOutputStream(file)
|
||||
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) {
|
||||
val file = File(path, "messages")
|
||||
fun restoreMessages() {
|
||||
val file = File(BaresipService.filesPath, "messages")
|
||||
if (file.exists()) {
|
||||
try {
|
||||
val fis = FileInputStream(file)
|
||||
@ -62,6 +62,5 @@ class Message(val aor: String, val peerUri: String, val message: String, val tim
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
6
app/src/main/res/menu/chats_menu.xml
Normal file
6
app/src/main/res/menu/chats_menu.xml
Normal 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>
|
||||
@ -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
|
||||
agregar pares a los contactos?</string>
|
||||
<string name="short_chat_question">¿Quieres eliminar el chat con \'%1$s\'?</string>
|
||||
<string name="delete_chats">Eliminar</string>
|
||||
|
||||
<!-- Config Activity -->
|
||||
<string name="configuration">Configuración</string>
|
||||
|
||||
@ -147,6 +147,7 @@
|
||||
<string name="delete_history">Tyhjennä</string>
|
||||
<string name="disable_history">Poista käytöstä</string>
|
||||
<string name="enable_history">Ota käyttöön</string>
|
||||
<string name="delete_history_alert">Haluatko tyhjentää tilin \'%1$s\' puheluhistorian?</string>
|
||||
<!-- Chat Activity -->
|
||||
<string name="chat">Viestiketju</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="long_chat_question">Haluatko poistaa viestiketjun tai
|
||||
luoda uuden kontaktin \'%1$s\'?</string>
|
||||
<string name="short_chat_question">Haluatko poistaa viestiketjun
|
||||
\'%1$s\'?
|
||||
</string>
|
||||
<string name="short_chat_question">Haluatko poistaa viestiketjun \'%1$s\'?</string>
|
||||
<string name="delete_chats">Tyhjennä</string>
|
||||
<string name="delete_chats_alert">Haluatko tyhjentää tilin \'%1$s\' viestihistorian?</string>
|
||||
<!-- Config Activity -->
|
||||
<string name="configuration">Konfiguraatio</string>
|
||||
<string name="start_automatically">Käynnistä automaattisesti</string>
|
||||
|
||||
@ -132,6 +132,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\'
|
||||
<string name="delete_history">Delete</string>
|
||||
<string name="disable_history">Disable</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 -->
|
||||
<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
|
||||
add peer to contacts?</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 -->
|
||||
<string name="configuration">Configuration</string>
|
||||
|
||||
Reference in New Issue
Block a user