From 972669fa658e90cbd7f1bbf407b9598e23f8964c Mon Sep 17 00:00:00 2001 From: Antonio Jorge Garcia Tranin Date: Mon, 6 May 2024 10:02:58 -0400 Subject: [PATCH 1/3] feat: add save galleries list in room db --- .../response/TattooClientProfileResponse.kt | 8 ++++++-- .../java/br/com/connectattoo/data/Gallery.kt | 11 +++++++++++ .../connectattoo/data/TattooClientProfile.kt | 3 ++- .../entity/TattooClientProfileEntity.kt | 19 +++++++++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 app/src/main/java/br/com/connectattoo/data/Gallery.kt diff --git a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt index 7214e8a..87ac9b4 100644 --- a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt +++ b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt @@ -1,6 +1,8 @@ package br.com.connectattoo.api.response +import br.com.connectattoo.data.Gallery import br.com.connectattoo.data.Tag +import br.com.connectattoo.data.toGalleryList import br.com.connectattoo.data.toTagEntity import br.com.connectattoo.local.database.entity.TattooClientProfileEntity @@ -10,7 +12,8 @@ data class TattooClientProfileResponse( val birthDate: String? = "", val imageProfile: String? = "", val tags: List = emptyList(), - val email: String? = "" + val email: String? = "", + val galleries: List = emptyList() ) { fun toTattooClientProfileEntity(): TattooClientProfileEntity { return TattooClientProfileEntity( @@ -19,7 +22,8 @@ data class TattooClientProfileResponse( birthDate = this.birthDate ?: "", imageProfile = this.imageProfile ?: "", tags = this.tags.toTagEntity(), - email = this.email + email = this.email, + galleries = this.galleries.toGalleryList() ) } } diff --git a/app/src/main/java/br/com/connectattoo/data/Gallery.kt b/app/src/main/java/br/com/connectattoo/data/Gallery.kt new file mode 100644 index 0000000..eb009cd --- /dev/null +++ b/app/src/main/java/br/com/connectattoo/data/Gallery.kt @@ -0,0 +1,11 @@ +package br.com.connectattoo.data + +data class Gallery( + val id: String? = "", + val name: String? = "" +) + +fun List.toGalleryList(): List = + this.map { + it + } diff --git a/app/src/main/java/br/com/connectattoo/data/TattooClientProfile.kt b/app/src/main/java/br/com/connectattoo/data/TattooClientProfile.kt index 2358b75..3717311 100644 --- a/app/src/main/java/br/com/connectattoo/data/TattooClientProfile.kt +++ b/app/src/main/java/br/com/connectattoo/data/TattooClientProfile.kt @@ -6,5 +6,6 @@ data class TattooClientProfile( val birthDate: String? = "", val imageProfile: String? = "", val tags: List = emptyList(), - val email: String? = "" + val email: String? = "", + val galleries: List = emptyList() ) diff --git a/app/src/main/java/br/com/connectattoo/local/database/entity/TattooClientProfileEntity.kt b/app/src/main/java/br/com/connectattoo/local/database/entity/TattooClientProfileEntity.kt index 5c06905..ea3ebf3 100644 --- a/app/src/main/java/br/com/connectattoo/local/database/entity/TattooClientProfileEntity.kt +++ b/app/src/main/java/br/com/connectattoo/local/database/entity/TattooClientProfileEntity.kt @@ -4,7 +4,9 @@ import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.PrimaryKey import androidx.room.TypeConverter +import br.com.connectattoo.data.Gallery import br.com.connectattoo.data.TattooClientProfile +import br.com.connectattoo.data.toGalleryList import com.google.gson.Gson import com.google.gson.reflect.TypeToken @@ -16,7 +18,8 @@ data class TattooClientProfileEntity( @ColumnInfo(name = "birth_date") val birthDate: String? = "", @ColumnInfo(name = "image_profile") val imageProfile: String? = "", var tags: List = emptyList(), - val email: String? = "" + val email: String? = "", + var galleries: List = emptyList(), ) { fun toTattooClientProfile(): TattooClientProfile = @@ -26,7 +29,8 @@ data class TattooClientProfileEntity( birthDate = this.birthDate ?: "", imageProfile = this.imageProfile ?: "", tags = this.tags.toTag(), - email = this.email + email = this.email, + galleries = this.galleries.toGalleryList() ) } @@ -44,6 +48,17 @@ class TattooClientProfileConverters { val listType = object : TypeToken>() {}.type return gson.fromJson(tagsAsString, listType) } + @TypeConverter + fun fromGalleryList(gallery: List): String { + val gson = Gson() + return gson.toJson(gallery) + } + @TypeConverter + fun toGalleryList(galleryAsString: String): List { + val gson = Gson() + val listType = object : TypeToken>() {}.type + return gson.fromJson(galleryAsString, listType) + } } From 06a046645c0a4259366ebc3ae77963b94ceff094 Mon Sep 17 00:00:00 2001 From: Antonio Jorge Garcia Tranin Date: Mon, 6 May 2024 11:02:34 -0400 Subject: [PATCH 2/3] feat: adds the presentation of galleries to the user profile and fake images --- .../response/TattooClientProfileResponse.kt | 27 +++- .../com/connectattoo/data/MyGalleryProfile.kt | 2 +- .../tattooclient/TattooClientProfileState.kt | 4 +- .../TattooClientProfileViewModel.kt | 130 +++++++++++------- 4 files changed, 107 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt index 87ac9b4..88e39b8 100644 --- a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt +++ b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt @@ -13,7 +13,7 @@ data class TattooClientProfileResponse( val imageProfile: String? = "", val tags: List = emptyList(), val email: String? = "", - val galleries: List = emptyList() + val galleries: List = mock() ) { fun toTattooClientProfileEntity(): TattooClientProfileEntity { return TattooClientProfileEntity( @@ -27,3 +27,28 @@ data class TattooClientProfileResponse( ) } } + +fun mock(): List { + val gallery = listOf( + Gallery( + id = "6524a08f-a04d-4bc2-97f4-c975a329ed29", + name = "Animais Cartoon" + ), + Gallery( + "535c2bc1-46b8-47e2-84ee-ac3dd4cead1f", + "Caveiras" + ), + Gallery( + + "5e880889-8093-4b31-82c9-f331ce8fc92e", + "Mãos" + ), + Gallery( + "d8c7cf42-184f-4d03-906d-6b4daa8bc72a", + "Costas Fechadas" + ) + + + ) + return gallery +} diff --git a/app/src/main/java/br/com/connectattoo/data/MyGalleryProfile.kt b/app/src/main/java/br/com/connectattoo/data/MyGalleryProfile.kt index efaa879..4249372 100644 --- a/app/src/main/java/br/com/connectattoo/data/MyGalleryProfile.kt +++ b/app/src/main/java/br/com/connectattoo/data/MyGalleryProfile.kt @@ -1,7 +1,7 @@ package br.com.connectattoo.data data class MyGalleryProfile( - val id: Int? = null, + val id: String? = null, val title: String? = null, val firstImage: String? = null, val secondImage: String? = null, diff --git a/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileState.kt b/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileState.kt index 8dcbfeb..6dfc87b 100644 --- a/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileState.kt +++ b/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileState.kt @@ -1,5 +1,6 @@ package br.com.connectattoo.ui.profile.tattooclient +import br.com.connectattoo.data.Gallery import br.com.connectattoo.data.TattooClientProfile import br.com.connectattoo.data.Tag import br.com.connectattoo.data.MyGalleryProfile @@ -12,10 +13,11 @@ data class TattooClientProfileState( val txtScheduleTomorrow: String? = null, val txtScheduleHour: String? = null, val listTagsTattooClientProfile: List? = listOf(), - val listGalleriesTattooClientProfile: List? = listOf(), + val listGalleriesTattooClientProfile: MutableList? = mutableListOf(), val userImage: String? = null, val imageTattooArtist: String? = null, val tattooClientProfile: TattooClientProfile? = null, val tag: List? = emptyList(), + val listGalleries: List? = emptyList(), val stateError: String? = "" ) diff --git a/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileViewModel.kt b/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileViewModel.kt index 6fef1ad..5d30b97 100644 --- a/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileViewModel.kt +++ b/app/src/main/java/br/com/connectattoo/ui/profile/tattooclient/TattooClientProfileViewModel.kt @@ -22,64 +22,86 @@ class TattooClientProfileViewModel : ViewModel() { val uiStateFlow: StateFlow get() = _uiStateFlow init { - getListGalleriesTattooClientProfile() getImageTattooArtistNextAppointment() } private fun getListGalleriesTattooClientProfile() { - val listImages = listOf( - MyGalleryProfile( - 1, - title = "Animais Cartoon", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + - "Cartoon%2FCoelho.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + - "Cartoon%2FDinossauro_com_oculos.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + - "Cartoon%2FGirafa.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + - "Cartoon%2FUrso.png", - - ), - MyGalleryProfile( - 2, - title = "Caveiras", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras%2F" + - "Caveira_1.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + - "%2FCaveira_2.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + - "%2FCaveira_3.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + - "%2FCaveira_4.png" - - ), - MyGalleryProfile( - 3, - title = "Costas Fechadas", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + - "Fechadas%2FCostas_Cobra.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + - "Fechadas%2FCostas_Diabo.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + - "Fechadas%2FCostas_Face.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + - "Fechadas%2FCostas_caveiras.png", - - ), - MyGalleryProfile( - 4, - title = "Mãos", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FDuasmãos.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_1.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_coraç-ão.png", - "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_olho.png", - - ), - ) - _state = _state.copy(listGalleriesTattooClientProfile = listImages) + if (!_state.listGalleries.isNullOrEmpty()) { + + _state.listGalleries?.forEach { gallery -> + if (!gallery.id.isNullOrEmpty()) { + val listImagesUrl = getImagesGalleryFake(gallery.id) + _state.listGalleriesTattooClientProfile?.add( + MyGalleryProfile( + gallery.id, + title = gallery.name, + listImagesUrl[0], + listImagesUrl[1], + listImagesUrl[2], + listImagesUrl[3] + ) + ) + } + } + } + } + + private fun getImagesGalleryFake(id: String): List { + return when (id) { + "6524a08f-a04d-4bc2-97f4-c975a329ed29" -> { + listOf( + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + + "Cartoon%2FCoelho.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + + "Cartoon%2FDinossauro_com_oculos.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + + "Cartoon%2FGirafa.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FAnimais%20" + + "Cartoon%2FUrso.png" + ) + } + + "535c2bc1-46b8-47e2-84ee-ac3dd4cead1f" -> { + listOf( + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras%2F" + + "Caveira_1.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + + "%2FCaveira_2.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + + "%2FCaveira_3.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCaveiras" + + "%2FCaveira_4.png" + ) + } + + "d8c7cf42-184f-4d03-906d-6b4daa8bc72a" -> { + listOf( + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + + "Fechadas%2FCostas_Cobra.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + + "Fechadas%2FCostas_Diabo.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + + "Fechadas%2FCostas_Face.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FCostas%20" + + "Fechadas%2FCostas_caveiras.png", + ) + } + + "5e880889-8093-4b31-82c9-f331ce8fc92e" -> { + listOf( + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FDuasmãos.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_1.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_coraç-ão.png", + "https://pub-777ce89a8a3641429d92a32c49eac191.r2.dev/galleries%2FMãos%2FMão_olho.png", + ) + } + + else -> emptyList() + } + } + @RequiresApi(Build.VERSION_CODES.O) fun getInitialInformationTattooClientProfile(profileRepository: ProfileRepository) { _uiStateFlow.value = UiState.Loading @@ -105,8 +127,10 @@ class TattooClientProfileViewModel : ViewModel() { _state = _state.copy( txtNameUser = "${clientProfile.displayName}", - listTagsTattooClientProfile = clientProfile.tags + listTagsTattooClientProfile = clientProfile.tags, + listGalleries = clientProfile.galleries ) + getListGalleriesTattooClientProfile() _uiStateFlow.value = UiState.Success } } From 74d450d863da35eef92cd600a33808c89bf348fa Mon Sep 17 00:00:00 2001 From: Antonio Jorge Garcia Tranin Date: Mon, 6 May 2024 11:04:30 -0400 Subject: [PATCH 3/3] refactor: remove mock fake galleries list --- .../response/TattooClientProfileResponse.kt | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt index 88e39b8..87ac9b4 100644 --- a/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt +++ b/app/src/main/java/br/com/connectattoo/api/response/TattooClientProfileResponse.kt @@ -13,7 +13,7 @@ data class TattooClientProfileResponse( val imageProfile: String? = "", val tags: List = emptyList(), val email: String? = "", - val galleries: List = mock() + val galleries: List = emptyList() ) { fun toTattooClientProfileEntity(): TattooClientProfileEntity { return TattooClientProfileEntity( @@ -27,28 +27,3 @@ data class TattooClientProfileResponse( ) } } - -fun mock(): List { - val gallery = listOf( - Gallery( - id = "6524a08f-a04d-4bc2-97f4-c975a329ed29", - name = "Animais Cartoon" - ), - Gallery( - "535c2bc1-46b8-47e2-84ee-ac3dd4cead1f", - "Caveiras" - ), - Gallery( - - "5e880889-8093-4b31-82c9-f331ce8fc92e", - "Mãos" - ), - Gallery( - "d8c7cf42-184f-4d03-906d-6b4daa8bc72a", - "Costas Fechadas" - ) - - - ) - return gallery -}