Skip to content

Commit

Permalink
Merge pull request #13 from Louiixx-h/improvement/replace-xml-for-jet…
Browse files Browse the repository at this point in the history
…pack-compose

[IMPROVEMENT] - Replace xml for jetpack compose
  • Loading branch information
Louiixx-h committed Oct 14, 2023
2 parents 5a9a084 + 0d73897 commit 1adb824
Show file tree
Hide file tree
Showing 57 changed files with 765 additions and 799 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci_pipeline.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: cute-cat-gallery-ci-pipeline
on:
pull_request:
branches: [main]
branches: [main, develop]
push:
branches: [main]
branches: [main, develop]
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -22,6 +22,11 @@ jobs:
with:
arguments: build
gradle-version: 7.6
- name: Run KLint
uses: gradle/gradle-build-action@v2.9.0
with:
arguments: ktlintCheck
gradle-version: 7.6
- name: Run Tests
uses: gradle/gradle-build-action@v2.9.0
with:
Expand Down
80 changes: 53 additions & 27 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,65 +1,91 @@
plugins {
id 'com.android.application'
id 'kotlin-android'
id "com.android.application"
id "kotlin-android"
}

android {
compileSdk 33

viewBinding {
enabled = true
}
compileSdk 34

defaultConfig {
applicationId "com.luishenrique.cutecatsgallery"
minSdk 21
targetSdkVersion 33
minSdkVersion 21
targetSdkVersion 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
debuggable = true
buildConfigField "String", "API_URL", "\"https://api.imgur.com/3/\""
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
release {
minifyEnabled true
buildConfigField "String", "API_URL", "\"https://api.imgur.com/3/\""
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '17'
jvmTarget = "17"
}
composeOptions {
kotlinCompilerExtensionVersion = compose_compiler_version
}
namespace "com.luishenrique.cutecatsgallery"

buildFeatures {
compose = true
}
namespace 'com.luishenrique.cutecatsgallery'
}

dependencies {

api project(path: ':domain')
// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"

// Compose
implementation platform("androidx.compose:compose-bom:2023.10.00")
implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
implementation "androidx.activity:activity-compose:1.8.0"
implementation "androidx.compose.material3:material3:1.1.2"
implementation "androidx.compose.material:material-android:1.5.3"
implementation "io.coil-kt:coil-compose:2.4.0"
implementation "androidx.navigation:navigation-compose:2.7.4"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
androidTestImplementation platform("androidx.compose:compose-bom:2023.10.00")
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"

implementation 'com.google.accompanist:accompanist-swiperefresh:0.32.0'

// progressbar cat
implementation 'com.roger.catloadinglibrary:catloadinglibrary:1.0.9'
implementation "com.roger.catloadinglibrary:catloadinglibrary:1.0.9"

// glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation "com.github.bumptech.glide:glide:4.15.1"

// coroutines
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-RC'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3"

// koin
implementation 'org.koin:koin-android-viewmodel:2.1.6'
implementation "io.insert-koin:koin-android:$koin_version"

// viewmodel
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.0'
// viewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2"

implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
implementation "androidx.core:core-ktx:1.12.0"
implementation "com.google.android.material:material:1.10.0"
implementation "androidx.appcompat:appcompat:1.6.1"
testImplementation "junit:junit:4.13.2"
androidTestImplementation "androidx.test.ext:junit:1.1.5"
androidTestImplementation "androidx.test.espresso:espresso-core:3.5.1"
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
android:supportsRtl="true"
android:theme="@style/Theme.CuteCatsGallery">
<activity
android:name=".ui.view.HomeActivity"
android:name=".home.presentation.HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
14 changes: 2 additions & 12 deletions app/src/main/kotlin/com/luishenrique/cutecatsgallery/App.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package com.luishenrique.cutecatsgallery

import android.app.Application
import com.luishenrique.cutecatsgallery.di.viewModelModule
import com.luishenrique.domain.di.apiServiceModule
import com.luishenrique.domain.di.repositoryModule
import com.luishenrique.domain.di.useCaseModule
import com.luishenrique.cutecatsgallery.di.DependencyInjection
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

Expand All @@ -15,14 +12,7 @@ class App : Application() {

startKoin {
androidContext(this@App)
modules(
listOf(
viewModelModule,
apiServiceModule,
repositoryModule,
useCaseModule,
)
)
modules(DependencyInjection.modules)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.luishenrique.cutecatsgallery.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

abstract class BaseViewModel : ViewModel() {
protected fun <T> request(
block: suspend () -> T,
onStartRequest: () -> Unit = {},
onSuccess: (T) -> Unit,
onError: (ErrorContent) -> Unit,
onFinally: () -> Unit = {}
) : Job {
return viewModelScope.launch {
onStartRequest.invoke()
runCatching {
val response = withContext(Dispatchers.IO) { block.invoke() }
onSuccess.invoke(response)
}.onFailure {
onError.invoke(ErrorContent(it.message.toString(), it))
}
onFinally.invoke()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.luishenrique.cutecatsgallery.base

data class ErrorContent(
val message: String,
val throwable: Throwable
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.luishenrique.cutecatsgallery.commonComponents

import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarColors
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun Toolbar(
colors: TopAppBarColors = TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
titleContentColor = MaterialTheme.colorScheme.primary,
),
title: @Composable () -> Unit
) {
TopAppBar(
colors = colors,
title = {
title.invoke()
}
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.luishenrique.cutecatsgallery.di

import com.luishenrique.cutecatsgallery.home.di.HomeModule

object DependencyInjection {
val modules = listOf(
RetrofitModule.instance,
HomeModule.instance
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.luishenrique.cutecatsgallery.di

import com.luishenrique.cutecatsgallery.BuildConfig
import com.luishenrique.cutecatsgallery.network.CuteCatsInterceptor
import okhttp3.OkHttpClient
import org.koin.core.module.dsl.factoryOf
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.module
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitModule {
val instance = module {
factoryOf(::CuteCatsInterceptor)
factoryOf(::provideOkHttpClient)
singleOf(::provideRetrofit)
}

private fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl(BuildConfig.API_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create()).build()
}

private fun provideOkHttpClient(interceptor: CuteCatsInterceptor): OkHttpClient {
return OkHttpClient().newBuilder().addInterceptor(interceptor).build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.luishenrique.cutecatsgallery.home.data.dataSource

import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse

interface GalleryDataSource {
suspend fun finAllCats(page: Int): GalleryResponse

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.luishenrique.cutecatsgallery.home.data.dataSource

import com.luishenrique.cutecatsgallery.home.data.network.HomeApiService
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse

class GalleryDataSourceImpl(private val service: HomeApiService) : GalleryDataSource {

override suspend fun finAllCats(page: Int): GalleryResponse {
return service.finAllCats(page = page)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.luishenrique.cutecatsgallery.home.data.mapper

import com.luishenrique.cutecatsgallery.home.data.network.response.CardImageInfoResponse
import com.luishenrique.cutecatsgallery.home.data.network.response.CardImageResponse
import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse
import com.luishenrique.cutecatsgallery.home.domain.model.CardImage
import com.luishenrique.cutecatsgallery.home.domain.model.CardImageInfo
import com.luishenrique.cutecatsgallery.home.domain.model.Gallery

object GalleryMapper {

fun mapToModel(response: GalleryResponse) : Gallery {
return Gallery(
data = getCards(response.data)
)
}

private fun getCards(data: List<CardImageResponse?>?): List<CardImage> {
return data?.map { getCardImage(it) }.orEmpty()
}

private fun getCardImage(cardImage: CardImageResponse?) : CardImage {
return CardImage(
title = cardImage?.title.orEmpty(),
username = cardImage?.username.orEmpty(),
score = cardImage?.score ?: 0,
images = getImages(cardImage?.images).orEmpty()
)
}

private fun getImages(images: List<CardImageInfoResponse>?): List<CardImageInfo>? {
return images?.map { getCardImageInfo(it) }
}

private fun getCardImageInfo(cardImageInfo: CardImageInfoResponse?) : CardImageInfo {
return CardImageInfo(
type = cardImageInfo?.type.orEmpty(),
link = cardImageInfo?.link.orEmpty(),
gifv = cardImageInfo?.gifv.orEmpty(),
mp4 = cardImageInfo?.mp4.orEmpty()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.luishenrique.cutecatsgallery.home.data.network

import com.luishenrique.cutecatsgallery.home.data.network.response.GalleryResponse
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface HomeApiService {

@GET("gallery/search/?q=cats")
suspend fun finAllCats(
@Header("Authorization") authHeader: String = "Client-ID 1ceddedc03a5d71",
@Query("sort") sort: String = "viral",
@Query("q_type") type: String = "jpg",
@Query("q_size_px") size: String = "big",
@Query("page") page: Int = 1
): GalleryResponse
}
Loading

0 comments on commit 1adb824

Please sign in to comment.