mirror of
https://github.com/Myzel394/NumberHub.git
synced 2025-06-19 08:45:27 +02:00
Landscape mode support for EpochConverter
This commit is contained in:
parent
56b89ab0f8
commit
790457cb6f
@ -16,7 +16,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sadellie.unitto.feature.converter.components
|
package com.sadellie.unitto.core.ui.common
|
||||||
|
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
@ -36,7 +36,7 @@ import androidx.compose.ui.unit.dp
|
|||||||
* When Landscape mode will place [content1] and [content2] in a [Row].
|
* When Landscape mode will place [content1] and [content2] in a [Row].
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
internal fun PortraitLandscape(
|
fun PortraitLandscape(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
content1: @Composable (Modifier) -> Unit,
|
content1: @Composable (Modifier) -> Unit,
|
||||||
content2: @Composable (Modifier) -> Unit,
|
content2: @Composable (Modifier) -> Unit,
|
@ -50,7 +50,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
|
|||||||
import com.sadellie.unitto.core.ui.R
|
import com.sadellie.unitto.core.ui.R
|
||||||
import com.sadellie.unitto.core.ui.common.AnimatedTopBarText
|
import com.sadellie.unitto.core.ui.common.AnimatedTopBarText
|
||||||
import com.sadellie.unitto.feature.converter.components.Keyboard
|
import com.sadellie.unitto.feature.converter.components.Keyboard
|
||||||
import com.sadellie.unitto.feature.converter.components.PortraitLandscape
|
import com.sadellie.unitto.core.ui.common.PortraitLandscape
|
||||||
import com.sadellie.unitto.feature.converter.components.TopScreenPart
|
import com.sadellie.unitto.feature.converter.components.TopScreenPart
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
|
|
||||||
|
@ -19,27 +19,19 @@
|
|||||||
package com.sadellie.unitto.feature.epoch
|
package com.sadellie.unitto.feature.epoch
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Spacer
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
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.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.sadellie.unitto.core.ui.common.UnittoTopAppBar
|
import com.sadellie.unitto.core.ui.common.UnittoTopAppBar
|
||||||
|
import com.sadellie.unitto.core.ui.common.PortraitLandscape
|
||||||
import com.sadellie.unitto.feature.epoch.component.DateTextField
|
import com.sadellie.unitto.feature.epoch.component.DateTextField
|
||||||
import com.sadellie.unitto.feature.epoch.component.EpochKeyboard
|
import com.sadellie.unitto.feature.epoch.component.EpochKeyboard
|
||||||
import com.sadellie.unitto.feature.epoch.component.TopPart
|
import com.sadellie.unitto.feature.epoch.component.TopPart
|
||||||
@ -74,15 +66,12 @@ private fun EpochScreen(
|
|||||||
title = stringResource(R.string.epoch_converter),
|
title = stringResource(R.string.epoch_converter),
|
||||||
navigateUpAction = navigateUpAction
|
navigateUpAction = navigateUpAction
|
||||||
) { padding ->
|
) { padding ->
|
||||||
Column(
|
PortraitLandscape(
|
||||||
modifier = Modifier.padding(padding),
|
modifier = Modifier.padding(padding),
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
content1 = {
|
||||||
) {
|
|
||||||
TopPart(
|
TopPart(
|
||||||
modifier = Modifier
|
modifier = it,
|
||||||
.fillMaxSize()
|
swap = swap,
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
.weight(1f),
|
|
||||||
unixToDate = !uiState.dateToUnix,
|
unixToDate = !uiState.dateToUnix,
|
||||||
dateField = {
|
dateField = {
|
||||||
Column(
|
Column(
|
||||||
@ -119,27 +108,15 @@ private fun EpochScreen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
},
|
||||||
Button(
|
content2 = {
|
||||||
onClick = swap,
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth()
|
|
||||||
.padding(horizontal = 8.dp),
|
|
||||||
) {
|
|
||||||
Icon(Icons.Default.SwapHoriz, null)
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
Text("SWAP")
|
|
||||||
}
|
|
||||||
|
|
||||||
EpochKeyboard(
|
EpochKeyboard(
|
||||||
modifier = Modifier
|
modifier = it,
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 8.dp)
|
|
||||||
.weight(1f),
|
|
||||||
addSymbol = addSymbol,
|
addSymbol = addSymbol,
|
||||||
clearSymbols = clearSymbols,
|
clearSymbols = clearSymbols,
|
||||||
deleteSymbol = deleteSymbol
|
deleteSymbol = deleteSymbol
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* 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.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
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(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
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(horizontal = 8.dp),
|
||||||
|
contentPadding = PaddingValues(vertical = 26.dp, horizontal = 8.dp),
|
||||||
|
interactionSource = interactionSource
|
||||||
|
) {
|
||||||
|
Icon(Icons.Default.SwapHoriz, null)
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
Text("SWAP")
|
||||||
|
}
|
||||||
|
}
|
@ -19,20 +19,26 @@
|
|||||||
package com.sadellie.unitto.feature.epoch.component
|
package com.sadellie.unitto.feature.epoch.component
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyItemScope
|
import androidx.compose.foundation.lazy.LazyItemScope
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TopPart(
|
fun TopPart(
|
||||||
modifier: Modifier,
|
modifier: Modifier,
|
||||||
unixToDate: Boolean,
|
unixToDate: Boolean,
|
||||||
|
swap: () -> Unit,
|
||||||
dateField: @Composable() (LazyItemScope.() -> Unit),
|
dateField: @Composable() (LazyItemScope.() -> Unit),
|
||||||
unixField: @Composable() (LazyItemScope.() -> Unit),
|
unixField: @Composable() (LazyItemScope.() -> Unit),
|
||||||
) {
|
) {
|
||||||
LazyColumn(
|
Column(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
LazyColumn(
|
||||||
verticalArrangement = Arrangement.Bottom
|
verticalArrangement = Arrangement.Bottom
|
||||||
) {
|
) {
|
||||||
if (unixToDate) {
|
if (unixToDate) {
|
||||||
@ -43,4 +49,6 @@ fun TopPart(
|
|||||||
item("unix") { unixField() }
|
item("unix") { unixField() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
SwapButton(swap)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user