Skip to content

Commit

Permalink
Inter Layer Dependency Bug Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
manishkaushik900 committed Jun 27, 2023
1 parent 4ce6e35 commit 6f253cc
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 34 deletions.
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'kotlin-kapt'
// id 'kotlin-kapt'
id 'com.google.dagger.hilt.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
}

android {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.pixabay.imagesearch.data

import androidx.compose.ui.tooling.preview.PreviewParameterProvider
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.mappers.toImageModel
import com.pixabay.imagesearch.data.entities.ImageItem
import com.pixabay.imagesearch.data.entities.PixabayResponse
import com.pixabay.imagesearch.data.entities.toImageModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.pixabay.imagesearch.data
package com.pixabay.imagesearch.data.entities

import android.os.Parcelable
import com.squareup.moshi.Json
import kotlinx.android.parcel.Parcelize

data class PixabayResponse(

@Json(name="hits")
@Json(name="hits")
val hits: List<ImageItem> = listOf(),

@Json(name="total")
@Json(name="total")
val total: Int? = null,

@Json(name="totalHits")
@Json(name="totalHits")
val totalHits: Int? = null
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.pixabay.imagesearch.data
package com.pixabay.imagesearch.data.entities

import android.os.Parcelable
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import kotlinx.android.parcel.Parcelize
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel


fun ImageItem.toImageModel() = MappedImageItemModel(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pixabay.imagesearch.data.remote

import com.pixabay.imagesearch.data.PixabayResponse
import com.pixabay.imagesearch.data.entities.PixabayResponse
import retrofit2.http.GET
import retrofit2.http.Query

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.pixabay.imagesearch.data.repository

import com.pixabay.imagesearch.data.ImageItem
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.mappers.toImageModel
import com.pixabay.imagesearch.data.entities.toImageModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.pixabay.imagesearch.domain.repositories.ImageSearchRepository
import javax.inject.Inject

Expand All @@ -15,16 +14,12 @@ class ImageSearchRepositoryImpl @Inject constructor(
return try {
val result = networkDataSource.fetchSearchData(query = query)

if(result.hits.isNullOrEmpty()){
if(result.hits.isEmpty()){
throw IllegalStateException("Empty product list")
}
result.hits.map {
it.toImageModel()
}
// ifEmpty {
// throw IllegalStateException("Empty product list")
// }

} catch (e: Exception) {
throw e
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pixabay.imagesearch.data.repository

import com.pixabay.imagesearch.data.remote.ApiService
import com.pixabay.imagesearch.data.PixabayResponse
import com.pixabay.imagesearch.data.entities.PixabayResponse
import javax.inject.Inject

/*Network data source to fetch data from server using api service client*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.pixabay.imagesearch.domain.mappers
package com.pixabay.imagesearch.domain.entities

import android.os.Parcelable
import kotlinx.android.parcel.Parcelize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pixabay.imagesearch.domain.repositories

import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel

interface ImageSearchRepository {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pixabay.imagesearch.domain.usecases

import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.pixabay.imagesearch.domain.repositories.ImageSearchRepository
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import androidx.compose.runtime.Composable
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.pixabay.imagesearch.data.ImageItem
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.pixabay.imagesearch.ui.searchImage.ImageDetailScreen


Expand Down Expand Up @@ -54,6 +53,7 @@ enum class AppScreens {
ImageDetail
}

/*
val dummyImageItem = ImageItem(
webformatHeight = 426,
imageWidth = 4752,
Expand All @@ -70,4 +70,4 @@ val dummyImageItem = ImageItem(
largeImageURL = "https://pixabay.com/get/gd633530a25ff1a68c565f37e278c215b78650926392edf43841971bfc710c6dd449b49794fd4d786d7f7e926a6006695_1280.jpg",
views = 944821,
likes = 1889
)
)*/
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@ import androidx.compose.ui.unit.dp
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.pixabay.imagesearch.R
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.mappers.toImageModel
import com.pixabay.imagesearch.ui.commons.dummyImageItem
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.pixabay.imagesearch.ui.commons.ImageDownloader



@Composable
internal fun ImageDetailScreen(result: MappedImageItemModel, onBackClicked: () -> Unit) {
val downloadManager = ImageDownloader(LocalContext.current)
Expand Down Expand Up @@ -214,7 +211,7 @@ fun DetailBottomCard(
fun SearchScreenPreview() {
MaterialTheme {
Surface {
ImageDetailScreen(dummyImageItem.toImageModel()) {}
// ImageDetailScreen(dummyImageItem.toImageModel()) {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.pixabay.imagesearch.ui.searchImage

import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel


internal data class SearchImageState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import coil.request.ImageRequest
import com.pixabay.imagesearch.R
import com.pixabay.imagesearch.domain.mappers.MappedImageItemModel
import com.pixabay.imagesearch.domain.entities.MappedImageItemModel
import com.pixabay.imagesearch.ui.commons.AnimatedShimmer
import com.pixabay.imagesearch.ui.searchImage.ImageSearchViewModel
import com.pixabay.imagesearch.ui.searchImage.SearchImageEvent
Expand Down

0 comments on commit 6f253cc

Please sign in to comment.