mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-27 03:49:04 +03:00
Implement stop sharing button visibility.
This commit is contained in:
parent
daa0734e5b
commit
83e79207c1
4 changed files with 21 additions and 7 deletions
|
@ -64,7 +64,7 @@ class LiveLocationBottomSheetController @Inject constructor(
|
|||
avatarRenderer(host.avatarRenderer)
|
||||
remainingTime(remainingTime)
|
||||
locationUpdateTimeMillis(liveLocationViewState.locationTimestampMillis)
|
||||
showStopSharingButton(false)
|
||||
showStopSharingButton(liveLocationViewState.showStopSharingButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,8 +65,6 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
|
|||
@EpoxyAttribute
|
||||
var showStopSharingButton: Boolean = false
|
||||
|
||||
private var timer: CountUpTimer? = null
|
||||
|
||||
override fun bind(holder: Holder) {
|
||||
super.bind(holder)
|
||||
avatarRenderer.render(matrixItem, holder.itemUserAvatarImageView)
|
||||
|
@ -80,7 +78,9 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
|
|||
}
|
||||
}
|
||||
|
||||
timer = CountUpTimer(1000).apply {
|
||||
stopTimer(holder)
|
||||
|
||||
holder.timer = CountUpTimer(1000).apply {
|
||||
tickListener = object : CountUpTimer.TickListener {
|
||||
override fun onTick(milliseconds: Long) {
|
||||
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis)
|
||||
|
@ -90,6 +90,16 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
|
|||
}
|
||||
}
|
||||
|
||||
override fun unbind(holder: Holder) {
|
||||
super.unbind(holder)
|
||||
stopTimer(holder)
|
||||
}
|
||||
|
||||
private fun stopTimer(holder: Holder) {
|
||||
holder.timer?.stop()
|
||||
holder.timer = null
|
||||
}
|
||||
|
||||
private fun getFormattedLastUpdatedAt(locationUpdateTimeMillis: Long?): String {
|
||||
if (locationUpdateTimeMillis == null) return ""
|
||||
val elapsedTime = clock.epochMillis() - locationUpdateTimeMillis
|
||||
|
@ -98,6 +108,7 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
|
|||
}
|
||||
|
||||
class Holder : VectorEpoxyHolder() {
|
||||
var timer: CountUpTimer? = null
|
||||
val itemUserAvatarImageView by bind<ImageView>(R.id.itemUserAvatarImageView)
|
||||
val itemUserDisplayNameTextView by bind<TextView>(R.id.itemUserDisplayNameTextView)
|
||||
val itemRemainingTimeTextView by bind<TextView>(R.id.itemRemainingTimeTextView)
|
||||
|
|
|
@ -39,5 +39,6 @@ data class UserLiveLocationViewState(
|
|||
val pinDrawable: Drawable,
|
||||
val locationData: LocationData,
|
||||
val endOfLiveTimestampMillis: Long?,
|
||||
val locationTimestampMillis: Long?
|
||||
val locationTimestampMillis: Long?,
|
||||
val showStopSharingButton: Boolean
|
||||
)
|
||||
|
|
|
@ -44,14 +44,16 @@ class UserLiveLocationViewStateMapper @Inject constructor(
|
|||
}
|
||||
else -> {
|
||||
locationPinProvider.create(userId) { pinDrawable ->
|
||||
activeSessionHolder.getActiveSession().getUser(userId)?.toMatrixItem()?.let { matrixItem ->
|
||||
val session = activeSessionHolder.getActiveSession()
|
||||
session.getUser(userId)?.toMatrixItem()?.let { matrixItem ->
|
||||
val locationTimestampMillis = liveLocationShareAggregatedSummary.lastLocationDataContent?.getBestTimestampMillis()
|
||||
val viewState = UserLiveLocationViewState(
|
||||
matrixItem = matrixItem,
|
||||
pinDrawable = pinDrawable,
|
||||
locationData = locationData,
|
||||
endOfLiveTimestampMillis = liveLocationShareAggregatedSummary.endOfLiveTimestampMillis,
|
||||
locationTimestampMillis = locationTimestampMillis
|
||||
locationTimestampMillis = locationTimestampMillis,
|
||||
showStopSharingButton = userId == session.myUserId
|
||||
)
|
||||
continuation.resume(viewState) {
|
||||
// do nothing on cancellation
|
||||
|
|
Loading…
Reference in a new issue