Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add app preference for remove node indent #951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/src/main/java/com/orgzly/android/prefs/AppPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ public static void isReverseNoteClickAction(Context context, boolean value) {
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
}

public static boolean isRemoveNoteIndent(Context context) {
return getDefaultSharedPreferences(context).getBoolean(
context.getResources().getString(R.string.pref_key_is_remove_indent),
context.getResources().getBoolean(R.bool.pref_default_is_remove_indent));
}

public static void isRemoveNoteIndent(Context context, boolean value) {
String key = context.getResources().getString(R.string.pref_key_is_remove_indent);
getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
}

/*
* Schedule new note.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,14 @@ class NoteItemViewBinder(private val context: Context, private val inBook: Boole
}

private fun setupTitle(holder: NoteItemViewHolder, noteView: NoteView) {
holder.binding.itemHeadTitle.setText(generateTitle(noteView))
val level = if (inBook) noteView.note.position.level else 0

if (AppPreferences.isRemoveNoteIndent(context)) {
holder.binding.itemHeadTitle.setText("--".repeat(level)+" "+generateTitle(noteView))
}
else {
holder.binding.itemHeadTitle.setText(generateTitle(noteView))
}
}

fun generateTitle(noteView: NoteView): CharSequence {
Expand Down Expand Up @@ -244,28 +251,33 @@ class NoteItemViewBinder(private val context: Context, private val inBook: Boole
val container = holder.binding.itemHeadIndentContainer

val level = if (inBook) note.position.level - 1 else 0
var titleIndentLevel = level

if (AppPreferences.isRemoveNoteIndent(context)) {
titleIndentLevel = 0
}

when {
container.childCount < level -> { // More levels needed
container.childCount < titleIndentLevel -> { // More levels needed
// Make all existing levels visible
for (i in 1..container.childCount) {
container.getChildAt(i - 1).visibility = View.VISIBLE
}

// Inflate the rest
for (i in container.childCount + 1..level) {
for (i in container.childCount + 1..titleIndentLevel) {
View.inflate(container.context, R.layout.indent, container)
}
}

level < container.childCount -> { // Too many levels
titleIndentLevel< container.childCount -> { // Too many levels
// Make required levels visible
for (i in 1..level) {
for (i in 1..titleIndentLevel) {
container.getChildAt(i - 1).visibility = View.VISIBLE
}

// Hide the rest
for (i in level + 1..container.childCount) {
for (i in titleIndentLevel + 1..container.childCount) {
container.getChildAt(i - 1).visibility = View.GONE
}
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@
<string name="monospaced_font_summary">为笔记内容和笔记本序言使用等宽字体</string>
<string name="reversed_note_click_action">反转笔记点击动作</string>
<string name="reversed_note_click_action_summary">点击选择笔记,长按打开笔记</string>
<string name="remove_note_indent">移除笔记缩进</string>
<string name="remove_mote_indent_summary">移除笔记缩进以节省屏幕空间</string>
<string name="look_and_feel">外观 &amp; 感觉</string>
<string name="notes_list">笔记列表</string>
<string name="prefs_title_new_note">新建笔记</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/prefs_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<string name="pref_key_is_reverse_click_action" translatable="false">pref_key_is_reverse_click_action</string>
<bool name="pref_default_is_reverse_click_action" translatable="false">false</bool>

<string name="pref_key_is_remove_indent" translatable="false">pref_key_is_remove_indent</string>
<bool name="pref_default_is_remove_indent" translatable="false">false</bool>

<string name="pref_key_is_notes_content_displayed_in_list" translatable="false">pref_key_is_notes_content_displayed_in_list</string>
<bool name="pref_default_is_notes_content_displayed_in_list" translatable="false">true</bool>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@
<string name="monospaced_font_summary">Use monospaced font for note\'s content and notebook\'s preface</string>
<string name="reversed_note_click_action">Swap note click and long-click actions</string>
<string name="reversed_note_click_action_summary">Click to select note, long-click to open</string>
<string name="remove_note_indent">Remove note indent</string>
<string name="remove_mote_indent_summary">Remove note indent to save screen space</string>
<string name="look_and_feel">Look &amp; Feel</string>
<string name="notes_list">List of notes</string>
<string name="prefs_title_new_note">New note</string>
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/xml/prefs_screen_look_and_feel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
android:summary="@string/reversed_note_click_action_summary"
android:defaultValue="@bool/pref_default_is_reverse_click_action"/>

<SwitchPreference
android:key="@string/pref_key_is_remove_indent"
android:title="@string/remove_note_indent"
android:summary="@string/remove_mote_indent_summary"
android:defaultValue="@bool/pref_default_is_remove_indent"/>

<ListPreference
android:key="@string/pref_key_color_scheme"
android:title="@string/color_scheme"
Expand Down