Implemented functionality in settings for text style, size, opacity, highlight style, intensity, opacity, and order

This commit is contained in:
denizk0461
2023-05-16 09:49:16 +02:00
parent 8454d4f924
commit 7b598903ae
7 changed files with 124 additions and 30 deletions
@@ -10,6 +10,7 @@ import com.denizd.textbasic.databinding.FragmentSettingsNewBinding
import com.denizd.textbasic.db.QuoteStorage
import com.denizd.textbasic.util.SettingsPreference
import com.denizd.textbasic.util.viewBinding
import com.denizd.textbasic.widget.CanvasText
import com.google.android.material.button.MaterialButton
class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
@@ -23,6 +24,9 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
storage = QuoteStorage.getInstance(context)
// --- text font --- //
// --- font style --- //
binding.toggleGroupFont.apply {
check(when (storage.getTypefaceStyle()) {
@@ -40,6 +44,8 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
R.id.toggle_button_font_bold_italic -> 3
else -> 0
})
updatePreview()
}
}
}
@@ -118,25 +124,70 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
// --- highlight style --- //
binding.toggleGroupHighlightStyle.apply {
check(when (storage.getBackgroundType()) {
0 -> R.id.toggle_button_highlight_background
1 -> R.id.toggle_button_highlight_stroke
2 -> R.id.toggle_button_highlight_shadow
else -> R.id.toggle_button_highlight_none // 3
})
check(checkBackgroundIntensity(storage.getBackgroundType()))
addOnButtonCheckedListener { _, checkedId, isChecked ->
if (isChecked) {
storage.setBackgroundType(when (checkedId) {
R.id.toggle_button_highlight_background -> 0
R.id.toggle_button_highlight_stroke -> 1
R.id.toggle_button_highlight_shadow -> 2
else -> 3 // none
})
when (checkedId) {
R.id.toggle_button_highlight_background -> {
storage.setBackgroundType(0)
checkBackgroundIntensity(0)
}
R.id.toggle_button_highlight_stroke -> {
storage.setBackgroundType(1)
checkBackgroundIntensity(1)
}
R.id.toggle_button_highlight_shadow -> {
storage.setBackgroundType(2)
checkBackgroundIntensity(2)
}
else -> {
storage.setBackgroundType(3)
checkBackgroundIntensity(3)
} // none
}
updatePreview()
}
}
}
// --- highlight intensity --- //
binding.textIntensity.text = storage.getInt(SettingsPreference.HIGHLIGHT_INTENSITY, 100).toString()
binding.buttonIntensityDecreaseFast.setOnClickAction(
0,
100,
isPositive = false,
isFast = true,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityDecrease.setOnClickAction(
0,
100,
isPositive = false,
isFast = false,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityIncrease.setOnClickAction(
0,
100,
isPositive = true,
isFast = false,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
binding.buttonIntensityIncreaseFast.setOnClickAction(
0,
100,
isPositive = true,
isFast = true,
binding.textIntensity,
SettingsPreference.HIGHLIGHT_INTENSITY,
)
// --- text highlight transparency --- //
binding.textHighlightTransparency.text = storage.getInt(SettingsPreference.HIGHLIGHT_TRANSPARENCY, 100).toString()
@@ -189,6 +240,31 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
@SuppressLint("SetTextI18n")
binding.appVersionText.text =
"${BuildConfig.VERSION_NAME}-${if (BuildConfig.DEBUG) "dev" else "release"}"
updatePreview()
}
/**
* Retrieves which button to check for the highlight, and sets the visibility of the intensity
* modifying layout accordingly.
*/
private fun checkBackgroundIntensity(index: Int): Int = when (index) {
0 -> { // background
binding.layoutIntensity.visibility = View.GONE
R.id.toggle_button_highlight_background
}
1 -> { // stroke
binding.layoutIntensity.visibility = View.VISIBLE
R.id.toggle_button_highlight_stroke
}
2 -> { // shadow
binding.layoutIntensity.visibility = View.VISIBLE
R.id.toggle_button_highlight_shadow
}
else -> { // none
binding.layoutIntensity.visibility = View.GONE
R.id.toggle_button_highlight_none
}
}
// TODO horrible, horrible, horrible function. but it works. fix this in the future. please.
@@ -223,6 +299,15 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
storage.setInt(pref, value)
textField.text = value.toString()
updatePreview()
}
}
private fun updatePreview() {
val bitmap = CanvasText.drawText(context, true)
binding.textPreview.setImageBitmap(bitmap)
}
}