Skip to content

Commit

Permalink
VersionCode: 30
Browse files Browse the repository at this point in the history
Increase the reusable of some code
Compatible with Android 10+ (without dynamic colors)
Fixed a text error
Added an option to change font weight
Added an option to disable auto save
  • Loading branch information
Z-Siqi committed Nov 8, 2023
1 parent 15436fc commit 1b5e8b8
Show file tree
Hide file tree
Showing 17 changed files with 330 additions and 209 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ android {

defaultConfig {
applicationId "com.sqz.writingboard"
minSdk 31
minSdk 29
targetSdk 34
versionCode 29
versionName "0.2.8"
versionCode 30
versionName "0.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -68,7 +68,7 @@ dependencies {
//ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2"
//navigation
implementation "androidx.navigation:navigation-compose:2.7.4"
implementation "androidx.navigation:navigation-compose:2.7.5"
//datastore
implementation "androidx.datastore:datastore-preferences:1.0.0"
//splashscreen
Expand Down
Binary file modified app/release/app-release.apk
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 29,
"versionName": "0.2.8",
"versionCode": 30,
"versionName": "0.3.0",
"outputFile": "app-release.apk"
}
],
Expand Down
243 changes: 114 additions & 129 deletions app/src/main/java/com/sqz/writingboard/ui/WritingBoardLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Settings
import androidx.compose.material3.FloatingActionButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -50,6 +49,7 @@ import com.sqz.writingboard.settingState
import com.sqz.writingboard.ui.component.WritingBoardManual
import com.sqz.writingboard.ui.theme.PurpleForManual
import com.sqz.writingboard.ui.theme.RedForManual
import com.sqz.writingboard.ui.theme.themeColor

@Composable
fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifier) {
Expand All @@ -61,29 +61,9 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
var isKeyboardVisible by remember { mutableStateOf(false) }
var hideModeController by remember { mutableStateOf(false) }

val readTheme = settingState.readSegmentedButtonState("theme", context)
val readButtonStyle = settingState.readSegmentedButtonState("button_style", context)
val readEditButton = settingState.readSwitchState("edit_button", context)

val backgroundColor = when (readTheme) {
0 -> MaterialTheme.colorScheme.surfaceContainerLowest
1 -> MaterialTheme.colorScheme.surfaceVariant
2 -> MaterialTheme.colorScheme.secondaryContainer
else -> MaterialTheme.colorScheme.surfaceVariant
}
val shapeColor = when (readTheme) {
0 -> MaterialTheme.colorScheme.secondaryContainer
1 -> MaterialTheme.colorScheme.primary
2 -> MaterialTheme.colorScheme.secondary
else -> MaterialTheme.colorScheme.primary
}
val boardColor = when (readTheme) {
0 -> MaterialTheme.colorScheme.surfaceBright
1 -> MaterialTheme.colorScheme.surfaceContainerLow
2 -> MaterialTheme.colorScheme.tertiaryContainer
else -> MaterialTheme.colorScheme.surfaceContainerLow
}

var editAction by remember { mutableStateOf(false) }
if (editAction) {
valueState.editButton = true
Expand Down Expand Up @@ -117,63 +97,60 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
doneAction = true
}
},
color = backgroundColor
color = themeColor("backgroundColor")
) {
when (settingState.readSegmentedButtonState("button_style", context)) {
0 -> {
if (!hideModeController) {
Column(
verticalArrangement = Arrangement.Top
if (
(!hideModeController) &&
(settingState.readSegmentedButtonState("button_style", context) == 0)
) {
Column(
verticalArrangement = Arrangement.Top
) {
val area = modifier
.fillMaxWidth()
.height(80.dp)
Spacer(
modifier = if (
(settingState.readSwitchState("off_button_manual", context))
) {
val area = modifier
.fillMaxWidth()
.height(80.dp)
Spacer(
modifier = if (settingState.readSwitchState(
"off_button_manual",
context
)
) {
modifier
.pointerInput(Unit) {
detectTapGestures { _ ->
onClickSetting = true
}
} then area
} else {
modifier.background(color = RedForManual) then area
}
)
modifier
.pointerInput(Unit) {
detectTapGestures { _ ->
onClickSetting = true
}
} then area
} else {
modifier.background(color = RedForManual) then area
}
Column(
verticalArrangement = Arrangement.Bottom
)
}
Column(
verticalArrangement = Arrangement.Bottom
) {
val area = modifier
.fillMaxWidth()
.height(120.dp)
Spacer(
modifier = if (
(settingState.readSwitchState("off_editButton_manual", context)) &&
(readEditButton)
) {
val area = modifier
.fillMaxWidth()
.height(120.dp)
Spacer(
modifier = if (
(settingState.readSwitchState("off_editButton_manual", context)) &&
(readEditButton)
) {
modifier
.pointerInput(Unit) {
detectTapGestures { _ ->
editAction = true
}
} then area
} else if (
(!settingState.readSwitchState("off_editButton_manual", context)) &&
(readButtonStyle == 0) &&
(readEditButton)
) {
modifier.background(color = PurpleForManual) then area
} else {
modifier
}
)
modifier
.pointerInput(Unit) {
detectTapGestures { _ ->
editAction = true
}
} then area
} else if (
(!settingState.readSwitchState("off_editButton_manual", context)) &&
(readButtonStyle == 0) &&
(readEditButton)
) {
modifier.background(color = PurpleForManual) then area
} else {
modifier
}
}
)
}
}
Column(
Expand All @@ -182,14 +159,14 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
.shadow(5.dp, RoundedCornerShape(26.dp))
.border(
4.dp,
color = shapeColor,
color = themeColor("shapeColor"),
RoundedCornerShape(26.dp)
),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Surface(
color = boardColor,
color = themeColor("boardColor"),
modifier = modifier.fillMaxSize(),
shape = RoundedCornerShape(26.dp)
) {
Expand Down Expand Up @@ -305,49 +282,8 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
}
}
//manual of button style
if (
(!settingState.readSwitchState("off_button_manual", context)) &&
(readButtonStyle == 0)
) {
WritingBoardManual(
modifierPadding = modifier.padding(bottom = 380.dp, end = 58.dp),
onClick = {
settingState.writeSwitchState(
"off_button_manual",
context,
true
)
navController.navigate("WritingBoardNone")
Handler(Looper.getMainLooper()).postDelayed(50) {
navController.popBackStack()
valueState.updateScreen = false
}
},
text = stringResource(R.string.button_manual)
)
}
//manual of edit button
if (
(!settingState.readSwitchState("off_editButton_manual", context)) &&
(readButtonStyle == 0) &&
(readEditButton)
) {
WritingBoardManual(
modifierPadding = modifier.padding(top = 300.dp, end = 50.dp),
onClick = {
settingState.writeSwitchState(
"off_editButton_manual",
context,
true
)
navController.navigate("WritingBoardNone")
Handler(Looper.getMainLooper()).postDelayed(50) {
navController.popBackStack()
valueState.updateScreen = false
}
},
text = stringResource(R.string.edit_button_manual)
)
if (readButtonStyle == 0) {
Manual(navController)
}
if (valueState.ee) {
navController.navigate("EE")
Expand All @@ -356,22 +292,71 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
}
valueState.ee = false
}

KeyboardVisibilityObserver { isVisible ->
isKeyboardVisible = isVisible
if (isVisible) {
hideModeController = true
} else {
hideModeController = false
if (settingState.readSwitchState("clean_pointer_focus", context)) {
focusManager.clearFocus()
doneAction = true
}
}
KeyboardVisibilityObserver { isVisible ->
isKeyboardVisible = isVisible
if (isVisible) {
hideModeController = true
} else {
hideModeController = false
if (settingState.readSwitchState("clean_pointer_focus", context)) {
focusManager.clearFocus()
doneAction = true
}
}
}
}


@Composable
private fun Manual(navController: NavController, modifier: Modifier = Modifier) {
val valueState: ValueState = viewModel()
val context = LocalContext.current
val readEditButton = settingState.readSwitchState("edit_button", context)
if (
(!settingState.readSwitchState("off_button_manual", context))
) {
WritingBoardManual(
modifierPadding = modifier.padding(bottom = 380.dp, end = 58.dp),
onClick = {
settingState.writeSwitchState(
"off_button_manual",
context,
true
)
navController.navigate("WritingBoardNone")
Handler(Looper.getMainLooper()).postDelayed(50) {
navController.popBackStack()
valueState.updateScreen = false
}
},
text = stringResource(R.string.button_manual)
)
}
//manual of edit button
if (
(!settingState.readSwitchState("off_editButton_manual", context)) &&
(readEditButton)
) {
WritingBoardManual(
modifierPadding = modifier.padding(top = 300.dp, end = 50.dp),
onClick = {
settingState.writeSwitchState(
"off_editButton_manual",
context,
true
)
navController.navigate("WritingBoardNone")
Handler(Looper.getMainLooper()).postDelayed(50) {
navController.popBackStack()
valueState.updateScreen = false
}
},
text = stringResource(R.string.edit_button_manual)
)
}
}

@Preview(showBackground = true)
@Composable
fun WritingBoardPreview() {
Expand Down
Loading

0 comments on commit 1b5e8b8

Please sign in to comment.