refactor: merge ClusterNetwotkModule into NetworkModule
This commit is contained in:
parent
c216c02520
commit
3a096f342c
|
|
@ -5,7 +5,6 @@ import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.appModule
|
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.networkModule
|
||||||
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.viewModelModule
|
import com.syaroful.agrilinkvocpro.growth_recipe_feature.di.viewModelModule
|
||||||
import com.syaroful.agrilinkvocpro.growth_recipe_feature.naviagtion.SetupNavigation
|
import com.syaroful.agrilinkvocpro.growth_recipe_feature.naviagtion.SetupNavigation
|
||||||
|
|
@ -17,18 +16,17 @@ class GrowthRecipeActivity : ComponentActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
loadKoinModules(listOf(appModule, networkModule, clusterNetworkModule, viewModelModule))
|
loadKoinModules(listOf(appModule, networkModule, viewModelModule))
|
||||||
enableEdgeToEdge()
|
enableEdgeToEdge()
|
||||||
setContent {
|
setContent {
|
||||||
AgrilinkVocproTheme {
|
AgrilinkVocproTheme {
|
||||||
SetupNavigation()
|
SetupNavigation()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
unloadKoinModules(listOf(appModule, networkModule, clusterNetworkModule, viewModelModule))
|
unloadKoinModules(listOf(appModule, networkModule, viewModelModule))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -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) }
|
|
||||||
}
|
|
||||||
|
|
@ -1,26 +1,57 @@
|
||||||
package com.syaroful.agrilinkvocpro.growth_recipe_feature.di
|
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 com.syaroful.agrilinkvocpro.growth_recipe_feature.data.network.GrowthRecipeService
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
import org.koin.core.qualifier.named
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
import retrofit2.Retrofit
|
import retrofit2.Retrofit
|
||||||
import retrofit2.converter.gson.GsonConverterFactory
|
import retrofit2.converter.gson.GsonConverterFactory
|
||||||
import java.util.concurrent.TimeUnit
|
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 {
|
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()
|
OkHttpClient.Builder()
|
||||||
.connectTimeout(2, TimeUnit.SECONDS)
|
.connectTimeout(2, TimeUnit.SECONDS)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
single {
|
single(RECIPE_RETROFIT) {
|
||||||
Retrofit.Builder()
|
Retrofit.Builder()
|
||||||
.baseUrl("http://labai.polinema.ac.id:3042/")
|
.baseUrl("http://labai.polinema.ac.id:3042/")
|
||||||
.client(get())
|
.client(get(RECIPE_CLIENT))
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
single<GrowthRecipeService> { get<Retrofit>().create(GrowthRecipeService::class.java) }
|
single<GrowthRecipeService> {
|
||||||
|
get<Retrofit>(RECIPE_RETROFIT).create(GrowthRecipeService::class.java)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,6 @@ fun GrowthRecipeScreen(
|
||||||
}
|
}
|
||||||
when (graphicState) {
|
when (graphicState) {
|
||||||
is ResultState.Loading -> {
|
is ResultState.Loading -> {
|
||||||
isRefreshing.value = true
|
|
||||||
Row {
|
Row {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import java.util.Date
|
||||||
|
|
||||||
|
|
||||||
private const val TAG = "GrowthRecipeViewModel"
|
private const val TAG = "GrowthRecipeViewModel"
|
||||||
|
|
||||||
class GrowthRecipeViewModel(
|
class GrowthRecipeViewModel(
|
||||||
private val userPreferences: UserPreferences,
|
private val userPreferences: UserPreferences,
|
||||||
private val growthRecipeRepository: GraphicDataRepository
|
private val growthRecipeRepository: GraphicDataRepository
|
||||||
|
|
@ -25,7 +26,8 @@ class GrowthRecipeViewModel(
|
||||||
|
|
||||||
private val _getGraphicState =
|
private val _getGraphicState =
|
||||||
MutableStateFlow<ResultState<NpkGraphicDayResponse>>(ResultState.Idle)
|
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 today = Date()
|
||||||
private val tenDaysAgo = Date(today.time - 9 * 24 * 60 * 60 * 1000)
|
private val tenDaysAgo = Date(today.time - 9 * 24 * 60 * 60 * 1000)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user