refactor: merge ClusterNetwotkModule into NetworkModule

This commit is contained in:
Cutiful 2025-07-11 09:24:16 +07:00
parent c216c02520
commit 3a096f342c
5 changed files with 40 additions and 36 deletions

View File

@ -5,7 +5,6 @@ import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.appModule
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.clusterNetworkModule
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.networkModule
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.viewModelModule
import com.syaroful.agrilinkvocpro.growth_recipe_feature.naviagtion.SetupNavigation
@ -17,18 +16,17 @@ class GrowthRecipeActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loadKoinModules(listOf(appModule, networkModule, clusterNetworkModule, viewModelModule))
loadKoinModules(listOf(appModule, networkModule, viewModelModule))
enableEdgeToEdge()
setContent {
AgrilinkVocproTheme {
SetupNavigation()
}
}
}
override fun onDestroy() {
super.onDestroy()
unloadKoinModules(listOf(appModule, networkModule, clusterNetworkModule, viewModelModule))
unloadKoinModules(listOf(appModule, networkModule, viewModelModule))
}
}

View File

@ -1,26 +0,0 @@
package com.syaroful.agrilinkvocpro.growth_recipe_feature.di
import com.syaroful.agrilinkvocpro.growth_recipe_feature.data.network.ClusteringService
import okhttp3.OkHttpClient
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
val clusterNetworkModule = module {
single {
OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.build()
}
single {
Retrofit.Builder()
.baseUrl("http://labai.polinema.ac.id:5050/")
.client(get())
.addConverterFactory(GsonConverterFactory.create())
.build()
}
single<ClusteringService> { get<Retrofit>().create(ClusteringService::class.java) }
}

View File

@ -1,26 +1,57 @@
package com.syaroful.agrilinkvocpro.growth_recipe_feature.di
import com.syaroful.agrilinkvocpro.growth_recipe_feature.data.network.ClusteringService
import com.syaroful.agrilinkvocpro.growth_recipe_feature.data.network.GrowthRecipeService
import okhttp3.OkHttpClient
import org.koin.core.qualifier.named
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit
val CLUSTER_CLIENT = named("CLUSTER_CLIENT")
val CLUSTER_RETROFIT = named("CLUSTER_RETROFIT")
val RECIPE_CLIENT = named("RECIPE_CLIENT")
val RECIPE_RETROFIT = named("RECIPE_RETROFIT")
val networkModule = module {
single {
// Cluster client and retrofit
single(CLUSTER_CLIENT) {
OkHttpClient.Builder()
.connectTimeout(5, TimeUnit.SECONDS)
.build()
}
single(CLUSTER_RETROFIT) {
Retrofit.Builder()
.baseUrl("http://labai.polinema.ac.id:5050/")
.client(get(CLUSTER_CLIENT))
.addConverterFactory(GsonConverterFactory.create())
.build()
}
single<ClusteringService> {
get<Retrofit>(CLUSTER_RETROFIT).create(ClusteringService::class.java)
}
// Growth Recipe client and retrofit
single(RECIPE_CLIENT) {
OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.SECONDS)
.build()
}
single {
single(RECIPE_RETROFIT) {
Retrofit.Builder()
.baseUrl("http://labai.polinema.ac.id:3042/")
.client(get())
.client(get(RECIPE_CLIENT))
.addConverterFactory(GsonConverterFactory.create())
.build()
}
single<GrowthRecipeService> { get<Retrofit>().create(GrowthRecipeService::class.java) }
single<GrowthRecipeService> {
get<Retrofit>(RECIPE_RETROFIT).create(GrowthRecipeService::class.java)
}
}

View File

@ -137,7 +137,6 @@ fun GrowthRecipeScreen(
}
when (graphicState) {
is ResultState.Loading -> {
isRefreshing.value = true
Row {
Box(
modifier = Modifier

View File

@ -18,6 +18,7 @@ import java.util.Date
private const val TAG = "GrowthRecipeViewModel"
class GrowthRecipeViewModel(
private val userPreferences: UserPreferences,
private val growthRecipeRepository: GraphicDataRepository
@ -25,7 +26,8 @@ class GrowthRecipeViewModel(
private val _getGraphicState =
MutableStateFlow<ResultState<NpkGraphicDayResponse>>(ResultState.Idle)
val getGraphicState: StateFlow<ResultState<NpkGraphicDayResponse>> = _getGraphicState.asStateFlow()
val getGraphicState: StateFlow<ResultState<NpkGraphicDayResponse>> =
_getGraphicState.asStateFlow()
private val today = Date()
private val tenDaysAgo = Date(today.time - 9 * 24 * 60 * 60 * 1000)