Skip to content

Commit

Permalink
Create settings screen (#12)
Browse files Browse the repository at this point in the history
* feat: ๐ŸŽธ build basic SettingsScreen

* chore: ๐Ÿค– add dependencies for compose-destinations

* feat: ๐ŸŽธ add navigation to HomeScreen and SettingsScreen

* feat: ๐ŸŽธ add version info to SettingsScreen
  • Loading branch information
ricky9667 authored Jul 16, 2023
1 parent 99a9788 commit 46b6faa
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 10 deletions.
10 changes: 7 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
id("com.google.devtools.ksp") version "1.8.10-1.0.9"
id("org.jlleitschuh.gradle.ktlint") version "11.4.1"
}

Expand Down Expand Up @@ -31,11 +32,11 @@ android {
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "17"
}
buildFeatures {
compose = true
Expand Down Expand Up @@ -68,6 +69,9 @@ dependencies {
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material3:material3")
implementation("com.louiscad.splitties:splitties-systemservices:3.0.0")
implementation("com.github.alorma:compose-settings-ui-m3:0.27.0")
implementation("io.github.raamcosta.compose-destinations:core:1.8.42-beta")
ksp("io.github.raamcosta.compose-destinations:ksp:1.8.42-beta")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/rickyhu/hushkeyboard/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import com.rickyhu.hushkeyboard.ui.home.HomeScreen
import com.ramcosta.composedestinations.DestinationsNavHost
import com.rickyhu.hushkeyboard.ui.NavGraphs
import com.rickyhu.hushkeyboard.ui.theme.HushKeyboardTheme

class MainActivity : ComponentActivity() {
Expand All @@ -19,7 +20,7 @@ class MainActivity : ComponentActivity() {
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
HomeScreen()
DestinationsNavHost(navGraph = NavGraphs.root)
}
}
}
Expand Down
19 changes: 14 additions & 5 deletions app/src/main/java/com/rickyhu/hushkeyboard/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,30 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.rickyhu.hushkeyboard.R
import com.rickyhu.hushkeyboard.ui.destinations.SettingsScreenDestination
import com.rickyhu.hushkeyboard.ui.theme.HushKeyboardTheme
import splitties.systemservices.inputMethodManager

@Destination(start = true)
@Composable
fun HomeScreen(navigator: DestinationsNavigator) {
HomeContent(onSettingsClick = { navigator.navigate(SettingsScreenDestination()) })
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun HomeScreen() {
private fun HomeContent(
onSettingsClick: () -> Unit = {}
) {
val context = LocalContext.current
var text by remember { mutableStateOf("") }

Scaffold(
floatingActionButton = {
FloatingActionButton(
onClick = {}
) {
FloatingActionButton(onClick = onSettingsClick) {
Icon(Icons.Default.Settings, contentDescription = "Settings")
}
},
Expand Down Expand Up @@ -129,6 +138,6 @@ fun HomeScreen() {
@Composable
fun HomeScreenPreview() {
HushKeyboardTheme {
HomeScreen()
HomeContent()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.rickyhu.hushkeyboard.ui.settings

import android.content.Intent
import android.net.Uri
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Info
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import com.alorma.compose.settings.ui.SettingsMenuLink
import com.ramcosta.composedestinations.annotation.Destination
import com.rickyhu.hushkeyboard.ui.theme.HushKeyboardTheme

@Destination
@Composable
fun SettingsScreen() = SettingsContent()

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun SettingsContent() {
val context = LocalContext.current

Scaffold(
topBar = {
TopAppBar(title = { Text("Settings") })
},
content = { padding ->
Column(modifier = Modifier.padding(padding)) {
SettingsMenuLink(
icon = { Icon(imageVector = Icons.Default.Info, contentDescription = "Info") },
title = { Text("Version") },
subtitle = { Text("v0.1.0") },
onClick = {
val url = "https://github.com/ricky9667/HushKeyboard"
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
context.startActivity(intent)
}
)
}
}
)
}

@Preview
@Composable
fun SettingsScreenPreview() {
HushKeyboardTheme {
SettingsContent()
}
}

0 comments on commit 46b6faa

Please sign in to comment.