Archived
Text Basic 2.0.2: Fixed the awful function responsible for changing the number picker values based on which button had been clicked; changed number clickers to use respective functions in QuoteStorage.kt rather than generic getInt() and setInt()
This commit is contained in:
+2
-2
@@ -11,8 +11,8 @@ android {
|
||||
applicationId "com.denizk0461.textbasic"
|
||||
minSdk 23
|
||||
targetSdk 33
|
||||
versionCode 9
|
||||
versionName "2.0.1"
|
||||
versionCode 10
|
||||
versionName "2.0.2"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -11,8 +11,8 @@
|
||||
"type": "SINGLE",
|
||||
"filters": [],
|
||||
"attributes": [],
|
||||
"versionCode": 9,
|
||||
"versionName": "2.0.1",
|
||||
"versionCode": 10,
|
||||
"versionName": "2.0.2",
|
||||
"outputFile": "app-release.apk"
|
||||
}
|
||||
],
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package com.denizd.textbasic.db
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.graphics.Typeface
|
||||
import com.denizd.textbasic.util.ColorTransparentUtils
|
||||
import com.denizd.textbasic.R
|
||||
import com.denizd.textbasic.util.SettingsPreference
|
||||
|
||||
class QuoteStorage private constructor(context: Context) {
|
||||
@@ -69,26 +66,6 @@ class QuoteStorage private constructor(context: Context) {
|
||||
prefs.edit().putInt(KEY_TEXT_SIZE, newValue).apply()
|
||||
}
|
||||
|
||||
fun getInt(
|
||||
pref: SettingsPreference,
|
||||
defaultValue: Int = 0,
|
||||
): Int = prefs.getInt(pref.key, defaultValue)
|
||||
fun setInt(
|
||||
pref: SettingsPreference,
|
||||
newValue: Int,
|
||||
) {
|
||||
prefs.edit().putInt(pref.key, newValue).apply()
|
||||
}
|
||||
|
||||
fun isInvertedEnabled(): Boolean = prefs.getBoolean(KEY_INVERTED, false)
|
||||
fun getTextTransparency(): Int = prefs.getInt(KEY_TEXT_TRANSPARENCY, 100)
|
||||
fun setTextTransparency(newValue: Int) {
|
||||
prefs.edit().putInt(KEY_TEXT_TRANSPARENCY, newValue).apply()
|
||||
}
|
||||
fun getBackgroundTransparency(): Int = prefs.getInt(KEY_BG_TRANSPARENCY, 100)
|
||||
fun setBackgroundTransparency(newValue: Int) {
|
||||
prefs.edit().putInt(KEY_BG_TRANSPARENCY, newValue).apply()
|
||||
}
|
||||
fun isOrderRandom(): Boolean = prefs.getBoolean(KEY_RANDOM, false)
|
||||
fun setIsOrderRandom(newValue: Boolean) {
|
||||
prefs.edit().putBoolean(KEY_RANDOM, newValue).apply()
|
||||
@@ -123,7 +100,6 @@ class QuoteStorage private constructor(context: Context) {
|
||||
fun setTypefaceStyle(newValue: Int) {
|
||||
prefs.edit().putInt(KEY_TYPEFACE_STYLE, newValue).apply()
|
||||
}
|
||||
fun getOutlineSize(): Float = prefs.getFloat(KEY_OUTLINE_SIZE, 8f)
|
||||
fun getOutlineSizeNew(): Int = prefs.getInt(KEY_OUTLINE_SIZE_NEW, 8)
|
||||
|
||||
fun getTextColour(): String = prefs.getString(SettingsPreference.TEXT_COLOUR.key, "ffffff") ?: "ffffff"
|
||||
@@ -136,32 +112,9 @@ class QuoteStorage private constructor(context: Context) {
|
||||
prefs.edit().putString(SettingsPreference.HIGHLIGHT_COLOUR.key, newValue).apply()
|
||||
}
|
||||
|
||||
// Pair<text colour, background colour>
|
||||
fun getColours(
|
||||
isInverted: Boolean = isInvertedEnabled(),
|
||||
textTransparency: Int = getTextTransparency(),
|
||||
bgTransparency: Int = getBackgroundTransparency(),
|
||||
context: Context
|
||||
): Pair<Int, Int> {
|
||||
val colours = when (isInverted) {
|
||||
true -> Pair(R.color.widget_dark, R.color.widget_light)
|
||||
false -> Pair(R.color.widget_light, R.color.widget_dark)
|
||||
}
|
||||
|
||||
return Pair(
|
||||
Color.parseColor(
|
||||
ColorTransparentUtils.transparentColor(
|
||||
context.getColor(colours.first),
|
||||
textTransparency,
|
||||
)
|
||||
),//Color.parseColor(ColorTransparentUtils.transparentColor(colours.first, 10)),
|
||||
Color.parseColor(
|
||||
ColorTransparentUtils.transparentColor(
|
||||
context.getColor(colours.second),
|
||||
bgTransparency,
|
||||
)
|
||||
)
|
||||
)
|
||||
fun getHighlightIntensity(): Int = prefs.getInt(SettingsPreference.HIGHLIGHT_INTENSITY.key, 10)
|
||||
fun setHighlightIntensity(newValue: Int) {
|
||||
prefs.edit().putInt(SettingsPreference.HIGHLIGHT_INTENSITY.key, newValue).apply()
|
||||
}
|
||||
|
||||
fun setSize(size: Pair<Int, Int>) {
|
||||
@@ -173,32 +126,6 @@ class QuoteStorage private constructor(context: Context) {
|
||||
|
||||
fun getSize(): Pair<Int, Int> = Pair(prefs.getInt(KEY_AVG_WIDTH, 1), prefs.getInt(KEY_AVG_HEIGHT, 1))
|
||||
|
||||
fun saveSettings(
|
||||
textSize: Int,
|
||||
inverted: Boolean,
|
||||
textTransparency: Int,
|
||||
bgTransparency: Int,
|
||||
random: Boolean,
|
||||
widgetPosition: Int,
|
||||
backgroundType: Int,
|
||||
typefaceIndex: Int,
|
||||
typefaceStyleIndex: Int,
|
||||
outlineSize: Float,
|
||||
) {
|
||||
prefs.edit().apply {
|
||||
putInt(KEY_TEXT_SIZE, textSize)
|
||||
putBoolean(KEY_INVERTED, inverted)
|
||||
putInt(KEY_TEXT_TRANSPARENCY, textTransparency)
|
||||
putInt(KEY_BG_TRANSPARENCY, bgTransparency)
|
||||
putBoolean(KEY_RANDOM, random)
|
||||
putInt(KEY_WIDGET_POSITION, widgetPosition)
|
||||
putInt(KEY_BACKGROUND_TYPE, backgroundType)
|
||||
putInt(KEY_TYPEFACE, typefaceIndex)
|
||||
putInt(KEY_TYPEFACE_STYLE, typefaceStyleIndex)
|
||||
putFloat(KEY_OUTLINE_SIZE, outlineSize)
|
||||
}.apply()
|
||||
}
|
||||
|
||||
fun saveQuotes(quotes: Array<String>) {
|
||||
prefs.edit()
|
||||
.putString(KEY_QUOTES, quotes.joinToString(SEPARATOR.toString()))
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.denizd.textbasic.db.QuoteStorage
|
||||
import com.denizd.textbasic.util.showSnackBar
|
||||
import com.denizd.textbasic.util.viewBinding
|
||||
|
||||
|
||||
class QuoteFragment : BaseFragment(R.layout.fragment_quote), QuoteAdapter.OnDeleteListener {
|
||||
|
||||
private lateinit var storage: QuoteStorage
|
||||
|
||||
@@ -9,7 +9,6 @@ import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageButton
|
||||
import android.widget.TextView
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.transition.TransitionManager
|
||||
@@ -19,11 +18,9 @@ import com.denizd.textbasic.adapter.DropdownAdapter
|
||||
import com.denizd.textbasic.databinding.FragmentSettingsNewBinding
|
||||
import com.denizd.textbasic.db.QuoteStorage
|
||||
import com.denizd.textbasic.sheet.TextSheet
|
||||
import com.denizd.textbasic.util.SettingsPreference
|
||||
import com.denizd.textbasic.util.getConstrast
|
||||
import com.denizd.textbasic.util.viewBinding
|
||||
import com.denizd.textbasic.widget.CanvasText
|
||||
import com.google.android.material.button.MaterialButton
|
||||
import com.skydoves.colorpickerview.ColorEnvelope
|
||||
import com.skydoves.colorpickerview.ColorPickerDialog
|
||||
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
|
||||
@@ -82,40 +79,48 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
}
|
||||
|
||||
// --- text size --- //
|
||||
binding.textSize.text = storage.getInt(SettingsPreference.TEXT_SIZE, 18).toString()
|
||||
binding.textSize.text = storage.getTextSize().toString()
|
||||
|
||||
binding.buttonSizeDecreaseFast.setOnClickAction(
|
||||
binding.buttonSizeDecreaseFast.setOnClickListener {
|
||||
storage.setTextSize(getValueInBoundary(
|
||||
binding.textSize.text.toString().toInt(),
|
||||
4,
|
||||
256,
|
||||
isPositive = false,
|
||||
isFast = true,
|
||||
binding.textSize,
|
||||
SettingsPreference.TEXT_SIZE,
|
||||
)
|
||||
binding.buttonSizeDecrease.setOnClickAction(
|
||||
-10,
|
||||
))
|
||||
binding.textSize.text = storage.getTextSize().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonSizeDecrease.setOnClickListener {
|
||||
storage.setTextSize(getValueInBoundary(
|
||||
binding.textSize.text.toString().toInt(),
|
||||
4,
|
||||
256,
|
||||
isPositive = false,
|
||||
isFast = false,
|
||||
binding.textSize,
|
||||
SettingsPreference.TEXT_SIZE,
|
||||
)
|
||||
binding.buttonSizeIncrease.setOnClickAction(
|
||||
-1,
|
||||
))
|
||||
binding.textSize.text = storage.getTextSize().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonSizeIncrease.setOnClickListener {
|
||||
storage.setTextSize(getValueInBoundary(
|
||||
binding.textSize.text.toString().toInt(),
|
||||
4,
|
||||
256,
|
||||
isPositive = true,
|
||||
isFast = false,
|
||||
binding.textSize,
|
||||
SettingsPreference.TEXT_SIZE,
|
||||
)
|
||||
binding.buttonSizeIncreaseFast.setOnClickAction(
|
||||
1,
|
||||
))
|
||||
binding.textSize.text = storage.getTextSize().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonSizeIncreaseFast.setOnClickListener {
|
||||
storage.setTextSize(getValueInBoundary(
|
||||
binding.textSize.text.toString().toInt(),
|
||||
4,
|
||||
256,
|
||||
isPositive = true,
|
||||
isFast = true,
|
||||
binding.textSize,
|
||||
SettingsPreference.TEXT_SIZE,
|
||||
)
|
||||
10,
|
||||
))
|
||||
binding.textSize.text = storage.getTextSize().toString()
|
||||
updatePreview()
|
||||
}
|
||||
|
||||
// --- text colour --- //
|
||||
setTextColour(storage.getTextColour())
|
||||
@@ -155,40 +160,48 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
}
|
||||
|
||||
// --- highlight intensity --- //
|
||||
binding.textIntensity.text = storage.getInt(SettingsPreference.HIGHLIGHT_INTENSITY, 100).toString()
|
||||
binding.textIntensity.text = storage.getHighlightIntensity().toString()
|
||||
|
||||
binding.buttonIntensityDecreaseFast.setOnClickAction(
|
||||
binding.buttonIntensityDecreaseFast.setOnClickListener {
|
||||
storage.setHighlightIntensity(getValueInBoundary(
|
||||
binding.textIntensity.text.toString().toInt(),
|
||||
0,
|
||||
100,
|
||||
isPositive = false,
|
||||
isFast = true,
|
||||
binding.textIntensity,
|
||||
SettingsPreference.HIGHLIGHT_INTENSITY,
|
||||
)
|
||||
binding.buttonIntensityDecrease.setOnClickAction(
|
||||
-10,
|
||||
))
|
||||
binding.textIntensity.text = storage.getHighlightIntensity().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonIntensityDecrease.setOnClickListener {
|
||||
storage.setHighlightIntensity(getValueInBoundary(
|
||||
binding.textIntensity.text.toString().toInt(),
|
||||
0,
|
||||
100,
|
||||
isPositive = false,
|
||||
isFast = false,
|
||||
binding.textIntensity,
|
||||
SettingsPreference.HIGHLIGHT_INTENSITY,
|
||||
)
|
||||
binding.buttonIntensityIncrease.setOnClickAction(
|
||||
-1,
|
||||
))
|
||||
binding.textIntensity.text = storage.getHighlightIntensity().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonIntensityIncrease.setOnClickListener {
|
||||
storage.setHighlightIntensity(getValueInBoundary(
|
||||
binding.textIntensity.text.toString().toInt(),
|
||||
0,
|
||||
100,
|
||||
isPositive = true,
|
||||
isFast = false,
|
||||
binding.textIntensity,
|
||||
SettingsPreference.HIGHLIGHT_INTENSITY,
|
||||
)
|
||||
binding.buttonIntensityIncreaseFast.setOnClickAction(
|
||||
1,
|
||||
))
|
||||
binding.textIntensity.text = storage.getHighlightIntensity().toString()
|
||||
updatePreview()
|
||||
}
|
||||
binding.buttonIntensityIncreaseFast.setOnClickListener {
|
||||
storage.setHighlightIntensity(getValueInBoundary(
|
||||
binding.textIntensity.text.toString().toInt(),
|
||||
0,
|
||||
100,
|
||||
isPositive = true,
|
||||
isFast = true,
|
||||
binding.textIntensity,
|
||||
SettingsPreference.HIGHLIGHT_INTENSITY,
|
||||
)
|
||||
10,
|
||||
))
|
||||
binding.textIntensity.text = storage.getHighlightIntensity().toString()
|
||||
updatePreview()
|
||||
}
|
||||
|
||||
// --- highlight colour --- //
|
||||
setHighlightColour(storage.getHighlightColour())
|
||||
@@ -274,17 +287,14 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
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
|
||||
@@ -292,41 +302,22 @@ class SettingsNewFragment : BaseFragment(R.layout.fragment_settings_new) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO horrible, horrible, horrible function. but it works. fix this in the future. please.
|
||||
private fun MaterialButton.setOnClickAction(
|
||||
min: Int,
|
||||
max: Int,
|
||||
isPositive: Boolean,
|
||||
isFast: Boolean,
|
||||
textField: TextView,
|
||||
pref: SettingsPreference,
|
||||
) {
|
||||
setOnClickListener {
|
||||
var value = storage.getInt(pref)
|
||||
if (isFast) {
|
||||
if (isPositive) {
|
||||
if ((value + 10) > max) {
|
||||
value = max
|
||||
} else {
|
||||
value += 10
|
||||
}
|
||||
} else {
|
||||
if ((value - 10) < min) {
|
||||
value = min
|
||||
} else {
|
||||
value -= 10
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (isPositive && (value != max)) value += 1
|
||||
if (!isPositive && (value != min)) value -= 1
|
||||
}
|
||||
|
||||
storage.setInt(pref, value)
|
||||
textField.text = value.toString()
|
||||
|
||||
updatePreview()
|
||||
}
|
||||
/**
|
||||
* Adds a step to a numeric value while staying within bounds as defined by min and max.
|
||||
*
|
||||
* @param value value to change
|
||||
* @param min minimum boundary
|
||||
* @param max maximum boundary
|
||||
* @param step step to add to the given value; may be positive or negative
|
||||
* @return new value with step added, or boundary if it would have been exceeded otherwise
|
||||
*/
|
||||
private fun getValueInBoundary(value: Int, min: Int, max: Int, step: Int): Int = when {
|
||||
// If the new value exceeds the maximum value, return max
|
||||
(value + step) > max -> max
|
||||
// If the new value is below the minimum value, return min
|
||||
(value + step) < min -> min
|
||||
// Return the value with the step added
|
||||
else -> value + step
|
||||
}
|
||||
|
||||
private fun setTextColour(colour: String) {
|
||||
|
||||
@@ -164,59 +164,6 @@ class CanvasText {
|
||||
return bmp
|
||||
}
|
||||
|
||||
// private fun calculateWidgetGravity(widgetGravity: Int, bitmap: Bitmap, boundsText: Rect, isPreview: Boolean) : Pair<Float, Float> {
|
||||
// return if (isPreview) {
|
||||
// Pair((bitmap.width - boundsText.width()) / 2f, (bitmap.height + boundsText.height()) / 2f)
|
||||
// } else when (widgetGravity) {
|
||||
// 0 -> { // top left
|
||||
// Pair(0f + boundsText.left, (boundsText.height() - boundsText.top).toFloat())
|
||||
// }
|
||||
// 1 -> { // top center
|
||||
// Pair(
|
||||
// (bitmap.width - boundsText.width()) / 2f,
|
||||
// (boundsText.height() - boundsText.top).toFloat()
|
||||
// )
|
||||
// }
|
||||
// 2 -> { // top right
|
||||
// Pair(
|
||||
// (bitmap.width - (boundsText.right)).toFloat(),
|
||||
// (boundsText.height() - boundsText.top).toFloat()
|
||||
// )
|
||||
// }
|
||||
// 3 -> { // center left
|
||||
// Pair(0f + boundsText.left, (bitmap.height + boundsText.height()) / 2f)
|
||||
// }
|
||||
// // 4 == else branch
|
||||
// 5 -> { // center right
|
||||
// Pair(
|
||||
// (bitmap.width - (boundsText.right)).toFloat(),
|
||||
// (bitmap.height + boundsText.height()) / 2f
|
||||
// )
|
||||
// }
|
||||
// 6 -> { // bottom left
|
||||
// Pair(0f + boundsText.left, (bitmap.height - boundsText.bottom).toFloat())
|
||||
// }
|
||||
// 7 -> { // bottom center
|
||||
// Pair(
|
||||
// (bitmap.width - boundsText.width()) / 2f,
|
||||
// (bitmap.height - boundsText.bottom).toFloat()
|
||||
// )
|
||||
// }
|
||||
// 8 -> { // bottom right
|
||||
// Pair(
|
||||
// (bitmap.width - (boundsText.right)).toFloat(),
|
||||
// (bitmap.height - boundsText.bottom).toFloat()
|
||||
// )
|
||||
// }
|
||||
// else -> { // center center LIKE 4
|
||||
// Pair(
|
||||
// (bitmap.width - boundsText.width()) / 2f,
|
||||
// (bitmap.height + boundsText.height()) / 2f
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun roundedRect(
|
||||
left: Float, top: Float, right: Float, bottom: Float,
|
||||
roundingX: Float, roundingY: Float
|
||||
|
||||
Reference in New Issue
Block a user