interact context menu
This commit is contained in:
@@ -4,8 +4,10 @@ import android.content.Intent
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
|
import cafe.adriel.voyager.navigator.Navigator
|
||||||
import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator
|
import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator
|
||||||
import com.megboyzz.devmenu.ui.components.MainScaffold
|
import com.megboyzz.devmenu.ui.components.MainScaffold
|
||||||
|
import com.megboyzz.devmenu.ui.screens.HomeScreen
|
||||||
|
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ class MainActivity : ComponentActivity() {
|
|||||||
val intent = Intent(this, gameActivityClass)
|
val intent = Intent(this, gameActivityClass)
|
||||||
|
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
|
finish()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,17 +34,8 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
|
|
||||||
BottomSheetNavigator {
|
BottomSheetNavigator {
|
||||||
|
Navigator(HomeScreen(::runGame))
|
||||||
}
|
|
||||||
|
|
||||||
MainScaffold(
|
|
||||||
onSettingsClick = { /*TODO*/ },
|
|
||||||
onSearchValueChanged = {},
|
|
||||||
onFloatingButtonClick = ::runGame
|
|
||||||
) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-24
@@ -27,10 +27,10 @@ import androidx.compose.ui.draw.clip
|
|||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.painter.Painter
|
import androidx.compose.ui.graphics.painter.Painter
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.megboyzz.devmenu.R
|
import com.megboyzz.devmenu.R
|
||||||
import com.megboyzz.devmenu.ui.asPainter
|
import com.megboyzz.devmenu.ui.asPainter
|
||||||
|
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ClickableMenuPosition(
|
fun ClickableMenuPosition(
|
||||||
@@ -95,23 +95,27 @@ fun FsElementInContextMenu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ContextMenuState {
|
||||||
|
Main,
|
||||||
|
Delete,
|
||||||
|
Props
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FileContextMenu(
|
fun FileContextMenu(
|
||||||
name: String,
|
fsElementEntity: FsElementModel,
|
||||||
type: ElementType,
|
|
||||||
onRemoveElement: () -> Unit,
|
onRemoveElement: () -> Unit,
|
||||||
onUpdateType: (ElementType) -> ElementType?
|
onUpdateType: (ElementType) -> ElementType?
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var innerType by remember { mutableStateOf(type) }
|
var innerType by remember { mutableStateOf(fsElementEntity.type) }
|
||||||
var isMain by remember { mutableStateOf(true) }
|
var state by remember { mutableStateOf(ContextMenuState.Main) }
|
||||||
|
|
||||||
|
|
||||||
CoreFileContextMenu {
|
CoreFileContextMenu {
|
||||||
FsElementInContextMenu(name = name, type = type)
|
FsElementInContextMenu(name = fsElementEntity.name, type = fsElementEntity.type)
|
||||||
Divider()
|
Divider()
|
||||||
AnimatedBoxForContextMenuContent(isVisible = isMain){
|
AnimatedBoxForContextMenuContent(isVisible = state == ContextMenuState.Main){
|
||||||
AnimatedBoxForContextMenuContent(isVisible = innerType == ElementType.isFile) {
|
AnimatedBoxForContextMenuContent(isVisible = innerType == ElementType.isFile) {
|
||||||
ClickableMenuPosition(
|
ClickableMenuPosition(
|
||||||
name = "Заменить",
|
name = "Заменить",
|
||||||
@@ -155,11 +159,11 @@ fun FileContextMenu(
|
|||||||
ClickableMenuPosition(
|
ClickableMenuPosition(
|
||||||
name = "Удалить",
|
name = "Удалить",
|
||||||
icon = R.drawable.trash.asPainter(),
|
icon = R.drawable.trash.asPainter(),
|
||||||
onClick = { isMain = !isMain }
|
onClick = { state = ContextMenuState.Delete }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
AnimatedBoxForContextMenuContent(isVisible = !isMain) {
|
AnimatedBoxForContextMenuContent(isVisible = state == ContextMenuState.Delete) {
|
||||||
ClickableMenuPosition(
|
ClickableMenuPosition(
|
||||||
name = "Удалить",
|
name = "Удалить",
|
||||||
icon = R.drawable.trash.asPainter(),
|
icon = R.drawable.trash.asPainter(),
|
||||||
@@ -167,11 +171,24 @@ fun FileContextMenu(
|
|||||||
)
|
)
|
||||||
RemoveFileButtonsGroup(
|
RemoveFileButtonsGroup(
|
||||||
onDelete = onRemoveElement,
|
onDelete = onRemoveElement,
|
||||||
onCancel = { isMain = !isMain }
|
onCancel = { state = ContextMenuState.Main }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AnimatedBoxForContextMenuContent(isVisible = state == ContextMenuState.Props) {
|
||||||
|
ClickableMenuPosition(
|
||||||
|
name = "Свойства",
|
||||||
|
icon = R.drawable.info.asPainter(),
|
||||||
|
withEnd = false,
|
||||||
|
)
|
||||||
|
RemoveButton(text = "Назад") {
|
||||||
|
state = ContextMenuState.Main
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun AnimatedBoxForContextMenuContent(
|
fun AnimatedBoxForContextMenuContent(
|
||||||
@@ -253,17 +270,3 @@ fun CoreFileContextMenu(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
|
||||||
fun ClicablePreview() {
|
|
||||||
|
|
||||||
FileContextMenu(
|
|
||||||
name = "my_file.txt",
|
|
||||||
type = ElementType.isFile,
|
|
||||||
onRemoveElement = {},
|
|
||||||
onUpdateType = {null}
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +1,17 @@
|
|||||||
package com.megboyzz.devmenu.ui.components
|
package com.megboyzz.devmenu.ui.components
|
||||||
|
|
||||||
import android.widget.Toast
|
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.combinedClickable
|
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
|
||||||
import androidx.compose.material.ripple.rememberRipple
|
|
||||||
import androidx.compose.material3.Icon
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.platform.LocalContext
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import com.megboyzz.devmenu.R
|
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||||
import com.megboyzz.devmenu.ui.asPainter
|
|
||||||
import com.megboyzz.devmenu.ui.theme.DevMenuTheme
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun FsElement(
|
fun FsElement(
|
||||||
name: String,
|
fsElementEntity: FsElementModel,
|
||||||
type: ElementType,
|
|
||||||
onClick: () -> Unit,
|
onClick: () -> Unit,
|
||||||
onLongPressClick: () -> Unit
|
onLongPressClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
@@ -41,28 +24,7 @@ fun FsElement(
|
|||||||
onLongClick = onLongPressClick
|
onLongClick = onLongPressClick
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
FsElementIcon(type = type)
|
FsElementIcon(type = fsElementEntity.type)
|
||||||
Text(text = name)
|
Text(text = fsElementEntity.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview
|
|
||||||
@Composable
|
|
||||||
fun FileIcon() {
|
|
||||||
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.background(Color.White)
|
|
||||||
) {
|
|
||||||
FsElement(
|
|
||||||
name = "my_file.txt",
|
|
||||||
type = ElementType.isReplaced,
|
|
||||||
onLongPressClick = {Toast.makeText(context, "long!", Toast.LENGTH_SHORT).show()},
|
|
||||||
onClick = {Toast.makeText(context, "one!", Toast.LENGTH_SHORT).show()}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -45,12 +45,13 @@ import com.megboyzz.devmenu.ui.theme.DevMenuTheme
|
|||||||
@Composable
|
@Composable
|
||||||
fun MainScaffold(
|
fun MainScaffold(
|
||||||
onSettingsClick: () -> Unit,
|
onSettingsClick: () -> Unit,
|
||||||
|
searchValue: String,
|
||||||
onSearchValueChanged: (String) -> Unit,
|
onSearchValueChanged: (String) -> Unit,
|
||||||
onFloatingButtonClick: () -> Unit,
|
onFloatingButtonClick: () -> Unit,
|
||||||
content: @Composable (PaddingValues) -> Unit
|
content: @Composable (PaddingValues) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|
||||||
var searchValue by remember { mutableStateOf("") }
|
var searchValue by remember { mutableStateOf(searchValue) }
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
|
||||||
@@ -151,6 +152,7 @@ fun ScaffoldPreview() {
|
|||||||
MainScaffold(
|
MainScaffold(
|
||||||
onSettingsClick = { /*TODO*/ },
|
onSettingsClick = { /*TODO*/ },
|
||||||
onSearchValueChanged = {},
|
onSearchValueChanged = {},
|
||||||
|
searchValue = "",
|
||||||
onFloatingButtonClick = { /*TODO*/ }
|
onFloatingButtonClick = { /*TODO*/ }
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.megboyzz.devmenu.ui.entities
|
||||||
|
|
||||||
|
import com.megboyzz.devmenu.ui.components.ElementType
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
data class FsElementModel(
|
||||||
|
val name: String,
|
||||||
|
val type: ElementType,
|
||||||
|
val size: Long,
|
||||||
|
val date: Date
|
||||||
|
)
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.megboyzz.devmenu.ui.screens
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
|
import com.megboyzz.devmenu.ui.components.FileContextMenu
|
||||||
|
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||||
|
|
||||||
|
class FileContextMenuScreen(
|
||||||
|
private val fsElementModel: FsElementModel,
|
||||||
|
private val onRemoveFile: () -> Unit,
|
||||||
|
) : Screen {
|
||||||
|
@Composable
|
||||||
|
override fun Content() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
FileContextMenu(
|
||||||
|
fsElementEntity = fsElementModel,
|
||||||
|
onRemoveElement = onRemoveFile,
|
||||||
|
onUpdateType = {null}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.megboyzz.devmenu.ui.screens
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import cafe.adriel.voyager.core.screen.Screen
|
||||||
|
import cafe.adriel.voyager.navigator.bottomSheet.LocalBottomSheetNavigator
|
||||||
|
import com.megboyzz.devmenu.ui.components.ElementType
|
||||||
|
import com.megboyzz.devmenu.ui.components.FsElement
|
||||||
|
import com.megboyzz.devmenu.ui.components.MainScaffold
|
||||||
|
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||||
|
import java.util.Date
|
||||||
|
|
||||||
|
class HomeScreen(
|
||||||
|
private val onFloatingButtonClick: () -> Unit
|
||||||
|
): Screen {
|
||||||
|
@Composable
|
||||||
|
override fun Content() {
|
||||||
|
|
||||||
|
val bottomSheetNavigator = LocalBottomSheetNavigator.current
|
||||||
|
|
||||||
|
var searchValue by remember{ mutableStateOf("") }
|
||||||
|
|
||||||
|
val fsElementModel = FsElementModel(
|
||||||
|
name = "my_txt.txt",
|
||||||
|
type = ElementType.isHidden,
|
||||||
|
size = 123,
|
||||||
|
date = Date()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
MainScaffold(
|
||||||
|
onSettingsClick = { /*TODO Переход к настройкам */ },
|
||||||
|
onSearchValueChanged = { searchValue = it },
|
||||||
|
searchValue = searchValue,
|
||||||
|
onFloatingButtonClick = onFloatingButtonClick
|
||||||
|
) {
|
||||||
|
FsElement(
|
||||||
|
fsElementEntity = fsElementModel,
|
||||||
|
onClick = { /*TODO*/ },
|
||||||
|
onLongPressClick = {
|
||||||
|
bottomSheetNavigator.show(
|
||||||
|
FileContextMenuScreen(
|
||||||
|
fsElementModel = fsElementModel,
|
||||||
|
onRemoveFile = {}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user