Skip to content

Commit

Permalink
Merge pull request #84 from snuhcs-course/fix/android-profile-emojis
Browse files Browse the repository at this point in the history
Fix `myCreatedEmoji` and `myCreatedEmoji` not showing
  • Loading branch information
yangchanhk98 authored Dec 1, 2023
2 parents db073a0 + 740f384 commit 343f967
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.goliath.emojihub.models.Emoji
import com.goliath.emojihub.views.components.EmojiCell
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -37,9 +33,9 @@ import androidx.hilt.navigation.compose.hiltViewModel
import androidx.paging.compose.collectAsLazyPagingItems
import com.goliath.emojihub.LocalNavController
import com.goliath.emojihub.NavigationDestination
import com.goliath.emojihub.models.createDummyEmoji
import com.goliath.emojihub.ui.theme.Color.White
import com.goliath.emojihub.viewmodels.EmojiViewModel
import com.goliath.emojihub.views.components.EmojiCellDisplay
import com.goliath.emojihub.views.components.TopNavigationBar

@Composable
Expand Down Expand Up @@ -109,7 +105,7 @@ fun EmojiPage(
) {
items(emojiList.itemCount) { index ->
emojiList[index]?.let{
EmojiCell(emoji = it) { selectedEmoji ->
EmojiCell(emoji = it, displayMode = EmojiCellDisplay.VERTICAL) { selectedEmoji ->
viewModel.currentEmoji = selectedEmoji
navController.navigate(NavigationDestination.PlayEmojiVideo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import com.goliath.emojihub.ui.theme.Color
import com.goliath.emojihub.ui.theme.Color.EmojiHubDividerColor
import com.goliath.emojihub.viewmodels.EmojiViewModel
import com.goliath.emojihub.viewmodels.PostViewModel
import com.goliath.emojihub.views.components.EmojiCell
import com.goliath.emojihub.views.components.EmojiCellDisplay
import com.goliath.emojihub.views.components.CustomBottomSheet
import com.goliath.emojihub.views.components.PostCell
import com.goliath.emojihub.views.components.TopNavigationBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.goliath.emojihub.viewmodels.PostViewModel
import com.goliath.emojihub.viewmodels.UserViewModel
import com.goliath.emojihub.views.components.CustomDialog
import com.goliath.emojihub.views.components.EmojiCell
import com.goliath.emojihub.views.components.EmojiCellDisplay
import com.goliath.emojihub.views.components.EmptyProfile
import com.goliath.emojihub.views.components.PreviewPostCell
import com.goliath.emojihub.views.components.ProfileMenuCell
Expand Down Expand Up @@ -129,7 +130,7 @@ fun ProfilePage(
) {
items(myCreatedEmojiList.itemCount) { index ->
myCreatedEmojiList[index]?.let {
EmojiCell(emoji = it, onSelected = {})
EmojiCell(emoji = it, displayMode = EmojiCellDisplay.HORIZONTAL, onSelected = {})
}
}
}
Expand All @@ -143,7 +144,7 @@ fun ProfilePage(
) {
items(mySavedEmojiList.itemCount) { index ->
mySavedEmojiList[index]?.let {
EmojiCell(emoji = it, onSelected = {})
EmojiCell(emoji = it, displayMode = EmojiCellDisplay.HORIZONTAL, onSelected = {})
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fun CustomBottomSheet (
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
items(emojiList, key = { it.id }) { emoji ->
EmojiCell(emoji = emoji) {
EmojiCell(emoji = emoji, displayMode = EmojiCellDisplay.VERTICAL) {
emojiCellClicked(emoji)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.goliath.emojihub.views.components

import android.net.Uri
import android.util.Log
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand All @@ -9,69 +8,66 @@ import androidx.compose.runtime.Composable
import com.goliath.emojihub.models.Emoji
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Card
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.SaveAlt
import androidx.compose.material3.IconButton
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.hilt.navigation.compose.hiltViewModel
import coil.compose.AsyncImage
import coil.compose.rememberAsyncImagePainter
import com.goliath.emojihub.extensions.toEmoji
import com.goliath.emojihub.ui.theme.Color.Black
import com.goliath.emojihub.ui.theme.Color.White
import com.goliath.emojihub.viewmodels.EmojiViewModel

enum class EmojiCellDisplay {
VERTICAL, HORIZONTAL
}

@Composable
fun EmojiCell (
emoji: Emoji,
displayMode: EmojiCellDisplay,
onSelected: (Emoji) -> Unit
) {
//replace to emoji.thumbnailLink
val thumbnailLink = emoji.thumbnailLink.takeIf{ it.isNotEmpty()} ?:"https://i.pinimg.com/236x/4b/05/0c/4b050ca4fcf588eedc58aa6135f5eecf.jpg"
Log.d("create_TN", "${emoji.thumbnailLink}")
val context = LocalContext.current
Log.d("create_TN", emoji.thumbnailLink)

Card (
modifier = Modifier
.fillMaxWidth()
.height(292.dp)
.clickable { onSelected(emoji) },
modifier = when (displayMode) {
EmojiCellDisplay.VERTICAL -> Modifier
.fillMaxWidth()
.height(292.dp)
.clickable { onSelected(emoji) }
EmojiCellDisplay.HORIZONTAL -> Modifier
.width(132.dp)
.height(240.dp)
.clickable { onSelected(emoji) } },
shape = RoundedCornerShape(4.dp),
elevation = 0.dp
) {
Box(Modifier.fillMaxSize().background(Color.Gray).alpha(0.25F))

Image(
painter = rememberAsyncImagePainter(thumbnailLink),
contentDescription = null,
modifier = Modifier.fillMaxWidth(),
contentScale = ContentScale.Crop
)

Box(
modifier = Modifier.padding(8.dp)
) {
Box(modifier = Modifier.padding(8.dp)) {
Text(
text = "@" + emoji.createdBy,
modifier = Modifier.align(Alignment.TopStart),
Expand All @@ -85,9 +81,7 @@ fun EmojiCell (
) {
IconButton(
modifier = Modifier.size(16.dp),
onClick = {
// TODO: save emoji
}
onClick = {}
) {
Icon(
imageVector = Icons.Filled.SaveAlt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
Expand All @@ -22,7 +21,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.goliath.emojihub.models.dummyPost
import com.goliath.emojihub.ui.theme.Color

@Composable
Expand Down

0 comments on commit 343f967

Please sign in to comment.