interact context menu
This commit is contained in:
@@ -4,8 +4,10 @@ import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import cafe.adriel.voyager.navigator.Navigator
|
||||
import cafe.adriel.voyager.navigator.bottomSheet.BottomSheetNavigator
|
||||
import com.megboyzz.devmenu.ui.components.MainScaffold
|
||||
import com.megboyzz.devmenu.ui.screens.HomeScreen
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
@@ -15,6 +17,7 @@ class MainActivity : ComponentActivity() {
|
||||
val intent = Intent(this, gameActivityClass)
|
||||
|
||||
startActivity(intent)
|
||||
finish()
|
||||
|
||||
}
|
||||
|
||||
@@ -31,17 +34,8 @@ class MainActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
setContent {
|
||||
|
||||
BottomSheetNavigator {
|
||||
|
||||
}
|
||||
|
||||
MainScaffold(
|
||||
onSettingsClick = { /*TODO*/ },
|
||||
onSearchValueChanged = {},
|
||||
onFloatingButtonClick = ::runGame
|
||||
) {
|
||||
|
||||
Navigator(HomeScreen(::runGame))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+27
-24
@@ -27,10 +27,10 @@ import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.painter.Painter
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.megboyzz.devmenu.R
|
||||
import com.megboyzz.devmenu.ui.asPainter
|
||||
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||
|
||||
@Composable
|
||||
fun ClickableMenuPosition(
|
||||
@@ -95,23 +95,27 @@ fun FsElementInContextMenu(
|
||||
}
|
||||
}
|
||||
|
||||
enum class ContextMenuState {
|
||||
Main,
|
||||
Delete,
|
||||
Props
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun FileContextMenu(
|
||||
name: String,
|
||||
type: ElementType,
|
||||
fsElementEntity: FsElementModel,
|
||||
onRemoveElement: () -> Unit,
|
||||
onUpdateType: (ElementType) -> ElementType?
|
||||
) {
|
||||
|
||||
var innerType by remember { mutableStateOf(type) }
|
||||
var isMain by remember { mutableStateOf(true) }
|
||||
var innerType by remember { mutableStateOf(fsElementEntity.type) }
|
||||
var state by remember { mutableStateOf(ContextMenuState.Main) }
|
||||
|
||||
|
||||
CoreFileContextMenu {
|
||||
FsElementInContextMenu(name = name, type = type)
|
||||
FsElementInContextMenu(name = fsElementEntity.name, type = fsElementEntity.type)
|
||||
Divider()
|
||||
AnimatedBoxForContextMenuContent(isVisible = isMain){
|
||||
AnimatedBoxForContextMenuContent(isVisible = state == ContextMenuState.Main){
|
||||
AnimatedBoxForContextMenuContent(isVisible = innerType == ElementType.isFile) {
|
||||
ClickableMenuPosition(
|
||||
name = "Заменить",
|
||||
@@ -155,11 +159,11 @@ fun FileContextMenu(
|
||||
ClickableMenuPosition(
|
||||
name = "Удалить",
|
||||
icon = R.drawable.trash.asPainter(),
|
||||
onClick = { isMain = !isMain }
|
||||
onClick = { state = ContextMenuState.Delete }
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedBoxForContextMenuContent(isVisible = !isMain) {
|
||||
AnimatedBoxForContextMenuContent(isVisible = state == ContextMenuState.Delete) {
|
||||
ClickableMenuPosition(
|
||||
name = "Удалить",
|
||||
icon = R.drawable.trash.asPainter(),
|
||||
@@ -167,11 +171,24 @@ fun FileContextMenu(
|
||||
)
|
||||
RemoveFileButtonsGroup(
|
||||
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
|
||||
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
|
||||
|
||||
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.Box
|
||||
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.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
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 com.megboyzz.devmenu.R
|
||||
import com.megboyzz.devmenu.ui.asPainter
|
||||
import com.megboyzz.devmenu.ui.theme.DevMenuTheme
|
||||
import com.megboyzz.devmenu.ui.entities.FsElementModel
|
||||
|
||||
@Composable
|
||||
fun FsElement(
|
||||
name: String,
|
||||
type: ElementType,
|
||||
fsElementEntity: FsElementModel,
|
||||
onClick: () -> Unit,
|
||||
onLongPressClick: () -> Unit
|
||||
) {
|
||||
@@ -41,28 +24,7 @@ fun FsElement(
|
||||
onLongClick = onLongPressClick
|
||||
)
|
||||
) {
|
||||
FsElementIcon(type = type)
|
||||
Text(text = name)
|
||||
FsElementIcon(type = fsElementEntity.type)
|
||||
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
|
||||
fun MainScaffold(
|
||||
onSettingsClick: () -> Unit,
|
||||
searchValue: String,
|
||||
onSearchValueChanged: (String) -> Unit,
|
||||
onFloatingButtonClick: () -> Unit,
|
||||
content: @Composable (PaddingValues) -> Unit
|
||||
) {
|
||||
|
||||
var searchValue by remember { mutableStateOf("") }
|
||||
var searchValue by remember { mutableStateOf(searchValue) }
|
||||
|
||||
Scaffold(
|
||||
|
||||
@@ -151,6 +152,7 @@ fun ScaffoldPreview() {
|
||||
MainScaffold(
|
||||
onSettingsClick = { /*TODO*/ },
|
||||
onSearchValueChanged = {},
|
||||
searchValue = "",
|
||||
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