164 lines
5.5 KiB
Kotlin
164 lines
5.5 KiB
Kotlin
package ru.omni_devel.cards
|
|
|
|
import android.content.Intent
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.gestures.detectTapGestures
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.IntrinsicSize
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.material3.Button
|
|
import androidx.compose.material3.ButtonDefaults
|
|
import androidx.compose.material3.DropdownMenu
|
|
import androidx.compose.material3.DropdownMenuItem
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.input.pointer.pointerInput
|
|
import androidx.compose.ui.platform.LocalContext
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import androidx.core.graphics.toColorInt
|
|
|
|
@Composable
|
|
fun Page(name: String, innerPadding: PaddingValues, content: @Composable () -> Unit) {
|
|
Column() {
|
|
TopBar(name, innerPadding)
|
|
|
|
Column(
|
|
modifier = Modifier
|
|
.fillMaxSize()
|
|
.padding(horizontal = 16.dp)
|
|
.background(MaterialTheme.colorScheme.background)
|
|
) {
|
|
content()
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
fun TopBar(text: String, innerPadding: PaddingValues) {
|
|
Row(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.background(MaterialTheme.colorScheme.primaryContainer)
|
|
.padding(top = innerPadding.calculateTopPadding())
|
|
.padding(horizontal = 8.dp)
|
|
.padding(bottom = 8.dp)
|
|
) {
|
|
Text(
|
|
text,
|
|
modifier = Modifier.padding(vertical = 4.dp, horizontal = 12.dp),
|
|
fontSize = 24.sp,
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
fun CardButton(cardInfo: CardInfo, onDeleteCard: (Int) -> Unit) {
|
|
val context = LocalContext.current
|
|
var menuExpanded by remember { mutableStateOf(false) }
|
|
|
|
Box(modifier = Modifier.fillMaxWidth()) {
|
|
Surface(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.pointerInput(Unit) {
|
|
detectTapGestures(
|
|
onTap = {
|
|
val intent = Intent(context, ShowCardActivity::class.java)
|
|
intent.putExtra("cardId", cardInfo.id)
|
|
context.startActivity(intent)
|
|
},
|
|
onLongPress = {
|
|
menuExpanded = true
|
|
}
|
|
)
|
|
},
|
|
shape = ButtonDefaults.shape,
|
|
color = MaterialTheme.colorScheme.primaryContainer,
|
|
tonalElevation = 2.dp
|
|
) {
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min),
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
) {
|
|
Box(
|
|
modifier = Modifier
|
|
.fillMaxHeight()
|
|
.width(32.dp)
|
|
.background(
|
|
if (cardInfo.color == null) MaterialTheme.colorScheme.secondaryContainer.copy(alpha = 0.625f)
|
|
else Color(cardInfo.color.toColorInt()).copy(alpha = 0.625f)
|
|
)
|
|
)
|
|
|
|
Text(
|
|
cardInfo.name,
|
|
fontSize = 16.sp,
|
|
color = MaterialTheme.colorScheme.onPrimaryContainer,
|
|
modifier = Modifier
|
|
.padding(16.dp)
|
|
.fillMaxWidth()
|
|
.weight(1f),
|
|
textAlign = TextAlign.Start
|
|
)
|
|
}
|
|
}
|
|
|
|
DropdownMenu(
|
|
expanded = menuExpanded,
|
|
onDismissRequest = { menuExpanded = false }
|
|
) {
|
|
DropdownMenuItem(
|
|
text = { Text(stringResource(R.string.do_edit_card)) },
|
|
onClick = {
|
|
menuExpanded = false
|
|
|
|
val intent = Intent(context, EditCardActivity::class.java)
|
|
|
|
intent.putExtra("cardId", cardInfo.id)
|
|
|
|
context.startActivity(intent)
|
|
}
|
|
)
|
|
DropdownMenuItem(
|
|
text = { Text(stringResource(R.string.do_delete_card)) },
|
|
onClick = {
|
|
menuExpanded = false
|
|
|
|
onDeleteCard(cardInfo.id)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
fun FullWidthButton(onClick: () -> Unit, content: @Composable () -> Unit) {
|
|
Button(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
onClick = onClick
|
|
) {
|
|
content()
|
|
}
|
|
}
|