forked from melod1n/fast-messenger
return of debug token for auth; ability to disable haptic and set logging level; etc
This commit is contained in:
+6
-5
@@ -2,6 +2,7 @@ package dev.meloda.fast.messageshistory
|
||||
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.core.content.edit
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.ViewModel
|
||||
@@ -52,7 +53,7 @@ interface MessagesHistoryViewModel {
|
||||
|
||||
fun onRefresh()
|
||||
fun onAttachmentButtonClicked()
|
||||
fun onMessageInputChanged(newText: String)
|
||||
fun onMessageInputChanged(newText: TextFieldValue)
|
||||
fun onEmojiButtonClicked()
|
||||
fun onActionButtonClicked()
|
||||
|
||||
@@ -110,11 +111,11 @@ class MessagesHistoryViewModelImpl(
|
||||
|
||||
}
|
||||
|
||||
override fun onMessageInputChanged(newText: String) {
|
||||
override fun onMessageInputChanged(newText: TextFieldValue) {
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
message = newText,
|
||||
actionMode = if (newText.isEmptyOrBlank()) ActionMode.Record
|
||||
actionMode = if (newText.text.isEmptyOrBlank()) ActionMode.Record
|
||||
else ActionMode.Send
|
||||
)
|
||||
}
|
||||
@@ -317,7 +318,7 @@ class MessagesHistoryViewModelImpl(
|
||||
}
|
||||
|
||||
private fun sendMessage() {
|
||||
lastMessageText = screenState.value.message
|
||||
lastMessageText = screenState.value.message.text
|
||||
|
||||
val newMessage = VkMessage(
|
||||
id = -1 - sendingMessages.size,
|
||||
@@ -363,7 +364,7 @@ class MessagesHistoryViewModelImpl(
|
||||
|
||||
screenState.setValue { old ->
|
||||
old.copy(
|
||||
message = "",
|
||||
message = TextFieldValue(),
|
||||
actionMode = ActionMode.Record,
|
||||
messages = listOf(newUiMessage).plus(old.messages)
|
||||
)
|
||||
|
||||
+3
-2
@@ -1,6 +1,7 @@
|
||||
package dev.meloda.fast.messageshistory.model
|
||||
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import dev.meloda.fast.common.model.UiImage
|
||||
import dev.meloda.fast.model.api.domain.VkAttachment
|
||||
|
||||
@@ -11,7 +12,7 @@ data class MessagesHistoryScreenState(
|
||||
val status: String?,
|
||||
val avatar: UiImage,
|
||||
val messages: List<UiItem>,
|
||||
val message: String,
|
||||
val message: TextFieldValue,
|
||||
val attachments: List<VkAttachment>,
|
||||
val isLoading: Boolean,
|
||||
val isPaginating: Boolean,
|
||||
@@ -26,7 +27,7 @@ data class MessagesHistoryScreenState(
|
||||
status = null,
|
||||
avatar = UiImage.Color(0),
|
||||
messages = emptyList(),
|
||||
message = "",
|
||||
message = TextFieldValue(),
|
||||
attachments = emptyList(),
|
||||
isLoading = true,
|
||||
isPaginating = false,
|
||||
|
||||
+43
-23
@@ -72,6 +72,11 @@ import androidx.compose.ui.unit.LayoutDirection
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.view.HapticFeedbackConstantsCompat
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeChild
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||
import dev.meloda.fast.datastore.AppSettings
|
||||
import dev.meloda.fast.datastore.SettingsKeys
|
||||
import dev.meloda.fast.datastore.UserSettings
|
||||
import dev.meloda.fast.messageshistory.MessagesHistoryViewModel
|
||||
@@ -83,10 +88,6 @@ import dev.meloda.fast.messageshistory.util.indexOfMessageByCmId
|
||||
import dev.meloda.fast.model.BaseError
|
||||
import dev.meloda.fast.ui.theme.LocalThemeConfig
|
||||
import dev.meloda.fast.ui.util.ImmutableList
|
||||
import dev.chrisbanes.haze.HazeState
|
||||
import dev.chrisbanes.haze.hazeChild
|
||||
import dev.chrisbanes.haze.materials.ExperimentalHazeMaterialsApi
|
||||
import dev.chrisbanes.haze.materials.HazeMaterials
|
||||
import kotlinx.coroutines.launch
|
||||
import org.koin.androidx.compose.koinViewModel
|
||||
import org.koin.compose.koinInject
|
||||
@@ -138,7 +139,7 @@ fun MessagesHistoryScreen(
|
||||
onRefreshDropdownItemClicked: () -> Unit = {},
|
||||
onToggleAnimationsDropdownItemClicked: (Boolean) -> Unit = {},
|
||||
onPaginationConditionsMet: () -> Unit = {},
|
||||
onMessageInputChanged: (String) -> Unit = {},
|
||||
onMessageInputChanged: (TextFieldValue) -> Unit = {},
|
||||
onAttachmentButtonClicked: () -> Unit = {},
|
||||
onActionButtonClicked: () -> Unit = {}
|
||||
) {
|
||||
@@ -367,8 +368,9 @@ fun MessagesHistoryScreen(
|
||||
Column(verticalArrangement = Arrangement.Bottom) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
view.performHapticFeedback(HapticFeedbackConstantsCompat.REJECT)
|
||||
|
||||
if (AppSettings.Debug.enableHaptic) {
|
||||
view.performHapticFeedback(HapticFeedbackConstantsCompat.REJECT)
|
||||
}
|
||||
scope.launch {
|
||||
for (i in 20 downTo 0 step 4) {
|
||||
rotation.animateTo(
|
||||
@@ -397,15 +399,10 @@ fun MessagesHistoryScreen(
|
||||
}
|
||||
}
|
||||
|
||||
var message by remember { mutableStateOf(TextFieldValue(screenState.message)) }
|
||||
|
||||
TextField(
|
||||
modifier = Modifier.weight(1f),
|
||||
value = message,
|
||||
onValueChange = { newText ->
|
||||
message = newText
|
||||
onMessageInputChanged(newText.text)
|
||||
},
|
||||
value = screenState.message,
|
||||
onValueChange = onMessageInputChanged,
|
||||
colors = TextFieldDefaults.colors(
|
||||
unfocusedContainerColor = Color.Transparent,
|
||||
focusedContainerColor = Color.Transparent,
|
||||
@@ -421,36 +418,59 @@ fun MessagesHistoryScreen(
|
||||
}
|
||||
)
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val attachmentRotation = remember { Animatable(0f) }
|
||||
|
||||
Column(verticalArrangement = Arrangement.Bottom) {
|
||||
IconButton(onClick = onAttachmentButtonClicked) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (AppSettings.Debug.enableHaptic) {
|
||||
view.performHapticFeedback(HapticFeedbackConstantsCompat.REJECT)
|
||||
}
|
||||
scope.launch {
|
||||
for (i in 20 downTo 0 step 4) {
|
||||
attachmentRotation.animateTo(
|
||||
targetValue = i.toFloat(),
|
||||
animationSpec = tween(50)
|
||||
)
|
||||
if (i > 0) {
|
||||
attachmentRotation.animateTo(
|
||||
targetValue = -i.toFloat(),
|
||||
animationSpec = tween(50)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(id = UiR.drawable.round_attach_file_24),
|
||||
contentDescription = "Add attachment button",
|
||||
tint = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.rotate(30f)
|
||||
modifier = Modifier.rotate(30f + attachmentRotation.value)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
}
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
val rotation = remember { Animatable(0f) }
|
||||
val micRotation = remember { Animatable(0f) }
|
||||
|
||||
Column(verticalArrangement = Arrangement.Bottom) {
|
||||
IconButton(
|
||||
onClick = {
|
||||
if (screenState.actionMode == ActionMode.Record) {
|
||||
view.performHapticFeedback(HapticFeedbackConstantsCompat.REJECT)
|
||||
|
||||
if (AppSettings.Debug.enableHaptic) {
|
||||
view.performHapticFeedback(HapticFeedbackConstantsCompat.REJECT)
|
||||
}
|
||||
scope.launch {
|
||||
for (i in 20 downTo 0 step 4) {
|
||||
rotation.animateTo(
|
||||
micRotation.animateTo(
|
||||
targetValue = i.toFloat(),
|
||||
animationSpec = tween(50)
|
||||
)
|
||||
if (i > 0) {
|
||||
rotation.animateTo(
|
||||
micRotation.animateTo(
|
||||
targetValue = -i.toFloat(),
|
||||
animationSpec = tween(50)
|
||||
)
|
||||
@@ -461,7 +481,7 @@ fun MessagesHistoryScreen(
|
||||
onActionButtonClicked()
|
||||
}
|
||||
},
|
||||
modifier = Modifier.rotate(rotation.value)
|
||||
modifier = Modifier.rotate(micRotation.value)
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ class MessagesHistoryValidator {
|
||||
val results = mutableListOf<MessagesHistoryValidationResult>()
|
||||
|
||||
results.addIf(MessagesHistoryValidationResult.MessageEmpty) {
|
||||
screenState.message.isBlank()
|
||||
screenState.message.text.isBlank()
|
||||
}
|
||||
|
||||
results.addIf(MessagesHistoryValidationResult.AttachmentsEmpty) {
|
||||
|
||||
Reference in New Issue
Block a user