Skip to content

Commit

Permalink
Fix code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPushkin committed Dec 7, 2023
1 parent 76af886 commit 9c2d402
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import ru.spbu.depnav.data.model.MarkerText
private val INSERTED_MAP = MapInfo(123, "test-map", 100, 100, 128, 5, 3)

/** Instrumentation tests for [MarkerWithTextDao]. */
@Suppress("TooManyFunctions") // OK for a test class
@Suppress("TooManyFunctions", "StringLiteralDuplication") // OK for a test class
class MarketWithTextDaoTest : AppDatabaseDaoTest() {
private lateinit var markerWithTextDao: MarkerWithTextDao

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ data class MarkerWithText(val marker: Marker, val text: MarkerText) {
}

companion object {
val ID_DIVIDER = ':'
const val ID_DIVIDER = ':'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private val ACTIVATION_EXIT_SPEC = tween<Float>(
@Composable
@Suppress(
"LongMethod", // No point in further shrinking
"LongParameterList" // Considered OK for composables
"LongParameterList" // Considered OK for a composable
)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
fun MapSearchBar(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private fun SearchResultLongContentsPreview() {
Language.EN,
"Some very very very very very long title",
"Some very very very very very very long location",
"Some description"
"Some very very very very very very long description"
),
onClick = {}
) {}
Expand Down
95 changes: 59 additions & 36 deletions app/src/main/java/ru/spbu/depnav/ui/screen/MapScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ import ru.spbu.depnav.ui.theme.DEFAULT_PADDING
import ru.spbu.depnav.ui.viewmodel.MapUiState
import ru.spbu.depnav.ui.viewmodel.MapViewModel
import ru.spbu.depnav.ui.viewmodel.SearchResults
import ru.spbu.depnav.ui.viewmodel.SearchUiState
import ru.spbu.depnav.ui.viewmodel.SearchViewModel

/** Screen containing a navigable map. */
Expand Down Expand Up @@ -134,62 +135,84 @@ fun MapScreen(
val readyMapUiState = mapUiState as? MapUiState.Ready ?: return@ModalNavigationDrawer
val searchUiState by searchVm.uiState.collectAsStateWithLifecycle()

val markerAlpha by mapVm.markerAlpha.collectAsStateWithLifecycle()
val markersVisible by remember { derivedStateOf { markerAlpha > 0f } }

val mapColor = MaterialTheme.colorScheme.outline
LaunchedEffect(mapColor) { mapVm.setMapColor(mapColor) }

MapUI(state = readyMapUiState.mapState)

Box(modifier = Modifier.fillMaxSize()) {
CompositionLocalProvider(LocalAbsoluteTonalElevation provides 4.dp) {
AnimatedSearchBar(
visible = readyMapUiState.showOnMapUi,
mapTitle = readyMapUiState.mapTitle,
query = searchUiState.query,
onQueryChange = searchVm::search,
searchResults = searchUiState.results,
onResultClick = { markerId ->
mapVm.focusOnMarker(markerId)
searchVm.addToSearchHistory(markerId)
},
onMenuCLick = { scope.launch { drawerState.open() } }
)

AnimatedFloorSwitch(
visible = readyMapUiState.showOnMapUi,
currentFloor = readyMapUiState.currentFloor,
maxFloor = readyMapUiState.floorsNum,
onFloorSwitch = mapVm::setFloor
)

val markerAlpha by mapVm.markerAlpha.collectAsStateWithLifecycle()
val markersVisible by remember { derivedStateOf { markerAlpha > 0f } }

AnimatedBottom(
pinnedMarker = readyMapUiState.pinnedMarker,
showZoomInHint = !markersVisible
)
}
}
OnMapUi(
mapUiState = readyMapUiState,
searchUiState = searchUiState,
onSearchQueryChange = searchVm::search,
onSearchResultClick = { markerId ->
mapVm.focusOnMarker(markerId)
searchVm.addToSearchHistory(markerId)
},
onMainMenuClick = { scope.launch { drawerState.open() } },
onFloorSwitch = mapVm::setFloor,
markersVisible = markersVisible
)
}
}

val locale = Locale.current // This one is not a State
LaunchedEffect(key1 = ConfigurationCompat.getLocales(LocalConfiguration.current)[0]) {
LaunchedEffect(ConfigurationCompat.getLocales(LocalConfiguration.current)[0]) {
val locale = Locale.current // This is not a State
searchVm.onLocaleChange(locale)
mapVm.onLocaleChange(locale)
}
}

@Composable
@Suppress("LongParameterList") // Considered OK for composables
@Suppress("LongParameterList") // Considered OK for a composable
private fun OnMapUi(
mapUiState: MapUiState.Ready,
searchUiState: SearchUiState,
onSearchQueryChange: (String) -> Unit,
onSearchResultClick: (Int) -> Unit,
onMainMenuClick: () -> Unit,
onFloorSwitch: (Int) -> Unit,
markersVisible: Boolean
) {
CompositionLocalProvider(LocalAbsoluteTonalElevation provides 4.dp) {
Box(modifier = Modifier.fillMaxSize()) {
AnimatedSearchBar(
visible = mapUiState.showOnMapUi,
mapTitle = mapUiState.mapTitle,
query = searchUiState.query,
onQueryChange = onSearchQueryChange,
searchResults = searchUiState.results,
onResultClick = onSearchResultClick,
onMenuClick = onMainMenuClick
)

AnimatedFloorSwitch(
visible = mapUiState.showOnMapUi,
currentFloor = mapUiState.currentFloor,
maxFloor = mapUiState.floorsNum,
onFloorSwitch = onFloorSwitch
)

AnimatedBottom(
pinnedMarker = mapUiState.pinnedMarker,
showZoomInHint = !markersVisible
)
}
}
}

@Composable
@Suppress("LongParameterList") // Considered OK for a composable
private fun BoxScope.AnimatedSearchBar(
visible: Boolean,
mapTitle: String,
query: String,
onQueryChange: (String) -> Unit,
searchResults: SearchResults,
onResultClick: (Int) -> Unit,
onMenuCLick: () -> Unit
onMenuClick: () -> Unit
) {
var searchBarActive by rememberSaveable { mutableStateOf(false) }
if (!visible) {
Expand Down Expand Up @@ -221,7 +244,7 @@ private fun BoxScope.AnimatedSearchBar(
onActiveChange = { searchBarActive = it },
results = searchResults,
onResultClick = onResultClick,
onMenuClick = onMenuCLick,
onMenuClick = onMenuClick,
modifier = Modifier.padding(horizontal = horizontalPadding)
)
}
Expand Down
30 changes: 9 additions & 21 deletions app/src/main/java/ru/spbu/depnav/ui/viewmodel/MapViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,12 @@ class MapViewModel @Inject constructor(

onTap { _, _ ->
state.update {
it.copy(
showOnMapUi = if (it.pinnedMarker != null) {
removeMarker(PIN_ID)
it.showOnMapUi
} else {
!it.showOnMapUi
},
pinnedMarker = null
)
if (it.pinnedMarker != null) {
removeMarker(PIN_ID)
it.copy(pinnedMarker = null)
} else {
it.copy(showOnMapUi = !it.showOnMapUi)
}
}
}

Expand All @@ -238,12 +235,7 @@ class MapViewModel @Inject constructor(
addLayer(layer)
}
for (markerWithText in firstFloor.markers.values) {
addMarker(
markerWithText.extendedId,
markerWithText.marker,
markerWithText.text,
markerAlpha
)
with(markerWithText) { addMarker(extendedId, marker, text, markerAlpha) }
}

markerAlphaUpdater.cancel("New map state arrived")
Expand Down Expand Up @@ -323,12 +315,7 @@ class MapViewModel @Inject constructor(
}
}
for (markerWithText in floor.markers.values) {
addMarker(
markerWithText.extendedId,
markerWithText.marker,
markerWithText.text,
markerAlpha
)
with(markerWithText) { addMarker(extendedId, marker, text, markerAlpha) }
}
}
state.update {
Expand Down Expand Up @@ -444,6 +431,7 @@ class MapViewModel @Inject constructor(

/** Describes states of map UI. */
sealed interface MapUiState {
/** State that has a list of available maps. */
sealed interface WithAvailableMaps : MapUiState {
/** Maps available in the app. */
val availableMaps: List<AvailableMap>
Expand Down

0 comments on commit 9c2d402

Please sign in to comment.