Skip to content

Commit

Permalink
Added design at setting screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Siqi committed Sep 7, 2023
1 parent b170513 commit 95596a6
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ android {

dependencies {

implementation 'androidx.core:core-ktx:1.10.1'
implementation 'androidx.core:core-ktx:1.12.0'
implementation platform('org.jetbrains.kotlin:kotlin-bom:1.8.0')
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.2'
implementation 'androidx.activity:activity-compose:1.7.2'
implementation platform('androidx.compose:compose-bom:2022.10.00')
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.compose.material3:material3'
implementation 'androidx.compose.material3:material3:1.1.1'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand All @@ -65,7 +65,7 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-tooling'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
//ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0-alpha01"
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2"
//navigation
implementation "androidx.navigation:navigation-compose:2.7.1"
//datastore
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": 7,
"versionName": "0.0.7",
"versionCode": 8,
"versionName": "0.0.8",
"outputFile": "app-release.apk"
}
],
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/java/com/sqz/writingboard/ClassActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sqz.writingboard

import android.content.Context
import android.util.Log
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
Expand All @@ -13,11 +14,13 @@ class WritingBoard : ViewModel() {

class ButtonState : ViewModel() {
var doneButton by mutableStateOf(false)
var cleanButton by mutableStateOf(false)
}

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 @@ -26,5 +29,7 @@ class WritingBoardSettingState {
val editor = sharedPreferences.edit()
editor.putBoolean(name, state)
editor.apply()
Log.i("WritingBoardTag", "writeSwitchState")
}
}

40 changes: 40 additions & 0 deletions app/src/main/java/com/sqz/writingboard/KeyboardListening.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.sqz.writingboard

import android.content.Context
import android.graphics.Rect
import android.view.ViewTreeObserver
import android.view.inputmethod.InputMethodManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView

@Composable
fun KeyboardVisibilityObserver(
onKeyboardVisibilityChanged: (Boolean) -> Unit
) {
val context = LocalContext.current
val rootView = LocalView.current
val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager

DisposableEffect(rootView, imm) {
val listener = ViewTreeObserver.OnGlobalLayoutListener {
val rect = Rect()
rootView.getWindowVisibleDisplayFrame(rect)
val screenHeight = rootView.height

// Calculate the remaining visible height of the layout. If it's less than half of the screen height, consider the keyboard visible.
val keypadHeight = screenHeight - rect.bottom
val isKeyboardVisible = keypadHeight > screenHeight * 0.15

onKeyboardVisibilityChanged(isKeyboardVisible)
}

rootView.viewTreeObserver.addOnGlobalLayoutListener(listener)

// Remove the listener when the DisposableEffect is disposed.
onDispose {
rootView.viewTreeObserver.removeOnGlobalLayoutListener(listener)
}
}
}
14 changes: 11 additions & 3 deletions app/src/main/java/com/sqz/writingboard/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.sqz.writingboard

import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -14,6 +15,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.sqz.writingboard.ui.WritingBoardLayout
import com.sqz.writingboard.ui.WritingBoardNone
import com.sqz.writingboard.ui.WritingBoardSetting
import com.sqz.writingboard.ui.theme.WritingBoardTheme

Expand All @@ -27,19 +29,25 @@ class MainActivity : ComponentActivity() {
modifier = Modifier
.fillMaxSize()
.systemBarsPadding(),
color = MaterialTheme.colorScheme.background
color = MaterialTheme.colorScheme.surfaceVariant
) {
val navController = rememberNavController()
val context = LocalContext.current
NavHost(
navController = navController,
startDestination = "WritingBoard"
){
) {
composable("WritingBoard") {
WritingBoardLayout(navController)
Log.i("WritingBoardTag", "NavHost: Screen is WritingBoardLayout.")
}
composable("Setting"){
composable("Setting") {
WritingBoardSetting(navController, context = context)
Log.i("WritingBoardTag", "NavHost: Screen is WritingBoardSetting.")
}
composable("WritingBoardNone") {
WritingBoardNone()
Log.i("WritingBoardTag", "NavHost: Screen is WritingBoardSetting.")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.sqz.writingboard.ui

import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview

@Composable
fun WritingBoardNone(modifier: Modifier = Modifier) {
Surface(
modifier = modifier
.background(
MaterialTheme.colorScheme.surfaceVariant
)
) { Log.i("WritingBoardTag", "NoneScreen has open") }
}

@Preview(showBackground = true)
@Composable
fun WritingBoardScreenPreview() {
WritingBoardNone()
}
Loading

0 comments on commit 95596a6

Please sign in to comment.