Skip to content

Commit

Permalink
style(format): run `./gradlew --init-script gradle/init.gradle.kts sp…
Browse files Browse the repository at this point in the history
…otlessApply` to format + lint all files
  • Loading branch information
deepanchal committed Aug 18, 2023
1 parent 1c700f4 commit 1fb4245
Show file tree
Hide file tree
Showing 430 changed files with 2,189 additions and 1,687 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class ExampleInstrumentedTest {
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Assert.assertEquals("com.crisiscleanup.demo.debug", appContext.packageName)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class CrisisCleanupAppStateTest {
windowSizeClass = getCompactWindowClass(),
navController = navController,
networkMonitor = networkMonitor,
coroutineScope = backgroundScope
coroutineScope = backgroundScope,
)
}

Expand Down Expand Up @@ -88,7 +88,7 @@ class CrisisCleanupAppStateTest {
for (i in destinations.indices) {
assertEquals(
destinations[i],
state.topLevelDestinations[i].name.lowercase(Locale.getDefault())
state.topLevelDestinations[i].name.lowercase(Locale.getDefault()),
)
}
}
Expand All @@ -100,7 +100,7 @@ class CrisisCleanupAppStateTest {
windowSizeClass = getCompactWindowClass(),
navController = NavHostController(LocalContext.current),
networkMonitor = networkMonitor,
coroutineScope = backgroundScope
coroutineScope = backgroundScope,
)
}

Expand All @@ -115,7 +115,7 @@ class CrisisCleanupAppStateTest {
windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(800.dp, 800.dp)),
navController = NavHostController(LocalContext.current),
networkMonitor = networkMonitor,
coroutineScope = backgroundScope
coroutineScope = backgroundScope,
)
}

Expand All @@ -125,13 +125,12 @@ class CrisisCleanupAppStateTest {

@Test
fun CrisisCleanupAppState_showNavRail_large() = runTest {

composeTestRule.setContent {
state = CrisisCleanupAppState(
windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)),
navController = NavHostController(LocalContext.current),
networkMonitor = networkMonitor,
coroutineScope = backgroundScope
coroutineScope = backgroundScope,
)
}

Expand All @@ -141,21 +140,20 @@ class CrisisCleanupAppStateTest {

@Test
fun stateIsOfflineWhenNetworkMonitorIsOffline() = runTest(UnconfinedTestDispatcher()) {

composeTestRule.setContent {
state = CrisisCleanupAppState(
windowSizeClass = WindowSizeClass.calculateFromSize(DpSize(900.dp, 1200.dp)),
navController = NavHostController(LocalContext.current),
networkMonitor = networkMonitor,
coroutineScope = backgroundScope
coroutineScope = backgroundScope,
)
}

backgroundScope.launch { state.isOffline.collect() }
networkMonitor.setConnected(false)
assertEquals(
true,
state.isOffline.value
state.isOffline.value,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ class AndroidLocationProvider @Inject constructor(
}
return null
}
}
}
16 changes: 11 additions & 5 deletions app/src/main/java/com/crisiscleanup/AndroidPermissionManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ class AndroidPermissionManager @Inject constructor(
private var activityWr: WeakReference<ComponentActivity> = WeakReference(null)

private val screenshotReadPermission =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) READ_MEDIA_IMAGES
else READ_EXTERNAL_STORAGE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
READ_MEDIA_IMAGES
} else {
READ_EXTERNAL_STORAGE
}

override fun onCreate(owner: LifecycleOwner) {
(owner as? ComponentActivity)?.let { activity ->
Expand All @@ -50,8 +53,11 @@ class AndroidPermissionManager @Inject constructor(
// Assume unchanged permission since requested
val permission = permissionChanges.value.first
val status =
if (isGranted) PermissionStatus.Granted
else PermissionStatus.Denied
if (isGranted) {
PermissionStatus.Granted
} else {
PermissionStatus.Denied
}
permissionChanges.value = Pair(permission, status)

if (permission == ACCESS_COARSE_LOCATION || permission == ACCESS_FINE_LOCATION) {
Expand All @@ -67,7 +73,7 @@ class AndroidPermissionManager @Inject constructor(

private fun publishLocationPermission() {
hasLocationPermission.value = hasPermission(ACCESS_COARSE_LOCATION) ||
hasPermission(ACCESS_FINE_LOCATION)
hasPermission(ACCESS_FINE_LOCATION)
}

private fun hasPermission(permission: String): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ class AppVisualAlertManager @Inject constructor() : VisualAlertManager {
override fun setNonProductionAppAlert(show: Boolean) {
showNonProductionAlert.set(show)
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/crisiscleanup/CrisisCleanupAppEnv.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ class CrisisCleanupAppEnv @Inject constructor() : AppEnv {
block()
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ class FirebaseFeedbackReceiver @Inject constructor(

Firebase.appDistribution.startFeedback("Do share O_o")
}
}
}
9 changes: 6 additions & 3 deletions app/src/main/java/com/crisiscleanup/MainActivityViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ class MainActivityViewModel @Inject constructor(
.map {
isAccountExpired.value = !it.areTokensValid

if (it.hasAuthenticated) AuthState.Authenticated(it)
else AuthState.NotAuthenticated
if (it.hasAuthenticated) {
AuthState.Authenticated(it)
} else {
AuthState.NotAuthenticated
}
}
.stateIn(
scope = viewModelScope,
Expand Down Expand Up @@ -134,4 +137,4 @@ sealed interface AuthState {
data object Loading : AuthState
data class Authenticated(val accountData: AccountData) : AuthState
data object NotAuthenticated : AuthState
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/com/crisiscleanup/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ interface AppModule {
@Singleton
@Binds
fun bindsCrisisCleanupAuthInterceptorProvider(
provider: CrisisCleanupAuthInterceptorProvider
provider: CrisisCleanupAuthInterceptorProvider,
): AuthInterceptorProvider

@Singleton
@Binds
fun bindsCrisisCleanupInterceptorProvider(
provider: CrisisCleanupInterceptorProvider
provider: CrisisCleanupInterceptorProvider,
): RetrofitInterceptorProvider

@Singleton
Expand Down Expand Up @@ -78,4 +78,4 @@ object AppObjectModule {
fun providesContentResolver(
@ApplicationContext context: Context,
): ContentResolver = context.contentResolver
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/com/crisiscleanup/di/JankStatsModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object JankStatsModule {
@Provides
fun providesJankStats(
window: Window,
frameListener: JankStats.OnFrameListener
frameListener: JankStats.OnFrameListener,
): JankStats {
return JankStats.createAndTrack(window, frameListener)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ class CrisisCleanupAppLogger @Inject constructor(
crashlytics.log(message)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ class CrisisCleanupNavigationObserver @Inject constructor(
override fun onRouteChange(route: String?, arguments: Bundle?) {
navigationRoute.value = Pair(navigationRoute.value.second, route)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ enum class TopLevelDestination(
selectedIcon = ImageVectorIcon(CrisisCleanupIcons.Menu),
unselectedIcon = ImageVectorIcon(CrisisCleanupIcons.Menu),
titleTranslateKey = "nav.menu",
)
),
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,4 @@ class CrisisCleanupAuthInterceptorProvider @Inject constructor() : AuthIntercept
}
}

private class NetworkAuthException(message: String) : IOException(message)
private class NetworkAuthException(message: String) : IOException(message)
57 changes: 34 additions & 23 deletions app/src/main/java/com/crisiscleanup/ui/CrisisCleanupApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ fun CrisisCleanupApp(
) {
CrisisCleanupBackground {
Box(Modifier.fillMaxSize()) {

val snackbarHostState = remember { SnackbarHostState() }

val isOffline by appState.isOffline.collectAsStateWithLifecycle()
Expand All @@ -104,11 +103,13 @@ fun CrisisCleanupApp(

LaunchedEffect(isOffline) {
val notConnectedMessage = translator("info.no_internet")
if (isOffline) snackbarHostState.showSnackbar(
message = notConnectedMessage,
duration = SnackbarDuration.Indefinite,
withDismissAction = true,
)
if (isOffline) {
snackbarHostState.showSnackbar(
message = notConnectedMessage,
duration = SnackbarDuration.Indefinite,
withDismissAction = true,
)
}
}

val authState by viewModel.authState.collectAsStateWithLifecycle()
Expand Down Expand Up @@ -222,14 +223,14 @@ private fun AuthenticateContent(
.consumeWindowInsets(padding)
.windowInsetsPadding(
WindowInsets.safeDrawing.only(
WindowInsetsSides.Horizontal
)
WindowInsetsSides.Horizontal,
),
),
enableBackHandler = enableBackHandler,
closeAuthentication = { toggleAuthentication(false) },
isDebug = isDebuggable,
)
}
},
)
}

Expand Down Expand Up @@ -295,7 +296,7 @@ private fun NavigableContent(
destinations = appState.topLevelDestinations,
onNavigateToDestination = appState::navigateToTopLevelDestination,
currentDestination = appState.currentDestination,
modifier = Modifier.testTag("CrisisCleanupBottomBar")
modifier = Modifier.testTag("CrisisCleanupBottomBar"),
)
}

Expand All @@ -304,7 +305,7 @@ private fun NavigableContent(
Spacer(
Modifier
.fillMaxWidth()
.windowInsetsPadding(windowInsets)
.windowInsetsPadding(windowInsets),
)
}
},
Expand All @@ -315,9 +316,12 @@ private fun NavigableContent(
.padding(padding)
.consumeWindowInsets(padding)
.windowInsetsPadding(
if (isFullscreen) WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal)
else WindowInsets.safeDrawing
)
if (isFullscreen) {
WindowInsets.safeDrawing.only(WindowInsetsSides.Horizontal)
} else {
WindowInsets.safeDrawing
},
),
) {
if (showNavigation && appState.shouldShowNavRail) {
CrisisCleanupNavRail(
Expand All @@ -326,7 +330,7 @@ private fun NavigableContent(
currentDestination = appState.currentDestination,
modifier = Modifier
.testTag("CrisisCleanupNavRail")
.safeDrawingPadding()
.safeDrawingPadding(),
)
}

Expand All @@ -336,10 +340,14 @@ private fun NavigableContent(
if (!showNavigation &&
snackbarHostState.currentSnackbarData != null &&
keyboardVisibility == ScreenKeyboardVisibility.NotVisible
) 64.dp else 0.dp
) {
64.dp
} else {
0.dp
}

CompositionLocalProvider(
LocalAppLayout provides AppLayoutArea(snackbarHostState)
LocalAppLayout provides AppLayoutArea(snackbarHostState),
) {
CrisisCleanupNavHost(
navController = appState.navController,
Expand All @@ -351,7 +359,7 @@ private fun NavigableContent(
Spacer(
Modifier
.height(snackbarAreaHeight)
.animateContentSize()
.animateContentSize(),
)
}
}
Expand Down Expand Up @@ -420,14 +428,17 @@ private fun AppHeader(
isLoading = isAppHeaderLoading,
)
}
}
},
)
}

@Composable
private fun TopLevelDestination.Icon(isSelected: Boolean, description: String) {
val icon = if (isSelected) selectedIcon
else unselectedIcon
val icon = if (isSelected) {
selectedIcon
} else {
unselectedIcon
}
when (icon) {
is ImageVectorIcon -> Icon(
imageVector = icon.imageVector,
Expand Down Expand Up @@ -473,7 +484,7 @@ private fun CrisisCleanupBottomBar(
destinations: List<TopLevelDestination>,
onNavigateToDestination: (TopLevelDestination) -> Unit,
currentDestination: NavDestination?,
modifier: Modifier = Modifier
modifier: Modifier = Modifier,
) {
val translator = LocalAppTranslator.current
CrisisCleanupNavigationBar(modifier = modifier) {
Expand All @@ -484,7 +495,7 @@ private fun CrisisCleanupBottomBar(
selected = selected,
onClick = { onNavigateToDestination(destination) },
icon = { destination.Icon(selected, title) },
modifier = Modifier.testTag("navItem_${title}"),
modifier = Modifier.testTag("navItem_$title"),
label = {
Text(
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class CrisisCleanupAppHeaderUiState @Inject constructor(
override fun setTitle(title: String) {
this.title.value = title
}
}
}
Loading

0 comments on commit 1fb4245

Please sign in to comment.