Skip to content

Commit 7a0cdff

Browse files
committed
Make text sizes more flexible
1 parent dde6d3d commit 7a0cdff

39 files changed

Lines changed: 206 additions & 124 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ import com.philkes.notallyx.presentation.view.note.listitem.ListManager
110110
import com.philkes.notallyx.presentation.view.note.listitem.adapter.ListItemVH
111111
import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
112112
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
113-
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
113+
import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
114114
import com.philkes.notallyx.utils.changehistory.ChangeHistory
115115
import com.philkes.notallyx.utils.changehistory.EditTextState
116116
import com.philkes.notallyx.utils.changehistory.EditTextWithHistoryChange
@@ -1036,7 +1036,7 @@ fun Window.setLightStatusAndNavBar(value: Boolean, view: View = decorView) {
10361036

10371037
fun ChipGroup.bindLabels(
10381038
labels: List<String>,
1039-
textSize: TextSize,
1039+
textSize: Int,
10401040
paddingTop: Boolean,
10411041
color: Int? = null,
10421042
onClick: ((label: String) -> Unit)? = null,
@@ -1131,7 +1131,7 @@ fun Context.createTextView(textResId: Int, padding: Int = 16.dp): TextView {
11311131
}
11321132
}
11331133

1134-
fun Chip.setupReminderChip(baseNote: BaseNote) {
1134+
fun Chip.setupReminderChip(baseNote: BaseNote, textSize: Float? = null) {
11351135
val now = Date(System.currentTimeMillis())
11361136
val mostRecentNotificationDate =
11371137
baseNote.reminders.findNextNotificationDate()
@@ -1143,6 +1143,15 @@ fun Chip.setupReminderChip(baseNote: BaseNote) {
11431143
this.apply {
11441144
visibility = VISIBLE
11451145
text = mostRecentNotificationDate.format()
1146+
textSize?.let {
1147+
setTextSize(TypedValue.COMPLEX_UNIT_SP, it)
1148+
chipIconSize =
1149+
TypedValue.applyDimension(
1150+
TypedValue.COMPLEX_UNIT_SP,
1151+
it + 4,
1152+
resources.displayMetrics,
1153+
)
1154+
}
11461155
setCloseIconVisible(baseNote.reminders.haveAnyRepetition())
11471156
val isElapsed = mostRecentNotificationDate < now
11481157
alpha = if (isElapsed) 0.5f else 1.0f

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ abstract class NotallyFragment : Fragment(), ItemListener {
263263
dateFormat.value,
264264
notesSorting.value,
265265
BaseNoteVHPreferences(
266-
textSize.value,
266+
textSizeOverview.value,
267267
maxItems.value,
268268
maxLines.value,
269269
maxTitle.value,

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ 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
89
import android.view.LayoutInflater
910
import android.view.View
1011
import androidx.core.view.isVisible
@@ -509,6 +510,46 @@ fun PreferenceSeekbarBinding.setup(
509510
}
510511
}
511512

513+
fun PreferenceSeekbarBinding.setupTextSizePreference(
514+
preference: IntPreference,
515+
context: Context,
516+
value: Int = preference.value,
517+
tooltipResId: Int? = null,
518+
onChange: (newValue: Int) -> Unit,
519+
) {
520+
setup(
521+
value,
522+
preference.titleResId!!,
523+
preference.min,
524+
preference.max,
525+
context,
526+
tooltipResId = tooltipResId,
527+
) { newValue ->
528+
onChange(newValue)
529+
}
530+
PreviewText.apply {
531+
isVisible = false
532+
setTextSize(TypedValue.COMPLEX_UNIT_SP, value.toFloat())
533+
}
534+
Slider.apply {
535+
addOnChangeListener { _, newValue, _ ->
536+
PreviewText.setTextSize(TypedValue.COMPLEX_UNIT_SP, newValue)
537+
}
538+
addOnSliderTouchListener(
539+
object : Slider.OnSliderTouchListener {
540+
override fun onStartTrackingTouch(slider: Slider) {
541+
PreviewText.isVisible = true
542+
}
543+
544+
override fun onStopTrackingTouch(slider: Slider) {
545+
PreviewText.isVisible = false
546+
onChange(slider.value.toInt())
547+
}
548+
}
549+
)
550+
}
551+
}
552+
512553
fun PreferenceSeekbarBinding.setupAutoSaveIdleTime(
513554
preference: IntPreference,
514555
context: Context,

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,22 @@ class SettingsFragment : Fragment() {
307307
}
308308
}
309309

310-
textSize.observe(viewLifecycleOwner) { value ->
311-
binding.TextSize.setup(textSize, value, requireContext()) { newValue ->
312-
model.savePreference(textSize, newValue)
310+
textSizeNoteEditor.observe(viewLifecycleOwner) { value ->
311+
binding.TextSize.setupTextSizePreference(
312+
textSizeNoteEditor,
313+
requireContext(),
314+
value = value,
315+
) { newValue ->
316+
model.savePreference(textSizeNoteEditor, newValue)
317+
}
318+
}
319+
textSizeOverview.observe(viewLifecycleOwner) { value ->
320+
binding.TextSizeOverview.setupTextSizePreference(
321+
textSizeOverview,
322+
requireContext(),
323+
value = value,
324+
) { newValue ->
325+
model.savePreference(textSizeOverview, newValue)
313326
}
314327
}
315328
alwaysShowSearchBar.observe(viewLifecycleOwner) { value ->

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ 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
78+
import com.philkes.notallyx.presentation.viewmodel.preference.editBodySize
79+
import com.philkes.notallyx.presentation.viewmodel.preference.editTitleSize
7780
import com.philkes.notallyx.presentation.widget.WidgetProvider
7881
import com.philkes.notallyx.utils.FileError
7982
import com.philkes.notallyx.utils.changeStatusAndNavigationBarColor
@@ -979,7 +982,10 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
979982

980983
fun setupEditNoteReminderChip() {
981984
notallyModel.originalNote?.let { note ->
982-
binding.EditNoteReminderChip.setupReminderChip(note)
985+
binding.EditNoteReminderChip.setupReminderChip(
986+
note,
987+
notallyModel.textSize.displayBodySize,
988+
)
983989
binding.EditNoteReminderChip.setOnClickListener {
984990
val intent =
985991
Intent(this@EditActivity, RemindersActivity::class.java)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ open class PickNoteActivity : LockedActivity<ActivityPickNoteBinding>(), ItemLis
5252
dateFormat.value,
5353
notesSorting.value,
5454
BaseNoteVHPreferences(
55-
textSize.value,
55+
textSizeOverview.value,
5656
maxItems.value,
5757
maxLines.value,
5858
maxTitle.value,

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ import com.philkes.notallyx.presentation.view.misc.highlightableview.SEARCH_SNIP
3939
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
42-
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
42+
import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
43+
import com.philkes.notallyx.presentation.viewmodel.preference.displayTitleSize
4344
import java.io.File
4445

4546
data class BaseNoteVHPreferences(
46-
val textSize: TextSize,
47+
val textSize: Int,
4748
val maxItems: Int,
4849
val maxLines: Int,
4950
val maxTitleLines: Int,
@@ -73,11 +74,6 @@ class BaseNoteVH(
7374
Date.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
7475
Note.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
7576

76-
LinearLayout.children.forEach { view ->
77-
view as TextView
78-
view.setTextSize(TypedValue.COMPLEX_UNIT_SP, body)
79-
}
80-
8177
Title.maxLines = preferences.maxTitleLines
8278
Note.maxLines = preferences.maxLines
8379

@@ -163,7 +159,7 @@ class BaseNoteVH(
163159
isVisible = true
164160
}
165161
}
166-
binding.ReminderChip.setupReminderChip(baseNote)
162+
binding.ReminderChip.setupReminderChip(baseNote, preferences.textSize.displayBodySize)
167163
setColor(baseNote.color)
168164
}
169165

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import com.philkes.notallyx.data.model.NoteViewMode
1010
import com.philkes.notallyx.presentation.view.note.listitem.HighlightText
1111
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
1212
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
13-
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
1413

1514
class CheckedListItemAdapter(
1615
@ColorInt var backgroundColor: Int,
17-
private val textSize: TextSize,
16+
private val textSize: Int,
1817
elevation: Float,
1918
private val preferences: NotallyXPreferences,
2019
private val listManager: ListManager,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import com.philkes.notallyx.data.model.NoteViewMode
1111
import com.philkes.notallyx.presentation.view.note.listitem.HighlightText
1212
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
1313
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
14-
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
1514

1615
class ListItemAdapter(
1716
@ColorInt var backgroundColor: Int,
18-
private val textSize: TextSize,
17+
private val textSize: Int,
1918
elevation: Float,
2019
private val preferences: NotallyXPreferences,
2120
private val listManager: ListManager,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import com.philkes.notallyx.databinding.RecyclerListItemBinding
1212
import com.philkes.notallyx.presentation.view.note.listitem.ListItemDragCallback
1313
import com.philkes.notallyx.presentation.view.note.listitem.ListManager
1414
import com.philkes.notallyx.presentation.viewmodel.preference.NotallyXPreferences
15-
import com.philkes.notallyx.presentation.viewmodel.preference.TextSize
1615

1716
data class ListItemHighlight(
1817
val itemPos: Int,
@@ -25,7 +24,7 @@ data class ListItemHighlight(
2524
abstract class ListItemAdapterBase(
2625
private val adapter: RecyclerView.Adapter<*>,
2726
@ColorInt var backgroundColor: Int,
28-
private val textSize: TextSize,
27+
private val textSize: Int,
2928
elevation: Float,
3029
private val preferences: NotallyXPreferences,
3130
private val listManager: ListManager,

0 commit comments

Comments
 (0)