Skip to content

Commit 0672614

Browse files
authored
Merge pull request #584 from Aga-C/add_checklist_items_top
Added new checklist items at the top (#583)
2 parents 6552fd4 + af38da3 commit 0672614

File tree

5 files changed

+24
-1
lines changed

5 files changed

+24
-1
lines changed

app/src/main/kotlin/com/simplemobiletools/notes/pro/dialogs/NewChecklistItemDialog.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ import android.view.inputmethod.EditorInfo
99
import androidx.appcompat.widget.AppCompatEditText
1010
import com.simplemobiletools.commons.extensions.*
1111
import com.simplemobiletools.commons.helpers.DARK_GREY
12+
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
1213
import com.simplemobiletools.notes.pro.R
14+
import com.simplemobiletools.notes.pro.extensions.config
1315
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
16+
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.dialog_holder
1417
import kotlinx.android.synthetic.main.item_add_checklist.view.*
1518

1619
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
@@ -31,6 +34,8 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
3134
add_item.setOnClickListener {
3235
addNewEditText()
3336
}
37+
settings_add_checklist_top.beVisibleIf(activity.config.sorting == SORT_BY_CUSTOM)
38+
settings_add_checklist_top.isChecked = activity.config.addNewChecklistItemsTop
3439
}
3540

3641
activity.getAlertDialogBuilder()
@@ -40,6 +45,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
4045
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { alertDialog ->
4146
alertDialog.showKeyboard(titles.first())
4247
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
48+
activity.config.addNewChecklistItemsTop = view.settings_add_checklist_top.isChecked
4349
when {
4450
titles.all { it.text!!.isEmpty() } -> activity.toast(R.string.empty_name)
4551
else -> {

app/src/main/kotlin/com/simplemobiletools/notes/pro/fragments/ChecklistFragment.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
152152
}
153153
}
154154

155-
items.addAll(newItems)
155+
if (config?.addNewChecklistItemsTop == true) {
156+
items.addAll(0, newItems)
157+
} else {
158+
items.addAll(newItems)
159+
}
160+
156161
saveNote()
157162
setupAdapter()
158163
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Config.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,8 @@ class Config(context: Context) : BaseConfig(context) {
8989
var fontSizePercentage: Int
9090
get() = prefs.getInt(FONT_SIZE_PERCENTAGE, 100)
9191
set(fontSizePercentage) = prefs.edit().putInt(FONT_SIZE_PERCENTAGE, fontSizePercentage).apply()
92+
93+
var addNewChecklistItemsTop: Boolean
94+
get() = prefs.getBoolean(ADD_NEW_CHECKLIST_ITEMS_TOP, false)
95+
set(addNewCheckListItemsTop) = prefs.edit().putBoolean(ADD_NEW_CHECKLIST_ITEMS_TOP, addNewCheckListItemsTop).apply()
9296
}

app/src/main/kotlin/com/simplemobiletools/notes/pro/helpers/Constants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const val LAST_CREATED_NOTE_TYPE = "last_created_note_type"
3737
const val MOVE_DONE_CHECKLIST_ITEMS = "move_undone_checklist_items" // it has been replaced from moving undone items at the top to moving done to bottom
3838
const val FONT_SIZE_PERCENTAGE = "font_size_percentage"
3939
const val EXPORT_MIME_TYPE = "text/plain"
40+
const val ADD_NEW_CHECKLIST_ITEMS_TOP = "add_new_checklist_items_top"
4041

4142
// gravity
4243
const val GRAVITY_LEFT = 0

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,12 @@
3232
android:paddingBottom="@dimen/medium_margin"
3333
android:src="@drawable/ic_plus_vector" />
3434

35+
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
36+
android:id="@+id/settings_add_checklist_top"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:text="@string/add_to_the_top"
40+
android:visibility="gone" />
41+
3542
</LinearLayout>
3643
</ScrollView>

0 commit comments

Comments
 (0)