Skip to content

Commit c1cdee8

Browse files
committed
Add default list note view mode setting
1 parent f734488 commit c1cdee8

7 files changed

Lines changed: 49 additions & 0 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,16 @@ class SettingsFragment : Fragment() {
353353
}
354354
}
355355

356+
defaultListNoteViewMode.observe(viewLifecycleOwner) { value ->
357+
binding.DefaultListNoteViewMode.setup(
358+
defaultListNoteViewMode,
359+
value,
360+
requireContext(),
361+
) { newValue ->
362+
model.savePreference(defaultListNoteViewMode, newValue)
363+
}
364+
}
365+
356366
autoRemoveDeletedNotesAfterDays.observe(viewLifecycleOwner) { value ->
357367
binding.AutoEmptyBin.setupAutoEmptyBin(
358368
autoRemoveDeletedNotesAfterDays,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ abstract class EditActivity(private val type: Type) : LockedActivity<ActivityEdi
196196
setupListeners()
197197
setStateFromModel(savedInstanceState)
198198

199+
if (
200+
!notallyModel.isNewNote &&
201+
notallyModel.type == Type.LIST &&
202+
savedInstanceState == null
203+
) {
204+
val lastUsedViewMode = notallyModel.viewMode.value
205+
notallyModel.viewMode.value =
206+
preferences.defaultListNoteViewMode.value.toNoteViewMode(lastUsedViewMode)
207+
}
208+
199209
configureUI()
200210
binding.ScrollView.visibility = VISIBLE
201211
setupEditNoteReminderChip()

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ class NotallyXPreferences private constructor(private val context: Context) {
5959
R.string.list_item_auto_sort,
6060
)
6161

62+
val defaultListNoteViewMode =
63+
createEnumPreference(
64+
preferences,
65+
"defaultListNoteViewMode",
66+
DefaultListNoteViewMode.LAST_USED,
67+
R.string.default_list_note_view_mode,
68+
)
69+
6270
val maxItems =
6371
IntPreference(
6472
"maxItemsToDisplayInList.v1",
@@ -313,6 +321,7 @@ class NotallyXPreferences private constructor(private val context: Context) {
313321
editNoteActivityTopActions,
314322
editNoteActivityBottomAction,
315323
defaultNoteColor,
324+
defaultListNoteViewMode,
316325
)
317326
.forEach { it.refresh() }
318327
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,20 @@ enum class ListItemSort(override val textResId: Int) : StaticTextProvider {
388388
AUTO_SORT_BY_CHECKED(R.string.auto_sort_by_checked),
389389
}
390390

391+
enum class DefaultListNoteViewMode(override val textResId: Int) : StaticTextProvider {
392+
READ_ONLY(R.string.read_only),
393+
EDIT(R.string.edit),
394+
LAST_USED(R.string.last_used);
395+
396+
fun toNoteViewMode(lastUsed: NoteViewMode): NoteViewMode {
397+
return when (this) {
398+
READ_ONLY -> NoteViewMode.READ_ONLY
399+
EDIT -> NoteViewMode.EDIT
400+
LAST_USED -> lastUsed
401+
}
402+
}
403+
}
404+
391405
enum class BiometricLock(override val textResId: Int) : StaticTextProvider {
392406
ENABLED(R.string.enabled),
393407
DISABLED(R.string.disabled);

app/src/main/res/layout/fragment_settings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
android:id="@+id/StartView"
6262
layout="@layout/preference" />
6363

64+
<include
65+
android:id="@+id/DefaultListNoteViewMode"
66+
layout="@layout/preference" />
67+
6468
<include
6569
android:id="@+id/AutoSaveAfterIdle"
6670
layout="@layout/preference_seekbar" />

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
<string name="day">Day</string>
113113
<string name="days">Days</string>
114114
<string name="default_color_hint">This is the default color for new notes. To change it, make another color the default</string>
115+
<string name="default_list_note_view_mode">Default List-Note View Mode</string>
116+
<string name="last_used">Last Used</string>
115117
<string name="delete">Delete</string>
116118
<string name="delete_all">Delete all</string>
117119
<string name="delete_all_notes">Delete all notes\?</string>

app/translations.xlsx

231 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)