Skip to content

Commit

Permalink
优化topAppBar弹出菜单
Browse files Browse the repository at this point in the history
  • Loading branch information
wilinz committed Aug 13, 2022
1 parent 606103a commit 3fdd4a2
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions app/src/main/java/org/autojs/autoxjs/ui/main/MainActivityCompose.kt
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private fun TopBar(
}
}
1 -> {
IconButton(onClick = { AutoJs.getInstance().scriptEngineService.stopAll()}) {
IconButton(onClick = { AutoJs.getInstance().scriptEngineService.stopAll() }) {
Icon(
imageVector = Icons.Default.Clear,
contentDescription = stringResource(id = R.string.desc_more)
Expand All @@ -400,10 +400,10 @@ fun TopAppBarMenu(
) {
DropdownMenu(expanded = expanded, onDismissRequest = onDismissRequest, offset = offset) {
val context = LocalContext.current
newDirectory(context, scriptListFragment)
NewFile(context, scriptListFragment)
ImportFile(context, scriptListFragment)
NewProject(context, scriptListFragment)
NewDirectory(context, scriptListFragment, onDismissRequest)
NewFile(context, scriptListFragment, onDismissRequest)
ImportFile(context, scriptListFragment, onDismissRequest)
NewProject(context, scriptListFragment, onDismissRequest)
// DropdownMenuItem(onClick = { /*TODO*/ }) {
// MyIcon(
// painter = painterResource(id = R.drawable.ic_timed_task),
Expand All @@ -417,9 +417,10 @@ fun TopAppBarMenu(

@OptIn(ExperimentalPermissionsApi::class)
@Composable
private fun newDirectory(
private fun NewDirectory(
context: Context,
scriptListFragment: ScriptListFragment
scriptListFragment: ScriptListFragment,
onDismissRequest: () -> Unit
) {
val permission = rememberExternalStoragePermissionsState {
if (it) getScriptOperations(
Expand All @@ -428,7 +429,10 @@ private fun newDirectory(
).newDirectory()
else showExternalStoragePermissionToast(context)
}
DropdownMenuItem(onClick = { permission.launchMultiplePermissionRequest() }) {
DropdownMenuItem(onClick = {
onDismissRequest()
permission.launchMultiplePermissionRequest()
}) {
MyIcon(
painter = painterResource(id = R.drawable.ic_floating_action_menu_dir),
contentDescription = null
Expand All @@ -442,7 +446,8 @@ private fun newDirectory(
@Composable
private fun NewFile(
context: Context,
scriptListFragment: ScriptListFragment
scriptListFragment: ScriptListFragment,
onDismissRequest: () -> Unit
) {
val permission = rememberExternalStoragePermissionsState {
if (it) getScriptOperations(
Expand All @@ -451,7 +456,10 @@ private fun NewFile(
).newFile()
else showExternalStoragePermissionToast(context)
}
DropdownMenuItem(onClick = { permission.launchMultiplePermissionRequest() }) {
DropdownMenuItem(onClick = {
onDismissRequest()
permission.launchMultiplePermissionRequest()
}) {
MyIcon(
painter = painterResource(id = R.drawable.ic_floating_action_menu_file),
contentDescription = null
Expand All @@ -465,7 +473,8 @@ private fun NewFile(
@Composable
private fun ImportFile(
context: Context,
scriptListFragment: ScriptListFragment
scriptListFragment: ScriptListFragment,
onDismissRequest: () -> Unit
) {
val permission = rememberExternalStoragePermissionsState {
if (it) getScriptOperations(
Expand All @@ -474,7 +483,10 @@ private fun ImportFile(
).importFile()
else showExternalStoragePermissionToast(context)
}
DropdownMenuItem(onClick = { permission.launchMultiplePermissionRequest() }) {
DropdownMenuItem(onClick = {
onDismissRequest()
permission.launchMultiplePermissionRequest()
}) {
MyIcon(
painter = painterResource(id = R.drawable.ic_floating_action_menu_open),
contentDescription = null
Expand All @@ -487,9 +499,11 @@ private fun ImportFile(
@Composable
private fun NewProject(
context: Context,
scriptListFragment: ScriptListFragment
scriptListFragment: ScriptListFragment,
onDismissRequest: () -> Unit
) {
DropdownMenuItem(onClick = {
onDismissRequest()
ProjectConfigActivity_.intent(context)
.extra(
ProjectConfigActivity.EXTRA_PARENT_DIRECTORY,
Expand Down

0 comments on commit 3fdd4a2

Please sign in to comment.