Skip to content

Commit

Permalink
add okhttplogging
Browse files Browse the repository at this point in the history
  • Loading branch information
fjr619 committed May 13, 2024
1 parent 182d46b commit aceff10
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ dependencies {
//Retrofit
implementation ("com.squareup.retrofit2:retrofit:2.9.0")
implementation ("com.squareup.retrofit2:converter-gson:2.9.0")
implementation ("com.squareup.okhttp3:logging-interceptor:4.12.0")

// //Kotlinx Serialization
// implementation ("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/fjr619/newsloc/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import javax.inject.Singleton
Expand All @@ -27,8 +29,12 @@ object AppModule {
@Provides
@Singleton
fun provideApiInstance(): NewsApi {
val interceptor = HttpLoggingInterceptor()
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY)
val client = OkHttpClient.Builder().addInterceptor(interceptor).build()
return Retrofit
.Builder()
.client(client)
.baseUrl(Constants.BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
Expand Down Expand Up @@ -37,6 +38,7 @@ import com.fjr619.newsloc.util.snackbar.LocalSnackbarController
import com.fjr619.newsloc.util.snackbar.asString

val LocalAnimatedVisibilityScope = staticCompositionLocalOf<AnimatedVisibilityScope> { error("") }
var refreshHome = false

@OptIn(ExperimentalSharedTransitionApi::class)
@Composable
Expand Down Expand Up @@ -66,11 +68,12 @@ fun NewsGraph(
val viewModel: HomeViewModel = hiltViewModel()
val detailViewModel: DetailViewModel =
from.hiltSharedViewModel(navController = navController)

val items = viewModel.news.collectAsLazyPagingItems()

CompositionLocalProvider(value = LocalAnimatedVisibilityScope provides this@composable) {
HomeScreen(
paddingValues = paddingValues,
articles = viewModel.news.collectAsLazyPagingItems(),
articles = items,
navigateToSearch = newsNavController::navigateToBottomBarRoute,
navigateToDetail = {
detailViewModel.onEvent(DetailEvent.GetDetailArticle(it))
Expand All @@ -79,7 +82,7 @@ fun NewsGraph(
},
pullToRefreshLayoutState = viewModel.pullToRefreshState,
onRefresh = {
viewModel.onEvent(HomeEvent.GetArticles)
items.refresh()
},
onExitApp = {
activity?.finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,17 @@ import kotlinx.coroutines.flow.drop
import kotlin.math.abs

@SuppressLint("RememberReturnType")
@OptIn(ExperimentalMaterial3Api::class, ExperimentalFoundationApi::class)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun SwipeBox(
modifier: Modifier = Modifier,
onDelete: () -> Unit,
content: @Composable () -> Unit
) {

val threshold by remember {
mutableStateOf(150.dp)
}
val view = LocalView.current
val icon: ImageVector = Icons.Outlined.Delete
val alignment: Alignment = Alignment.CenterEnd
Expand All @@ -58,7 +61,7 @@ fun SwipeBox(
derivedStateOf {
mutableStateOf(
abs(offset) >= with(density) {
{ 150.dp.toPx() }
{ threshold.toPx() }
}.invoke()
).value
}
Expand All @@ -74,21 +77,20 @@ fun SwipeBox(
} else false
},
positionalThreshold = with(density) {
{ 150.dp.toPx() }
{ threshold.toPx() }
}
)

val iconSize = animateDpAsState(
targetValue = if (offsetMatch) {
40.dp
35.dp
} else {
24.dp
}, label = ""
).value

when (swipeState.dismissDirection) {
SwipeToDismissBoxValue.EndToStart -> {

color = animateColorAsState(
targetValue = if (offsetMatch) {
MaterialTheme.colorScheme.errorContainer
Expand Down Expand Up @@ -141,25 +143,4 @@ fun SwipeBox(
) {
content()
}

// when (swipeState.currentValue) {
// SwipeToDismissBoxValue.EndToStart -> {
// LaunchedEffect(swipeState) {
// onDelete()
// swipeState.snapTo(SwipeToDismissBoxValue.Settled)
// }
// }
//
// else -> {}

// SwipeToDismissBoxValue.StartToEnd -> {
// LaunchedEffect(swipeState) {
//// onEdit()
// swipeState.snapTo(SwipeToDismissBoxValue.Settled)
// }
// }
//
// SwipeToDismissBoxValue.Settled -> {
// }
// }
}

0 comments on commit aceff10

Please sign in to comment.