Skip to content

Commit

Permalink
Merge pull request #81 from krzdabrowski/renovate/minor-and-patch-cha…
Browse files Browse the repository at this point in the history
…nges

Update dependencies for minor & patch changes
  • Loading branch information
krzdabrowski authored Sep 5, 2024
2 parents a0e1858 + ad62965 commit fea180d
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 157 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ ktlint_standard_no-blank-line-in-list = disabled
# Set signature body expression wrapping to default (even if default, it is required for multiline-expression-wrapping)
ktlint_function_signature_body_expression_wrapping = default

# Ignore forcing one-line classes into multiple lines
ktlint_standard_class-signature = disabled

# Ignore putting every dot-chain in the same line as closing parenthesis
ktlint_standard_chain-method-continuation = disabled


[*.md]
trim_trailing_whitespace = false
Expand Down
4 changes: 0 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ android {
}
}

composeCompiler {
enableStrongSkippingMode = true
}

kotlin {
jvmToolchain(17)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ internal object DatabaseModule {
@Provides
fun provideAppDatabase(
@ApplicationContext context: Context,
): AppDatabase {
return Room.databaseBuilder(
context,
AppDatabase::class.java,
APP_DATABASE_NAME,
).build()
}
): AppDatabase = Room.databaseBuilder(
context,
AppDatabase::class.java,
APP_DATABASE_NAME,
).build()

@Singleton
@Provides
fun provideRocketDao(database: AppDatabase): RocketDao {
return database.rocketDao()
}
fun provideRocketDao(database: AppDatabase): RocketDao = database.rocketDao()
}
7 changes: 2 additions & 5 deletions basic-feature/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ android {
}
}

composeCompiler {
enableStrongSkippingMode = true
}

kotlin {
jvmToolchain(17)

compilerOptions {
freeCompilerArgs.addAll(
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api"
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi"
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ import kotlinx.coroutines.flow.flowOf
internal object FakeRocketModule {

@Provides
fun provideFakeGetRocketsUseCase(): GetRocketsUseCase {
return GetRocketsUseCase {
flowOf(
Result.success(generateTestRocketsFromDomain()),
)
}
fun provideFakeGetRocketsUseCase(): GetRocketsUseCase = GetRocketsUseCase {
flowOf(
Result.success(generateTestRocketsFromDomain()),
)
}

@Provides
fun provideNoopRefreshRocketsUseCase(): RefreshRocketsUseCase {
return RefreshRocketsUseCase {
resultOf { }
}
fun provideNoopRefreshRocketsUseCase(): RefreshRocketsUseCase = RefreshRocketsUseCase {
resultOf { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,16 @@ internal object RocketModule {

@Provides
@Singleton
fun provideRocketApi(retrofit: Retrofit): RocketApi {
return retrofit.create(RocketApi::class.java)
}
fun provideRocketApi(retrofit: Retrofit): RocketApi = retrofit.create(RocketApi::class.java)

@Provides
fun provideGetRocketsUseCase(rocketRepository: RocketRepository): GetRocketsUseCase {
return GetRocketsUseCase {
getRockets(rocketRepository)
}
fun provideGetRocketsUseCase(rocketRepository: RocketRepository): GetRocketsUseCase = GetRocketsUseCase {
getRockets(rocketRepository)
}

@Provides
fun provideRefreshRocketsUseCase(rocketRepository: RocketRepository): RefreshRocketsUseCase {
return RefreshRocketsUseCase {
refreshRockets(rocketRepository)
}
fun provideRefreshRocketsUseCase(rocketRepository: RocketRepository): RefreshRocketsUseCase = RefreshRocketsUseCase {
refreshRockets(rocketRepository)
}

@Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ class RocketRepositoryImpl @Inject constructor(
private val rocketDao: RocketDao,
) : RocketRepository {

override fun getRockets(): Flow<List<Rocket>> {
return rocketDao
.getRockets()
.map { rocketsCached ->
rocketsCached.map { it.toDomainModel() }
}
.onEach { rockets ->
if (rockets.isEmpty()) {
refreshRockets()
}
override fun getRockets(): Flow<List<Rocket>> = rocketDao.getRockets()
.map { rocketsCached ->
rocketsCached.map { it.toDomainModel() }
}
.onEach { rockets ->
if (rockets.isEmpty()) {
refreshRockets()
}
}
}

override suspend fun refreshRockets() {
rocketApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ fun getRockets(rocketRepository: RocketRepository): Flow<Result<List<Rocket>>> =
false
}
}
.catch { // for other than IOException but it will stop collecting Flow
.catch {
// for other than IOException but it will stop collecting Flow
emit(Result.failure(it)) // also catch does re-throw CancellationException
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import eu.krzdabrowski.starter.basicfeature.presentation.RocketsUiState.PartialS
import eu.krzdabrowski.starter.basicfeature.presentation.RocketsUiState.PartialState.Loading
import eu.krzdabrowski.starter.basicfeature.presentation.mapper.toPresentationModel
import eu.krzdabrowski.starter.core.presentation.mvi.BaseViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
Expand All @@ -22,6 +23,8 @@ import javax.inject.Inject
private const val HTTP_PREFIX = "http"
private const val HTTPS_PREFIX = "https"

private const val ROCKETS_REFRESH_FAILURE_INDICATOR_DURATION_IN_MILLIS = 500L // to make refresh indicator visible for a while

@HiltViewModel
class RocketsViewModel @Inject constructor(
private val getRocketsUseCase: GetRocketsUseCase,
Expand Down Expand Up @@ -81,6 +84,7 @@ class RocketsViewModel @Inject constructor(
private fun refreshRockets(): Flow<PartialState> = flow<PartialState> {
refreshRocketsUseCase()
.onFailure {
delay(ROCKETS_REFRESH_FAILURE_INDICATOR_DURATION_IN_MILLIS)
emit(Error(it))
}
}.onStart {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package eu.krzdabrowski.starter.basicfeature.presentation.composable

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.pulltorefresh.PullToRefreshContainer
import androidx.compose.material3.pulltorefresh.PullToRefreshState
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.pulltorefresh.PullToRefreshBox
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
Expand Down Expand Up @@ -47,21 +42,14 @@ internal fun RocketsScreen(
onIntent: (RocketsIntent) -> Unit,
) {
val snackbarHostState = remember { SnackbarHostState() }
val pullToRefreshState = rememberPullToRefreshState()

HandlePullToRefresh(
pullState = pullToRefreshState,
uiState = uiState,
onIntent = onIntent,
)

Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
) { paddingValues ->
Box(
modifier = Modifier
.padding(paddingValues)
.nestedScroll(pullToRefreshState.nestedScrollConnection),
PullToRefreshBox(
modifier = Modifier.padding(paddingValues),
isRefreshing = uiState.isLoading,
onRefresh = { onIntent(RefreshRockets) },
) {
if (uiState.rockets.isNotEmpty()) {
RocketsAvailableContent(
Expand All @@ -74,31 +62,6 @@ internal fun RocketsScreen(
uiState = uiState,
)
}

PullToRefreshContainer(
state = pullToRefreshState,
modifier = Modifier
.align(Alignment.TopCenter),
)
}
}
}

@Composable
private fun HandlePullToRefresh(
pullState: PullToRefreshState,
uiState: RocketsUiState,
onIntent: (RocketsIntent) -> Unit,
) {
if (pullState.isRefreshing) {
LaunchedEffect(onIntent) {
onIntent(RefreshRockets)
}
}

if (uiState.isLoading.not()) {
LaunchedEffect(true) {
pullState.endRefresh()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class RocketsViewModelTest {

// Then
objectUnderTest.uiState.test {
skipItems(1) // Loading-Refreshing state

val actualItem = awaitItem()

assertTrue(actualItem.isError)
Expand Down
4 changes: 0 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ android {
}
}

composeCompiler {
enableStrongSkippingMode = true
}

kotlin {
jvmToolchain(17)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ class HiltTestRunner : AndroidJUnitRunner() {
cl: ClassLoader?,
name: String?,
context: Context?,
): Application {
return super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
): Application = super.newApplication(cl, HiltTestApplication::class.java.name, context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ internal fun <T, R> Flow<T>.flatMapConcurrently(
semaphore.release()
}
}
exceptionWasThrownEarlier.invokeOnCompletion { thrown -> // should never be null
exceptionWasThrownEarlier.invokeOnCompletion { thrown ->
// should never be null
// don't nest CancellationExceptions arbitrarily deep
evalTransform.cancel(thrown!!.asCancellation())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,24 @@ internal object NetworkModule {

@Provides
@Named(INTERCEPTOR_LOGGING_NAME)
fun provideHttpLoggingInterceptor(): Interceptor {
return if (BuildConfig.DEBUG) {
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
} else {
noOpInterceptor()
fun provideHttpLoggingInterceptor(): Interceptor = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
} else {
noOpInterceptor()
}

@Provides
@Singleton
fun provideOkHttpClient(
@Named(INTERCEPTOR_LOGGING_NAME) loggingInterceptor: Interceptor,
): OkHttpClient {
return OkHttpClient
.Builder()
.apply {
addNetworkInterceptor(loggingInterceptor)
}
.build()
}
): OkHttpClient = OkHttpClient
.Builder()
.apply {
addNetworkInterceptor(loggingInterceptor)
}
.build()

@Provides
@Singleton
Expand All @@ -62,9 +58,7 @@ internal object NetworkModule {
.build()
}

private fun noOpInterceptor(): Interceptor {
return Interceptor { chain ->
chain.proceed(chain.request())
}
private fun noOpInterceptor(): Interceptor = Interceptor { chain ->
chain.proceed(chain.request())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package eu.krzdabrowski.starter.core.utils
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.flowWithLifecycle
import kotlinx.coroutines.flow.Flow

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import kotlinx.coroutines.TimeoutCancellationException
*
* Cancellation exceptions need to be rethrown. See https://github.com/Kotlin/kotlinx.coroutines/issues/1814.
*/
inline fun <R> resultOf(block: () -> R): Result<R> {
return try {
Result.success(block())
} catch (t: TimeoutCancellationException) {
Result.failure(t)
} catch (c: CancellationException) {
throw c
} catch (e: Exception) {
Result.failure(e)
}
inline fun <R> resultOf(block: () -> R): Result<R> = try {
Result.success(block())
} catch (t: TimeoutCancellationException) {
Result.failure(t)
} catch (c: CancellationException) {
throw c
} catch (e: Exception) {
Result.failure(e)
}
Loading

0 comments on commit fea180d

Please sign in to comment.