Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
root = true

[*.{kt,kts}]
ktlint_function_naming_ignore_when_annotated_with = Composable
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21
cache: gradle

- name: Build App
Expand Down
35 changes: 22 additions & 13 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile

plugins {
kotlin("kapt")
alias(libs.plugins.android.application)
Expand All @@ -11,12 +14,17 @@ plugins {

android {
namespace = "com.rickyhu.hushkeyboard"
compileSdk = 35
compileSdk = 36

compileOptions {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}

defaultConfig {
applicationId = "com.rickyhu.hushkeyboard"
minSdk = 26
targetSdk = 35
minSdk = 29
targetSdk = 36
versionCode = 3
versionName = "0.4.0"

Expand All @@ -31,22 +39,15 @@ android {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
kotlinCompilerExtensionVersion = "1.5.15"
}
packaging {
resources {
Expand All @@ -60,7 +61,15 @@ android {
}
}

tasks.getByPath("preBuild").dependsOn("ktlintFormat")
tasks {
getByPath("preBuild").dependsOn("ktlintFormat")
withType<KotlinJvmCompile>().configureEach {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_21)
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
}
}
}

ktlint {
android.set(true)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.HushKeyboard"
tools:targetApi="31">
tools:targetApi="36">
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/com/rickyhu/hushkeyboard/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/com/rickyhu/hushkeyboard/data/AppSettings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@ data class AppSettings(
val wideNotationOption: WideNotationOption = WideNotationOption.WideWithW,
val smartDelete: Boolean = true,
val addSpaceAfterNotation: Boolean = true,
val vibrateOnTap: Boolean = true
val vibrateOnTap: Boolean = true,
)

enum class ThemeOption { System, Light, Dark }

enum class WideNotationOption {
WideWithW, WideWithLowercase;
WideWithW,
WideWithLowercase,
;

override fun toString() = when (this) {
WideWithW -> "Use w (Rw)"
WideWithLowercase -> "Use lowercase (r)"
}
override fun toString() =
when (this) {
WideWithW -> "Use w (Rw)"
WideWithLowercase -> "Use lowercase (r)"
}
}
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
package com.rickyhu.hushkeyboard.data

import androidx.datastore.core.Serializer
import java.io.InputStream
import java.io.OutputStream
import kotlinx.serialization.SerializationException
import kotlinx.serialization.json.Json
import java.io.InputStream
import java.io.OutputStream

object AppSettingsSerializer : Serializer<AppSettings> {
override val defaultValue: AppSettings
get() = AppSettings()

override suspend fun readFrom(input: InputStream): AppSettings {
return try {
override suspend fun readFrom(input: InputStream): AppSettings =
try {
Json.decodeFromString(
deserializer = AppSettings.serializer(),
string = input.readBytes().decodeToString()
string = input.readBytes().decodeToString(),
)
} catch (e: SerializationException) {
e.printStackTrace()
defaultValue
}
}

override suspend fun writeTo(t: AppSettings, output: OutputStream) {
override suspend fun writeTo(
t: AppSettings,
output: OutputStream,
) {
output.write(
Json.encodeToString(
serializer = AppSettings.serializer(),
value = t
).encodeToByteArray()
Json
.encodeToString(
serializer = AppSettings.serializer(),
value = t,
).encodeToByteArray(),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,31 @@ import javax.inject.Inject

private val Context.dataStore by dataStore("app-settings.json", AppSettingsSerializer)

class SettingsRepository @Inject constructor(
@ApplicationContext context: Context
) {

private val dataStore = context.dataStore
val settings = dataStore.data

suspend fun updateThemeOption(themeOption: ThemeOption) {
dataStore.updateData { it.copy(themeOption = themeOption) }
}

suspend fun updateWideNotationOption(wideNotationOption: WideNotationOption) {
dataStore.updateData { it.copy(wideNotationOption = wideNotationOption) }
}

suspend fun updateSmartDelete(smartDelete: Boolean) {
dataStore.updateData { it.copy(smartDelete = smartDelete) }
}

suspend fun updateAddSpaceBetweenNotation(addSpaceBetweenNotation: Boolean) {
dataStore.updateData { it.copy(addSpaceAfterNotation = addSpaceBetweenNotation) }
}

suspend fun updateVibrateOnTap(vibrateOnTap: Boolean) {
dataStore.updateData { it.copy(vibrateOnTap = vibrateOnTap) }
class SettingsRepository
@Inject
constructor(
@ApplicationContext context: Context,
) {
private val dataStore = context.dataStore
val settings = dataStore.data

suspend fun updateThemeOption(themeOption: ThemeOption) {
dataStore.updateData { it.copy(themeOption = themeOption) }
}

suspend fun updateWideNotationOption(wideNotationOption: WideNotationOption) {
dataStore.updateData { it.copy(wideNotationOption = wideNotationOption) }
}

suspend fun updateSmartDelete(smartDelete: Boolean) {
dataStore.updateData { it.copy(smartDelete = smartDelete) }
}

suspend fun updateAddSpaceBetweenNotation(addSpaceBetweenNotation: Boolean) {
dataStore.updateData { it.copy(addSpaceAfterNotation = addSpaceBetweenNotation) }
}

suspend fun updateVibrateOnTap(vibrateOnTap: Boolean) {
dataStore.updateData { it.copy(vibrateOnTap = vibrateOnTap) }
}
}
}
54 changes: 30 additions & 24 deletions app/src/main/java/com/rickyhu/hushkeyboard/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,67 +41,73 @@ import com.rickyhu.hushkeyboard.theme.HushKeyboardTheme
@Composable
fun HomeScreen(
navigateToIntroduction: () -> Unit = {},
navigateToSettings: () -> Unit = {}
navigateToSettings: () -> Unit = {},
) {
var text by remember { mutableStateOf("") }

Scaffold(
content = { paddingValues ->
Column(
modifier = Modifier
.fillMaxSize()
.padding(paddingValues),
modifier =
Modifier
.fillMaxSize()
.padding(paddingValues),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
verticalArrangement = Arrangement.Center,
) {
Card(
shape = RoundedCornerShape(8.dp),
elevation = CardDefaults.cardElevation(defaultElevation = 4.dp),
modifier = Modifier
.clip(CircleShape)
.size(200.dp)
.border(BorderStroke(1.dp, Color.Gray), CircleShape)
modifier =
Modifier
.clip(CircleShape)
.size(200.dp)
.border(BorderStroke(1.dp, Color.Gray), CircleShape),
) {
Image(
painter = painterResource(id = R.drawable.app_icon),
contentDescription = "App Icon"
contentDescription = "App Icon",
)
}
Spacer(modifier = Modifier.height(16.dp))
Text(
text = stringResource(R.string.app_name),
style = MaterialTheme.typography.displayMedium,
modifier = Modifier.padding(32.dp)
modifier = Modifier.padding(32.dp),
)
Button(
onClick = navigateToIntroduction,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
modifier =
Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
Text(text = stringResource(R.string.home_setup_keyboard_button))
}
Button(
onClick = navigateToSettings,
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp)
modifier =
Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 8.dp),
) {
Text(text = stringResource(R.string.home_settings_button))
}
OutlinedTextField(
value = text,
onValueChange = { text = it },
label = { Text(text = "Type here") },
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text
),
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
keyboardOptions =
KeyboardOptions(
keyboardType = KeyboardType.Text,
),
modifier =
Modifier
.fillMaxWidth()
.padding(16.dp),
)
}
}
},
)
}

Expand Down
Loading