Skip to content

Commit

Permalink
Merge pull request #91 from azrael8576/style/kotlinify
Browse files Browse the repository at this point in the history
Kotlinify codebase
  • Loading branch information
azrael8576 authored Jan 29, 2024
2 parents 1b8f63e + 8a76102 commit 822d97a
Show file tree
Hide file tree
Showing 21 changed files with 220 additions and 173 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://editorconfig.org/
# This configuration is used by ktlint when spotless invokes it

[*.{kt,kts}]
ij_kotlin_allow_trailing_comma=true
ij_kotlin_allow_trailing_comma_on_call_site=true
ktlint_function_naming_ignore_when_annotated_with=Composable, Test
10 changes: 5 additions & 5 deletions app/src/androidTest/java/com/wei/picquest/ui/NavigationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ class NavigationTest {
}

/*
* When pressing back from any top level destination except "Home", the app navigates back
* to the "Home" destination, no matter which destinations you visited in between.
*/
* When pressing back from any top level destination except "Home", the app navigates back
* to the "Home" destination, no matter which destinations you visited in between.
*/
@Test
fun navigationBar_backFromAnyDestination_returnsToHome() {
homeEndToEndRobot(composeTestRule) {
Expand All @@ -68,8 +68,8 @@ class NavigationTest {
}

/*
* There should always be at most one instance of a top-level destination at the same time.
*/
* There should always be at most one instance of a top-level destination at the same time.
*/
@Test(expected = NoActivityResumedException::class)
fun topDestination_back_quitsApp() {
homeEndToEndRobot(composeTestRule) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/wei/picquest/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class MainActivity : ComponentActivity() {
onDispose {}
}

CompositionLocalProvider() {
CompositionLocalProvider {
PqTheme(darkTheme = darkTheme) {
PqApp(
networkMonitor = networkMonitor,
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/wei/picquest/navigation/PqNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import androidx.navigation.compose.NavHost
import androidx.window.layout.DisplayFeature
import com.wei.picquest.core.designsystem.ui.DeviceOrientation
import com.wei.picquest.feature.contactme.contactme.navigation.contactMeGraph
import com.wei.picquest.feature.home.home.navigation.HOME_ROUTE
import com.wei.picquest.feature.home.home.navigation.homeGraph
import com.wei.picquest.feature.home.home.navigation.homeRoute
import com.wei.picquest.feature.photo.photolibrary.navigation.photoLibraryGraph
import com.wei.picquest.feature.photo.photosearch.navigation.photoSearchGraph
import com.wei.picquest.feature.video.videolibrary.navigation.videoLibraryGraph
Expand All @@ -26,7 +26,7 @@ fun PqNavHost(
modifier: Modifier = Modifier,
appState: PqAppState,
displayFeatures: List<DisplayFeature>,
startDestination: String = homeRoute,
startDestination: String = HOME_ROUTE,
) {
val navController = appState.navController
val navigationType = appState.navigationType
Expand Down
54 changes: 33 additions & 21 deletions app/src/main/java/com/wei/picquest/ui/PqApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import com.wei.picquest.core.designsystem.component.PqNavigationRail
import com.wei.picquest.core.designsystem.component.PqNavigationRailItem
import com.wei.picquest.core.designsystem.theme.SPACING_LARGE
import com.wei.picquest.core.designsystem.ui.PqNavigationType
import com.wei.picquest.core.manager.ErrorTextPrefix
import com.wei.picquest.core.manager.ERROR_TEXT_PREFIX
import com.wei.picquest.core.manager.Message
import com.wei.picquest.core.manager.SnackbarManager
import com.wei.picquest.core.manager.SnackbarState
Expand All @@ -69,11 +69,12 @@ fun PqApp(
networkMonitor: NetworkMonitor,
windowSizeClass: WindowSizeClass,
displayFeatures: List<DisplayFeature>,
appState: PqAppState = rememberPqAppState(
networkMonitor = networkMonitor,
windowSizeClass = windowSizeClass,
displayFeatures = displayFeatures,
),
appState: PqAppState =
rememberPqAppState(
networkMonitor = networkMonitor,
windowSizeClass = windowSizeClass,
displayFeatures = displayFeatures,
),
snackbarManager: SnackbarManager,
) {
val snackbarHostState = remember { SnackbarHostState() }
Expand Down Expand Up @@ -109,7 +110,8 @@ fun PqApp(
}
PqBackground {
Scaffold(
modifier = Modifier.semantics {
modifier =
Modifier.semantics {
testTagsAsResourceId = true
},
containerColor = Color.Transparent,
Expand All @@ -122,7 +124,7 @@ fun PqApp(
ConditionalContent(
condition = !appState.isInPictureInPicture && !appState.isFullScreenCurrentDestination,
content = {
val isError = snackbarData.visuals.message.startsWith(ErrorTextPrefix)
val isError = snackbarData.visuals.message.startsWith(ERROR_TEXT_PREFIX)
PqAppSnackbar(snackbarData, isError)
},
)
Expand All @@ -131,7 +133,8 @@ fun PqApp(
},
bottomBar = {
ConditionalContent(
condition = !appState.isInPictureInPicture &&
condition =
!appState.isInPictureInPicture &&
!appState.isFullScreenCurrentDestination &&
appState.navigationType == PqNavigationType.BOTTOM_NAVIGATION,
content = {
Expand All @@ -157,15 +160,17 @@ fun PqApp(
),
) {
ConditionalContent(
condition = !appState.isInPictureInPicture &&
condition =
!appState.isInPictureInPicture &&
!appState.isFullScreenCurrentDestination &&
appState.navigationType == PqNavigationType.PERMANENT_NAVIGATION_DRAWER,
content = {
PqNavDrawer(
destinations = appState.topLevelDestinations,
onNavigateToDestination = appState::navigateToTopLevelDestination,
currentDestination = appState.currentDestination,
modifier = Modifier
modifier =
Modifier
.testTag(pqNavDrawer)
.padding(SPACING_LARGE.dp)
.safeDrawingPadding(),
Expand All @@ -174,23 +179,26 @@ fun PqApp(
)

ConditionalContent(
condition = !appState.isInPictureInPicture &&
condition =
!appState.isInPictureInPicture &&
!appState.isFullScreenCurrentDestination &&
appState.navigationType == PqNavigationType.NAVIGATION_RAIL,
content = {
PqNavRail(
destinations = appState.topLevelDestinations,
onNavigateToDestination = appState::navigateToTopLevelDestination,
currentDestination = appState.currentDestination,
modifier = Modifier
modifier =
Modifier
.testTag(pqNavRail)
.safeDrawingPadding(),
)
},
)

Column(
modifier = Modifier
modifier =
Modifier
.fillMaxSize(),
) {
PqNavHost(
Expand Down Expand Up @@ -331,7 +339,7 @@ suspend fun collectAndShowSnackbar(

if (message.state == SnackbarState.Error) {
snackbarHostState.showSnackbar(
message = ErrorTextPrefix + text,
message = ERROR_TEXT_PREFIX + text,
)
} else {
snackbarHostState.showSnackbar(message = text)
Expand All @@ -341,13 +349,17 @@ suspend fun collectAndShowSnackbar(
}
}

fun getMessageText(message: Message, context: Context): String {
fun getMessageText(
message: Message,
context: Context,
): String {
return when (message.uiText) {
is UiText.DynamicString -> (message.uiText as UiText.DynamicString).value
is UiText.StringResource -> context.getString(
(message.uiText as UiText.StringResource).resId,
*(message.uiText as UiText.StringResource).args.map { it.toString(context) }
.toTypedArray(),
)
is UiText.StringResource ->
context.getString(
(message.uiText as UiText.StringResource).resId,
*(message.uiText as UiText.StringResource).args.map { it.toString(context) }
.toTypedArray(),
)
}
}
Loading

0 comments on commit 822d97a

Please sign in to comment.