Skip to content

Commit

Permalink
Merge pull request #44 from manununhez/epic/40-code-improvement
Browse files Browse the repository at this point in the history
epic/40-code-improvement
  • Loading branch information
manununhez authored Apr 16, 2024
2 parents 9791be0 + 6bf7031 commit 2f533db
Show file tree
Hide file tree
Showing 49 changed files with 727 additions and 317 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# PurrfectPics
# PurrfectPics ![ic_launcher_round](https://github.com/manununhez/purrfect-pics/assets/5048531/1fab47b6-03fb-4901-b6c9-0fe60cbaecd1)

PurrfectPics is your ultimate companion for discovering, customizing, and sharing adorable cat
images on Android. With a wide range of features, PurrfectPics brings joy to every cat lover's
Expand All @@ -16,23 +16,29 @@ heart.

### Android Libraries

- **UI Components:** [AndroidX Core KTX](https://developer.android.com/jetpack/androidx/releases/core) | [Material Components for Android](https://github.com/material-components/material-components-android) | [Compose UI](https://developer.android.com/jetpack/androidx/releases/compose-ui)
- **Testing:** [JUnit](https://junit.org/junit5/) | [MockK](https://mockk.io/) | [Turbine](https://github.com/cashapp/turbine)
- **Dependency Injection:** [Hilt](https://developer.android.com/training/dependency-injection/hilt-android)
- **UI Components:
** [AndroidX Core KTX](https://developer.android.com/jetpack/androidx/releases/core) | [Material Components for Android](https://github.com/material-components/material-components-android) | [Compose UI](https://developer.android.com/jetpack/androidx/releases/compose-ui)
- **Testing:
** [JUnit](https://junit.org/junit5/) | [MockK](https://mockk.io/) | [Turbine](https://github.com/cashapp/turbine)
- **Dependency Injection:
** [Hilt](https://developer.android.com/training/dependency-injection/hilt-android)
- **Coroutines:** [Kotlin Coroutines](https://kotlinlang.org/docs/coroutines-overview.html)
- **Networking:** [Retrofit](https://square.github.io/retrofit/)
- **Image Loading:** [Coil](https://coil-kt.github.io/coil/)

### Compose Libraries

- **UI Components:** [Material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) | [Compose UI](https://developer.android.com/jetpack/androidx/releases/compose-ui)
- **Navigation:** [Navigation Compose](https://developer.android.com/jetpack/androidx/releases/navigation) | [Hilt Navigation Compose](https://developer.android.com/training/dependency-injection/hilt-android#navigation-compose)
- **Material Design:** [Material Components for Android](https://github.com/material-components/material-components-android)
- **UI Components:
** [Material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) | [Compose UI](https://developer.android.com/jetpack/androidx/releases/compose-ui)
- **Navigation:
** [Navigation Compose](https://developer.android.com/jetpack/androidx/releases/navigation) | [Hilt Navigation Compose](https://developer.android.com/training/dependency-injection/hilt-android#navigation-compose)
- **Material Design:
** [Material Components for Android](https://github.com/material-components/material-components-android)

## Screenshots

| ![Screenshot 2024-04-15 at 6 34 16 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/a8024c0c-e31f-4189-b268-1167048658ad) | ![Screenshot 2024-04-15 at 6 35 33 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/1a72c5ea-ee22-4470-8e98-6215ebb86924) | ![Screenshot 2024-04-15 at 6 36 08 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/c31637d7-ddfe-436a-8e16-d27244d638ea) |
|---|---|---|
| ![Screenshot 2024-04-16 at 10 26 30 AM](https://github.com/manununhez/purrfect-pics/assets/5048531/c08f645e-a362-4d2e-bfff-c99d8966e2b8) | ![Screenshot 2024-04-15 at 6 34 16 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/a8024c0c-e31f-4189-b268-1167048658ad) | ![Screenshot 2024-04-15 at 6 35 33 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/1a72c5ea-ee22-4470-8e98-6215ebb86924) | ![Screenshot 2024-04-15 at 6 36 08 PM](https://github.com/manununhez/purrfect-pics/assets/5048531/c31637d7-ddfe-436a-8e16-d27244d638ea) |
|------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|

## Considerations

Expand All @@ -44,7 +50,8 @@ heart.
the other hand, Coil image lib does use disk and memory cache to smooth image loading.
- KtfmtFormat plugin applied for code formatting.
- There is a known issue with the splash screen not showing on Android 12. A temporary
solution is to **open the app from the app tray**, as indicated [here](https://stackoverflow.com/questions/69812590/android-12-splash-screen-icon-not-displaying))
solution is to **open the app from the app tray**, as
indicated [here](https://stackoverflow.com/questions/69812590/android-12-splash-screen-icon-not-displaying))

## Getting Started

Expand Down Expand Up @@ -82,4 +89,4 @@ PurrfectPics is licensed under the [MIT License](LICENSE).
## About

PurrfectPics is developed and maintained by [Manuel Nuñez](mailto:[email protected]). For
inquiries, please contact [[email protected]].
inquiries, please contact [[email protected]].
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ android {
}

dependencies {
implementation(projects.core.commonUi)
implementation(projects.core.ui)
implementation(projects.core.data)
implementation(projects.core.domain)
implementation(projects.features.home.ui)
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.manuelnunez.apps.core.common

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

class EitherTest {

@Test
fun `test fold with success`() {
val successData = 42
val successValue: Either<Int, String> = eitherSuccess(successData)
val result = successValue.fold(success = { "Success: $it" }, error = { "Error: $it" })

assertEquals(Either.Success(successData), successValue)
assertEquals("Success: $successData", result)
}

@Test
fun `test fold with error`() {
val messageError = "An error occurred"
val errorValue: Either<Int, String> = eitherError(messageError)
val result = errorValue.fold(success = { "Success: $it" }, error = { "Error: $it" })

assertEquals(Either.Error(messageError), errorValue)
assertEquals(messageError, result)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.paging.PagingData
import com.manuelnunez.apps.core.common.Either
import com.manuelnunez.apps.core.common.eitherError
import com.manuelnunez.apps.core.common.eitherSuccess
import com.manuelnunez.apps.core.common.fold
import com.manuelnunez.apps.core.data.PAGE_SIZE
import com.manuelnunez.apps.core.data.PREFETCH_DISTANCE
import com.manuelnunez.apps.core.data.datasource.paging.CataasCatsPagingSource
Expand All @@ -15,7 +16,6 @@ import com.manuelnunez.apps.core.services.executors.RetrofitServiceRequest
import com.manuelnunez.apps.core.services.executors.ServiceError
import com.manuelnunez.apps.core.services.executors.ServicesExecutor
import com.manuelnunez.apps.core.services.service.CataasService
import com.manuelnunez.apps.core.services.util.Result
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

Expand All @@ -33,8 +33,14 @@ constructor(private val servicesExecutor: ServicesExecutor, private val apiServi
override fun getItems(): Either<List<CataasResponseDTO>, ServiceError> {
val response = servicesExecutor.execute(RetrofitServiceRequest(apiService.searchCats()))

return if (response is Result.Success) eitherSuccess(response.data.data)
else eitherError((response as Result.Error).exception)
return response.fold(
success = {
eitherSuccess(it.data)
},
error = {
eitherError(it)
}
)
}

override fun getAllItems(): Flow<PagingData<Item>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.paging.PagingData
import com.manuelnunez.apps.core.common.Either
import com.manuelnunez.apps.core.common.eitherError
import com.manuelnunez.apps.core.common.eitherSuccess
import com.manuelnunez.apps.core.common.fold
import com.manuelnunez.apps.core.data.PAGE_SIZE
import com.manuelnunez.apps.core.data.PREFETCH_DISTANCE
import com.manuelnunez.apps.core.data.datasource.paging.PexeelsCatsPagingSource
Expand All @@ -15,7 +16,6 @@ import com.manuelnunez.apps.core.services.executors.RetrofitServiceRequest
import com.manuelnunez.apps.core.services.executors.ServiceError
import com.manuelnunez.apps.core.services.executors.ServicesExecutor
import com.manuelnunez.apps.core.services.service.PexelsService
import com.manuelnunez.apps.core.services.util.Result
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

Expand All @@ -33,8 +33,14 @@ constructor(private val servicesExecutor: ServicesExecutor, private val apiServi
override fun getItems(): Either<PexelsSearchResponseDTO, ServiceError> {
val response = servicesExecutor.execute(RetrofitServiceRequest(apiService.searchCats()))

return if (response is Result.Success) eitherSuccess(response.data.data)
else eitherError((response as Result.Error).exception)
return response.fold(
success = {
eitherSuccess(it.data)
},
error = {
eitherError(it)
}
)
}

override fun getAllItems(): Flow<PagingData<Item>> =
Expand Down
Loading

0 comments on commit 2f533db

Please sign in to comment.