Skip to content

Commit

Permalink
VersionCode: 22
Browse files Browse the repository at this point in the history
Fixed hideModeController won't reset
Optimize log recording
Fixed scroll to top when edit text
  • Loading branch information
Z-Siqi committed Oct 17, 2023
1 parent 920672b commit ddff5ee
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 77 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "com.sqz.writingboard"
minSdk 31
targetSdk 34
versionCode 21
versionName "0.2.0"
versionCode 22
versionName "0.2.2"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
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": 21,
"versionName": "0.2.0",
"versionCode": 22,
"versionName": "0.2.2",
"outputFile": "app-release.apk"
}
],
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/com/sqz/writingboard/ClassActivity.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.sqz.writingboard

import android.content.Context
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.text.input.TextFieldValue
import androidx.lifecycle.ViewModel
import com.sqz.writingboard.ui.setting
Expand All @@ -24,11 +22,10 @@ class ValueState : ViewModel() {
var saveAction by mutableStateOf(false)
var buttonSaveAction by mutableStateOf(false)
var ee by mutableStateOf(false)
var requestFocus = FocusRequester()
var editButton by mutableStateOf(false)
var updateScreen by mutableStateOf(false)
var openLayout by mutableStateOf(false)
var editScroll by mutableStateOf(false)
var editScroll by mutableIntStateOf(1)
}

class WritingBoardSettingState {
Expand All @@ -46,7 +43,6 @@ class WritingBoardSettingState {

fun readSwitchState(name: String, context: Context): Boolean {
val sharedPreferences = context.getSharedPreferences("WritingBoardSetting", Context.MODE_PRIVATE)
Log.i("WritingBoardTag", "readSwitchState")
return sharedPreferences.getBoolean(name, false)
}

Expand All @@ -55,7 +51,6 @@ class WritingBoardSettingState {
val editor = sharedPreferences.edit()
editor.putBoolean(name, state)
editor.apply()
Log.i("WritingBoardTag", "writeSwitchState")
}

@Composable
Expand All @@ -72,7 +67,6 @@ class WritingBoardSettingState {

fun readSegmentedButtonState(name: String, context: Context): Int {
val sharedPreferences = context.getSharedPreferences("WritingBoardSetting", Context.MODE_PRIVATE)
Log.i("WritingBoardTag", "readSegmentedButtonState")
return sharedPreferences.getInt(name, 1)
}

Expand All @@ -81,6 +75,5 @@ class WritingBoardSettingState {
val editor = sharedPreferences.edit()
editor.putInt(name, state)
editor.apply()
Log.i("WritingBoardTag", "writeSwitchState")
}
}
10 changes: 8 additions & 2 deletions app/src/main/java/com/sqz/writingboard/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sqz.writingboard

import android.content.Context
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
Expand All @@ -11,6 +12,9 @@ import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
Expand All @@ -20,6 +24,8 @@ import com.sqz.writingboard.ui.WritingBoardNone
import com.sqz.writingboard.ui.WritingBoardSetting
import com.sqz.writingboard.ui.theme.WritingBoardTheme

val settingState = WritingBoardSettingState()
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "WritingBoard")
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -48,7 +54,7 @@ class MainActivity : ComponentActivity() {
}
composable("WritingBoardNone") {
WritingBoardNone()
Log.i("WritingBoardTag", "NavHost: Screen is WritingBoardSetting.")
Log.i("WritingBoardTag", "NavHost: Screen is WritingBoardNone.")
}
composable("EE") {
WritingBoardEE()
Expand All @@ -58,4 +64,4 @@ class MainActivity : ComponentActivity() {
}
}
}
}
}
81 changes: 35 additions & 46 deletions app/src/main/java/com/sqz/writingboard/ui/WritingBoardLayout.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sqz.writingboard.ui

import android.content.Context
import android.os.Handler
import android.os.Looper
import android.util.Log
Expand Down Expand Up @@ -39,34 +38,18 @@ import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.core.os.postDelayed
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.preferencesDataStore
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
import com.sqz.writingboard.KeyboardVisibilityObserver
import com.sqz.writingboard.R
import com.sqz.writingboard.ValueState
import com.sqz.writingboard.WritingBoardSettingState
import com.sqz.writingboard.settingState
import com.sqz.writingboard.ui.theme.PurpleForManual
import com.sqz.writingboard.ui.theme.RedForManual

val settingState = WritingBoardSettingState()
val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "WritingBoard")

@Composable
fun WritingBoardTextInit(context: Context) {
when (settingState.readSegmentedButtonState("font_size", context)) {
0 -> WritingBoardText(18.sp)
1 -> WritingBoardText(23.sp)
2 -> WritingBoardText(33.sp)
}
}

@Composable
fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifier) {

Expand Down Expand Up @@ -100,17 +83,32 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
else -> MaterialTheme.colorScheme.surfaceContainerLow
}

var editAction by remember { mutableStateOf(false) }
if (editAction){
valueState.editButton = true
valueState.editScroll = 0
Log.i("WritingBoardTag", "Edit button is clicked")
editAction = false
}
var doneAction by remember { mutableStateOf(false) }
if (doneAction){
keyboardDone?.hide()
focusManager.clearFocus()
valueState.buttonSaveAction = true
valueState.doneButton = false
valueState.editButton = false
Log.i("WritingBoardTag", "Done button is clicked")
doneAction = false
}

//Layout
Surface(
modifier = modifier
.fillMaxSize()
.imePadding()
.pointerInput(Unit) {
detectTapGestures { _ ->
keyboardDone?.hide()
focusManager.clearFocus()
valueState.doneButton = false
valueState.editButton = false
doneAction = true
}
},
color = backgroundColor
Expand All @@ -130,6 +128,7 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
.pointerInput(Unit) {
detectTapGestures { _ ->
valueState.saveAction = true
valueState.editScroll = 1
navController.navigate("Setting")
}
} then area
Expand All @@ -152,10 +151,7 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
modifier
.pointerInput(Unit) {
detectTapGestures { _ ->
valueState.requestFocus.requestFocus()
valueState.editButton = true
valueState.editScroll = true
Log.i("WritingBoardTag", "Edit button is clicked")
editAction = true
}
} then area
} else if (
Expand Down Expand Up @@ -190,10 +186,12 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
.fillMaxSize(),
shape = RoundedCornerShape(26.dp)
) {
WritingBoardTextInit(context)
Handler(Looper.getMainLooper()).postDelayed(550) {
valueState.openLayout = true
Log.i("WritingBoardTag", "Initializing WritingBoard Text")
WritingBoardText()
if (!valueState.openLayout){
Handler(Looper.getMainLooper()).postDelayed(550) {
valueState.openLayout = true
Log.i("WritingBoardTag", "Initializing WritingBoard Text")
}
}
if (valueState.cleanButton) {
navController.navigate("WritingBoardNone")
Expand Down Expand Up @@ -227,14 +225,7 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
}
//done button
Spacer(modifier = modifier.height(10.dp))
FloatingActionButton(onClick = {
keyboardDone?.hide()
focusManager.clearFocus()
valueState.buttonSaveAction = true
valueState.doneButton = false
valueState.editButton = false
Log.i("WritingBoardTag", "Done button is clicked")
}) {
FloatingActionButton(onClick = { doneAction = true }) {
Icon(
imageVector = Icons.Filled.Done,
contentDescription = "Done"
Expand Down Expand Up @@ -278,12 +269,7 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
verticalArrangement = Arrangement.Bottom,
horizontalAlignment = Alignment.End
) {
FloatingActionButton(onClick = {
valueState.requestFocus.requestFocus()
valueState.editButton = true
valueState.editScroll = true
Log.i("WritingBoardTag", "Edit button is clicked")
}) {
FloatingActionButton(onClick = { editAction = true }) {
Icon(
imageVector = Icons.Filled.Edit,
contentDescription = "Edit"
Expand All @@ -302,7 +288,9 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
) {
FloatingActionButton(onClick = {
valueState.saveAction = true
focusManager.clearFocus()
navController.navigate("Setting")
valueState.editScroll = 0
}) {
Icon(
imageVector = Icons.Filled.Settings,
Expand Down Expand Up @@ -357,6 +345,7 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
)
}
if (valueState.ee){
valueState.editScroll = 0
navController.navigate("EE")
Handler(Looper.getMainLooper()).postDelayed(80000) {
navController.popBackStack()
Expand All @@ -368,10 +357,10 @@ fun WritingBoardLayout(navController: NavController, modifier: Modifier = Modifi
isKeyboardVisible = isVisible
if (isVisible) {
valueState.doneButton = true
valueState.editScroll = false
hideModeController = true
} else {
valueState.doneButton = false
doneAction = true
hideModeController = false
if (settingState.readSwitchState("clean_pointer_focus", context)) {
focusManager.clearFocus()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import androidx.navigation.compose.rememberNavController
import com.sqz.writingboard.R
import com.sqz.writingboard.ValueState
import com.sqz.writingboard.WritingBoardSettingState
import com.sqz.writingboard.settingState

val setting = WritingBoardSettingState()

Expand Down
Loading

0 comments on commit ddff5ee

Please sign in to comment.