Skip to content

Instantly share code, notes, and snippets.

View cp-hardik-p's full-sized avatar

hardik parmar cp-hardik-p

View GitHub Profile
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {}
@InstallIn(SingletonComponent::class)
@InstallIn(SingletonComponent::class)
@Module
object NetworkModule {
@Singleton
@Provides
fun provideRetrofit(): Retrofit {
return Retrofit.Builder()
.baseUrl("https://howtodoandroid.com/apis/")
.addConverterFactory(GsonConverterFactory.create())
@AndroidEntryPoint
class MainActivity : ComponentActivity() {}
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetpackTheme {
val mainViewModel = hiltViewModel<MainViewModel>()
// A surface container using the 'background' color from the theme
@HiltViewModel
class MainViewModel @Inject constructor(private val apiService: ApiService) : ViewModel() {
var movieListResponse: List<Movie> by mutableStateOf(listOf())
var errorMessage: String by mutableStateOf("")
fun getMovieList() {
viewModelScope.launch {
try {
val movieList = apiService.getMovies()
movieListResponse = movieList
} catch (e: Exception) {
dependencies {
implementation(libs.timber)
}
dependencies{
implementation(libs.retrofit)
implementation(libs.converter.gson)
implementation(libs.adapter.rxjava3)
}
dependencies{
implementation(libs.bundles.retrofit.bundle)
}
enableFeaturePreview("VERSION_CATALOGS")