Skip to content

Commit

Permalink
Update request redeploy querying all incidents
Browse files Browse the repository at this point in the history
  • Loading branch information
hueachilles committed Aug 15, 2024
1 parent ac0a42f commit e802df4
Show file tree
Hide file tree
Showing 23 changed files with 299 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class CrisisCleanupTutorialViewTracker @Inject constructor(
) : TutorialViewTracker {
class CrisisCleanupTutorialViewTracker @Inject constructor() : TutorialViewTracker {
override val viewSizePositionLookup =
SnapshotStateMap<TutorialViewId, LayoutSizePosition>().also {
it[AppNavBar] = LayoutSizePosition()
it[IncidentSelectDropdown] = LayoutSizePosition()
it[AccountToggle] = LayoutSizePosition()
}
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/crisiscleanup/ui/CrisisCleanupApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -457,4 +457,3 @@ private fun ExpiredAccountAlert(
}
}
}

54 changes: 29 additions & 25 deletions app/src/main/java/com/crisiscleanup/ui/TutorialGraphics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ private fun DrawScope.spotlightStepForwardOffset(
viewSizePosition: LayoutSizePosition,
): Offset {
val center = viewSizePosition.position.y + viewSizePosition.size.height * 0.5f
val y = size.height * (if (center > size.height * 0.5f) {
0.2f
} else {
0.8f
})
val y = size.height * (
if (center > size.height * 0.5f) {
0.2f
} else {
0.8f
}
)
val x = viewSizePosition.position.x + if (isHorizontalBar) {
32f
} else {
Expand Down Expand Up @@ -229,22 +231,24 @@ private fun DrawScope.menuTutorialDynamicContent(

val lineX = size.width * 0.5f
val lineStartY =
instructionOffset.y + (if (isSpotlightCenterAbove) {
-16f
} else {
val instructionConstraints = Constraints(
maxWidth = (size.width - instructionOffset.x).toInt(),
)
val textLayout = textMeasurer.measure(
stepInstruction,
instructionStyle,
overflow = TextOverflow.Visible,
constraints = instructionConstraints,
)
val textSize = textLayout.size
instructionOffset.y + (
if (isSpotlightCenterAbove) {
-16f
} else {
val instructionConstraints = Constraints(
maxWidth = (size.width - instructionOffset.x).toInt(),
)
val textLayout = textMeasurer.measure(
stepInstruction,
instructionStyle,
overflow = TextOverflow.Visible,
constraints = instructionConstraints,
)
val textSize = textLayout.size

textSize.height.toFloat() + 16f
})
textSize.height.toFloat() + 16f
}
)
val lineStart = Offset(lineX, lineStartY)
val lineEndY =
sizeOffset.topLeft.y + (if (isSpotlightCenterAbove) sizeOffset.size.height + 32f else -32f)
Expand Down Expand Up @@ -275,11 +279,11 @@ private fun DrawScope.spotlightAboveStepForwardOffset(
Offset(if (isHorizontalBar) 0f else 32f, 0f),
)
val x = referencePosition.position.x +
if (isHorizontalBar) {
32f
} else {
referencePosition.size.width * 0.2f
}
if (isHorizontalBar) {
32f
} else {
referencePosition.size.width * 0.2f
}
val y = size.height * 0.6f
return Offset(x, y)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ enum class TutorialStep {
AccountInfo,
ProvideAppFeedback,
IncidentSelect,
End
End,
}

@Qualifier
@Retention(RUNTIME)
annotation class Tutorials(val director: CrisisCleanupTutorialDirectors)

enum class CrisisCleanupTutorialDirectors {
Menu
Menu,
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IncidentsRepository {

suspend fun getIncident(id: Long, loadFormFields: Boolean = false): Incident?
suspend fun getIncidents(startAt: Instant): List<Incident>
suspend fun getIncidentsList(): List<IncidentIdNameType>

fun streamIncident(id: Long): Flow<Incident?>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.crisiscleanup.core.database.model.asExternalModel
import com.crisiscleanup.core.datastore.LocalAppPreferencesDataSource
import com.crisiscleanup.core.model.data.INCIDENT_ORGANIZATIONS_STABLE_MODEL_BUILD_VERSION
import com.crisiscleanup.core.model.data.Incident
import com.crisiscleanup.core.model.data.IncidentIdNameType
import com.crisiscleanup.core.network.CrisisCleanupNetworkDataSource
import com.crisiscleanup.core.network.model.NetworkIncident
import com.crisiscleanup.core.network.model.NetworkIncidentLocation
Expand Down Expand Up @@ -83,6 +84,23 @@ class OfflineFirstIncidentsRepository @Inject constructor(
.map(PopulatedIncident::asExternalModel)
}

override suspend fun getIncidentsList(): List<IncidentIdNameType> {
try {
return networkDataSource.getIncidentsList()
.map {
IncidentIdNameType(
it.id,
it.name,
it.shortName,
disasterLiteral = it.type,
)
}
} catch (e: Exception) {
logger.logException(e)
}
return emptyList()
}

override fun streamIncident(id: Long) =
incidentDao.streamFormFieldsIncident(id).mapLatest { it?.asExternalModel() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fun ListOptionsDropdown(
Row(
modifier
.actionHeight()
// TODO Common dimensions
.roundedOutline(radius = 3.dp)
.clickable(
onClick = onToggleDropdown,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import androidx.compose.material.icons.filled.QuestionMark
import androidx.compose.material.icons.filled.Remove
import androidx.compose.material.icons.filled.Rotate90DegreesCcw
import androidx.compose.material.icons.filled.Rotate90DegreesCw
import androidx.compose.material.icons.filled.Schedule
import androidx.compose.material.icons.filled.SentimentNeutral
import androidx.compose.material.icons.filled.UnfoldMore
import androidx.compose.material.icons.filled.Visibility
Expand Down Expand Up @@ -88,6 +89,7 @@ object CrisisCleanupIcons {
val MyLocation = icons.MyLocation
val Organization = icons.Domain
val Person = icons.Person
val PendingRequestRedeploy = icons.Schedule
val Phone = icons.Phone
val PhotoGrid = icons.PhotoLibrary
val Play = icons.PlayArrow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ val primaryBlueOneTenthColor = primaryBlueColor.copy(alpha = 0.1f)
val primaryRedColor = Color(0xFFED4747)
val primaryOrangeColor = Color(0xFFF79820)
val devActionColor = Color(0xFFF50057)
val green600 = Color(0xFF43A047)
internal val crisisCleanupYellow100 = Color(0xFFFFDC68)
internal val crisisCleanupYellow100HalfTransparent = crisisCleanupYellow100.copy(alpha = 0.5f)
val survivorNoteColor = crisisCleanupYellow100HalfTransparent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ val EmptyList = CrisisCleanupList(
shared = ListShare.Private,
permission = ListPermission.Read,
incidentId = EmptyIncident.id,
incident = IncidentIdNameType(id = EmptyIncident.id, "", "", ""),
incident = EmptyIncidentIdNameType,
)

enum class ListModel(val literal: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ data class IncidentIdNameType(
val disasterLiteral: String,
val disaster: Disaster = disasterFromLiteral(disasterLiteral),
)

val Incident.idNameType: IncidentIdNameType
get() = IncidentIdNameType(
id,
name,
shortName,
disasterLiteral,
)

val EmptyIncidentIdNameType = EmptyIncident.idNameType
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.crisiscleanup.core.network.model.NetworkLocation
import com.crisiscleanup.core.network.model.NetworkOrganizationShort
import com.crisiscleanup.core.network.model.NetworkOrganizationsResult
import com.crisiscleanup.core.network.model.NetworkPersonContact
import com.crisiscleanup.core.network.model.NetworkShortIncident
import com.crisiscleanup.core.network.model.NetworkTeamResult
import com.crisiscleanup.core.network.model.NetworkUserProfile
import com.crisiscleanup.core.network.model.NetworkWorkTypeRequest
Expand All @@ -39,6 +40,12 @@ interface CrisisCleanupNetworkDataSource {
after: Instant? = null,
): List<NetworkIncident>

suspend fun getIncidentsList(
fields: List<String> = listOf("id", "name", "short_name", "incident_type"),
limit: Int = 250,
ordering: String = "-start_at",
): List<NetworkShortIncident>

suspend fun getIncidentLocations(
locationIds: List<Long>,
): List<NetworkLocation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,20 @@ data class NetworkIncidentFormField(
val name: String,
)
}

@Serializable
data class NetworkIncidentsListResult(
val errors: List<NetworkCrisisCleanupApiError>? = null,
val count: Int? = null,
val results: List<NetworkShortIncident>? = null,
)

@Serializable
data class NetworkShortIncident(
val id: Long,
val name: String,
@SerialName("short_name")
val shortName: String,
@SerialName("incident_type")
val type: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.crisiscleanup.core.network.model.NetworkCountResult
import com.crisiscleanup.core.network.model.NetworkFlagsFormData
import com.crisiscleanup.core.network.model.NetworkFlagsFormDataResult
import com.crisiscleanup.core.network.model.NetworkIncidentResult
import com.crisiscleanup.core.network.model.NetworkIncidentsListResult
import com.crisiscleanup.core.network.model.NetworkIncidentsResult
import com.crisiscleanup.core.network.model.NetworkLanguageTranslationResult
import com.crisiscleanup.core.network.model.NetworkLanguagesResult
Expand Down Expand Up @@ -76,6 +77,16 @@ private interface DataSourceApi {
after: Instant?,
): NetworkIncidentsResult

@GET("incidents_list")
suspend fun getIncidentsList(
@Query("fields")
fields: String,
@Query("limit")
limit: Int,
@Query("sort")
ordering: String,
): NetworkIncidentsListResult

@TokenAuthenticationHeader
@GET("locations")
suspend fun getLocations(
Expand Down Expand Up @@ -330,6 +341,16 @@ class DataApiClient @Inject constructor(
it.results ?: emptyList()
}

override suspend fun getIncidentsList(
fields: List<String>,
limit: Int,
ordering: String,
) = networkApi.getIncidentsList(fields.joinToString(","), limit, ordering)
.let {
it.errors?.tryThrowException()
it.results ?: emptyList()
}

override suspend fun getIncidentLocations(locationIds: List<Long>) =
networkApi.getLocations(locationIds.joinToString(","), locationIds.size)
.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ data class LayoutSizePosition(
)

val LayoutCoordinates.sizePosition: LayoutSizePosition
get() = LayoutSizePosition(size, positionInRoot())
get() = LayoutSizePosition(size, positionInRoot())
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import com.crisiscleanup.core.model.data.TutorialViewId

interface TutorialViewTracker {
val viewSizePositionLookup: SnapshotStateMap<TutorialViewId, LayoutSizePosition>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.crisiscleanup.core.common.throttleLatest
import com.crisiscleanup.core.data.repository.IncidentsRepository
import com.crisiscleanup.core.model.data.Incident
import com.crisiscleanup.core.model.data.IncidentIdNameType
import com.crisiscleanup.core.model.data.idNameType
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
Expand Down Expand Up @@ -42,12 +43,9 @@ class QueryIncidentsManager(
private set

private val allIncidentsShort = allIncidents.mapLatest {
val all = it.map { incident ->
with(incident) {
IncidentIdNameType(id, name, shortName, disasterLiteral)
}
}
val all = it.map(Incident::idNameType)

// TODO Redesign and separate state
isLoadingAll.value = false

all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ class MenuTutorialDirector @Inject constructor() : TutorialDirector {
tutorialStep.value = nextStep
return nextStep != TutorialStep.End
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface DataModule {
interface MenuModule {
@Singleton
@Binds
@Tutorials(CrisisCleanupTutorialDirectors.Menu)
fun bindsTutorialDirector(
director: MenuTutorialDirector,
): TutorialDirector
}
}
Loading

0 comments on commit e802df4

Please sign in to comment.