Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

CheckIn deletion (EXPOSUREAPP-5410) #2654

Merged
merged 7 commits into from
Mar 22, 2021

Conversation

d4rken
Copy link
Member

@d4rken d4rken commented Mar 19, 2021

  • Wire up UI elements with delete confirmation and repository
  • Add delete method to respository
  • Refactore repository to offer blocking calls to the UI

@d4rken d4rken added enhancement Improvement of an existing feature maintainers Tag pull requests created by maintainers labels Mar 19, 2021
@d4rken d4rken added this to the 2.0.0 milestone Mar 19, 2021
@d4rken d4rken requested a review from a team March 19, 2021 14:52
# Conflicts:
#	Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckIn.kt
#	Corona-Warn-App/src/main/java/de/rki/coronawarnapp/eventregistration/checkins/CheckInRepository.kt
@LukasLechnerDev LukasLechnerDev self-assigned this Mar 19, 2021
@chris-cwa chris-cwa self-assigned this Mar 19, 2021
@chris-cwa chris-cwa self-requested a review March 19, 2021 15:48
Copy link
Contributor

@chris-cwa chris-cwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -68,6 +76,22 @@ class CheckInsViewModel @AssistedInject constructor(
savedState.set(SKEY_LAST_DEEPLINK, deepLink)
}

fun onRemoveCheckInConfirmed(checkIn: CheckIn?) {
Timber.d("removeCheckin(checkIn=%s)", checkIn)
launch(scope = appScope) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the withContext(NonCancellable) in the Repository, I think we don't need to use the appScope and can simply use the viewModelScope

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there might still be a racecondition.
Maybe, I'll think about this a bit more and fix it in a follow up PR if necessary.

    launch(scope = appScope) {
            if (checkIn == null) { // <------ If we cancel the scope here, is `clear` still called? 
                checkInsRepository.clear()
            } else {
                checkInsRepository.deleteCheckIns(listOf(checkIn))
            }
     }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, good point. I am pretty sure clear() wouldn't be called in the situation you described, because the suspend function withContext() would immediately throw a CancellationException and the "NonCancellable" code block wouldn't be executed.

=> Leave it as it is :)

checkInDao.deleteAll()
}
suspend fun updateCheckIn(checkInId: Long, update: (CheckIn) -> CheckIn) = withContext(NonCancellable) {
Timber.d("updateCheckIn(checkInId=%d, update=%s)", checkInId, update)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't String templates nicer in Kotlin? 😀

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we print plain values like checkInId, yes, because there won't be a huge impact, but if we print complex parameters like data classes or callbacks in this case, using formatting args is better for performance, if logging is disabled, as they will not be evaluated toString().

We could now put checkInId as template, and update as formatting arg, but.... would this be a blocker for you 🙂 ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. Then its fine for me as it is.

@sonarcloud
Copy link

sonarcloud bot commented Mar 22, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

33.8% 33.8% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@LukasLechnerDev LukasLechnerDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@d4rken d4rken merged commit 414e240 into release/2.0.x Mar 22, 2021
@d4rken d4rken deleted the feature/5410-checkin-deletion branch March 22, 2021 11:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Improvement of an existing feature maintainers Tag pull requests created by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants