Allow to undo last chat message swipe removal
This commit is contained in:
parent
9963381419
commit
dabecf1077
6 changed files with 56 additions and 11 deletions
|
@ -21,5 +21,6 @@ package org.linphone.activities
|
||||||
|
|
||||||
interface SnackBarActivity {
|
interface SnackBarActivity {
|
||||||
fun showSnackBar(resourceId: Int)
|
fun showSnackBar(resourceId: Int)
|
||||||
|
fun showSnackBar(resourceId: Int, action: Int, listener: () -> Unit)
|
||||||
fun showSnackBar(message: String)
|
fun showSnackBar(message: String)
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,15 @@ class AssistantActivity : GenericActivity(), SnackBarActivity {
|
||||||
Snackbar.make(coordinator, resourceId, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(coordinator, resourceId, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showSnackBar(resourceId: Int, action: Int, listener: () -> Unit) {
|
||||||
|
Snackbar
|
||||||
|
.make(findViewById(R.id.coordinator), resourceId, Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(action) {
|
||||||
|
listener()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
override fun showSnackBar(message: String) {
|
override fun showSnackBar(message: String) {
|
||||||
Snackbar.make(coordinator, message, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(coordinator, message, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,16 @@ class MainActivity : GenericActivity(), SnackBarActivity, NavController.OnDestin
|
||||||
Snackbar.make(findViewById(R.id.coordinator), resourceId, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(findViewById(R.id.coordinator), resourceId, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun showSnackBar(resourceId: Int, action: Int, listener: () -> Unit) {
|
||||||
|
Snackbar
|
||||||
|
.make(findViewById(R.id.coordinator), resourceId, Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(action) {
|
||||||
|
Log.i("[Snack Bar] Action listener triggered")
|
||||||
|
listener()
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
|
||||||
override fun showSnackBar(message: String) {
|
override fun showSnackBar(message: String) {
|
||||||
Snackbar.make(findViewById(R.id.coordinator), message, Snackbar.LENGTH_LONG).show()
|
Snackbar.make(findViewById(R.id.coordinator), message, Snackbar.LENGTH_LONG).show()
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,9 +42,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.IllegalArgumentException
|
import java.lang.IllegalArgumentException
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.withContext
|
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
|
@ -256,15 +254,10 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
|
|
||||||
override fun onRightToLeftSwipe(viewHolder: RecyclerView.ViewHolder) {
|
override fun onRightToLeftSwipe(viewHolder: RecyclerView.ViewHolder) {
|
||||||
val position = viewHolder.bindingAdapterPosition
|
val position = viewHolder.bindingAdapterPosition
|
||||||
|
// adapter.notifyItemRemoved(viewHolder.bindingAdapterPosition)
|
||||||
|
|
||||||
val eventLog = adapter.currentList[position]
|
val eventLog = adapter.currentList[position]
|
||||||
val chatMessage = eventLog.eventLog.chatMessage
|
addDeleteMessageTaskToQueue(eventLog, position)
|
||||||
if (chatMessage != null) {
|
|
||||||
Log.i("[Chat Room] Deleting message $chatMessage at position $position")
|
|
||||||
listViewModel.deleteMessage(chatMessage)
|
|
||||||
} else {
|
|
||||||
Log.i("[Chat Room] Deleting event $eventLog at position $position")
|
|
||||||
listViewModel.deleteEventLogs(arrayListOf(eventLog))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RecyclerViewSwipeUtils(ItemTouchHelper.RIGHT or ItemTouchHelper.LEFT, swipeConfiguration, swipeListener)
|
RecyclerViewSwipeUtils(ItemTouchHelper.RIGHT or ItemTouchHelper.LEFT, swipeConfiguration, swipeListener)
|
||||||
|
@ -842,6 +835,34 @@ class DetailChatRoomFragment : MasterFragment<ChatRoomDetailFragmentBinding, Cha
|
||||||
popupWindow.showAsDropDown(binding.menu, 0, 0, Gravity.BOTTOM)
|
popupWindow.showAsDropDown(binding.menu, 0, 0, Gravity.BOTTOM)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun addDeleteMessageTaskToQueue(eventLog: EventLogData, position: Int) {
|
||||||
|
val task = lifecycleScope.launch {
|
||||||
|
delay(2800) // Duration of Snackbar.LENGTH_LONG
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
if (isActive) {
|
||||||
|
Log.i("[Chat Room] Message/event deletion task is still active, proceed")
|
||||||
|
val chatMessage = eventLog.eventLog.chatMessage
|
||||||
|
if (chatMessage != null) {
|
||||||
|
Log.i("[Chat Room] Deleting message $chatMessage at position $position")
|
||||||
|
listViewModel.deleteMessage(chatMessage)
|
||||||
|
} else {
|
||||||
|
Log.i("[Chat Room] Deleting event $eventLog at position $position")
|
||||||
|
listViewModel.deleteEventLogs(arrayListOf(eventLog))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(requireActivity() as MainActivity).showSnackBar(
|
||||||
|
R.string.chat_message_removal_info,
|
||||||
|
R.string.chat_message_abort_removal
|
||||||
|
) {
|
||||||
|
Log.i("[Chat Room] Canceled message/event deletion task: $task for message/event at position $position")
|
||||||
|
adapter.notifyItemRangeChanged(position, adapter.itemCount - position)
|
||||||
|
task.cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun scrollToFirstUnreadMessageOrBottom(smooth: Boolean) {
|
private fun scrollToFirstUnreadMessageOrBottom(smooth: Boolean) {
|
||||||
if (_adapter != null && adapter.itemCount > 0) {
|
if (_adapter != null && adapter.itemCount > 0) {
|
||||||
// Scroll to first unread message if any
|
// Scroll to first unread message if any
|
||||||
|
|
|
@ -630,4 +630,6 @@
|
||||||
<string name="audio_settings_prefer_bluetooth_devices_title">Acheminer l\'audio vers l\'appareil bluetooth, s\'il existe</string>
|
<string name="audio_settings_prefer_bluetooth_devices_title">Acheminer l\'audio vers l\'appareil bluetooth, s\'il existe</string>
|
||||||
<string name="audio_settings_prefer_bluetooth_devices_summary">Il aura la priorité sur le périphérique de sortie par défaut</string>
|
<string name="audio_settings_prefer_bluetooth_devices_summary">Il aura la priorité sur le périphérique de sortie par défaut</string>
|
||||||
<string name="call_settings_ringtones_title">Sonnerie</string>
|
<string name="call_settings_ringtones_title">Sonnerie</string>
|
||||||
|
<string name="chat_message_removal_info">Le message va être supprimé</string>
|
||||||
|
<string name="chat_message_abort_removal">Annuler</string>
|
||||||
</resources>
|
</resources>
|
|
@ -227,6 +227,8 @@
|
||||||
<item quantity="one">@string/chat_room_unread_message</item>
|
<item quantity="one">@string/chat_room_unread_message</item>
|
||||||
<item quantity="other">@string/chat_room_unread_messages</item>
|
<item quantity="other">@string/chat_room_unread_messages</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<string name="chat_message_removal_info">Message will be deleted</string>
|
||||||
|
<string name="chat_message_abort_removal">Abort</string>
|
||||||
|
|
||||||
<!-- Recordings -->
|
<!-- Recordings -->
|
||||||
<string name="recordings_empty_list">No recordings</string>
|
<string name="recordings_empty_list">No recordings</string>
|
||||||
|
|
Loading…
Reference in a new issue