mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-22 16:42:38 +00:00
implement barebones settings ui
This commit is contained in:
5 files changed
+161
-100
No files matched your search
@@ -26,6 +26,15 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:theme="@style/Theme.GeodeLauncher"
|
android:theme="@style/Theme.GeodeLauncher"
|
||||||
tools:targetApi="31">
|
tools:targetApi="31">
|
||||||
|
<activity
|
||||||
|
android:name=".SettingsActivity"
|
||||||
|
android:exported="false"
|
||||||
|
android:label="@string/title_activity_settings"
|
||||||
|
android:theme="@style/Theme.GeodeLauncher">
|
||||||
|
<meta-data
|
||||||
|
android:name="android.app.lib_name"
|
||||||
|
android:value="" />
|
||||||
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".GeometryDashActivity"
|
android:name=".GeometryDashActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -39,10 +48,11 @@
|
|||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:theme="@style/Theme.GeodeLauncher"
|
android:exported="true"
|
||||||
android:exported="true">
|
android:theme="@style/Theme.GeodeLauncher">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|||||||
@@ -11,24 +11,18 @@ import androidx.activity.ComponentActivity
|
|||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
import androidx.compose.foundation.Image
|
import androidx.compose.foundation.Image
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.selection.toggleable
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.Edit
|
|
||||||
import androidx.compose.material.icons.filled.PlayArrow
|
import androidx.compose.material.icons.filled.PlayArrow
|
||||||
import androidx.compose.material.icons.filled.Warning
|
import androidx.compose.material.icons.filled.Settings
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.mutableStateOf
|
|
||||||
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.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.semantics.Role
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.core.content.edit
|
|
||||||
import com.geode.geodelauncher.ui.theme.GeodeLauncherTheme
|
import com.geode.geodelauncher.ui.theme.GeodeLauncherTheme
|
||||||
import com.geode.geodelauncher.utils.LaunchUtils
|
import com.geode.geodelauncher.utils.LaunchUtils
|
||||||
|
|
||||||
@@ -60,7 +54,8 @@ fun onLaunch(context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onSettings(context: Context) {
|
fun onSettings(context: Context) {
|
||||||
Toast.makeText(context, "Settings are not implemented yet!", Toast.LENGTH_SHORT).show()
|
val launchIntent = Intent(context, SettingsActivity::class.java)
|
||||||
|
context.startActivity(launchIntent)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onOpenFolder(context: Context) {
|
fun onOpenFolder(context: Context) {
|
||||||
@@ -79,30 +74,6 @@ fun onOpenFolder(context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toggleLoadTesting(context: Context): Boolean {
|
|
||||||
val preferences = context.getSharedPreferences(
|
|
||||||
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE
|
|
||||||
)
|
|
||||||
|
|
||||||
val current = preferences.getBoolean(
|
|
||||||
context.getString(R.string.preference_load_testing), false
|
|
||||||
)
|
|
||||||
preferences.edit {
|
|
||||||
putBoolean(context.getString(R.string.preference_load_testing), !current)
|
|
||||||
commit()
|
|
||||||
}
|
|
||||||
|
|
||||||
return preferences.getBoolean(context.getString(R.string.preference_load_testing), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getLoadTesting(context: Context): Boolean {
|
|
||||||
val preferences = context.getSharedPreferences(
|
|
||||||
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE
|
|
||||||
)
|
|
||||||
|
|
||||||
return preferences.getBoolean(context.getString(R.string.preference_load_testing), false)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(gdInstalled: Boolean = true) {
|
fun MainScreen(gdInstalled: Boolean = true) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -132,21 +103,18 @@ fun MainScreen(gdInstalled: Boolean = true) {
|
|||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
Text("Launch")
|
Text("Launch")
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
IconButton(onClick = { onSettings(context) }) {
|
IconButton(onClick = { onSettings(context) }) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Filled.Settings,
|
Icons.Filled.Settings,
|
||||||
contentDescription = "Settings Icon"
|
contentDescription = "Settings Icon"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Text(
|
Text(
|
||||||
"Geometry Dash could not be found.",
|
"Geometry Dash could not be found.",
|
||||||
modifier = Modifier.padding(12.dp)
|
modifier = Modifier.padding(12.dp)
|
||||||
)
|
)
|
||||||
/*
|
|
||||||
Button(onClick = { onSettings(context) }) {
|
Button(onClick = { onSettings(context) }) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Filled.Settings,
|
Icons.Filled.Settings,
|
||||||
@@ -155,69 +123,6 @@ fun MainScreen(gdInstalled: Boolean = true) {
|
|||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
||||||
Text("Settings")
|
Text("Settings")
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
Spacer(modifier = Modifier.height(12.dp))
|
|
||||||
|
|
||||||
TestingUtils()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun TestingUtils() {
|
|
||||||
val context = LocalContext.current
|
|
||||||
|
|
||||||
val isLoadTesting = remember { mutableStateOf(getLoadTesting(context)) }
|
|
||||||
|
|
||||||
Card(
|
|
||||||
elevation = CardDefaults.elevatedCardElevation(),
|
|
||||||
colors = CardDefaults.elevatedCardColors(),
|
|
||||||
) {
|
|
||||||
Column(
|
|
||||||
Modifier.padding(16.dp),
|
|
||||||
verticalArrangement = Arrangement.spacedBy(4.dp, Alignment.CenterVertically),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
|
||||||
) {
|
|
||||||
Row {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Warning,
|
|
||||||
contentDescription = "Warning Icon"
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(4.dp))
|
|
||||||
Text("Testing Utils")
|
|
||||||
}
|
|
||||||
Row(
|
|
||||||
Modifier
|
|
||||||
.height(48.dp)
|
|
||||||
.toggleable(
|
|
||||||
value = isLoadTesting.value,
|
|
||||||
onValueChange = { isLoadTesting.value = toggleLoadTesting(context) },
|
|
||||||
role = Role.Checkbox
|
|
||||||
)
|
|
||||||
.padding(horizontal = 16.dp),
|
|
||||||
verticalAlignment = Alignment.CenterVertically
|
|
||||||
) {
|
|
||||||
Checkbox(
|
|
||||||
checked = isLoadTesting.value,
|
|
||||||
onCheckedChange = null
|
|
||||||
)
|
|
||||||
Text(
|
|
||||||
text = "Load files in /test",
|
|
||||||
style = MaterialTheme.typography.bodyLarge,
|
|
||||||
modifier = Modifier.padding(start = 16.dp)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
OutlinedButton(
|
|
||||||
onClick = { onOpenFolder(context) }
|
|
||||||
) {
|
|
||||||
Icon(
|
|
||||||
Icons.Filled.Edit,
|
|
||||||
contentDescription = "Folder Icon"
|
|
||||||
)
|
|
||||||
Spacer(Modifier.size(ButtonDefaults.IconSpacing))
|
|
||||||
Text("Copy external folder path")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
package com.geode.geodelauncher
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
|
import androidx.activity.OnBackPressedDispatcher
|
||||||
|
import androidx.activity.compose.setContent
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.selection.toggleable
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
|
import androidx.compose.material3.*
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
|
import androidx.compose.ui.semantics.Role
|
||||||
|
import androidx.compose.ui.text.style.TextOverflow
|
||||||
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.content.edit
|
||||||
|
import com.geode.geodelauncher.ui.theme.GeodeLauncherTheme
|
||||||
|
|
||||||
|
class SettingsActivity : ComponentActivity() {
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
setContent {
|
||||||
|
GeodeLauncherTheme {
|
||||||
|
Surface(
|
||||||
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
color = MaterialTheme.colorScheme.background
|
||||||
|
) {
|
||||||
|
SettingsScreen(
|
||||||
|
onBackPressedDispatcher = onBackPressedDispatcher
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun SettingsScreen(onBackPressedDispatcher: OnBackPressedDispatcher?) {
|
||||||
|
Scaffold(
|
||||||
|
topBar = {
|
||||||
|
TopAppBar(
|
||||||
|
navigationIcon = {
|
||||||
|
IconButton(onClick = { onBackPressedDispatcher?.onBackPressed() }) {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Filled.ArrowBack,
|
||||||
|
contentDescription = "Back"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Text(
|
||||||
|
"Settings",
|
||||||
|
maxLines = 1,
|
||||||
|
overflow = TextOverflow.Ellipsis
|
||||||
|
)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
|
content = { innerPadding ->
|
||||||
|
Column(
|
||||||
|
Modifier
|
||||||
|
.padding(innerPadding)
|
||||||
|
.fillMaxWidth(),
|
||||||
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
|
) {
|
||||||
|
OptionsCard(R.string.preference_load_testing_name, R.string.preference_load_testing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun toggleSetting(context: Context, @StringRes preferenceId: Int): Boolean {
|
||||||
|
val preferences = context.getSharedPreferences(
|
||||||
|
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE
|
||||||
|
)
|
||||||
|
|
||||||
|
val current = preferences.getBoolean(
|
||||||
|
context.getString(preferenceId), false
|
||||||
|
)
|
||||||
|
preferences.edit {
|
||||||
|
putBoolean(context.getString(preferenceId), !current)
|
||||||
|
commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
return preferences.getBoolean(context.getString(R.string.preference_load_testing), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getSetting(context: Context, @StringRes preferenceId: Int): Boolean {
|
||||||
|
val preferences = context.getSharedPreferences(
|
||||||
|
context.getString(R.string.preference_file_key), Context.MODE_PRIVATE
|
||||||
|
)
|
||||||
|
|
||||||
|
return preferences.getBoolean(context.getString(preferenceId), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun OptionsCard(@StringRes title: Int, @StringRes preferenceId: Int) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
val settingEnabled = remember {
|
||||||
|
mutableStateOf(getSetting(context, preferenceId)) }
|
||||||
|
Row(
|
||||||
|
Modifier.fillMaxWidth()
|
||||||
|
.height(64.dp)
|
||||||
|
.toggleable(
|
||||||
|
value = settingEnabled.value,
|
||||||
|
onValueChange = { settingEnabled.value = toggleSetting(context, preferenceId) },
|
||||||
|
role = Role.Switch,
|
||||||
|
)
|
||||||
|
.padding(horizontal = 16.dp),
|
||||||
|
Arrangement.SpaceBetween,
|
||||||
|
Alignment.CenterVertically,
|
||||||
|
) {
|
||||||
|
Text(context.getString(title))
|
||||||
|
Switch(checked = settingEnabled.value, onCheckedChange = null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showBackground = true)
|
||||||
|
@Composable
|
||||||
|
fun OptionsCardPreview() {
|
||||||
|
GeodeLauncherTheme {
|
||||||
|
OptionsCard(R.string.preference_load_testing_name, R.string.preference_load_testing)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(showSystemUi = true)
|
||||||
|
@Composable
|
||||||
|
fun DefaultPreview() {
|
||||||
|
GeodeLauncherTheme {
|
||||||
|
SettingsScreen(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,4 +5,6 @@
|
|||||||
<string name="no_activity_found">No activity found for this action.</string>
|
<string name="no_activity_found">No activity found for this action.</string>
|
||||||
<string name="preference_file_key">GeodeLauncherPreferencesFileKey</string>
|
<string name="preference_file_key">GeodeLauncherPreferencesFileKey</string>
|
||||||
<string name="preference_load_testing">PreferenceLoadTesting</string>
|
<string name="preference_load_testing">PreferenceLoadTesting</string>
|
||||||
|
<string name="preference_load_testing_name">Load files from /test</string>
|
||||||
|
<string name="title_activity_settings">SettingsActivity</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<style name="Theme.NoActionBar.Fullscreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
<style name="Theme.NoActionBar.Fullscreen" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||||
<item name="android:windowNoTitle">true</item>
|
<item name="android:windowNoTitle">true</item>
|
||||||
<item name="android:windowActionBar">false</item>
|
<item name="android:windowActionBar">false</item>
|
||||||
<item name="android:windowFullscreen">true</item>
|
<item name="android:windowFullscreen">true</item>
|
||||||
<item name="android:windowContentOverlay">@null</item>
|
<item name="android:windowContentOverlay">@null</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" />
|
<style name="Theme.GeodeLauncher" parent="android:Theme.Material.Light.NoActionBar" />
|
||||||
</resources>
|
</resources>
|
||||||
Reference in new issue
Block a user