This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 496
CheckIn cards & interaction (EXPOSUREAPP-5410) #2644
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dc02764
Fix duplicate fragment on navstack.
d4rken a4b3337
Active checkin card, first draft.
d4rken 8c357e2
CheckIn cards, second pass.
d4rken 82138ac
CheckIn cards, third pass.
d4rken f8b4dcd
CheckIn cards, fourth pass.
d4rken 7dbfa08
Fix textcolor on gradient in nightmode.
d4rken 4c8982d
Merge branch 'release/2.0.x' into feature/5410-checkin-cards
d4rken 7c8734b
Merge branch 'release/2.0.x' into feature/5410-checkin-cards
ralfgehrer 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
40 changes: 40 additions & 0 deletions
40
.../main/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkins/CheckInsAdapter.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,40 @@ | ||
package de.rki.coronawarnapp.ui.eventregistration.attendee.checkins | ||
|
||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.viewbinding.ViewBinding | ||
import de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items.ActiveCheckInVH | ||
import de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items.CheckInsItem | ||
import de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items.PastCheckInVH | ||
import de.rki.coronawarnapp.util.lists.BindableVH | ||
import de.rki.coronawarnapp.util.lists.diffutil.AsyncDiffUtilAdapter | ||
import de.rki.coronawarnapp.util.lists.diffutil.AsyncDiffer | ||
import de.rki.coronawarnapp.util.lists.modular.ModularAdapter | ||
import de.rki.coronawarnapp.util.lists.modular.mods.DataBinderMod | ||
import de.rki.coronawarnapp.util.lists.modular.mods.StableIdMod | ||
import de.rki.coronawarnapp.util.lists.modular.mods.TypedVHCreatorMod | ||
|
||
class CheckInsAdapter : | ||
ModularAdapter<CheckInsAdapter.ItemVH<CheckInsItem, ViewBinding>>(), | ||
AsyncDiffUtilAdapter<CheckInsItem> { | ||
|
||
override val asyncDiffer: AsyncDiffer<CheckInsItem> = AsyncDiffer(adapter = this) | ||
|
||
init { | ||
modules.addAll( | ||
listOf( | ||
StableIdMod(data), | ||
DataBinderMod<CheckInsItem, ItemVH<CheckInsItem, ViewBinding>>(data), | ||
TypedVHCreatorMod({ data[it] is ActiveCheckInVH.Item }) { ActiveCheckInVH(it) }, | ||
TypedVHCreatorMod({ data[it] is PastCheckInVH.Item }) { PastCheckInVH(it) }, | ||
) | ||
) | ||
} | ||
|
||
override fun getItemCount(): Int = data.size | ||
|
||
abstract class ItemVH<Item : CheckInsItem, VB : ViewBinding>( | ||
@LayoutRes layoutRes: Int, | ||
parent: ViewGroup | ||
) : ModularAdapter.VH(layoutRes, parent), BindableVH<Item, VB> | ||
} |
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
90 changes: 90 additions & 0 deletions
90
...java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkins/items/ActiveCheckInVH.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,90 @@ | ||
package de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items | ||
|
||
import android.view.ViewGroup | ||
import de.rki.coronawarnapp.R | ||
import de.rki.coronawarnapp.contactdiary.util.getLocale | ||
import de.rki.coronawarnapp.databinding.TraceLocationAttendeeCheckinsItemActiveBinding | ||
import de.rki.coronawarnapp.eventregistration.checkins.CheckIn | ||
import de.rki.coronawarnapp.util.TimeAndDateExtensions.toUserTimeZone | ||
import org.joda.time.Duration | ||
import org.joda.time.Instant | ||
import org.joda.time.PeriodType | ||
import org.joda.time.format.DateTimeFormat | ||
import org.joda.time.format.PeriodFormat | ||
import org.joda.time.format.PeriodFormatterBuilder | ||
|
||
class ActiveCheckInVH(parent: ViewGroup) : | ||
BaseCheckInVH<ActiveCheckInVH.Item, TraceLocationAttendeeCheckinsItemActiveBinding>( | ||
layoutRes = R.layout.trace_location_attendee_checkins_item_active, | ||
parent = parent | ||
) { | ||
|
||
override val viewBinding: Lazy<TraceLocationAttendeeCheckinsItemActiveBinding> = lazy { | ||
TraceLocationAttendeeCheckinsItemActiveBinding.bind(itemView) | ||
} | ||
|
||
private val hourPeriodFormatter by lazy { | ||
PeriodFormat.wordBased(context.getLocale()) | ||
} | ||
|
||
override val onBindData: TraceLocationAttendeeCheckinsItemActiveBinding.( | ||
item: Item, | ||
payloads: List<Any> | ||
) -> Unit = { item, _ -> | ||
val checkInStartUserTZ = item.checkin.checkInStart.toUserTimeZone() | ||
|
||
val checkinDuration = Duration(checkInStartUserTZ, Instant.now()) | ||
highlightDuration.text = highlightDurationForamtter.print(checkinDuration.toPeriod()) | ||
|
||
description.text = item.checkin.description | ||
address.text = item.checkin.address | ||
val startDate = checkInStartUserTZ.toLocalDate() | ||
traceLocationCardHighlightView.setCaption(startDate.toString(DateTimeFormat.mediumDate())) | ||
|
||
val autoCheckoutText = item.checkin.defaultCheckInLengthInMinutes?.let { checkoutLength -> | ||
val checkoutAt = checkInStartUserTZ.plus(Duration.standardMinutes(checkoutLength.toLong())) | ||
val checkoutIn = Duration(Instant.now(), checkoutAt).let { | ||
val periodType = when { | ||
it.isLongerThan(Duration.standardHours(1)) -> PeriodType.hours() | ||
it.isLongerThan(Duration.standardDays(1)) -> PeriodType.days() | ||
else -> PeriodType.minutes() | ||
} | ||
it.toPeriod(periodType) | ||
} | ||
|
||
context.getString( | ||
R.string.trace_location_checkins_card_automatic_checkout_info, | ||
checkInStartUserTZ.toLocalTime().toString("HH:mm"), | ||
hourPeriodFormatter.print(checkoutIn) | ||
) | ||
} | ||
|
||
checkoutInfo.text = autoCheckoutText ?: checkInStartUserTZ.toLocalTime().toString("HH:mm") | ||
|
||
menuAction.setupMenu(R.menu.menu_trace_location_attendee_checkin_item) { | ||
when (it.itemId) { | ||
R.id.menu_remove_item -> item.onRemoveItem(item.checkin).let { true } | ||
else -> false | ||
} | ||
} | ||
} | ||
|
||
data class Item( | ||
val checkin: CheckIn, | ||
val onCardClicked: (CheckIn) -> Unit, | ||
val onRemoveItem: (CheckIn) -> Unit, | ||
val onCheckout: (CheckIn) -> Unit, | ||
) : CheckInsItem { | ||
override val stableId: Long = checkin.id | ||
} | ||
|
||
companion object { | ||
private val highlightDurationForamtter = PeriodFormatterBuilder().apply { | ||
printZeroAlways() | ||
minimumPrintedDigits(2) | ||
appendHours() | ||
appendSuffix(":") | ||
appendMinutes() | ||
}.toFormatter() | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...n/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkins/items/BaseCheckInVH.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,30 @@ | ||
package de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items | ||
|
||
import android.view.Gravity | ||
import android.view.MenuItem | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.annotation.LayoutRes | ||
import androidx.annotation.MenuRes | ||
import androidx.appcompat.widget.PopupMenu | ||
import androidx.viewbinding.ViewBinding | ||
import de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.CheckInsAdapter | ||
|
||
abstract class BaseCheckInVH<ItemT : CheckInsItem, BindingT : ViewBinding>( | ||
parent: ViewGroup, | ||
@LayoutRes layoutRes: Int | ||
) : CheckInsAdapter.ItemVH<ItemT, BindingT>( | ||
layoutRes = layoutRes, | ||
parent = parent | ||
) { | ||
|
||
companion object { | ||
fun View.setupMenu(@MenuRes menuRes: Int, onMenuAction: (MenuItem) -> Boolean) { | ||
val menu = PopupMenu(context, this, Gravity.TOP or Gravity.END).apply { | ||
inflate(menuRes) | ||
setOnMenuItemClickListener { onMenuAction(it) } | ||
} | ||
setOnClickListener { menu.show() } | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...in/java/de/rki/coronawarnapp/ui/eventregistration/attendee/checkins/items/CheckInsItem.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,5 @@ | ||
package de.rki.coronawarnapp.ui.eventregistration.attendee.checkins.items | ||
|
||
import de.rki.coronawarnapp.util.lists.HasStableId | ||
|
||
interface CheckInsItem : HasStableId |
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.
Do we need 2nd level sort order - e.g.
checkInStart
- to have a stable sorting for active events?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.
Good point, by title would make sense, will add in follow up PRs.