Skip to content

Commit dd45842

Browse files
committed
PR fixes
1 parent a5f0db5 commit dd45842

8 files changed

Lines changed: 92 additions & 51 deletions

File tree

app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,10 @@ fun TextView.displayFormattedTimestamp(
299299
} else visibility = View.GONE
300300
}
301301

302+
fun TextView.setTextSizeSp(textSizeSp: Float) {
303+
setTextSize(TypedValue.COMPLEX_UNIT_SP, textSizeSp)
304+
}
305+
302306
val Int.dp: Int
303307
get() = (this * Resources.getSystem().displayMetrics.density + 0.5f).toInt()
304308

@@ -1043,7 +1047,7 @@ fun Window.setLightStatusAndNavBar(value: Boolean, view: View = decorView) {
10431047

10441048
fun ChipGroup.bindLabels(
10451049
labels: List<String>,
1046-
textSize: Int,
1050+
textSize: Float,
10471051
paddingTop: Boolean,
10481052
color: Int? = null,
10491053
onClick: ((label: String) -> Unit)? = null,
@@ -1062,7 +1066,7 @@ fun ChipGroup.bindLabels(
10621066
for (label in labels) {
10631067
LabelBinding.inflate(inflater, this, true).root.apply {
10641068
background = getOutlinedDrawable(this@bindLabels.context)
1065-
setTextSize(TypedValue.COMPLEX_UNIT_SP, labelSize)
1069+
setTextSizeSp(labelSize)
10661070
text = label
10671071
color?.let { setControlsContrastColorForAllViews(it) }
10681072
onClick?.let { setOnClickListener { it(label) } }
@@ -1151,7 +1155,7 @@ fun Chip.setupReminderChip(baseNote: BaseNote, textSize: Float? = null) {
11511155
visibility = VISIBLE
11521156
text = mostRecentNotificationDate.format()
11531157
textSize?.let {
1154-
setTextSize(TypedValue.COMPLEX_UNIT_SP, it)
1158+
setTextSizeSp(it)
11551159
chipIconSize =
11561160
TypedValue.applyDimension(
11571161
TypedValue.COMPLEX_UNIT_SP,

app/src/main/java/com/philkes/notallyx/presentation/activity/main/fragment/settings/PreferenceBindingExtensions.kt

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.hardware.biometrics.BiometricManager
55
import android.net.Uri
66
import android.os.Build
77
import android.text.method.PasswordTransformationMethod
8-
import android.util.TypedValue
98
import android.view.LayoutInflater
109
import android.view.View
1110
import androidx.core.view.isVisible
@@ -26,6 +25,7 @@ import com.philkes.notallyx.databinding.PreferenceSeekbarBinding
2625
import com.philkes.notallyx.presentation.checkedTag
2726
import com.philkes.notallyx.presentation.select
2827
import com.philkes.notallyx.presentation.setCancelButton
28+
import com.philkes.notallyx.presentation.setTextSizeSp
2929
import com.philkes.notallyx.presentation.showAndFocus
3030
import com.philkes.notallyx.presentation.showToast
3131
import com.philkes.notallyx.presentation.view.misc.MenuDialog
@@ -35,6 +35,7 @@ import com.philkes.notallyx.presentation.viewmodel.preference.BooleanPreference
3535
import com.philkes.notallyx.presentation.viewmodel.preference.Constants.PASSWORD_EMPTY
3636
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
3737
import com.philkes.notallyx.presentation.viewmodel.preference.EnumPreference
38+
import com.philkes.notallyx.presentation.viewmodel.preference.FloatPreference
3839
import com.philkes.notallyx.presentation.viewmodel.preference.IntPreference
3940
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.EMPTY_PATH
4041
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences.Companion.START_VIEW_DEFAULT
@@ -511,30 +512,28 @@ fun PreferenceSeekbarBinding.setup(
511512
}
512513

513514
fun PreferenceSeekbarBinding.setupTextSizePreference(
514-
preference: IntPreference,
515+
preference: FloatPreference,
515516
context: Context,
516-
value: Int = preference.value,
517+
value: Float = preference.value,
517518
tooltipResId: Int? = null,
518-
onChange: (newValue: Int) -> Unit,
519+
onChange: (newValue: Float) -> Unit,
519520
) {
520521
setup(
521-
value,
522+
value.toInt(),
522523
preference.titleResId!!,
523-
preference.min,
524-
preference.max,
524+
preference.min.toInt(),
525+
preference.max.toInt(),
525526
context,
526527
tooltipResId = tooltipResId,
527528
) { newValue ->
528-
onChange(newValue)
529+
onChange(newValue.toFloat())
529530
}
530531
PreviewText.apply {
531532
isVisible = false
532-
setTextSize(TypedValue.COMPLEX_UNIT_SP, value.toFloat())
533+
setTextSizeSp(value)
533534
}
534535
Slider.apply {
535-
addOnChangeListener { _, newValue, _ ->
536-
PreviewText.setTextSize(TypedValue.COMPLEX_UNIT_SP, newValue)
537-
}
536+
addOnChangeListener { _, newValue, _ -> PreviewText.setTextSizeSp(newValue) }
538537
addOnSliderTouchListener(
539538
object : Slider.OnSliderTouchListener {
540539
override fun onStartTrackingTouch(slider: Slider) {
@@ -543,7 +542,7 @@ fun PreferenceSeekbarBinding.setupTextSizePreference(
543542

544543
override fun onStopTrackingTouch(slider: Slider) {
545544
PreviewText.isVisible = false
546-
onChange(slider.value.toInt())
545+
onChange(slider.value)
547546
}
548547
}
549548
)

app/src/main/java/com/philkes/notallyx/presentation/activity/note/EditActivity.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import android.text.Editable
1313
import android.text.Spanned
1414
import android.text.style.URLSpan
1515
import android.util.Log
16-
import android.util.TypedValue
1716
import android.view.MenuItem
1817
import android.view.View
1918
import android.view.View.GONE
@@ -57,6 +56,7 @@ import com.philkes.notallyx.presentation.isLightColor
5756
import com.philkes.notallyx.presentation.setCancelButton
5857
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
5958
import com.philkes.notallyx.presentation.setLightStatusAndNavBar
59+
import com.philkes.notallyx.presentation.setTextSizeSp
6060
import com.philkes.notallyx.presentation.setupProgressDialog
6161
import com.philkes.notallyx.presentation.setupReminderChip
6262
import com.philkes.notallyx.presentation.showKeyboard
@@ -74,7 +74,7 @@ import com.philkes.notallyx.presentation.viewmodel.preference.EditAction
7474
import com.philkes.notallyx.presentation.viewmodel.preference.ListItemSort
7575
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
7676
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortBy
77-
import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
77+
import com.philkes.notallyx.presentation.viewmodel.preference.displaySmallerSize
7878
import com.philkes.notallyx.presentation.viewmodel.preference.editBodySize
7979
import com.philkes.notallyx.presentation.viewmodel.preference.editTitleSize
8080
import com.philkes.notallyx.presentation.widget.WidgetProvider
@@ -674,7 +674,10 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
674674
if (preferences.applyDateFormatInNoteView.value) {
675675
preferences.dateFormat.value
676676
} else DateFormat.ABSOLUTE
677-
binding.Date.displayFormattedTimestamp(date, dateFormat, datePrefixResId)
677+
binding.Date.apply {
678+
displayFormattedTimestamp(date, dateFormat, datePrefixResId)
679+
setTextSizeSp(notallyModel.textSize.displaySmallerSize)
680+
}
678681
binding.EnterTitle.setText(notallyModel.title)
679682
bindLabels()
680683
setColor()
@@ -928,13 +931,9 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
928931
}
929932
}
930933

931-
val title = notallyModel.textSize.editTitleSize
932-
val date = notallyModel.textSize.displayBodySize
933-
val body = notallyModel.textSize.editBodySize
934-
935-
binding.EnterTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, title)
936-
binding.Date.setTextSize(TypedValue.COMPLEX_UNIT_SP, date)
937-
binding.EnterBody.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
934+
binding.EnterTitle.setTextSizeSp(notallyModel.textSize.editTitleSize)
935+
binding.Date.setTextSizeSp(notallyModel.textSize.displaySmallerSize)
936+
binding.EnterBody.setTextSizeSp(notallyModel.textSize.editBodySize)
938937

939938
setupImages()
940939
setupFiles()
@@ -984,7 +983,7 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
984983
notallyModel.originalNote?.let { note ->
985984
binding.EditNoteReminderChip.setupReminderChip(
986985
note,
987-
notallyModel.textSize.displayBodySize,
986+
notallyModel.textSize.displaySmallerSize,
988987
)
989988
binding.EditNoteReminderChip.setOnClickListener {
990989
val intent =

app/src/main/java/com/philkes/notallyx/presentation/view/main/BaseNoteVH.kt

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.philkes.notallyx.presentation.view.main
22

33
import android.graphics.drawable.Drawable
4-
import android.util.TypedValue
54
import android.view.View.GONE
65
import android.view.View.VISIBLE
76
import android.widget.LinearLayout
@@ -32,6 +31,7 @@ import com.philkes.notallyx.presentation.dp
3231
import com.philkes.notallyx.presentation.extractColor
3332
import com.philkes.notallyx.presentation.getQuantityString
3433
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
34+
import com.philkes.notallyx.presentation.setTextSizeSp
3535
import com.philkes.notallyx.presentation.setupReminderChip
3636
import com.philkes.notallyx.presentation.view.misc.ItemListener
3737
import com.philkes.notallyx.presentation.view.misc.highlightableview.HighlightableTextView
@@ -40,11 +40,12 @@ import com.philkes.notallyx.presentation.view.note.listitem.init
4040
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
4141
import com.philkes.notallyx.presentation.viewmodel.preference.NotesSortBy
4242
import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
43+
import com.philkes.notallyx.presentation.viewmodel.preference.displaySmallerSize
4344
import com.philkes.notallyx.presentation.viewmodel.preference.displayTitleSize
4445
import java.io.File
4546

4647
data class BaseNoteVHPreferences(
47-
val textSize: Int,
48+
val textSize: Float,
4849
val maxItems: Int,
4950
val maxLines: Int,
5051
val maxTitleLines: Int,
@@ -66,13 +67,13 @@ class BaseNoteVH(
6667
}
6768

6869
init {
69-
val title = preferences.textSize.displayTitleSize
70-
val body = preferences.textSize.displayBodySize
7170

7271
binding.apply {
73-
Title.setTextSize(TypedValue.COMPLEX_UNIT_SP, title)
74-
Date.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
75-
Note.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
72+
val titleTextSize = preferences.textSize.displayTitleSize
73+
val bodyTextSize = preferences.textSize.displayBodySize
74+
Title.setTextSizeSp(titleTextSize)
75+
Date.setTextSizeSp(bodyTextSize)
76+
Note.setTextSizeSp(bodyTextSize)
7677

7778
Title.maxLines = preferences.maxTitleLines
7879
Note.maxLines = preferences.maxLines
@@ -115,7 +116,10 @@ class BaseNoteVH(
115116
Pair(baseNote.modifiedTimestamp, R.string.modified_date)
116117
else -> Pair(null, null)
117118
}
118-
binding.Date.displayFormattedTimestamp(date, dateFormat, datePrefixResId)
119+
binding.Date.apply {
120+
displayFormattedTimestamp(date, dateFormat, datePrefixResId)
121+
setTextSizeSp(preferences.textSize.displaySmallerSize)
122+
}
119123

120124
setImages(baseNote.images, imageRoot)
121125
setFiles(baseNote.files)
@@ -159,7 +163,7 @@ class BaseNoteVH(
159163
isVisible = true
160164
}
161165
}
162-
binding.ReminderChip.setupReminderChip(baseNote, preferences.textSize.displayBodySize)
166+
binding.ReminderChip.setupReminderChip(baseNote, preferences.textSize.displaySmallerSize)
163167
setColor(baseNote.color)
164168
}
165169

@@ -201,7 +205,7 @@ class BaseNoteVH(
201205
val keywordItemIdx =
202206
initializedItems.indexOfFirst { it.body.contains(keyword, ignoreCase = true) }
203207
if (keywordItemIdx == -1) {
204-
return bindList(initializedItems, isTitleEmpty)
208+
return bindList(initializedItems, isTitleEmpty, preferences.textSize.displayBodySize)
205209
}
206210
val listItemViews = children.filterIsInstance(HighlightableTextView::class.java).toList()
207211
listItemViews.forEach { it.visibility = GONE }
@@ -233,7 +237,11 @@ class BaseNoteVH(
233237
return
234238
}
235239
if (keyword.isBlank()) {
236-
bindList(initializedItems, baseNote.title.isEmpty())
240+
bindList(
241+
initializedItems,
242+
baseNote.title.isEmpty(),
243+
preferences.textSize.displayBodySize,
244+
)
237245
return
238246
}
239247
binding.LinearLayout.bindListSearch(initializedItems, keyword, baseNote.title.isEmpty())
@@ -248,7 +256,7 @@ class BaseNoteVH(
248256
} else binding.ItemsRemaining.visibility = GONE
249257
}
250258

251-
private fun bindList(initializedItems: List<ListItem>, isTitleEmpty: Boolean) {
259+
private fun bindList(initializedItems: List<ListItem>, isTitleEmpty: Boolean, textSize: Float) {
252260
binding.apply {
253261
bindItemsRemaining(initializedItems.size, preferences.maxItems)
254262
if (initializedItems.isEmpty()) {
@@ -273,6 +281,7 @@ class BaseNoteVH(
273281
if (index == filteredList.lastIndex) {
274282
updatePadding(bottom = 0)
275283
}
284+
setTextSizeSp(textSize)
276285
}
277286
} else view.visibility = GONE
278287
}

app/src/main/java/com/philkes/notallyx/presentation/view/note/listitem/adapter/ListItemVH.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.philkes.notallyx.presentation.view.note.listitem.adapter
22

33
import android.graphics.Paint
4-
import android.util.TypedValue
54
import android.view.KeyEvent
65
import android.view.MotionEvent
76
import android.view.View.GONE
@@ -27,6 +26,7 @@ import com.philkes.notallyx.presentation.clone
2726
import com.philkes.notallyx.presentation.createListTextWatcherWithHistory
2827
import com.philkes.notallyx.presentation.setControlsContrastColorForAllViews
2928
import com.philkes.notallyx.presentation.setOnNextAction
29+
import com.philkes.notallyx.presentation.setTextSizeSp
3030
import com.philkes.notallyx.presentation.view.misc.EditTextAutoClearFocus
3131
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
3232
import com.philkes.notallyx.presentation.view.note.listitem.firstBodyOrEmptyString
@@ -49,7 +49,7 @@ class ListItemVH(
4949
init {
5050
val body = textSize.editBodySize
5151
binding.EditText.apply {
52-
setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
52+
setTextSizeSp(body)
5353
filters = context.textMaxLengthFilter()
5454
textWatcher =
5555
createListTextWatcherWithHistory(

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/preference/NotallyXPreferences.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ class NotallyXPreferences private constructor(private val context: Context) {
3131
val theme = createEnumPreference(preferences, "theme", Theme.FOLLOW_SYSTEM, R.string.theme)
3232
val useDynamicColors = BooleanPreference("useDynamicColors", preferences, false)
3333
val textSizeNoteEditor =
34-
IntPreference("textSizeNoteEditor", preferences, 16, 12, 32, R.string.text_size_note_editor)
34+
FloatPreference(
35+
"textSizeNoteEditor",
36+
preferences,
37+
16f,
38+
12f,
39+
32f,
40+
R.string.text_size_note_editor,
41+
)
3542
val textSizeOverview =
36-
IntPreference("textSizeOverview", preferences, 14, 12, 32, R.string.text_size_overview)
43+
FloatPreference("textSizeOverview", preferences, 14f, 12f, 32f, R.string.text_size_overview)
3744
val dateFormat =
3845
createEnumPreference(preferences, "dateFormat", DateFormat.RELATIVE, R.string.date_format)
3946
val applyDateFormatInNoteView =

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/preference/Preference.kt

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,24 @@ class IntPreference(
223223
}
224224
}
225225

226+
class FloatPreference(
227+
val key: String,
228+
sharedPreferences: SharedPreferences,
229+
defaultValue: Float,
230+
val min: Float,
231+
val max: Float,
232+
titleResId: Int? = null,
233+
) : BasePreference<Float>(sharedPreferences, defaultValue, titleResId) {
234+
235+
override fun getValue(sharedPreferences: SharedPreferences): Float {
236+
return sharedPreferences.getFloat(key, defaultValue)
237+
}
238+
239+
override fun SharedPreferences.Editor.put(value: Float) {
240+
putFloat(key, value)
241+
}
242+
}
243+
226244
class LongPreference(val key: String, sharedPreferences: SharedPreferences, defaultValue: Long) :
227245
BasePreference<Long>(sharedPreferences, defaultValue) {
228246

@@ -348,17 +366,22 @@ enum class DateFormat : TextProvider {
348366
}
349367
}
350368

351-
val Int.editBodySize: Float
352-
get() = this.toFloat()
369+
typealias TextSizeSp = Float
370+
371+
val TextSizeSp.editBodySize: Float
372+
get() = this
373+
374+
val TextSizeSp.editTitleSize: Float
375+
get() = (this + 4)
353376

354-
val Int.editTitleSize: Float
355-
get() = (this + 4).toFloat()
377+
val TextSizeSp.displayBodySize: Float
378+
get() = (this - 2)
356379

357-
val Int.displayBodySize: Float
358-
get() = (this - 2).toFloat()
380+
val TextSizeSp.displaySmallerSize: Float
381+
get() = (this - 3)
359382

360-
val Int.displayTitleSize: Float
361-
get() = this.toFloat()
383+
val TextSizeSp.displayTitleSize: Float
384+
get() = this
362385

363386
enum class ListItemSort(override val textResId: Int) : StaticTextProvider {
364387
NO_AUTO_SORT(R.string.no_auto_sort),

app/translations.xlsx

3 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)