Add update-tick for call log timestamps.

This commit is contained in:
Alex Hart
2023-12-21 11:09:26 -04:00
committed by Clark Chen
parent 9c7f2250b9
commit 2b606a2dec
2 changed files with 35 additions and 15 deletions

View File

@@ -32,6 +32,11 @@ class CallLogAdapter(
callbacks: Callbacks callbacks: Callbacks
) : PagingMappingAdapter<CallLogRow.Id>() { ) : PagingMappingAdapter<CallLogRow.Id>() {
companion object {
private const val PAYLOAD_SELECTION_STATE = "PAYLOAD_SELECTION_STATE"
private const val PAYLOAD_TIMESTAMP = "PAYLOAD_TIMESTAMP"
}
init { init {
registerFactory( registerFactory(
CallModel::class.java, CallModel::class.java,
@@ -72,6 +77,10 @@ class CallLogAdapter(
) )
} }
fun onTimestampTick() {
notifyItemRangeChanged(0, itemCount, PAYLOAD_TIMESTAMP)
}
fun submitCallRows( fun submitCallRows(
rows: List<CallLogRow?>, rows: List<CallLogRow?>,
selectionState: CallLogSelectionState, selectionState: CallLogSelectionState,
@@ -98,9 +107,6 @@ class CallLogAdapter(
val selectionState: CallLogSelectionState, val selectionState: CallLogSelectionState,
val itemCount: Int val itemCount: Int
) : MappingModel<CallModel> { ) : MappingModel<CallModel> {
companion object {
const val PAYLOAD_SELECTION_STATE = "PAYLOAD_SELECTION_STATE"
}
override fun areItemsTheSame(newItem: CallModel): Boolean = call.id == newItem.call.id override fun areItemsTheSame(newItem: CallModel): Boolean = call.id == newItem.call.id
override fun areContentsTheSame(newItem: CallModel): Boolean { override fun areContentsTheSame(newItem: CallModel): Boolean {
@@ -133,10 +139,6 @@ class CallLogAdapter(
val itemCount: Int val itemCount: Int
) : MappingModel<CallLinkModel> { ) : MappingModel<CallLinkModel> {
companion object {
const val PAYLOAD_SELECTION_STATE = "PAYLOAD_SELECTION_STATE"
}
override fun areItemsTheSame(newItem: CallLinkModel): Boolean { override fun areItemsTheSame(newItem: CallLinkModel): Boolean {
return callLink.record.roomId == newItem.callLink.record.roomId return callLink.record.roomId == newItem.callLink.record.roomId
} }
@@ -149,7 +151,7 @@ class CallLogAdapter(
override fun getChangePayload(newItem: CallLinkModel): Any? { override fun getChangePayload(newItem: CallLinkModel): Any? {
return if (callLink == newItem.callLink && (!isSelectionStateTheSame(newItem) || !isItemCountTheSame(newItem))) { return if (callLink == newItem.callLink && (!isSelectionStateTheSame(newItem) || !isItemCountTheSame(newItem))) {
CallModel.PAYLOAD_SELECTION_STATE PAYLOAD_SELECTION_STATE
} else { } else {
null null
} }
@@ -183,6 +185,10 @@ class CallLogAdapter(
private val onStartVideoCallClicked: (Recipient) -> Unit private val onStartVideoCallClicked: (Recipient) -> Unit
) : BindingViewHolder<CallLinkModel, CallLogAdapterItemBinding>(binding) { ) : BindingViewHolder<CallLinkModel, CallLogAdapterItemBinding>(binding) {
override fun bind(model: CallLinkModel) { override fun bind(model: CallLinkModel) {
if (payload.size == 1 && payload.contains(PAYLOAD_TIMESTAMP)) {
return
}
itemView.setOnClickListener { itemView.setOnClickListener {
onCallLinkClicked(model.callLink) onCallLinkClicked(model.callLink)
} }
@@ -195,7 +201,7 @@ class CallLogAdapter(
binding.callSelected.isChecked = model.selectionState.contains(model.callLink.id) binding.callSelected.isChecked = model.selectionState.contains(model.callLink.id)
binding.callSelected.visible = model.selectionState.isNotEmpty(model.itemCount) binding.callSelected.visible = model.selectionState.isNotEmpty(model.itemCount)
if (payload.contains(CallModel.PAYLOAD_SELECTION_STATE)) { if (payload.isNotEmpty()) {
return return
} }
@@ -252,7 +258,11 @@ class CallLogAdapter(
binding.callSelected.isChecked = model.selectionState.contains(model.call.id) binding.callSelected.isChecked = model.selectionState.contains(model.call.id)
binding.callSelected.visible = model.selectionState.isNotEmpty(model.itemCount) binding.callSelected.visible = model.selectionState.isNotEmpty(model.itemCount)
if (payload.contains(CallModel.PAYLOAD_SELECTION_STATE)) { if (payload.contains(PAYLOAD_TIMESTAMP)) {
presentCallInfo(model.call, model.call.date)
}
if (payload.isNotEmpty()) {
return return
} }

View File

@@ -43,6 +43,7 @@ import org.thoughtcrime.securesms.components.menu.ActionItem
import org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity import org.thoughtcrime.securesms.components.settings.app.AppSettingsActivity
import org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment import org.thoughtcrime.securesms.components.settings.app.notifications.manual.NotificationProfileSelectionFragment
import org.thoughtcrime.securesms.components.settings.conversation.ConversationSettingsActivity import org.thoughtcrime.securesms.components.settings.conversation.ConversationSettingsActivity
import org.thoughtcrime.securesms.conversation.ConversationUpdateTick
import org.thoughtcrime.securesms.conversation.SignalBottomActionBarController import org.thoughtcrime.securesms.conversation.SignalBottomActionBarController
import org.thoughtcrime.securesms.conversationlist.ConversationFilterBehavior import org.thoughtcrime.securesms.conversationlist.ConversationFilterBehavior
import org.thoughtcrime.securesms.conversationlist.chatfilter.ConversationFilterSource import org.thoughtcrime.securesms.conversationlist.chatfilter.ConversationFilterSource
@@ -81,6 +82,8 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
private val disposables = LifecycleDisposable() private val disposables = LifecycleDisposable()
private val callLogContextMenu = CallLogContextMenu(this, this) private val callLogContextMenu = CallLogContextMenu(this, this)
private val callLogActionMode = CallLogActionMode(CallLogActionModeCallback()) private val callLogActionMode = CallLogActionMode(CallLogActionModeCallback())
private val conversationUpdateTick: ConversationUpdateTick = ConversationUpdateTick(this::onTimestampTick)
private var callLogAdapter: CallLogAdapter? = null
private lateinit var signalBottomActionBarController: SignalBottomActionBarController private lateinit var signalBottomActionBarController: SignalBottomActionBarController
@@ -115,20 +118,22 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
requireActivity().addMenuProvider(menuProvider, viewLifecycleOwner) requireActivity().addMenuProvider(menuProvider, viewLifecycleOwner)
initializeSharedElementTransition() initializeSharedElementTransition()
val adapter = CallLogAdapter(this) viewLifecycleOwner.lifecycle.addObserver(conversationUpdateTick)
val callLogAdapter = CallLogAdapter(this)
disposables.bindTo(viewLifecycleOwner) disposables.bindTo(viewLifecycleOwner)
adapter.setPagingController(viewModel.controller) callLogAdapter.setPagingController(viewModel.controller)
val scrollToPositionDelegate = ScrollToPositionDelegate( val scrollToPositionDelegate = ScrollToPositionDelegate(
recyclerView = binding.recycler, recyclerView = binding.recycler,
canJumpToPosition = { adapter.isAvailableAround(it) } canJumpToPosition = { callLogAdapter.isAvailableAround(it) }
) )
disposables += scrollToPositionDelegate disposables += scrollToPositionDelegate
disposables += Flowables.combineLatest(viewModel.data, viewModel.selected) disposables += Flowables.combineLatest(viewModel.data, viewModel.selected)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe { (data, selected) -> .subscribe { (data, selected) ->
val filteredCount = adapter.submitCallRows( val filteredCount = callLogAdapter.submitCallRows(
data, data,
selected, selected,
scrollToPositionDelegate::notifyListCommitted scrollToPositionDelegate::notifyListCommitted
@@ -147,7 +152,8 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
} }
} }
binding.recycler.adapter = adapter binding.recycler.adapter = callLogAdapter
this.callLogAdapter = callLogAdapter
requireListener<Material3OnScrollHelperBinder>().bindScrollHelper(binding.recycler) requireListener<Material3OnScrollHelperBinder>().bindScrollHelper(binding.recycler)
binding.fab.setOnClickListener { binding.fab.setOnClickListener {
@@ -200,6 +206,10 @@ class CallLogFragment : Fragment(R.layout.call_log_fragment), CallLogAdapter.Cal
viewModel.markAllCallEventsRead() viewModel.markAllCallEventsRead()
} }
private fun onTimestampTick() {
callLogAdapter?.onTimestampTick()
}
private fun initializeSharedElementTransition() { private fun initializeSharedElementTransition() {
ViewCompat.setTransitionName(binding.fab, "new_convo_fab") ViewCompat.setTransitionName(binding.fab, "new_convo_fab")
ViewCompat.setTransitionName(binding.fabSharedElementTarget, "camera_fab") ViewCompat.setTransitionName(binding.fabSharedElementTarget, "camera_fab")