Last active
August 25, 2023 00:28
-
-
Save rogergcc/b516ef9019d38da4be5ddc1e2e4f7b44 to your computer and use it in GitHub Desktop.
Manual Inyection VM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val viewModel by viewModels<MovieViewModel> { | |
MovieViewModelFactory( | |
IMovieRepositoryImpl( | |
RemoteMovieDataSource(RetrofitClient.webservice), | |
LocalMovieDataSource(AppDatabase.getDatabase(requireContext()).movieDao()) | |
) | |
) | |
} | |
//2 not arguments | |
//private val viewModel by viewModels<MovieViewModel>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MovieFragment : Fragment(R.layout.fragment_movie) | |
// ,MoviesAdapter.OnMovieClickListener { | |
override fun onMovieClick(movie: MovieResponse) { | |
val action = MovieFragmentDirections.actionMovieFragmentToMovieDetailFragment( | |
movie.poster_path, | |
movie.backdrop_path!!, | |
movie.vote_average.toFloat(), | |
movie.vote_count, | |
movie.overview, | |
movie.title, | |
movie.original_language, | |
movie.release_date | |
) | |
findNavController().navigate(action) | |
} | |
/////////////////////////////////// | |
class MoviesAdapter( | |
// private val itemClickListener: OnMovieClickListener, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MovieViewModelFactory(private val repo: IMovieRepository) : ViewModelProvider.Factory { | |
override fun <T : ViewModel> create(modelClass: Class<T>): T { | |
return modelClass.getConstructor(IMovieRepository::class.java).newInstance(repo) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RetrofitClient { | |
val webservice by lazy { | |
Retrofit.Builder() | |
.baseUrl(AppConstants.BASE_URL) | |
.addConverterFactory(GsonConverterFactory.create(GsonBuilder().create())) | |
.build().create(ApiService::class.java) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment