Skip to content

Commit

Permalink
Merge pull request #16 from soupslurpr/dropdown-menu-for-opening-and-…
Browse files Browse the repository at this point in the history
…creating-file

Make the opening and creating file buttons DropdownMenu's.
  • Loading branch information
soupslurpr committed Jun 5, 2023
2 parents 08859b5 + da5e77f commit e5f9395
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 10 deletions.
10 changes: 8 additions & 2 deletions app/src/main/kotlin/dev/soupslurpr/beautyxt/BeauTyXT.kt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fun BeauTyXTApp(
composable(route = BeauTyXTScreens.Start.name) {
StartupScreen(
modifier = modifier,
onOpenButtonClicked = {
onOpenTxtButtonClicked = {
openFileLauncher.launch(
arrayOf(
"text/*",
Expand All @@ -144,7 +144,13 @@ fun BeauTyXTApp(
ActivityOptionsCompat.makeBasic(),
)
},
onCreateButtonClicked = {
onOpenAnyButtonClicked = {
openFileLauncher.launch(
arrayOf("*/*"),
ActivityOptionsCompat.makeBasic(),
)
},
onCreateTxtButtonClicked = {
createFileLauncher.launch(
// Make default file name the current LocalDateTime, and for devices
// which don't support LocalDateTime, make it blank.
Expand Down
57 changes: 49 additions & 8 deletions app/src/main/kotlin/dev/soupslurpr/beautyxt/ui/StartupScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
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.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
Expand All @@ -35,10 +41,13 @@ import dev.soupslurpr.beautyxt.R
@Composable
fun StartupScreen(
modifier: Modifier,
onOpenButtonClicked: () -> Unit,
onCreateButtonClicked: () -> Unit,
onOpenTxtButtonClicked: () -> Unit,
onCreateTxtButtonClicked: () -> Unit,
onSettingsButtonClicked: () -> Unit,
onOpenAnyButtonClicked: () -> Unit,
) {
var isOpenDropdownMenuExpanded by remember { mutableStateOf(false) }
var isCreateDropdownMenuExpanded by remember { mutableStateOf(false) }
Column(
modifier = modifier
.padding(16.dp)
Expand All @@ -59,32 +68,63 @@ fun StartupScreen(
Text(
text = "Text, but beautiful.\n" +
"\n" +
"NEW! BeauTyXT now shows up as an option" +
" to open files in file explorers and other apps!",
"NEW! You can now open custom or any file type in BeauTyXT!\n" +
"Just make sure they are plain text.",
style = MaterialTheme.typography.bodySmall,
textAlign = TextAlign.Center
)
FilledTonalButton(
modifier = modifier.fillMaxWidth(),
onClick = { onOpenButtonClicked() }
onClick = { isOpenDropdownMenuExpanded = true }
) {
Icon(
painter = painterResource(id = R.drawable.baseline_file_open_24),
contentDescription = null
)
Spacer(modifier = modifier.width(8.dp))
Text(stringResource(R.string.open_existing_file))
DropdownMenu(
expanded = isOpenDropdownMenuExpanded,
onDismissRequest = { isOpenDropdownMenuExpanded = false },
) {
DropdownMenuItem(
text = { Text(text = ".txt") },
onClick = {
isOpenDropdownMenuExpanded = false
onOpenTxtButtonClicked()
},
)
DropdownMenuItem(
text = { Text(stringResource(R.string.any)) },
onClick = {
isOpenDropdownMenuExpanded = false
onOpenAnyButtonClicked()
},
)
}
}
FilledTonalButton(
modifier = modifier.fillMaxWidth(),
onClick = { onCreateButtonClicked() }
onClick = { isCreateDropdownMenuExpanded = true }
) {
Icon(
imageVector = Icons.Filled.Add,
contentDescription = null
)
Spacer(modifier = modifier.width(8.dp))
Text(stringResource(R.string.create_new_file))
DropdownMenu(
expanded = isCreateDropdownMenuExpanded,
onDismissRequest = { isCreateDropdownMenuExpanded = false },
) {
DropdownMenuItem(
text = { Text(text = ".txt") },
onClick = {
isCreateDropdownMenuExpanded = false
onCreateTxtButtonClicked()
},
)
}
}
FilledTonalButton(
modifier = modifier.fillMaxWidth(),
Expand All @@ -105,8 +145,9 @@ fun StartupScreen(
fun StartupPreview() {
StartupScreen(
modifier = Modifier.fillMaxSize(),
onOpenButtonClicked = {},
onCreateButtonClicked = {},
onOpenAnyButtonClicked = {},
onOpenTxtButtonClicked = {},
onCreateTxtButtonClicked = {},
onSettingsButtonClicked = {},
)
}
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
<string name="credits">Credits</string>
<string name="credits_setting_name">Credits</string>
<string name="credits_setting_description">View open source licenses of code that BeauTyXT uses in app</string>
<string name="any">any</string>
</resources>

0 comments on commit e5f9395

Please sign in to comment.