Skip to content

Commit

Permalink
Search for notes/goals added
Browse files Browse the repository at this point in the history
  • Loading branch information
T8RIN committed Mar 19, 2022
1 parent dd20f9b commit 08e3b73
Show file tree
Hide file tree
Showing 14 changed files with 414 additions and 107 deletions.
17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

7 changes: 7 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

286 changes: 238 additions & 48 deletions app/src/main/java/ru/tech/firenote/MainActivity.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ fun Navigation(
mainViewModel.showNoteCreation,
mainViewModel.globalNote,
mainViewModel.filterType,
mainViewModel.isDescendingFilter
mainViewModel.isDescendingFilter,
mainViewModel.searchString
)
}
composable(Screen.GoalsScreen.route) {
GoalListScreen(
mainViewModel.showGoalCreation,
mainViewModel.globalGoal,
mainViewModel.filterType,
mainViewModel.isDescendingFilter
mainViewModel.isDescendingFilter,
mainViewModel.searchString
)
}
composable(Screen.ProfileScreen.route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material.icons.outlined.Save
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
Expand Down Expand Up @@ -234,7 +234,9 @@ fun GoalCreationScreen(
if (text.isEmpty()) {
Text(
stringResource(R.string.subGoalHere),
modifier = Modifier.align(Alignment.CenterStart),
modifier = Modifier
.align(Alignment.CenterStart)
.padding(start = 12.dp),
color = Color.DarkGray
)
}
Expand All @@ -245,7 +247,7 @@ fun GoalCreationScreen(
IconButton(onClick = {
viewModel.removeFromContent(index)
}) {
Icon(Icons.Filled.Close, null, tint = darkColorScheme().onTertiary)
Icon(Icons.Rounded.Close, null, tint = darkColorScheme().onTertiary)
}

Spacer(Modifier.size(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.twotone.Cloud
import androidx.compose.material.icons.twotone.FindInPage
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.SnackbarResult
Expand Down Expand Up @@ -39,6 +40,7 @@ fun GoalListScreen(
globalGoal: MutableState<Goal?> = mutableStateOf(null),
filterType: MutableState<Int>,
isDescendingFilter: MutableState<Boolean>,
searchString: MutableState<String>,
viewModel: GoalListViewModel = hiltViewModel()
) {
val paddingValues = PaddingValues(top = 10.dp, start = 10.dp, end = 10.dp, bottom = 140.dp)
Expand All @@ -63,7 +65,7 @@ fun GoalListScreen(
}
is UIState.Success<*> -> {
val repoList = state.data as List<Goal>
val data = if (isDescendingFilter.value) {
var data = if (isDescendingFilter.value) {
when (filterType.value) {
1 -> repoList.sortedBy { (it.color ?: 0).priorityGoal }
3 -> repoList.sortedBy { it.timestamp }
Expand Down Expand Up @@ -91,14 +93,39 @@ fun GoalListScreen(
}
}

if (searchString.value.isNotEmpty()) {
data = repoList.filter {
val statement1 =
it.title?.lowercase()?.contains(searchString.value.lowercase()) ?: false
var statement2 = false
it.content?.forEach { data ->
if (data.content?.lowercase()
?.contains(searchString.value.lowercase()) == true
) statement2 = true
}

statement1 or statement2
}
if (data.isEmpty()) {
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(Icons.TwoTone.FindInPage, null, modifier = Modifier.fillMaxSize(0.3f))
Text(stringResource(R.string.nothingFound))
}
}
}

LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = paddingValues
) {
items(data.size) { index ->
val locGoal = data[index]
GoalItem(
cutCornerSize = 0.dp,
goal = locGoal,
onDeleteClick = {
goal = locGoal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.twotone.Cloud
import androidx.compose.material.icons.twotone.FindInPage
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.Icon
import androidx.compose.material3.SnackbarResult
Expand Down Expand Up @@ -41,6 +42,7 @@ fun NoteListScreen(
globalNote: MutableState<Note?> = mutableStateOf(null),
filterType: MutableState<Int>,
isDescendingFilter: MutableState<Boolean>,
searchString: MutableState<String>,
viewModel: NoteListViewModel = hiltViewModel()
) {
val notePaddingValues = PaddingValues(top = 10.dp, start = 10.dp, end = 10.dp, bottom = 140.dp)
Expand All @@ -65,7 +67,7 @@ fun NoteListScreen(
}
is UIState.Success<*> -> {
val repoList = state.data as List<Note>
val data = if (isDescendingFilter.value) {
var data = if (isDescendingFilter.value) {
when (filterType.value) {
1 -> repoList.sortedByDescending { (it.color ?: 0).priority }
2 -> repoList.sortedBy { it.timestamp }
Expand All @@ -79,6 +81,26 @@ fun NoteListScreen(
}
}

if (searchString.value.isNotEmpty()) {
data = repoList.filter {
it.content?.lowercase()?.contains(searchString.value.lowercase())
?.or(
it.title?.lowercase()?.contains(searchString.value.lowercase()) ?: false
) ?: false
}
if (data.isEmpty()) {
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Icon(Icons.TwoTone.FindInPage, null, modifier = Modifier.fillMaxSize(0.3f))
Text(stringResource(R.string.nothingFound))
}
}
}

LazyColumn(
verticalArrangement = Arrangement.spacedBy(8.dp),
contentPadding = notePaddingValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fun NoteActions(
)
DropdownMenuItem(
onClick = {
viewModel.filterType.value in 2..3
viewModel.filterType.value = 2
showFilter.value = false
},
text = { Text(stringResource(R.string.date)) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextOverflow
import com.google.accompanist.insets.statusBarsPadding

@Composable
fun AppBarWithInsets(
modifier: Modifier = Modifier,
title: String,
title: @Composable () -> Unit = {},
type: Int = APP_BAR_SIMPLE,
scrollBehavior: TopAppBarScrollBehavior? = null,
navigationIcon: @Composable () -> Unit = {},
Expand All @@ -30,13 +29,7 @@ fun AppBarWithInsets(
when (type) {
APP_BAR_CENTER -> {
CenterAlignedTopAppBar(
title = {
Text(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
title = title,
navigationIcon = navigationIcon,
actions = actions,
scrollBehavior = scrollBehavior,
Expand All @@ -46,13 +39,7 @@ fun AppBarWithInsets(
}
APP_BAR_SIMPLE -> {
SmallTopAppBar(
title = {
Text(
text = title,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
},
title = title,
navigationIcon = navigationIcon,
actions = actions,
scrollBehavior = scrollBehavior,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ru.tech.firenote.ui.route.Screen
fun BottomNavigationBar(
navController: NavHostController,
items: List<Screen>,
filterType: MutableState<Int>,
searchMode: MutableState<Boolean>,
title: MutableState<Int>,
selectedItem: MutableState<Int>,
alwaysShowLabel: Boolean = true
Expand Down Expand Up @@ -44,6 +44,7 @@ fun BottomNavigationBar(
navController.popBackStack()
launchSingleTop = true
}
searchMode.value = false
}
}
)
Expand Down
68 changes: 43 additions & 25 deletions app/src/main/java/ru/tech/firenote/ui/composable/single/GoalItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,33 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.clipPath
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import ru.tech.firenote.model.Goal
import ru.tech.firenote.ui.composable.provider.LocalWindowSize
import ru.tech.firenote.ui.composable.utils.WindowSize
import ru.tech.firenote.utils.Utils.blend
import java.text.SimpleDateFormat
import java.util.*

@Composable
fun GoalItem(
goal: Goal,
modifier: Modifier = Modifier,
cornerRadius: Dp = 10.dp,
cutCornerSize: Dp = 30.dp,
onDeleteClick: () -> Unit
) {
var doneAll = true
Expand All @@ -45,8 +49,8 @@ fun GoalItem(
) {
Canvas(modifier = Modifier.matchParentSize()) {
val clipPath = Path().apply {
lineTo(size.width - cutCornerSize.toPx(), 0f)
lineTo(size.width, cutCornerSize.toPx())
lineTo(size.width, 0f)
lineTo(size.width, 0f)
lineTo(size.width, size.height)
lineTo(0f, size.height)
close()
Expand All @@ -58,32 +62,45 @@ fun GoalItem(
size = size,
cornerRadius = CornerRadius(cornerRadius.toPx())
)
drawRoundRect(
color = Color(
(goal.color ?: 0).blend()
),
topLeft = Offset(size.width - cutCornerSize.toPx(), -100f),
size = Size(cutCornerSize.toPx() + 100f, cutCornerSize.toPx() + 100f),
cornerRadius = CornerRadius(cornerRadius.toPx())
)
}
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(16.dp)
.padding(end = 32.dp)
) {
Text(
text = goal.title ?: "",
style = MaterialTheme.typography.bodyLarge,
color = if (doneAll) Color.DarkGray else Color.Black,
textDecoration = if (doneAll) TextDecoration.LineThrough else TextDecoration.None,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)

val convertTime by derivedStateOf {
SimpleDateFormat("dd/MM/yyyy\nHH:mm", Locale.getDefault()).format(
goal.timestamp ?: 0L
)
}

Row(modifier = Modifier.fillMaxWidth()) {
Text(
modifier = Modifier.weight(2f),
text = goal.title ?: "",
style = MaterialTheme.typography.bodyLarge,
color = if (doneAll) Color.DarkGray else Color.Black,
textDecoration = if (doneAll) TextDecoration.LineThrough else TextDecoration.None,
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
Text(
modifier = Modifier.weight(1f),
text = convertTime,
style = MaterialTheme.typography.bodySmall,
color = Color.DarkGray,
maxLines = 2,
textAlign = TextAlign.Justify,
overflow = TextOverflow.Ellipsis
)
}

}
Spacer(modifier = Modifier.height(8.dp))
Column {
Column(Modifier.padding(end = 32.dp)) {
mapped?.let {
it.forEachIndexed { index, item ->
if (index <= when (LocalWindowSize.current) {
Expand All @@ -97,7 +114,8 @@ fun GoalItem(
style = MaterialTheme.typography.bodySmall,
color = if (item.done == true) Color.DarkGray else Color.Black,
textDecoration = if (item.done == true) TextDecoration.LineThrough else TextDecoration.None,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
maxLines = 5
)
}
}
Expand Down
Loading

0 comments on commit 08e3b73

Please sign in to comment.