Skip to content

Commit

Permalink
Added a function to search task
Browse files Browse the repository at this point in the history
[Change some background color]
[Added basic search function]
  • Loading branch information
Z-Siqi committed Sep 2, 2024
1 parent 2be7605 commit 61cf2a6
Show file tree
Hide file tree
Showing 9 changed files with 456 additions and 207 deletions.
117 changes: 117 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions app/src/main/java/com/sqz/checklist/database/DAO.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ interface TaskDao {
@Query("SELECT * FROM task WHERE isHistory = 0 AND reminder != ''")
suspend fun getIsRemindedList(): List<Task>

@Query("SELECT * FROM task WHERE isHistory = 0 AND description LIKE :search || '%'")
suspend fun searchedList(search: String): List<Task>


/* Get Value Actions */
@Query("SELECT reminder FROM task WHERE id = :id")
Expand Down
108 changes: 71 additions & 37 deletions app/src/main/java/com/sqz/checklist/ui/main/NavTooltipContent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import android.view.View
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Search
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ElevatedCard
Expand All @@ -39,10 +42,13 @@ import androidx.compose.ui.unit.sp
import androidx.core.content.ContextCompat
import com.sqz.checklist.R

enum class OnClickType {
ScrollDown, ScrollUp, Search
}

@Composable
fun NavTooltipContent(
onScrollDownClick: () -> Unit,
onScrollUpClick: () -> Unit,
onClickType: (OnClickType) -> Unit,
view: View,
modifier: Modifier = Modifier,
scrollUp: Boolean = false
Expand All @@ -60,41 +66,44 @@ fun NavTooltipContent(
),
verticalArrangement = Arrangement.Center
) {

Card(
shape = ShapeDefaults.Medium,
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
),
modifier = modifier.size(58.dp, 55.dp)
) {
Column(
modifier = modifier
.fillMaxSize()
.clickable {
if (!scrollUp) onScrollDownClick() else onScrollUpClick()
view.playSoundEffect(SoundEffectConstants.CLICK)
}
.padding(top = 3.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) {
Text(
text = stringResource(if (!scrollUp) R.string.scroll_to_end else R.string.scroll_to_top),
lineHeight = 12.sp,
fontSize = 12.sp,
fontWeight = FontWeight.W500,
textAlign = TextAlign.Center
)
if (!scrollUp) Icon(
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = stringResource(R.string.scroll_to_end)
) else Icon(
imageVector = Icons.Filled.KeyboardArrowUp,
contentDescription = stringResource(R.string.scroll_to_top)
)
NavButton(onClick = {
onClickType(OnClickType.Search)
view.playSoundEffect(SoundEffectConstants.CLICK)
}) {
Icon(
imageVector = Icons.Filled.Search,
contentDescription = stringResource(R.string.search)
)
Spacer(modifier = modifier.height(2.dp))
Text(
text = stringResource(R.string.search),
lineHeight = 12.sp,
fontSize = 12.sp,
fontWeight = FontWeight.W500,
textAlign = TextAlign.Center
)
}
Spacer(modifier = modifier.size(height = 10.dp, width = 10.dp))
NavButton(
onClick = {
if (!scrollUp) onClickType(OnClickType.ScrollDown) else onClickType(OnClickType.ScrollUp)
view.playSoundEffect(SoundEffectConstants.CLICK)
}
) {
Text(
text = stringResource(if (!scrollUp) R.string.scroll_to_end else R.string.scroll_to_top),
lineHeight = 12.sp,
fontSize = 12.sp,
fontWeight = FontWeight.W500,
textAlign = TextAlign.Center
)
if (!scrollUp) Icon(
imageVector = Icons.Filled.KeyboardArrowDown,
contentDescription = stringResource(R.string.scroll_to_end)
) else Icon(
imageVector = Icons.Filled.KeyboardArrowUp,
contentDescription = stringResource(R.string.scroll_to_top)
)
}
}
}
Expand All @@ -110,8 +119,33 @@ fun NavTooltipContent(
}
}

@Composable
private fun NavButton(
onClick: () -> Unit,
modifier: Modifier = Modifier,
content: @Composable () -> Unit
) {
Card(
shape = ShapeDefaults.Medium,
colors = CardDefaults.cardColors(
containerColor = MaterialTheme.colorScheme.primaryContainer,
contentColor = MaterialTheme.colorScheme.onSurfaceVariant
),
modifier = modifier.size(58.dp, 55.dp)
) {
Column(
modifier = modifier
.fillMaxSize()
.clickable { onClick() }
.padding(top = 3.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center,
) { content() }
}
}

@Preview(showBackground = true)
@Composable
private fun Preview() {
NavTooltipContent({}, {}, LocalView.current)
NavTooltipContent({}, LocalView.current)
}
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ class TaskLayoutViewModel : ViewModel() {
}
}

private var inSearchData by mutableStateOf(listOf<Task>())
fun updateInSearch(searchText: String = "", reset: Boolean = false): List<Task> {
if (searchText.isNotEmpty()) viewModelScope.launch {
inSearchData = MainActivity.taskDatabase.taskDao().searchedList(searchText)
}
if (reset) {
val reset by mutableStateOf(listOf<Task>())
inSearchData = reset
}
return this.inSearchData
}

/**
* Refresh List
**/
Expand Down
60 changes: 38 additions & 22 deletions app/src/main/java/com/sqz/checklist/ui/main/task/layout/LazyList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ const val CardHeight = 120
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LazyList(
item: List<Task>, pinnedItem: List<Task>, isRemindedItem: List<Task>,
item: List<Task>,
pinnedItem: List<Task>, isRemindedItem: List<Task>, inSearchItem: List<Task>,
lazyState: LazyListState,
reminderCard: (Int) -> Unit,
setReminder: (Int) -> Unit,
undoTask: (state: SwipeToDismissBoxState) -> Unit,
isInSearch: Boolean,
context: Context,
modifier: Modifier = Modifier,
) {
Expand All @@ -53,39 +55,53 @@ fun LazyList(
modifier = modifier.fillMaxSize(),
state = lazyState
) {
if (isRemindedItem.isNotEmpty()) {
item {
RemindedItem(
isRemindedItem = isRemindedItem,
if (!isInSearch) {
if (isRemindedItem.isNotEmpty()) {
item {
RemindedItem(
isRemindedItem = isRemindedItem,
reminderCard = reminderCard,
setReminder = setReminder,
screenWidthPx = screenWidthPx,
context = context
)
}
}
if (pinnedItem.isNotEmpty()) {
item {
PinnedItem(
pinnedItem = pinnedItem,
reminderCard = reminderCard,
setReminder = setReminder,
screenWidthPx = screenWidthPx,
context = context
)
}
}
item { Spacer(modifier = modifier.height(20.dp)) }
items(item, key = { it.id }) {
MainListItem(
it = it,
reminderCard = reminderCard,
setReminder = setReminder,
screenWidthPx = screenWidthPx,
undoTask = undoTask,
context = context
)
}
}
if (pinnedItem.isNotEmpty()) {
item {
PinnedItem(
pinnedItem = pinnedItem,
} else {
item { Spacer(modifier = modifier.height(72.dp)) }
items(inSearchItem, key = { it.id }) {
MainListItem(
it = it,
reminderCard = reminderCard,
setReminder = setReminder,
screenWidthPx = screenWidthPx,
undoTask = undoTask,
context = context
)
}
}
item { Spacer(modifier = modifier.height(20.dp)) }
items(item, key = { it.id }) {
MainListItem(
it = it,
reminderCard = reminderCard,
setReminder = setReminder,
screenWidthPx = screenWidthPx,
undoTask = undoTask,
context = context
)
}
item { Spacer(modifier = modifier.height(10.dp)) }
}
}
Expand Down Expand Up @@ -182,7 +198,7 @@ private fun PinnedItem(
.height(animatedPinnedHeight)
.padding(start = 8.dp, end = 8.dp),
shape = ShapeDefaults.Large,
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.surfaceContainerLow)
colors = CardDefaults.cardColors(MaterialTheme.colorScheme.background)
) {
Text(
text = stringResource(R.string.pinned_task),
Expand Down
Loading

0 comments on commit 61cf2a6

Please sign in to comment.