Skip to content

Commit

Permalink
Merge pull request #44 from connectattoo/feature/add-gallery-names-to…
Browse files Browse the repository at this point in the history
…-user-profile

CT-22/CT-137
  • Loading branch information
natanaelsc authored May 8, 2024
2 parents 4697a99 + 74d450d commit b6c6c4e
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -10,7 +12,8 @@ data class TattooClientProfileResponse(
val birthDate: String? = "",
val imageProfile: String? = "",
val tags: List<Tag> = emptyList(),
val email: String? = ""
val email: String? = "",
val galleries: List<Gallery> = emptyList()
) {
fun toTattooClientProfileEntity(): TattooClientProfileEntity {
return TattooClientProfileEntity(
Expand All @@ -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()
)
}
}
11 changes: 11 additions & 0 deletions app/src/main/java/br/com/connectattoo/data/Gallery.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package br.com.connectattoo.data

data class Gallery(
val id: String? = "",
val name: String? = ""
)

fun List<Gallery>.toGalleryList(): List<Gallery> =
this.map {
it
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ data class TattooClientProfile(
val birthDate: String? = "",
val imageProfile: String? = "",
val tags: List<Tag> = emptyList(),
val email: String? = ""
val email: String? = "",
val galleries: List<Gallery> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -16,7 +18,8 @@ data class TattooClientProfileEntity(
@ColumnInfo(name = "birth_date") val birthDate: String? = "",
@ColumnInfo(name = "image_profile") val imageProfile: String? = "",
var tags: List<TagEntity> = emptyList(),
val email: String? = ""
val email: String? = "",
var galleries: List<Gallery> = emptyList(),
) {

fun toTattooClientProfile(): TattooClientProfile =
Expand All @@ -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()
)

}
Expand All @@ -44,6 +48,17 @@ class TattooClientProfileConverters {
val listType = object : TypeToken<List<TagEntity>>() {}.type
return gson.fromJson(tagsAsString, listType)
}
@TypeConverter
fun fromGalleryList(gallery: List<Gallery>): String {
val gson = Gson()
return gson.toJson(gallery)
}
@TypeConverter
fun toGalleryList(galleryAsString: String): List<Gallery> {
val gson = Gson()
val listType = object : TypeToken<List<Gallery>>() {}.type
return gson.fromJson(galleryAsString, listType)
}

}

Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -12,10 +13,11 @@ data class TattooClientProfileState(
val txtScheduleTomorrow: String? = null,
val txtScheduleHour: String? = null,
val listTagsTattooClientProfile: List<Tag>? = listOf(),
val listGalleriesTattooClientProfile: List<MyGalleryProfile>? = listOf(),
val listGalleriesTattooClientProfile: MutableList<MyGalleryProfile>? = mutableListOf(),
val userImage: String? = null,
val imageTattooArtist: String? = null,
val tattooClientProfile: TattooClientProfile? = null,
val tag: List<Tag>? = emptyList(),
val listGalleries: List<Gallery>? = emptyList(),
val stateError: String? = ""
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,64 +22,86 @@ class TattooClientProfileViewModel : ViewModel() {
val uiStateFlow: StateFlow<UiState> 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<String> {
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
Expand All @@ -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
}
}
Expand Down

0 comments on commit b6c6c4e

Please sign in to comment.