-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Live Location Sharing - User List Bottom Sheet [PSF-890] #6170
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
453aa28
Add required resources.
onurays 88de113
Add bottom sheet layout.
onurays 44b2a7f
Refactor duration formatter to be able to user StringProvider.
onurays 924d7e1
Implement bottom sheet controller.
onurays 8247b1d
Add location update timestamp live location view state mapper.
onurays daa0734
Implement user list bottom sheet.
onurays 83e7920
Implement stop sharing button visibility.
onurays 2eaf843
Implement stop sharing function from bottom sheet.
onurays 8018ba3
Zoom to selected user from bottom sheet.
onurays 8bc7d3e
Changelog added.
onurays b262aad
Remove unused layout.
onurays aa344b1
Code documentation.
onurays 21abc3f
Code review fixes.
onurays 04679ea
Merge branch 'develop' into feature/ons/live_location_bottom_sheet
onurays 84b3d55
Fix unit tests.
onurays 353f290
Fix unit tests.
onurays File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Live Location Sharing - User List Bottom Sheet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"data": [ | ||
{ | ||
"displayName": "Amandine", | ||
"remainingTime": "9min left", | ||
"lastUpdatedAt": "Updated 12min ago" | ||
}, | ||
{ | ||
"displayName": "You", | ||
"remainingTime": "19min left", | ||
"lastUpdatedAt": "Updated 1min ago" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
...c/main/java/im/vector/app/features/location/live/map/LiveLocationBottomSheetController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.location.live.map | ||
|
||
import android.content.Context | ||
import com.airbnb.epoxy.EpoxyController | ||
import im.vector.app.R | ||
import im.vector.app.core.date.DateFormatKind | ||
import im.vector.app.core.date.VectorDateFormatter | ||
import im.vector.app.core.resources.DateProvider | ||
import im.vector.app.core.resources.StringProvider | ||
import im.vector.app.core.resources.toTimestamp | ||
import im.vector.app.core.time.Clock | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.app.features.location.live.map.bottomsheet.LiveLocationUserItem | ||
import im.vector.app.features.location.live.map.bottomsheet.liveLocationUserItem | ||
import javax.inject.Inject | ||
|
||
class LiveLocationBottomSheetController @Inject constructor( | ||
private val avatarRenderer: AvatarRenderer, | ||
private val vectorDateFormatter: VectorDateFormatter, | ||
private val stringProvider: StringProvider, | ||
private val clock: Clock, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 for injecting the clock! |
||
private val context: Context, | ||
) : EpoxyController() { | ||
|
||
interface Callback { | ||
fun onUserSelected(userId: String) | ||
fun onStopLocationClicked() | ||
} | ||
|
||
private var userLocations: List<UserLiveLocationViewState>? = null | ||
var callback: Callback? = null | ||
|
||
fun setData(userLocations: List<UserLiveLocationViewState>) { | ||
this.userLocations = userLocations | ||
requestModelBuild() | ||
} | ||
|
||
override fun buildModels() { | ||
val currentUserLocations = userLocations ?: return | ||
val host = this | ||
|
||
val userItemCallback = object : LiveLocationUserItem.Callback { | ||
override fun onUserSelected(userId: String) { | ||
host.callback?.onUserSelected(userId) | ||
} | ||
|
||
override fun onStopSharingClicked() { | ||
host.callback?.onStopLocationClicked() | ||
} | ||
} | ||
|
||
currentUserLocations.forEach { liveLocationViewState -> | ||
val remainingTime = getFormattedLocalTimeEndOfLive(liveLocationViewState.endOfLiveTimestampMillis) | ||
liveLocationUserItem { | ||
id(liveLocationViewState.matrixItem.id) | ||
callback(userItemCallback) | ||
matrixItem(liveLocationViewState.matrixItem) | ||
stringProvider(host.stringProvider) | ||
clock(host.clock) | ||
avatarRenderer(host.avatarRenderer) | ||
remainingTime(remainingTime) | ||
locationUpdateTimeMillis(liveLocationViewState.locationTimestampMillis) | ||
showStopSharingButton(liveLocationViewState.showStopSharingButton) | ||
} | ||
} | ||
} | ||
|
||
private fun getFormattedLocalTimeEndOfLive(endOfLiveDateTimestampMillis: Long?): String { | ||
val endOfLiveDateTime = DateProvider.toLocalDateTime(endOfLiveDateTimestampMillis) | ||
val formattedDateTime = endOfLiveDateTime.toTimestamp().let { vectorDateFormatter.format(it, DateFormatKind.MESSAGE_SIMPLE) } | ||
return stringProvider.getString(R.string.location_share_live_until, formattedDateTime) | ||
} | ||
} |
121 changes: 121 additions & 0 deletions
121
vector/src/main/java/im/vector/app/features/location/live/map/LiveLocationUserItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.location.live.map.bottomsheet | ||
|
||
import android.widget.Button | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.core.view.isVisible | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
import com.airbnb.epoxy.EpoxyModelClass | ||
import im.vector.app.R | ||
import im.vector.app.core.epoxy.VectorEpoxyHolder | ||
import im.vector.app.core.epoxy.VectorEpoxyModel | ||
import im.vector.app.core.epoxy.onClick | ||
import im.vector.app.core.resources.StringProvider | ||
import im.vector.app.core.time.Clock | ||
import im.vector.app.core.utils.TextUtils | ||
import im.vector.app.features.home.AvatarRenderer | ||
import im.vector.lib.core.utils.timer.CountUpTimer | ||
import org.matrix.android.sdk.api.util.MatrixItem | ||
import org.threeten.bp.Duration | ||
|
||
@EpoxyModelClass(layout = R.layout.item_live_location_users_bottom_sheet) | ||
abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Holder>() { | ||
|
||
interface Callback { | ||
fun onUserSelected(userId: String) | ||
fun onStopSharingClicked() | ||
} | ||
|
||
@EpoxyAttribute | ||
var callback: Callback? = null | ||
|
||
@EpoxyAttribute | ||
lateinit var matrixItem: MatrixItem | ||
|
||
@EpoxyAttribute | ||
lateinit var avatarRenderer: AvatarRenderer | ||
|
||
@EpoxyAttribute | ||
lateinit var stringProvider: StringProvider | ||
|
||
@EpoxyAttribute | ||
lateinit var clock: Clock | ||
|
||
@EpoxyAttribute | ||
var remainingTime: String? = null | ||
|
||
@EpoxyAttribute | ||
var locationUpdateTimeMillis: Long? = null | ||
|
||
@EpoxyAttribute | ||
var showStopSharingButton: Boolean = false | ||
|
||
override fun bind(holder: Holder) { | ||
super.bind(holder) | ||
avatarRenderer.render(matrixItem, holder.itemUserAvatarImageView) | ||
holder.itemUserDisplayNameTextView.text = matrixItem.displayName | ||
holder.itemRemainingTimeTextView.text = remainingTime | ||
|
||
holder.itemStopSharingButton.isVisible = showStopSharingButton | ||
if (showStopSharingButton) { | ||
holder.itemStopSharingButton.onClick { | ||
callback?.onStopSharingClicked() | ||
} | ||
} | ||
|
||
stopTimer(holder) | ||
holder.timer = CountUpTimer(1000).apply { | ||
tickListener = object : CountUpTimer.TickListener { | ||
override fun onTick(milliseconds: Long) { | ||
holder.itemLastUpdatedAtTextView.text = getFormattedLastUpdatedAt(locationUpdateTimeMillis) | ||
} | ||
} | ||
resume() | ||
} | ||
|
||
holder.view.setOnClickListener { callback?.onUserSelected(matrixItem.id) } | ||
} | ||
|
||
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 | ||
val duration = Duration.ofMillis(elapsedTime.coerceAtLeast(0L)) | ||
val formattedDuration = TextUtils.formatDurationWithUnits(stringProvider, duration, appendSeconds = false) | ||
return stringProvider.getString(R.string.live_location_bottom_sheet_last_updated_at, formattedDuration) | ||
} | ||
|
||
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) | ||
val itemLastUpdatedAtTextView by bind<TextView>(R.id.itemLastUpdatedAtTextView) | ||
val itemStopSharingButton by bind<Button>(R.id.itemStopSharingButton) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the second item used? I only see the first one used in text for preview of the item layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is seen in RecyclerView's preview.