Skip to content

Commit

Permalink
[Feature] - Added the ability to change clock size independently (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat authored Mar 27, 2024
1 parent 83aaf76 commit 13235f9
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ object Constants {
const val TEXT_SIZE_MIN = 10
const val TEXT_SIZE_MAX = 50

const val TEXT_MULTIPLIER_SIZE_MIN = 1f
const val TEXT_MULTIPLIER_SIZE_MAX = 5f

const val TEXT_MARGIN_MIN = 0
const val TEXT_MARGIN_MAX = 50

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/com/github/hecodes2much/mlauncher/data/Prefs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private const val CUSTOM_FONT = "CUSTOM_FONT"
private const val ALL_APPS_TEXT = "ALL_APPS_TEXT"

private const val TEXT_SIZE_LAUNCHER = "TEXT_SIZE_LAUNCHER"
private const val TEXT_SIZE_MULTIPLIER = "TEXT_SIZE_MULTIPLIER"
private const val TEXT_SIZE_SETTINGS = "TEXT_SIZE_SETTINGS"
private const val TEXT_MARGIN_SIZE = "TEXT_MARGIN_SIZE"

Expand Down Expand Up @@ -388,6 +389,16 @@ class Prefs(val context: Context) {
}
set(value) = prefs.edit().putInt(TEXT_SIZE_LAUNCHER, value).apply()

var textSizeMultiplier: Float
get() {
return try {
prefs.getFloat(TEXT_SIZE_MULTIPLIER, 1f)
} catch (_: Exception) {
1f
}
}
set(value) = prefs.edit().putFloat(TEXT_SIZE_MULTIPLIER, value).apply()

var textSizeSettings: Int
get() {
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class HomeFragment : Fragment(), View.OnClickListener, View.OnLongClickListener
if (prefs.showStatusBar) showStatusBar(requireActivity()) else hideStatusBar(requireActivity())
val typeface = ResourcesCompat.getFont(requireActivity(), R.font.roboto)

binding.clock.textSize = prefs.textSizeLauncher * 2.5f
binding.clock.textSize = prefs.textSizeLauncher * prefs.textSizeMultiplier
binding.date.textSize = prefs.textSizeLauncher.toFloat()
binding.batteryIcon.textSize = prefs.textSizeLauncher.toFloat() / 1.5f
binding.batteryText.textSize = prefs.textSizeLauncher.toFloat() / 1.5f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -51,6 +52,7 @@ import com.github.hecodes2much.mlauncher.style.SettingsTheme
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsArea
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsGestureItem
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsItem
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsNumberItem
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsSliderItem
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsTextButton
import com.github.hecodes2much.mlauncher.ui.compose.SettingsComposable.SettingsToggle
Expand Down Expand Up @@ -210,6 +212,18 @@ class SettingsFragment : Fragment() {
onSelect = { f -> setTextSizeLauncher(f) }
)
},
{ open, onChange ->
SettingsNumberItem(
title = stringResource(R.string.clock_text_size_multiplier),
fontSize = iconFs,
open = open,
onChange = onChange,
currentSelection = remember { mutableFloatStateOf(prefs.textSizeMultiplier) },
min = Constants.TEXT_MULTIPLIER_SIZE_MIN,
max = Constants.TEXT_MULTIPLIER_SIZE_MAX,
onSelect = { f -> setTextSizeMultiplier(f) }
)
},
{ open, onChange ->
SettingsSliderItem(
title = stringResource(R.string.app_padding_size),
Expand Down Expand Up @@ -802,6 +816,10 @@ class SettingsFragment : Fragment() {
prefs.textSizeSettings = size
}

private fun setTextSizeMultiplier(size: Float) {
prefs.textSizeMultiplier = size
}

private fun setTextMarginSize(size: Int) {
prefs.textMarginSize = size
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import com.github.hecodes2much.mlauncher.style.BORDER_SIZE
import com.github.hecodes2much.mlauncher.style.CORNER_RADIUS
import com.github.hecodes2much.mlauncher.style.SETTINGS_PADDING
import com.smarttoolfactory.slider.*
import java.math.BigDecimal
import java.math.RoundingMode

object SettingsComposable {

Expand Down Expand Up @@ -216,14 +218,14 @@ object SettingsComposable {
@Composable
fun SettingsNumberItem(
title: String,
currentSelection: MutableState<Int>,
min: Int = Int.MIN_VALUE,
max: Int = Int.MAX_VALUE,
currentSelection: MutableState<Float>,
min: Float = Float.MIN_VALUE,
max: Float = Float.MAX_VALUE,
open: MutableState<Boolean>,
onChange: (Boolean) -> Unit,
onValueChange: (Int) -> Unit = {},
onValueChange: (Float) -> Unit = {},
fontSize: TextUnit = TextUnit.Unspecified,
onSelect: (Int) -> Unit
onSelect: (Float) -> Unit
) {
Column {
Text(
Expand Down Expand Up @@ -429,12 +431,12 @@ object SettingsComposable {

@Composable
private fun SettingsNumberSelector(
number: MutableState<Int>,
min: Int,
max: Int,
number: MutableState<Float>,
min: Float,
max: Float,
fontSize: TextUnit = TextUnit.Unspecified,
onValueChange: (Int) -> Unit = {},
onCommit: (Int) -> Unit
onValueChange: (Float) -> Unit = {},
onCommit: (Float) -> Unit
) {
ConstraintLayout(
modifier = Modifier
Expand All @@ -444,8 +446,9 @@ object SettingsComposable {
val (plus, minus, text, button) = createRefs()
TextButton(
onClick = {
if (number.value > min) {
number.value -= 1
val newValue = (BigDecimal(number.value.toDouble()) + BigDecimal("0.1")).toFloat()
if (newValue <= max) {
number.value = newValue.roundToTwoDecimalPlaces()
onValueChange(number.value)
}
},
Expand All @@ -458,7 +461,7 @@ object SettingsComposable {
},
) {
Text(
"-",
"+",
style = SettingsTheme.typography.button,
fontSize = fontSize
)
Expand All @@ -478,8 +481,9 @@ object SettingsComposable {
)
TextButton(
onClick = {
if (number.value < max) {
number.value += 1
val newValue = (BigDecimal(number.value.toDouble()) - BigDecimal("0.1")).toFloat()
if (newValue >= min) {
number.value = newValue.roundToTwoDecimalPlaces()
onValueChange(number.value)
}
},
Expand All @@ -492,7 +496,7 @@ object SettingsComposable {
},
) {
Text(
"+",
"-",
style = SettingsTheme.typography.button,
fontSize = fontSize
)
Expand All @@ -516,6 +520,10 @@ object SettingsComposable {
}
}

private fun Float.roundToTwoDecimalPlaces(): Float {
return BigDecimal(this.toDouble()).setScale(2, RoundingMode.HALF_EVEN).toFloat()
}

@Composable
private fun SettingsSliderSelector(
number: MutableState<Int>,
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-en-rCA/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="theme_mode">Theme mode</string>
<string name="app_language">Interface Language</string>
<string name="app_text_size">Text Size</string>
<string name="clock_text_size_multiplier">Clock Text Size Multiplier</string>
<string name="app_padding_size">Padding Size</string>
<string name="follow_accent_colors">Accent Colors</string>
<string name="background_opacity">Background Opacity</string>
Expand Down Expand Up @@ -129,6 +130,4 @@
<string name="accessibility_service_name">mLauncher Actions Service</string>
<string name="accessibility_service_description">This accessibility service allows mLauncher to do certain actions such as locking the screen or opening the quick settings. Our accessibility service does not collect or share any data.</string>
<string name="version">Version</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values-en-rGB/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="theme_mode">Theme mode</string>
<string name="app_language">Interface Language</string>
<string name="app_text_size">Text Size</string>
<string name="clock_text_size_multiplier">Clock Text Size Multiplier</string>
<string name="app_padding_size">Padding Size</string>
<string name="follow_accent_colors">Accent Colors</string>
<string name="background_opacity">Background Opacity</string>
Expand Down Expand Up @@ -129,6 +130,4 @@
<string name="accessibility_service_name">mLauncher Actions Service</string>
<string name="accessibility_service_description">This accessibility service allows mLauncher to do certain actions such as locking the screen or opening the quick settings. Our accessibility service does not collect or share any data.</string>
<string name="version">Version</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values-en-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="theme_mode">Theme mode</string>
<string name="app_language">Interface Language</string>
<string name="app_text_size">Text Size</string>
<string name="clock_text_size_multiplier">Clock Text Size Multiplier</string>
<string name="app_padding_size">Padding Size</string>
<string name="follow_accent_colors">Accent Colors</string>
<string name="background_opacity">Background Opacity</string>
Expand Down Expand Up @@ -129,6 +130,4 @@
<string name="accessibility_service_name">mLauncher Actions Service</string>
<string name="accessibility_service_description">This accessibility service allows mLauncher to do certain actions such as locking the screen or opening the quick settings. Our accessibility service does not collect or share any data.</string>
<string name="version">Version</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
3 changes: 1 addition & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<string name="theme_mode">Theme mode</string>
<string name="app_language">Interface Language</string>
<string name="app_text_size">Text Size</string>
<string name="clock_text_size_multiplier">Clock Text Size Multiplier</string>
<string name="app_padding_size">Padding Size</string>
<string name="follow_accent_colors">Accent Colors</string>
<string name="background_opacity">Background Opacity</string>
Expand Down Expand Up @@ -129,6 +130,4 @@
<string name="accessibility_service_name">mLauncher Actions Service</string>
<string name="accessibility_service_description">This accessibility service allows mLauncher to do certain actions such as locking the screen or opening the quick settings. Our accessibility service does not collect or share any data.</string>
<string name="version">Version</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>

0 comments on commit 13235f9

Please sign in to comment.