This file contains hidden or 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
@HiltViewModel | |
class HomeScreenViewModel @Inject constructor( | |
private val imageRepository: ImageRepository | |
) : ViewModel() { | |
var state by mutableStateOf(HomeScreenState()) | |
private set | |
fun onEvent(event: HomeScreenEvents) { | |
when (event) { |
This file contains hidden or 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
@Module | |
@InstallIn(SingletonComponent::class) | |
abstract class RepositoryModule { | |
@Binds | |
@Singleton | |
abstract fun bindImageRepository( | |
imageRepositoryImpl: ImageRepositoryImpl | |
): ImageRepository | |
} |
This file contains hidden or 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
@Singleton | |
class ImageRepositoryImpl @Inject constructor( | |
private val imageApi: ImageApi | |
) : ImageRepository { | |
override fun getImages(text: String): Flow<Resources<List<Image>>> { | |
return flow { | |
emit(Resources.Loading(true)) | |
val remoteList = try { |
This file contains hidden or 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
interface ImageRepository { | |
fun getImages( | |
text: String | |
): Flow<Resources<List<Image>>> | |
} |
This file contains hidden or 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
fun ImageDto.toImage(): Image { | |
return Image( | |
id = id, | |
width = width, | |
height = height, | |
srcSmall = srcSmall, | |
src = src | |
) | |
} |
This file contains hidden or 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
data class Image( | |
var id: String, | |
var src: String, | |
var srcSmall: String, | |
var width: Int, | |
var height: Int, | |
) |
This file contains hidden or 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
import com.md.jetpackcomposemviarchitecture.data.remote.ImageApi | |
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 |
This file contains hidden or 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
import com.md.jetpackcomposemviarchitecture.data.remote.dto.ImageListDto | |
import retrofit2.http.GET | |
import retrofit2.http.Query | |
interface ImageApi { | |
@GET("search") | |
suspend fun getInfiniteApiImages( | |
@Query("q") q : String | |
): ImageListDto |
This file contains hidden or 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
<?xml version="1.0" encoding="utf-8"?> | |
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<application | |
android:name=".App" | |
android:allowBackup="true" | |
android:dataExtractionRules="@xml/data_extraction_rules" | |
android:fullBackupContent="@xml/backup_rules" | |
android:icon="@mipmap/ic_launcher" |
This file contains hidden or 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
import android.app.Application | |
import dagger.hilt.android.HiltAndroidApp | |
@HiltAndroidApp | |
class App : Application() { | |
override fun onCreate() { | |
super.onCreate() | |
} | |
} |