Skip to content

Commit

Permalink
Monospace font in Markdown editor setting
Browse files Browse the repository at this point in the history
Fix: #155
  • Loading branch information
Kin69 committed Aug 23, 2024
1 parent 5c0dd7a commit a4dafe5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ data class Settings(
var gallerySync: Boolean = true,
var showOnlyTitle: Boolean = false,
var termsOfService: Boolean = false,
var useMonoSpaceFont: Boolean = false,

var cornerRadius: Int = 32,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,13 @@ fun EditScreen(viewModel: EditViewModel,settingsViewModel: SettingsViewModel, pa
isExtremeAmoled = settingsViewModel.settings.value.extremeAmoledMode,
onClickBack = { onClickBack() }
) {
println(settingsViewModel.settings.value.useMonoSpaceFont)
CustomTextField(
value = viewModel.noteName.value,
modifier = Modifier.weight(1f),
onValueChange = { viewModel.updateNoteName(it) },
placeholder = stringResource(R.string.name),
useMonoSpaceFont = settingsViewModel.settings.value.useMonoSpaceFont
)
}
}
Expand All @@ -330,6 +332,7 @@ fun EditScreen(viewModel: EditViewModel,settingsViewModel: SettingsViewModel, pa
onValueChange = { viewModel.updateNoteDescription(it) },
modifier = Modifier.fillMaxSize(),
placeholder = stringResource(R.string.description),
useMonoSpaceFont = settingsViewModel.settings.value.useMonoSpaceFont
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.kin.easynotes.presentation.screens.edit.components
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
Expand All @@ -14,10 +15,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun CustomTextField(
Expand All @@ -28,8 +33,10 @@ fun CustomTextField(
interactionSource: MutableInteractionSource = MutableInteractionSource(),
singleLine: Boolean = false,
modifier: Modifier = Modifier,
hideContent: Boolean = false
hideContent: Boolean = false,
useMonoSpaceFont: Boolean = false
) {

val visualTransformation = if (hideContent) {
PasswordVisualTransformation()
} else {
Expand All @@ -38,6 +45,7 @@ fun CustomTextField(

TextField(
value = value,
textStyle = if (useMonoSpaceFont) LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace) else LocalTextStyle.current,
visualTransformation = visualTransformation,
onValueChange = onValueChange,
interactionSource = interactionSource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fun MarkdownScreen(navController: NavController, settingsViewModel: SettingsView
}
)
}

item {
Spacer(modifier = Modifier.height(18.dp))
SettingsBox(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.kin.easynotes.presentation.screens.settings.settings

import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Battery1Bar
import androidx.compose.material.icons.rounded.FontDownload
import androidx.compose.material.icons.rounded.Translate
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.core.os.LocaleListCompat
import androidx.navigation.NavController
import com.kin.easynotes.R
Expand Down Expand Up @@ -34,6 +40,18 @@ fun LanguageScreen(navController: NavController, settingsViewModel: SettingsView
customAction = { onExit -> OnLanguageClicked(settingsViewModel) { onExit() }
}
)
Spacer(modifier = Modifier.height(18.dp))
}
item {
SettingsBox(
title = stringResource(id = R.string.monospace_font),
icon = Icons.Rounded.FontDownload,
description = stringResource(id = R.string.monospace_font_description),
radius = shapeManager(radius = settingsViewModel.settings.value.cornerRadius, isBoth = true),
actionType = ActionType.SWITCH,
variable = settingsViewModel.settings.value.useMonoSpaceFont,
switchEnabled = { settingsViewModel.update(settingsViewModel.settings.value.copy(useMonoSpaceFont = it))}
)
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,6 @@
<string name="file_import_success">Successfully imported</string>
<string name="file_import_title">Import</string>
<string name="file_import_description">Import other text files as notes</string>
<string name="monospace_font_description">Use monospace font while editing note</string>
<string name="monospace_font">Monospace font</string>
</resources>

0 comments on commit a4dafe5

Please sign in to comment.