mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 00:35:26 +02:00
Remove 💩 module
This commit is contained in:
parent
b04e95e56e
commit
a4cb24c1ab
1
feature/epoch/.gitignore
vendored
1
feature/epoch/.gitignore
vendored
@ -1 +0,0 @@
|
||||
/build
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("unitto.library")
|
||||
id("unitto.library.compose")
|
||||
id("unitto.library.feature")
|
||||
id("unitto.android.hilt")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.sadellie.unitto.feature.epoch"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(mapOf("path" to ":data:epoch")))
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest>
|
||||
|
||||
</manifest>
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch
|
||||
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.sadellie.unitto.core.base.R
|
||||
import com.sadellie.unitto.core.ui.common.MenuButton
|
||||
import com.sadellie.unitto.core.ui.common.PortraitLandscape
|
||||
import com.sadellie.unitto.core.ui.common.UnittoScreenWithTopBar
|
||||
import com.sadellie.unitto.feature.epoch.component.EpochKeyboard
|
||||
import com.sadellie.unitto.feature.epoch.component.TopPart
|
||||
|
||||
@Composable
|
||||
internal fun EpochRoute(
|
||||
navigateToMenu: () -> Unit,
|
||||
viewModel: EpochViewModel = hiltViewModel()
|
||||
) {
|
||||
val uiState = viewModel.uiState.collectAsStateWithLifecycle()
|
||||
EpochScreen(
|
||||
navigateToMenu = navigateToMenu,
|
||||
uiState = uiState.value,
|
||||
addSymbol = viewModel::addSymbol,
|
||||
deleteSymbol = viewModel::deleteSymbol,
|
||||
swap = viewModel::swap,
|
||||
clearSymbols = viewModel::clearSymbols,
|
||||
onCursorChange = viewModel::onCursorChange
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EpochScreen(
|
||||
navigateToMenu: () -> Unit,
|
||||
uiState: EpochUIState,
|
||||
addSymbol: (String) -> Unit,
|
||||
deleteSymbol: () -> Unit,
|
||||
clearSymbols: () -> Unit,
|
||||
swap: () -> Unit,
|
||||
onCursorChange: (IntRange) -> Unit
|
||||
) {
|
||||
UnittoScreenWithTopBar(
|
||||
title = { Text(stringResource(R.string.epoch_converter)) },
|
||||
navigationIcon = { MenuButton { navigateToMenu() } }
|
||||
) { padding ->
|
||||
PortraitLandscape(
|
||||
modifier = Modifier.padding(padding),
|
||||
content1 = { topContentModifier ->
|
||||
TopPart(
|
||||
modifier = topContentModifier.padding(horizontal = 8.dp),
|
||||
dateToUnix = uiState.dateToUnix,
|
||||
dateValue = uiState.dateField,
|
||||
unixValue = uiState.unixField,
|
||||
swap = swap,
|
||||
selection = TextRange(uiState.selection.first, uiState.selection.last),
|
||||
onCursorChange = onCursorChange
|
||||
)
|
||||
},
|
||||
content2 = { bottomModifier ->
|
||||
EpochKeyboard(
|
||||
modifier = bottomModifier,
|
||||
addSymbol = addSymbol,
|
||||
clearSymbols = clearSymbols,
|
||||
deleteSymbol = deleteSymbol
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.sadellie.unitto.data.epoch.EpochDateConverter
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.flow.update
|
||||
import javax.inject.Inject
|
||||
|
||||
data class EpochUIState(
|
||||
val dateField: String = "",
|
||||
val unixField: String = "",
|
||||
val dateToUnix: Boolean = true,
|
||||
val selection: IntRange = 0..0
|
||||
)
|
||||
|
||||
@HiltViewModel
|
||||
class EpochViewModel @Inject constructor() : ViewModel() {
|
||||
|
||||
private val _input: MutableStateFlow<String> = MutableStateFlow("")
|
||||
private val _fromDateToUnix: MutableStateFlow<Boolean> = MutableStateFlow(true)
|
||||
private val _selection: MutableStateFlow<IntRange> = MutableStateFlow(IntRange(0, 0))
|
||||
|
||||
val uiState: StateFlow<EpochUIState> = combine(
|
||||
_input, _fromDateToUnix, _selection
|
||||
) { input, fromDateToUnix, selection ->
|
||||
if (fromDateToUnix) {
|
||||
EpochUIState(
|
||||
dateField = input,
|
||||
unixField = EpochDateConverter.convertDateToUnix(input),
|
||||
dateToUnix = fromDateToUnix,
|
||||
selection = selection
|
||||
)
|
||||
} else {
|
||||
val date = try {
|
||||
EpochDateConverter.convertUnixToDate(input)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
""
|
||||
}
|
||||
|
||||
EpochUIState(
|
||||
unixField = input,
|
||||
dateField = date,
|
||||
dateToUnix = fromDateToUnix,
|
||||
selection = selection
|
||||
)
|
||||
}
|
||||
}.stateIn(
|
||||
viewModelScope, SharingStarted.WhileSubscribed(5000L), EpochUIState()
|
||||
)
|
||||
|
||||
fun addSymbol(symbol: String) {
|
||||
val selection = _selection.value
|
||||
val maxSymbols = if (_fromDateToUnix.value) 14 else 10
|
||||
if (_input.value.length >= maxSymbols) return
|
||||
|
||||
_input.update {
|
||||
if (it.isEmpty()) symbol else it.replaceRange(selection.first, selection.last, symbol)
|
||||
}
|
||||
_selection.update { it.first + 1..it.first + 1 }
|
||||
}
|
||||
|
||||
fun deleteSymbol() {
|
||||
val selection = _selection.value
|
||||
val newSelectionStart = when (selection.last) {
|
||||
0 -> return
|
||||
selection.first -> _selection.value.first - 1
|
||||
else -> _selection.value.first
|
||||
}
|
||||
|
||||
_selection.update { newSelectionStart..newSelectionStart }
|
||||
_input.update { it.removeRange(newSelectionStart, selection.last) }
|
||||
}
|
||||
|
||||
fun clearSymbols() {
|
||||
_selection.update { 0..0 }
|
||||
_input.update { "" }
|
||||
}
|
||||
|
||||
fun swap() {
|
||||
clearSymbols()
|
||||
_fromDateToUnix.update { !it }
|
||||
}
|
||||
|
||||
fun onCursorChange(selectionRange: IntRange) {
|
||||
_selection.update { selectionRange }
|
||||
}
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.component
|
||||
|
||||
import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.input.OffsetMapping
|
||||
import androidx.compose.ui.text.input.TransformedText
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
|
||||
internal object DateVisTrans : VisualTransformation {
|
||||
override fun filter(text: AnnotatedString): TransformedText = TransformedText(
|
||||
text = AnnotatedString(text.text.toDateMask()),
|
||||
offsetMapping = offsetMapping
|
||||
)
|
||||
|
||||
private val offsetMapping = object : OffsetMapping {
|
||||
override fun originalToTransformed(offset: Int): Int {
|
||||
if (offset <= 2) return offset
|
||||
if (offset <= 4) return offset + 1
|
||||
if (offset <= 6) return offset + 2
|
||||
if (offset <= 8) return offset + 3
|
||||
if (offset <= 10) return offset + 4
|
||||
if (offset <= 14) return offset + 5
|
||||
return 20
|
||||
}
|
||||
|
||||
override fun transformedToOriginal(offset: Int): Int {
|
||||
if (offset <= 2) return offset
|
||||
if (offset <= 5) return offset - 1
|
||||
if (offset <= 9) return offset - 2
|
||||
if (offset <= 11) return offset - 3
|
||||
if (offset <= 14) return offset - 4
|
||||
if (offset <= 19) return offset - 5
|
||||
return 14
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun String.toDateMask(): String {
|
||||
var maskedText = this
|
||||
|
||||
if (maskedText.length > 2) maskedText = maskedText.replaceRange(2, 2, ":")
|
||||
if (maskedText.length > 5) maskedText = maskedText.replaceRange(5, 5, ":")
|
||||
if (maskedText.length > 8) maskedText = maskedText.replaceRange(8, 8, "\n")
|
||||
if (maskedText.length > 10) maskedText = maskedText.replaceRange(11, 11, "d")
|
||||
if (maskedText.length > 13) maskedText = maskedText.replaceRange(14, 14, "m")
|
||||
if (maskedText.length > 18) maskedText = maskedText.replaceRange(19, 19, "y")
|
||||
|
||||
return maskedText
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.component
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.CompositionLocalProvider
|
||||
import androidx.compose.ui.platform.LocalTextInputService
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import com.sadellie.unitto.core.ui.theme.NumbersTextStyleDisplayMedium
|
||||
|
||||
@Composable
|
||||
internal fun DateUnixTextFields(
|
||||
fromTextFieldValue: TextFieldValue,
|
||||
onCursorChange: (IntRange) -> Unit,
|
||||
fromSupportText: String,
|
||||
toTextValue: String,
|
||||
toSupportText: String,
|
||||
visualTransformation: VisualTransformation,
|
||||
fromPlaceholderText: String,
|
||||
toPlaceholderText: String
|
||||
) {
|
||||
Column {
|
||||
CompositionLocalProvider(
|
||||
LocalTextInputService provides null
|
||||
) {
|
||||
BasicTextField(
|
||||
value = fromTextFieldValue,
|
||||
onValueChange = { onCursorChange(it.selection.start..it.selection.end) },
|
||||
textStyle = NumbersTextStyleDisplayMedium.copy(
|
||||
textAlign = TextAlign.Start,
|
||||
color = MaterialTheme.colorScheme.onBackground
|
||||
),
|
||||
minLines = 1,
|
||||
maxLines = 2,
|
||||
visualTransformation = visualTransformation,
|
||||
decorationBox = { innerTextField ->
|
||||
Text(
|
||||
text = fromPlaceholderText,
|
||||
minLines = 1,
|
||||
maxLines = 2,
|
||||
style = NumbersTextStyleDisplayMedium,
|
||||
color = MaterialTheme.colorScheme.outline,
|
||||
textAlign = TextAlign.Start
|
||||
)
|
||||
innerTextField()
|
||||
}
|
||||
)
|
||||
}
|
||||
Text(text = fromSupportText)
|
||||
Text(
|
||||
text = toTextValue.ifEmpty { toPlaceholderText },
|
||||
style = NumbersTextStyleDisplayMedium,
|
||||
)
|
||||
Text(text = toSupportText)
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.component
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.sadellie.unitto.core.base.Token
|
||||
import com.sadellie.unitto.core.ui.common.KeyboardButtonLight
|
||||
import com.sadellie.unitto.core.ui.common.key.UnittoIcons
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Backspace
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key0
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key1
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key2
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key3
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key4
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key5
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key6
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key7
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key8
|
||||
import com.sadellie.unitto.core.ui.common.key.unittoicons.Key9
|
||||
|
||||
@Composable
|
||||
internal fun EpochKeyboard(
|
||||
modifier: Modifier,
|
||||
addSymbol: (String) -> Unit,
|
||||
clearSymbols: () -> Unit,
|
||||
deleteSymbol: () -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
) {
|
||||
// Button modifier
|
||||
val bModifier = Modifier
|
||||
.fillMaxSize()
|
||||
.weight(1f)
|
||||
.padding(4.dp)
|
||||
// Column modifier
|
||||
val cModifier = Modifier.weight(1f)
|
||||
val dModifier = Modifier
|
||||
.fillMaxSize()
|
||||
.weight(2f)
|
||||
.padding(4.dp)
|
||||
Row(cModifier) {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key7, false) { addSymbol(Token._7) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key8, false) { addSymbol(Token._8) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key9, false) { addSymbol(Token._9) }
|
||||
}
|
||||
Row(cModifier) {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key4, false) { addSymbol(Token._4) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key5, false) { addSymbol(Token._5) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key6, false) { addSymbol(Token._6) }
|
||||
}
|
||||
Row(cModifier) {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key1, false) { addSymbol(Token._1) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key2, false) { addSymbol(Token._2) }
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key3, false) { addSymbol(Token._3) }
|
||||
}
|
||||
Row(cModifier) {
|
||||
KeyboardButtonLight(bModifier, UnittoIcons.Key0, false) { addSymbol(Token._0) }
|
||||
KeyboardButtonLight(dModifier, UnittoIcons.Backspace, false, clearSymbols) { deleteSymbol() }
|
||||
}
|
||||
}
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.component
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.animateIntAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.SwapHoriz
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
internal fun SwapButton(
|
||||
modifier: Modifier,
|
||||
swap: () -> Unit
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isPressed by interactionSource.collectIsPressedAsState()
|
||||
val cornerRadius: Int by animateIntAsState(
|
||||
targetValue = if (isPressed) 30 else 50,
|
||||
animationSpec = tween(easing = FastOutSlowInEasing),
|
||||
)
|
||||
|
||||
Button(
|
||||
onClick = swap,
|
||||
shape = RoundedCornerShape(cornerRadius),
|
||||
modifier = modifier,
|
||||
contentPadding = PaddingValues(vertical = 26.dp, horizontal = 8.dp),
|
||||
interactionSource = interactionSource
|
||||
) {
|
||||
Icon(Icons.Default.SwapHoriz, null)
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text("SWAP")
|
||||
}
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.component
|
||||
|
||||
import androidx.compose.animation.Crossfade
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.TextRange
|
||||
import androidx.compose.ui.text.input.TextFieldValue
|
||||
import androidx.compose.ui.text.input.VisualTransformation
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@Composable
|
||||
fun TopPart(
|
||||
modifier: Modifier,
|
||||
dateToUnix: Boolean,
|
||||
swap: () -> Unit,
|
||||
dateValue: String,
|
||||
unixValue: String,
|
||||
selection: TextRange,
|
||||
onCursorChange: (IntRange) -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Crossfade(dateToUnix) {
|
||||
if (it) {
|
||||
DateUnixTextFields(
|
||||
fromTextFieldValue = TextFieldValue(text = dateValue, selection = selection),
|
||||
onCursorChange = onCursorChange,
|
||||
fromSupportText = "date",
|
||||
toTextValue = unixValue,
|
||||
toSupportText = "unix",
|
||||
visualTransformation = DateVisTrans,
|
||||
fromPlaceholderText = dateValue.padEnd(14, '0').toDateMask(),
|
||||
toPlaceholderText = "0"
|
||||
)
|
||||
} else {
|
||||
val dateMasked = dateValue.padEnd(14, '0').toDateMask()
|
||||
DateUnixTextFields(
|
||||
fromTextFieldValue = TextFieldValue(text = unixValue, selection = selection),
|
||||
onCursorChange = onCursorChange,
|
||||
fromSupportText = "unix",
|
||||
toTextValue = dateMasked,
|
||||
toSupportText = "date",
|
||||
visualTransformation = VisualTransformation.None,
|
||||
fromPlaceholderText = if (unixValue.isEmpty()) "0" else "",
|
||||
toPlaceholderText = dateMasked,
|
||||
)
|
||||
}
|
||||
}
|
||||
SwapButton(modifier = Modifier.fillMaxWidth(), swap = swap)
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Unitto is a unit converter for Android
|
||||
* Copyright (c) 2023 Elshan Agaev
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sadellie.unitto.feature.epoch.navigation
|
||||
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.navDeepLink
|
||||
import com.sadellie.unitto.core.base.TopLevelDestinations
|
||||
import com.sadellie.unitto.feature.epoch.EpochRoute
|
||||
|
||||
private val epochRoute: String by lazy { TopLevelDestinations.Epoch.route }
|
||||
|
||||
fun NavGraphBuilder.epochScreen(
|
||||
navigateToMenu: () -> Unit
|
||||
) {
|
||||
composable(
|
||||
route = epochRoute,
|
||||
deepLinks = listOf(
|
||||
navDeepLink { uriPattern = "app://com.sadellie.unitto/$epochRoute" }
|
||||
)
|
||||
) {
|
||||
EpochRoute(navigateToMenu = navigateToMenu)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user