Skip to content

Commit e100759

Browse files
committed
refactor: Pequenos ajustes de layout em Feed e Profile Screen
1 parent f60a2fd commit e100759

File tree

6 files changed

+106
-41
lines changed

6 files changed

+106
-41
lines changed

app/src/main/java/com/paradoxo/threadscompose/sampleData/SampleData.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ class SampleData {
5050
"https://raw.githubusercontent.com/git-jr/sample-files/7bc859dfa8a6241fa9c0d723ba6e7517bdfedd50/profile%20pics/profile_pic_emoji_5.png",
5151
)
5252

53+
val names = listOf(
54+
"Sheldon Cooper",
55+
"Eleanor Shellstrop",
56+
"Sherlock Holmes",
57+
"John Watson",
58+
"Walter White",
59+
"Jesse Pinkman",
60+
"Daenerys Targaryen",
61+
"Jon Snow",
62+
"Michael Scott",
63+
"Chrisjen Avasarala",
64+
"Tyrion Lannister",
65+
"Arya Stark",
66+
"Tommy Shelby",
67+
"Gol D. Roger",
68+
"Jake Peralta",
69+
"Amy Santiago",
70+
"Chloe Morningstar",
71+
"Barry allen",
72+
"David Mailer",
73+
"Elizabeth Keen"
74+
)
75+
5376
init {
5477
val randomNumbers = mutableListOf<Long>()
5578
repeat(1000) {
@@ -59,7 +82,7 @@ class SampleData {
5982
for (i in 1..10) {
6083
val userAccount = UserAccount(
6184
id = i.toString(),
62-
name = "Nome $i",
85+
name = names[Random.nextInt(0, names.size)],
6386
userName = "usuario$i",
6487
bio = bios[i - 1],
6588
imageProfileUrl = images.random(),
@@ -153,10 +176,11 @@ class SampleData {
153176
}
154177

155178
fun generateSampleInvitedUser(): UserAccount {
179+
val name = names[Random.nextInt(0, names.size)]
156180
return UserAccount(
157181
id = UUID.randomUUID().toString(),
158-
name = "Nome da pessoa convidada",
159-
userName = "convidada_42",
182+
name = name,
183+
userName = name.replace(" ", "").lowercase(),
160184
bio = "O tal do Lorem ipsum dolor sit amet, consectetur adipiscing elit",
161185
link = "https://github.com/git-jr",
162186
imageProfileUrl = images.random(),

app/src/main/java/com/paradoxo/threadscompose/ui/feed/FeedScreen.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.paradoxo.threadscompose.ui.feed
33
import androidx.compose.animation.core.Animatable
44
import androidx.compose.animation.core.Spring
55
import androidx.compose.animation.core.spring
6+
import androidx.compose.foundation.background
67
import androidx.compose.foundation.gestures.detectVerticalDragGestures
78
import androidx.compose.foundation.layout.Arrangement
89
import androidx.compose.foundation.layout.Box
@@ -24,6 +25,7 @@ import androidx.compose.runtime.remember
2425
import androidx.compose.runtime.rememberCoroutineScope
2526
import androidx.compose.runtime.saveable.rememberSaveable
2627
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.graphics.Color
2729
import androidx.compose.ui.input.pointer.pointerInput
2830
import androidx.compose.ui.tooling.preview.Preview
2931
import androidx.compose.ui.unit.dp
@@ -47,6 +49,7 @@ fun FeedScreen(
4749
) {
4850
LazyColumn(
4951
modifier = modifier
52+
.background(color = Color.White)
5053
.fillMaxSize()
5154
.systemBarsPadding()
5255
) {

app/src/main/java/com/paradoxo/threadscompose/ui/login/LoginViewModel.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.paradoxo.threadscompose.ui.login
22

33
import androidx.lifecycle.ViewModel
44
import androidx.lifecycle.viewModelScope
5+
import com.facebook.Profile
56
import com.google.firebase.auth.FirebaseAuth
67
import com.google.firebase.auth.ktx.auth
78
import com.google.firebase.ktx.Firebase
@@ -78,4 +79,19 @@ internal class LoginViewModel : ViewModel() {
7879
)
7980
} ?: onError()
8081
}
82+
83+
fun getCurrentUser(): UserAccount {
84+
val currentUser = Firebase.auth.currentUser
85+
val profile = Profile.getCurrentProfile()
86+
val profilePicUri = profile?.getProfilePictureUri(200, 200)
87+
88+
val userAccount = UserAccount(
89+
id = currentUser?.uid ?: "",
90+
name = currentUser?.displayName ?: "",
91+
userName = currentUser?.displayName?.lowercase()?.replace(" ", "_") ?: "",
92+
imageProfileUrl = profilePicUri?.toString() ?: "",
93+
)
94+
95+
return userAccount
96+
}
8197
}

app/src/main/java/com/paradoxo/threadscompose/ui/navigation/ThreadsNavController.kt

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ import androidx.compose.foundation.layout.padding
55
import androidx.compose.runtime.State
66
import androidx.compose.runtime.collectAsState
77
import androidx.compose.runtime.getValue
8+
import androidx.compose.runtime.mutableStateOf
9+
import androidx.compose.runtime.remember
810
import androidx.compose.runtime.rememberCoroutineScope
11+
import androidx.compose.runtime.toMutableStateList
912
import androidx.compose.ui.Modifier
1013
import androidx.compose.ui.platform.LocalContext
1114
import androidx.compose.ui.unit.dp
1215
import androidx.lifecycle.viewmodel.compose.viewModel
1316
import androidx.navigation.NavGraphBuilder
1417
import androidx.navigation.compose.composable
1518
import androidx.navigation.navigation
16-
import com.facebook.Profile
17-
import com.google.firebase.auth.ktx.auth
18-
import com.google.firebase.ktx.Firebase
1919
import com.paradoxo.threadscompose.model.UserAccount
2020
import com.paradoxo.threadscompose.network.firebase.PostFirestore
2121
import com.paradoxo.threadscompose.sampleData.SampleData
@@ -24,6 +24,7 @@ import com.paradoxo.threadscompose.ui.feed.FeedViewModel
2424
import com.paradoxo.threadscompose.ui.home.SessionState
2525
import com.paradoxo.threadscompose.ui.login.LoginScreen
2626
import com.paradoxo.threadscompose.ui.login.LoginViewModel
27+
import com.paradoxo.threadscompose.ui.notification.NotificationScreenState
2728
import com.paradoxo.threadscompose.ui.notification.NotificationsScreen
2829
import com.paradoxo.threadscompose.ui.post.PostScreen
2930
import com.paradoxo.threadscompose.ui.profile.ProfileEditScreen
@@ -70,20 +71,8 @@ internal fun NavGraphBuilder.loginGraph(
7071
val loginViewModel: LoginViewModel = viewModel()
7172
val context = LocalContext.current
7273

73-
val currentUser = Firebase.auth.currentUser
74-
75-
val profile = Profile.getCurrentProfile()
76-
val profilePicUri = profile?.getProfilePictureUri(200, 200)
77-
78-
val userAccount = UserAccount(
79-
id = currentUser?.uid ?: "",
80-
name = currentUser?.displayName ?: "",
81-
userName = currentUser?.displayName?.lowercase()?.replace(" ", "_") ?: "",
82-
imageProfileUrl = profilePicUri?.toString() ?: "",
83-
)
84-
8574
ProfileEditScreen(
86-
userAccount = userAccount,
75+
userAccount = loginViewModel.getCurrentUser(),
8776
onSave = { userAccountUpdated ->
8877
loginViewModel.saveNewUser(
8978
userAccount = userAccountUpdated,
@@ -151,10 +140,26 @@ internal fun NavGraphBuilder.homeGraph(
151140
}
152141
)
153142
}
154-
composable(Destinations.Notifications.route) { NotificationsScreen() }
143+
composable(Destinations.Notifications.route) {
144+
val notificationState by remember { mutableStateOf(NotificationScreenState()) }
145+
notificationState.notifications.addAll(SampleData().notifications)
146+
147+
val allNotifications = notificationState.notifications
148+
val notifications = allNotifications.toMutableStateList()
149+
150+
NotificationsScreen(
151+
allNotifications = allNotifications,
152+
notifications = notifications
153+
)
154+
}
155155
composable(Destinations.Profile.route) {
156+
157+
val postLists = remember { SampleData().posts }.toMutableStateList()
158+
156159
ProfileScreen(
157160
currentUser = state.value.userAccount,
161+
postLists = postLists,
162+
repliesList = postLists.shuffled().toMutableList(),
158163
modifier = Modifier.padding(paddingValues),
159164
onNavigateToInstagram = {
160165
onNavigateToInstagram()

app/src/main/java/com/paradoxo/threadscompose/ui/notification/NotificationsScreen.kt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ import androidx.compose.runtime.getValue
4343
import androidx.compose.runtime.mutableIntStateOf
4444
import androidx.compose.runtime.mutableStateOf
4545
import androidx.compose.runtime.remember
46+
import androidx.compose.runtime.saveable.rememberSaveable
4647
import androidx.compose.runtime.setValue
47-
import androidx.compose.runtime.toMutableStateList
4848
import androidx.compose.ui.Alignment
4949
import androidx.compose.ui.Modifier
5050
import androidx.compose.ui.draw.clip
@@ -62,16 +62,15 @@ import com.paradoxo.threadscompose.model.Notification
6262
import com.paradoxo.threadscompose.model.NotificationTypeEnum
6363
import com.paradoxo.threadscompose.sampleData.SampleData
6464
import com.paradoxo.threadscompose.ui.theme.ThreadsComposeTheme
65+
import com.paradoxo.threadscompose.utils.noRippleClickable
6566

6667
@OptIn(ExperimentalMaterial3Api::class)
6768
@Composable
68-
fun NotificationsScreen(modifier: Modifier = Modifier) {
69-
70-
val state by remember { mutableStateOf(NotificationScreenState()) }
71-
state.notifications.addAll(SampleData().notifications)
72-
73-
val allNotifications = state.notifications
74-
val notifications = allNotifications.toMutableStateList()
69+
fun NotificationsScreen(
70+
modifier: Modifier = Modifier,
71+
allNotifications: MutableList<Notification>,
72+
notifications: MutableList<Notification>
73+
) {
7574

7675
val tabItems = listOf("Tudo", "Respostas", "Menções", "Verificado")
7776

@@ -120,9 +119,19 @@ fun NotificationsScreen(modifier: Modifier = Modifier) {
120119
modifier = modifier
121120
.fillMaxSize()
122121
) {
123-
items(notifications) { notification ->
122+
items(
123+
notifications,
124+
key = { notification -> notification.id }
125+
) { notification ->
126+
val isFollowing = rememberSaveable {
127+
mutableStateOf(notification.isFollowing)
128+
}
124129
NotificationItem(
125130
notification = notification,
131+
onFollowClick = {
132+
isFollowing.value = !isFollowing.value
133+
},
134+
isFollowing = isFollowing.value
126135
)
127136
}
128137
}
@@ -200,7 +209,9 @@ private fun NotificationTabs(
200209

201210
@Composable
202211
private fun NotificationItem(
203-
notification: Notification
212+
notification: Notification,
213+
onFollowClick: (Notification) -> Unit = {},
214+
isFollowing: Boolean = false,
204215
) {
205216
val dividerColor = Color.Gray.copy(alpha = 0.2f)
206217
val iconSpecs = getIconByType(notification.type)
@@ -297,7 +308,7 @@ private fun NotificationItem(
297308
.weight(0.3f),
298309
verticalAlignment = Alignment.CenterVertically,
299310
) {
300-
val textIsFollowing = if (notification.isFollowing) {
311+
val textIsFollowing = if (isFollowing) {
301312
"Seguindo"
302313
} else {
303314
"Seguir"
@@ -321,6 +332,9 @@ private fun NotificationItem(
321332
shape = RoundedCornerShape(10.dp)
322333
)
323334
.clip(RoundedCornerShape(40))
335+
.noRippleClickable {
336+
onFollowClick(notification)
337+
}
324338
) {
325339
Text(
326340
text = textIsFollowing,
@@ -392,7 +406,9 @@ private fun NotificationItemPreview() {
392406
@Composable
393407
fun NotificationsScreenPreview() {
394408
ThreadsComposeTheme {
395-
NotificationsScreen()
409+
NotificationsScreen(
410+
allNotifications = mutableListOf(),
411+
notifications = mutableListOf(),
412+
)
396413
}
397-
}
398-
414+
}

app/src/main/java/com/paradoxo/threadscompose/ui/profile/ProfileScreen.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import androidx.compose.material3.Text
3434
import androidx.compose.material3.TopAppBar
3535
import androidx.compose.runtime.Composable
3636
import androidx.compose.runtime.getValue
37-
import androidx.compose.runtime.mutableStateOf
37+
import androidx.compose.runtime.mutableIntStateOf
3838
import androidx.compose.runtime.remember
3939
import androidx.compose.runtime.setValue
4040
import androidx.compose.ui.Alignment
@@ -54,6 +54,7 @@ import androidx.compose.ui.unit.sp
5454
import coil.compose.AsyncImage
5555
import coil.request.ImageRequest
5656
import com.paradoxo.threadscompose.R
57+
import com.paradoxo.threadscompose.model.Post
5758
import com.paradoxo.threadscompose.model.UserAccount
5859
import com.paradoxo.threadscompose.sampleData.SampleData
5960
import com.paradoxo.threadscompose.ui.PostItem
@@ -63,7 +64,9 @@ import com.paradoxo.threadscompose.ui.PostItem
6364
fun ProfileScreen(
6465
modifier: Modifier = Modifier,
6566
onNavigateToInstagram: () -> Unit = { },
66-
currentUser: UserAccount
67+
currentUser: UserAccount,
68+
postLists: MutableList<Post> = mutableListOf(),
69+
repliesList: MutableList<Post> = mutableListOf()
6770
) {
6871
Scaffold(
6972
modifier = modifier.fillMaxSize(),
@@ -112,10 +115,7 @@ fun ProfileScreen(
112115
},
113116
) { paddingValues ->
114117

115-
val postLists = SampleData().posts
116-
val repliesList = SampleData().posts.shuffled()
117-
118-
var tabState by remember { mutableStateOf(0) }
118+
var tabState by remember { mutableIntStateOf(0) }
119119
val titles = listOf("Threads", "Respostas")
120120
LazyColumn(
121121
modifier = Modifier
@@ -389,6 +389,7 @@ fun ProfileScreen(
389389
@Composable
390390
fun ProfileScreenPreview() {
391391
ProfileScreen(
392-
currentUser = SampleData().generateSampleInvitedUser()
392+
currentUser = SampleData().generateSampleInvitedUser(),
393+
postLists = SampleData().posts
393394
)
394395
}

0 commit comments

Comments
 (0)