Skip to content

Commit

Permalink
feat(ux): cải thiện hiệu suất của list
Browse files Browse the repository at this point in the history
- sửa một vài lỗi giao diện
  • Loading branch information
nqmgaming committed Nov 30, 2024
1 parent e65b696 commit c6f7b0d
Show file tree
Hide file tree
Showing 17 changed files with 28 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.MaterialTheme.colorScheme
import androidx.compose.material3.MaterialTheme.typography
Expand All @@ -35,9 +34,7 @@ import com.pwhs.quickmem.domain.model.folder.GetFolderResponseModel
import com.pwhs.quickmem.presentation.ads.BannerAds
import com.pwhs.quickmem.presentation.app.library.component.SearchTextField
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import timber.log.Timber

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AddFolderToClassList(
modifier: Modifier = Modifier,
Expand Down Expand Up @@ -109,8 +106,7 @@ fun AddFolderToClassList(
)
}
}
items(filterFolders) { folder ->
Timber.d("List folder ID: $folderImportedIds")
items(items = filterFolders, key = {it.id}) { folder ->
AddFolderToClassItem(
folder = folder,
onAddFolderToClass = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.pwhs.quickmem.domain.model.subject.SubjectModel
import com.pwhs.quickmem.domain.model.users.UserResponseModel
import com.pwhs.quickmem.presentation.app.library.component.SearchTextField
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import timber.log.Timber

@Composable
fun AddStudySetToClassList(
Expand Down Expand Up @@ -127,12 +126,10 @@ fun AddStudySetToClassList(
}
}
}
items(filterStudySets) { studySet ->
Timber.d("Check isAdd: ${studySetImportedIds.contains(studySet.id)}")
items(items = filterStudySets, key = {it.id}) { studySet ->
AddStudySetToClassItem(
studySet = studySet,
onAddStudySetToClass = {
Timber.d("Study set added: $it")
onAddStudySetToClass(it)
},
isAdded = studySetImportedIds.contains(studySet.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fun FoldersTabScreen(
modifier = Modifier
.fillMaxSize(),
) {
items(folder) { folders ->
items(items = folder, key = {it.id}) { folders ->
FolderItem(
modifier = Modifier.padding(horizontal = 16.dp),
title = folders.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fun MembersTabScreen(
modifier = Modifier
.fillMaxSize(),
) {
items(member) { member ->
items(items = member, key = {it.id}) { member ->
ClassMemberItem(
modifier = Modifier.padding(horizontal = 16.dp),
classMemberModel = member,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun StudySetsTabScreen(
modifier = Modifier
.fillMaxSize(),
) {
items(studySets) { studySet ->
items(items = studySets, key = {it.id}) { studySet ->
StudySetItem(
modifier = Modifier.padding(horizontal = 16.dp),
studySet = studySet,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pwhs.quickmem.presentation.app.explore

import android.app.Application
import android.widget.Toast
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.pwhs.quickmem.core.data.enums.CoinAction
Expand Down Expand Up @@ -229,6 +230,7 @@ class ExploreViewModel @Inject constructor(
when (coin) {
is Resources.Error -> {
Timber.e("Too many requests, please wait 1 minute")
_uiEvent.send(ExploreUiEvent.Error("Too many requests, please wait 1 minute"))
}

is Resources.Loading -> {
Expand All @@ -240,6 +242,11 @@ class ExploreViewModel @Inject constructor(
_uiState.update {
it.copy(coins = coin.data?.coins ?: 0)
}
Toast.makeText(
getApplication(),
"You have earned 1 coin",
Toast.LENGTH_SHORT
).show()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fun TopStreakScreen(
modifier = Modifier.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
items(topStreaks.size) { index ->
items(topStreaks.size, key = { it }) { index ->
val topStreak = topStreaks[index]
StreakItem(
rank = index + 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.pwhs.quickmem.domain.model.subject.SubjectModel
import com.pwhs.quickmem.domain.model.users.UserResponseModel
import com.pwhs.quickmem.presentation.app.library.component.SearchTextField
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import timber.log.Timber

@Composable
fun AddStudySetToFolderList(
Expand Down Expand Up @@ -127,12 +126,10 @@ fun AddStudySetToFolderList(
}
}
}
items(filterStudySets) { studySet ->
Timber.d("Check isAdd: ${studySetImportedIds.contains(studySet.id)}")
items(items = filterStudySets, key = {it.id}) { studySet ->
AddStudySetToFolderItem(
studySet = studySet,
onAddStudySetToFolder = {
Timber.d("Study set added: $it")
onAddStudySetToFolder(it)
},
isAdded = studySetImportedIds.contains(studySet.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ fun FolderDetailStudySetList(
LazyColumn(
horizontalAlignment = CenterHorizontally,
) {
items(studySets) { studySet ->
items(items = studySets, key = { it.id }) { studySet ->
StudySetItem(
studySet = studySet,
onStudySetClick = { onStudySetClick(studySet.id) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ private fun Home(
modifier = Modifier
.fillMaxWidth()
) {
items(studySets) { studySet ->
items(items = studySets, key = { it.id }) { studySet ->
StudySetHomeItem(
studySet = studySet,
onStudySetClick = { onStudySetClick(studySet) }
Expand Down Expand Up @@ -503,7 +503,7 @@ private fun Home(
modifier = Modifier
.fillMaxWidth()
) {
items(folders) { folder ->
items(items = folders, key = { it.id }) { folder ->
FolderHomeItem(
title = folder.title,
numOfStudySets = folder.studySetCount,
Expand Down Expand Up @@ -533,7 +533,7 @@ private fun Home(
modifier = Modifier
.fillMaxWidth()
) {
items(classes) { classItem ->
items(items = classes, key = {it.id}) { classItem ->
ClassHomeItem(
classItem = classItem,
onClick = { onClassClicked(classItem) }
Expand All @@ -554,7 +554,7 @@ private fun Home(
modifier = Modifier.padding(top = 24.dp)
)
}
items(subjects, key = { it.id }) { subject ->
items(items = subjects, key = { it.id }) { subject ->
SubjectItem(
subject = subject,
onSearchStudySetBySubject = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ fun NotificationListBottomSheet(

else -> {
LazyColumn {
items(notifications, key = { it.id }) { notification ->
items(items = notifications, key = { it.id }) { notification ->
NotificationItem(
notification = notification,
onMarkAsRead = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fun ListClassesScreen(
modifier = Modifier.padding(8.dp)
)
}
items(filterClass) { classItem ->
items(items = filterClass, key = {it.id}) { classItem ->
ClassItem(
modifier = Modifier.padding(horizontal = 16.dp),
classItem = classItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fun ListFolderScreen(
modifier = Modifier.padding(8.dp)
)
}
items(filterFolders) { folder ->
items(items = filterFolders, key = {it.id}) { folder ->
FolderItem(
modifier = Modifier.padding(horizontal = 16.dp),
title = folder.title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun ListStudySetScreen(
isLoading: Boolean = false,
studySets: List<GetStudySetResponseModel> = emptyList(),
onStudySetClick: (GetStudySetResponseModel) -> Unit = {},
onStudySetRefresh: () -> Unit = {},
onStudySetRefresh: () -> Unit = {},
avatarUrl: String = "",
username: String = "",
isOwner: Boolean = false
Expand Down Expand Up @@ -146,7 +146,7 @@ fun ListStudySetScreen(
modifier = Modifier.padding(8.dp)
)
}
items(filterStudySets) { studySet ->
items(items = filterStudySets, key = { it.id }) { studySet ->
StudySetItem(
modifier = Modifier.padding(horizontal = 16.dp),
studySet = studySet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fun AddStudySetToClassesList(
)
}
}
items(filterClass) { classItem ->
items(items = filterClass, key = { it.id }) { classItem ->
AddStudySetToClassesItem(
classItem = classItem,
onAddStudySetToClasses = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import com.pwhs.quickmem.domain.model.folder.GetFolderResponseModel
import com.pwhs.quickmem.presentation.ads.BannerAds
import com.pwhs.quickmem.presentation.app.library.component.SearchTextField
import com.pwhs.quickmem.ui.theme.QuickMemTheme
import timber.log.Timber

@Composable
fun AddStudySetToFoldersList(
Expand Down Expand Up @@ -107,8 +106,7 @@ fun AddStudySetToFoldersList(
)
}
}
items(filterFolders) { folder ->
Timber.d("List folder ID: $folderImportedIds")
items(items = filterFolders, key = { it.id }) { folder ->
AddStudySetToFoldersItem(
folder = folder,
onAddStudySetToFolders = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ fun MaterialTabScreen(
LazyRow(
modifier = Modifier.fillMaxWidth(),
) {
items(flashCards) { flashCard ->
items(items = flashCards, key = {it.id}) { flashCard ->
StudySetFlipCard(
frontText = flashCard.term,
backText = flashCard.definition,
Expand Down Expand Up @@ -279,7 +279,7 @@ fun MaterialTabScreen(
}
}

items(flashCards) { flashCards ->
items(items = flashCards, key = {it.id}) { flashCards ->
CardDetail(
isOwner = isOwner,
color = studySetColor,
Expand Down

0 comments on commit c6f7b0d

Please sign in to comment.