Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
asliayk committed Sep 30, 2024
1 parent bb694dc commit 976bc7c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.tum.informatics.www1.artemis.native_app.core.ui.common

import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.LocalTextStyle
import androidx.compose.runtime.Composable
Expand All @@ -11,8 +13,10 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.OffsetMapping
import androidx.compose.ui.text.input.TransformedText

Expand All @@ -27,7 +31,7 @@ fun BasicHintTextField(
hintStyle: TextStyle = LocalTextStyle.current
) {
var hasFocus by remember { mutableStateOf(false) }

val keyboardController = LocalSoftwareKeyboardController.current

val isValueDisplayed = value.isNotBlank() || (hasFocus && hideHintOnFocus)
val currentValue = if (isValueDisplayed) value else hint
Expand All @@ -48,6 +52,14 @@ fun BasicHintTextField(
AnnotatedString(text = currentValue, spanStyle = hintStyle.toSpanStyle()),
OffsetMapping.Identity
)
}
},
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Done
),
keyboardActions = KeyboardActions(
onDone = {
keyboardController?.hide()
}
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Create
import androidx.compose.material.icons.filled.HelpCenter
Expand Down Expand Up @@ -74,7 +72,6 @@ internal fun ExerciseScreenBody(
exerciseOverviewTab(
Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(horizontal = 8.dp)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,7 @@ data class ChannelChat(
override fun withUnreadMessagesCount(unreadMessagesCount: Long): Conversation =
copy(unreadMessagesCount = unreadMessagesCount)

override fun filterPredicate(query: String): Boolean = query in name
override fun filterPredicate(query: String): Boolean {
return name.contains(query, ignoreCase = true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ data class GroupChat(
override fun withUnreadMessagesCount(unreadMessagesCount: Long): Conversation =
copy(unreadMessagesCount = unreadMessagesCount)

override fun filterPredicate(query: String): Boolean =
if (name != null) query in name else query in humanReadableName
override fun filterPredicate(query: String): Boolean {
return (name!=null && name.contains(query, ignoreCase = true)) ||
(humanReadableName.contains(query, ignoreCase = true))

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ data class OneToOneChat(
override fun withUnreadMessagesCount(unreadMessagesCount: Long): Conversation =
copy(unreadMessagesCount = unreadMessagesCount)

override fun filterPredicate(query: String): Boolean = query in humanReadableTitle
override fun filterPredicate(query: String): Boolean {
return humanReadableTitle.contains(query, ignoreCase = true)
}
}

0 comments on commit 976bc7c

Please sign in to comment.