Skip to content

Commit

Permalink
Merge pull request #73 from CrisisCleanup/fixes-updates
Browse files Browse the repository at this point in the history
Fixes and updates across the app
  • Loading branch information
hueachilles authored Aug 29, 2023
2 parents 19f6522 + e126055 commit 1b47c36
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 129 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ plugins {

android {
defaultConfig {
val buildVersion = 135
val buildVersion = 139
applicationId = "com.crisiscleanup"
versionCode = buildVersion
versionName = "0.2.${buildVersion - 129}"
versionName = "0.5.${buildVersion - 136}"

// Custom test runner to set up Hilt dependency graph
testInstrumentationRunner = "com.crisiscleanup.core.testing.CrisisCleanupTestRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ class CrisisCleanupAccountUpdateRepository @Inject constructor(
}
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,13 @@ interface IncidentDao {
"""
UPDATE incident_form_fields
SET is_invalidated=1
WHERE incident_id=:incidentId
WHERE incident_id=:incidentId AND field_key NOT IN(:validFieldKeys)
""",
)
suspend fun invalidateFormFields(incidentId: Long)
suspend fun invalidateUnspecifiedFormFields(
incidentId: Long,
validFieldKeys: Set<String>,
)

@Upsert
suspend fun upsertFormFields(formFields: Collection<IncidentFormFieldEntity>)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ class IncidentDaoPlus @Inject constructor(
return
}

val validFields = formFields
.filterNot { it.isInvalidated }
val validFieldKeys = validFields
.map { it.fieldKey }
.toSet()
db.withTransaction {
val incidentDao = db.incidentDao()
incidentDao.invalidateFormFields(incidentId)
incidentDao.upsertFormFields(formFields)
incidentDao.invalidateUnspecifiedFormFields(
incidentId,
validFieldKeys,
)
incidentDao.upsertFormFields(validFields)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ data class NetworkPasswordResetPayload(
@Serializable
data class NetworkPasswordResetResult(
val status: String,
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fun rememberCloseKeyboard(rememberKey: Any): () -> Unit {
}
}


// https://stackoverflow.com/questions/68847559/how-can-i-detect-keyboard-opening-and-closing-in-jetpack-compose
@Composable
fun rememberIsKeyboardOpen(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,4 @@ class PasswordRecoverViewModel @Inject constructor(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private fun LoginScreen(
val isNotBusy by viewModel.isNotAuthenticating.collectAsStateWithLifecycle()

val focusEmail = viewModel.loginInputData.emailAddress.isEmpty() ||
viewModel.isInvalidEmail.value
viewModel.isInvalidEmail.value
val updateEmailInput =
remember(viewModel) { { s: String -> viewModel.loginInputData.emailAddress = s } }
val clearErrorVisuals = remember(viewModel) { { viewModel.clearErrorVisuals() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ fun PasswordRecoverRoute(
Spacer(Modifier.height(32.dp))
}

if (showMagicLink) {
MagicLinkView(
emailAddress = emailAddressNn,
isEditable = isNotLoading,
isBusy = isBusy,
)
}
// if (showMagicLink) {
// MagicLinkView(
// emailAddress = emailAddressNn,
// isEditable = isNotLoading,
// isBusy = isBusy,
// )
// }
}
}
}
Expand Down Expand Up @@ -362,4 +362,4 @@ private fun MagicLinkInitiatedView() {
listItemModifier,
style = LocalFontStyles.current.header3,
)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.crisiscleanup.feature.caseeditor

import com.crisiscleanup.core.common.AppEnv
import com.crisiscleanup.core.common.NetworkMonitor
import com.crisiscleanup.core.common.LocationProvider
import com.crisiscleanup.core.common.log.AppLogger
import com.crisiscleanup.core.common.log.TagLogger
import com.crisiscleanup.core.commoncase.model.FormFieldNode
Expand All @@ -17,8 +17,8 @@ import com.crisiscleanup.core.mapmarker.IncidentBoundsProvider
import com.crisiscleanup.core.model.data.AutoContactFrequency
import com.crisiscleanup.core.model.data.EmptyWorksite
import com.crisiscleanup.core.model.data.IncidentFormField
import com.crisiscleanup.core.model.data.WorksiteFlag
import com.crisiscleanup.core.model.data.WorksiteFormValue
import com.google.android.gms.maps.model.LatLng
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -45,14 +45,14 @@ internal class CaseEditorDataLoader(
incidentsRepository: IncidentsRepository,
incidentRefresher: IncidentRefresher,
incidentBoundsProvider: IncidentBoundsProvider,
locationProvider: LocationProvider,
worksitesRepository: WorksitesRepository,
worksiteChangeRepository: WorksiteChangeRepository,
languageRepository: LanguageTranslationsRepository,
languageRefresher: LanguageRefresher,
workTypeStatusRepository: WorkTypeStatusRepository,
translate: (String) -> String,
private val editableWorksiteProvider: EditableWorksiteProvider,
networkMonitor: NetworkMonitor,
coroutineScope: CoroutineScope,
coroutineDispatcher: CoroutineDispatcher,
appEnv: AppEnv,
Expand Down Expand Up @@ -193,15 +193,25 @@ internal class CaseEditorDataLoader(
val (localWorksite, isPulled) = third

val loadedWorksite = localWorksite?.worksite
var worksiteState = loadedWorksite ?: EmptyWorksite.copy(
incidentId = incidentIdIn,
autoContactFrequencyT = AutoContactFrequency.Often.literal,
flags = if (networkMonitor.isOnline.first()) {
EmptyWorksite.flags
} else {
listOf(WorksiteFlag.wrongLocation())
},
)
var worksiteState = if (loadedWorksite == null) {
var worksiteCoordinates = bounds.centroid
locationProvider.coordinates?.let {
val deviceLocation = LatLng(it.first, it.second)
if (bounds.containsLocation(deviceLocation)) {
worksiteCoordinates = deviceLocation
}
}

EmptyWorksite.copy(
incidentId = incidentIdIn,
autoContactFrequencyT = AutoContactFrequency.NotOften.literal,
latitude = worksiteCoordinates.latitude,
longitude = worksiteCoordinates.longitude,
flags = EmptyWorksite.flags,
)
} else {
loadedWorksite
}

with(editableWorksiteProvider) {
this.incident = incident
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,14 @@ class CaseEditorViewModel @Inject constructor(
incidentsRepository,
incidentRefresher,
incidentBoundsProvider,
locationProvider,
worksitesRepository,
worksiteChangeRepository,
languageRepository,
languageRefresher,
workTypeStatusRepository,
{ key -> translate(key) },
editableWorksiteProvider,
networkMonitor,
viewModelScope,
ioDispatcher,
appEnv,
Expand Down Expand Up @@ -682,7 +682,7 @@ class CaseEditorViewModel @Inject constructor(
}

sealed interface CaseEditorUiState {
object Loading : CaseEditorUiState
data object Loading : CaseEditorUiState

data class CaseData(
val orgId: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ import com.crisiscleanup.core.mapmarker.model.MapViewCameraZoom
import com.crisiscleanup.core.mapmarker.model.MapViewCameraZoomDefault
import com.crisiscleanup.core.mapmarker.util.smallOffset
import com.crisiscleanup.core.mapmarker.util.toLatLng
import com.crisiscleanup.core.model.data.EmptyWorksite
import com.crisiscleanup.core.model.data.Incident
import com.crisiscleanup.core.model.data.LocationAddress
import com.crisiscleanup.core.model.data.Worksite
import com.crisiscleanup.feature.caseeditor.model.LocationInputData
import com.crisiscleanup.feature.caseeditor.model.coordinates
import com.google.android.gms.maps.Projection
Expand Down Expand Up @@ -139,8 +137,6 @@ internal class EditableLocationDataEditor(
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
private val coroutineScope: CoroutineScope,
) : CaseLocationDataEditor {
// Worksite before lat,lng may have been auto updated
private val worksiteIn: Worksite
private val incidentId: Long

override val locationInputData: LocationInputData
Expand Down Expand Up @@ -201,29 +197,8 @@ internal class EditableLocationDataEditor(
}

init {
var worksite = worksiteProvider.editableWorksite.value
worksiteIn = worksite
incidentId = worksiteIn.incidentId

if (worksite.isNew &&
(
worksite.coordinates == EmptyWorksite.coordinates ||
worksite.coordinates == DefaultCoordinates
)
) {
val incidentBounds = worksiteProvider.incidentBounds
var worksiteCoordinates: LatLng = incidentBounds.centroid
locationProvider.coordinates?.let {
val deviceLocation = LatLng(it.first, it.second)
if (incidentBounds.containsLocation(deviceLocation)) {
worksiteCoordinates = deviceLocation
}
}
worksite = worksite.copy(
latitude = worksiteCoordinates.latitude,
longitude = worksiteCoordinates.longitude,
)
}
val worksite = worksiteProvider.editableWorksite.value
incidentId = worksite.incidentId

locationInputData = LocationInputData(
translator,
Expand Down Expand Up @@ -499,12 +474,12 @@ internal class EditableLocationDataEditor(
}

override fun onGeocodeAddressSelected(locationAddress: LocationAddress): Boolean {
val coordinates = locationAddress.toLatLng()
with(outOfBoundsManager) {
if (isPendingOutOfBounds) {
return false
}

val coordinates = locationAddress.toLatLng()
if (!isCoordinatesInBounds(coordinates)) {
onLocationOutOfBounds(coordinates, locationAddress)
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,23 @@ class SingleEditableWorksiteProvider @Inject constructor() :
incidentChangeData.set(null)
}

private fun setIncidentChange(incident: Incident, worksite: Worksite) {
incidentChangeData.set(
IncidentChangeData(
incident,
worksite.copy(incidentId = incident.id),
),
)
}

override fun setIncidentAddressChanged(incident: Incident, worksite: Worksite) {
val worksiteChange = worksite.copy(incidentId = incident.id)
incidentChangeData.set(IncidentChangeData(incident, worksiteChange))
setIncidentChange(incident, worksite)
incidentIdChange.value = incident.id
}

override fun updateIncidentChangeWorksite(worksite: Worksite) {
incidentChangeData.get()?.let {
val incident = it.incident
incidentChangeData.set(
IncidentChangeData(
incident,
worksite.copy(incidentId = incident.id),
),
)
setIncidentChange(it.incident, worksite)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.crisiscleanup.core.common.AppEnv
import com.crisiscleanup.core.common.KeyResourceTranslator
import com.crisiscleanup.core.common.NetworkMonitor
import com.crisiscleanup.core.common.LocationProvider
import com.crisiscleanup.core.common.PermissionManager
import com.crisiscleanup.core.common.PermissionStatus
import com.crisiscleanup.core.common.cameraPermissionGranted
Expand Down Expand Up @@ -87,6 +87,7 @@ class ExistingCaseViewModel @Inject constructor(
organizationsRepository: OrganizationsRepository,
incidentRefresher: IncidentRefresher,
incidentBoundsProvider: IncidentBoundsProvider,
locationProvider: LocationProvider,
worksitesRepository: WorksitesRepository,
languageRepository: LanguageTranslationsRepository,
accountDataRefresher: AccountDataRefresher,
Expand All @@ -99,7 +100,6 @@ class ExistingCaseViewModel @Inject constructor(
private val translator: KeyResourceTranslator,
private val worksiteChangeRepository: WorksiteChangeRepository,
private val syncPusher: SyncPusher,
networkMonitor: NetworkMonitor,
packageManager: PackageManager,
private val contentResolver: ContentResolver,
drawableResourceBitmapProvider: DrawableResourceBitmapProvider,
Expand Down Expand Up @@ -221,14 +221,14 @@ class ExistingCaseViewModel @Inject constructor(
incidentsRepository,
incidentRefresher,
incidentBoundsProvider,
locationProvider,
worksitesRepository,
worksiteChangeRepository,
languageRepository,
languageRefresher,
workTypeStatusRepository,
{ key -> translate(key) },
editableWorksiteProvider,
networkMonitor,
viewModelScope,
ioDispatcher,
appEnv,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class LocationSearchManager(
}
.flowOn(coroutineDispatcher)

private val oneMinute = 1 / 60
private val oneMinute = 1.0 / 60

private val addressSearch = searchQuery
.map { q ->
Expand Down
Loading

0 comments on commit 1b47c36

Please sign in to comment.