Code review fixes.

This commit is contained in:
Onuray Sahin 2022-05-30 15:40:36 +03:00
parent aa344b1ecd
commit 21abc3fa77
5 changed files with 23 additions and 18 deletions

View File

@ -86,12 +86,12 @@ object TextUtils {
}
}
fun formatDurationWithUnits(context: Context, duration: Duration): String {
return formatDurationWithUnits(duration, context::getString)
fun formatDurationWithUnits(context: Context, duration: Duration, appendSeconds: Boolean = true): String {
return formatDurationWithUnits(duration, context::getString, appendSeconds)
}
fun formatDurationWithUnits(stringProvider: StringProvider, duration: Duration): String {
return formatDurationWithUnits(duration, stringProvider::getString)
fun formatDurationWithUnits(stringProvider: StringProvider, duration: Duration, appendSeconds: Boolean = true): String {
return formatDurationWithUnits(duration, stringProvider::getString, appendSeconds)
}
/**
@ -99,9 +99,10 @@ object TextUtils {
* So we can pass the getString function either from Context or the StringProvider.
* @param duration duration to be formatted
* @param getString getString method from Context or StringProvider
* @param appendSeconds if false than formatter will not append seconds
* @return formatted duration with a localized form like "10h 30min 5sec"
*/
private fun formatDurationWithUnits(duration: Duration, getString: ((Int) -> String)): String {
private fun formatDurationWithUnits(duration: Duration, getString: ((Int) -> String), appendSeconds: Boolean = true): String {
val hours = getHours(duration)
val minutes = getMinutes(duration)
val seconds = getSeconds(duration)
@ -113,14 +114,14 @@ object TextUtils {
builder.append(" ")
appendMinutes(getString, builder, minutes)
}
if (seconds > 0) {
if (appendSeconds && seconds > 0) {
builder.append(" ")
appendSeconds(getString, builder, seconds)
}
}
minutes > 0 -> {
appendMinutes(getString, builder, minutes)
if (seconds > 0) {
if (appendSeconds && seconds > 0) {
builder.append(" ")
appendSeconds(getString, builder, seconds)
}

View File

@ -106,7 +106,8 @@ abstract class LiveLocationUserItem : VectorEpoxyModel<LiveLocationUserItem.Hold
if (locationUpdateTimeMillis == null) return ""
val elapsedTime = clock.epochMillis() - locationUpdateTimeMillis
val duration = Duration.ofMillis(elapsedTime.coerceAtLeast(0L))
return stringProvider.getString(R.string.live_location_bottom_sheet_last_updated_at, TextUtils.formatDurationWithUnits(stringProvider, duration))
val formattedDuration = TextUtils.formatDurationWithUnits(stringProvider, duration, appendSeconds = false)
return stringProvider.getString(R.string.live_location_bottom_sheet_last_updated_at, formattedDuration)
}
class Holder : VectorEpoxyHolder() {

View File

@ -70,7 +70,7 @@ class LocationLiveMapViewFragment @Inject constructor(
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
views.bottomSheetRecyclerView.configureWith(bottomSheetController, hasFixedSize = false, disableItemAnimation = true)
views.liveLocationBottomSheetRecyclerView.configureWith(bottomSheetController, hasFixedSize = false, disableItemAnimation = true)
bottomSheetController.callback = object : LiveLocationBottomSheetController.Callback {
override fun onUserSelected(userId: String) {
@ -95,7 +95,9 @@ class LocationLiveMapViewFragment @Inject constructor(
mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style ->
mapStyle = style
this@LocationLiveMapViewFragment.mapboxMap = WeakReference(mapboxMap)
symbolManager = SymbolManager(mapFragment.view as MapView, mapboxMap, style)
symbolManager = SymbolManager(mapFragment.view as MapView, mapboxMap, style).apply {
iconAllowOverlap = true
}
pendingLiveLocations
.takeUnless { it.isEmpty() }
?.let { updateMap(it) }
@ -109,7 +111,7 @@ class LocationLiveMapViewFragment @Inject constructor(
?: run {
val options = MapboxMapOptions.createFromAttributes(requireContext(), null)
SupportMapFragment.newInstance(options)
.also { addChildFragment(R.id.fragmentContainer, it, tag = MAP_FRAGMENT_TAG) }
.also { addChildFragment(R.id.liveLocationMapFragmentContainer, it, tag = MAP_FRAGMENT_TAG) }
}
override fun invalidate() = withState(viewModel) { viewState ->

View File

@ -7,7 +7,7 @@
android:background="@drawable/bg_live_location_users_bottom_sheet">
<FrameLayout
android:id="@+id/fragmentContainer"
android:id="@+id/liveLocationMapFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
@ -21,7 +21,7 @@
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View
android:id="@+id/bottomSheetHandle"
android:id="@+id/liveLocationMapBottomSheetHandle"
android:layout_width="36dp"
android:layout_height="6dp"
android:layout_marginTop="12dp"
@ -31,14 +31,14 @@
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/bottomSheetRecyclerView"
android:id="@+id/liveLocationBottomSheetRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/bottomSheetHandle"
app:layout_constraintTop_toBottomOf="@id/liveLocationMapBottomSheetHandle"
tools:listitem="@layout/item_live_location_users_bottom_sheet" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -3,7 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="80dp">
android:layout_height="80dp"
android:background="?selectableItemBackground">
<ImageView
android:id="@+id/itemUserAvatarImageView"
@ -52,9 +53,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/live_location_bottom_sheet_stop_sharing"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="@string/live_location_bottom_sheet_stop_sharing"/>
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>