diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index a250ad69..176fa0c8 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -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) diff --git a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt index 63220155..4a0fd4ab 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/CallsActivity.kt @@ -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() 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 -> { diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt index 9d70c4a2..7e4734fa 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatActivity.kt @@ -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() } diff --git a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt index 60b06f89..22a9c6c1 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/ChatsActivity.kt @@ -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 } } diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index 2bc533db..7b7fa48f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -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() { diff --git a/app/src/main/kotlin/com/tutpro/baresip/Message.kt b/app/src/main/kotlin/com/tutpro/baresip/Message.kt index e1c3ab74..4953515f 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/Message.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/Message.kt @@ -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 } } - } } diff --git a/app/src/main/res/menu/chats_menu.xml b/app/src/main/res/menu/chats_menu.xml new file mode 100644 index 00000000..6a56b4bc --- /dev/null +++ b/app/src/main/res/menu/chats_menu.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index f25043b4..450082c0 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -152,6 +152,7 @@ Verifique Aplicaciones → baresip → Permisos → Almacenamiento y ese archivo ¿Quieres eliminar el chat con un compañero? \'%1$s\' o agregar pares a los contactos? ¿Quieres eliminar el chat con \'%1$s\'? + Eliminar Configuración diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 750d423d..abced341 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -147,6 +147,7 @@ Tyhjennä Poista käytöstä Ota käyttöön + Haluatko tyhjentää tilin \'%1$s\' puheluhistorian? Viestiketju Viestiketju %1$s @@ -165,9 +166,9 @@ Virheellinen SIP URI Haluatko poistaa viestiketjun tai luoda uuden kontaktin \'%1$s\'? - Haluatko poistaa viestiketjun - \'%1$s\'? - + Haluatko poistaa viestiketjun \'%1$s\'? + Tyhjennä + Haluatko tyhjentää tilin \'%1$s\' viestihistorian? Konfiguraatio Käynnistä automaattisesti diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index af685839..ee876cf7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -132,6 +132,7 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\' Delete Disable Enable + Do you want to delete call history of account \'%1$s\'? Chat Messages @@ -152,6 +153,8 @@ Check Apps → baresip → Permissions → Storage and that file \'accounts.bs\' Do you want to delete chat with peer \'%1$s\' or add peer to contacts? Do you want to delete chat with \'%1$s\'? + Delete + Do you want to delete chat history of account \'%1$s\'? Configuration