Merge pull request #584 from Aga-C/add_checklist_items_top

Added new checklist items at the top (#583)
This commit is contained in:
Tibor Kaputa 2023-01-28 17:00:39 +01:00 committed by GitHub
commit 0672614101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 1 deletions

View File

@ -9,8 +9,11 @@ import android.view.inputmethod.EditorInfo
import androidx.appcompat.widget.AppCompatEditText
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DARK_GREY
import com.simplemobiletools.commons.helpers.SORT_BY_CUSTOM
import com.simplemobiletools.notes.pro.R
import com.simplemobiletools.notes.pro.extensions.config
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.*
import kotlinx.android.synthetic.main.dialog_new_checklist_item.view.dialog_holder
import kotlinx.android.synthetic.main.item_add_checklist.view.*
class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayList<String>) -> Unit) {
@ -31,6 +34,8 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
add_item.setOnClickListener {
addNewEditText()
}
settings_add_checklist_top.beVisibleIf(activity.config.sorting == SORT_BY_CUSTOM)
settings_add_checklist_top.isChecked = activity.config.addNewChecklistItemsTop
}
activity.getAlertDialogBuilder()
@ -40,6 +45,7 @@ class NewChecklistItemDialog(val activity: Activity, callback: (titles: ArrayLis
activity.setupDialogStuff(view, this, R.string.add_new_checklist_items) { alertDialog ->
alertDialog.showKeyboard(titles.first())
alertDialog.getButton(BUTTON_POSITIVE).setOnClickListener {
activity.config.addNewChecklistItemsTop = view.settings_add_checklist_top.isChecked
when {
titles.all { it.text!!.isEmpty() } -> activity.toast(R.string.empty_name)
else -> {

View File

@ -152,7 +152,12 @@ class ChecklistFragment : NoteFragment(), ChecklistItemsListener {
}
}
items.addAll(newItems)
if (config?.addNewChecklistItemsTop == true) {
items.addAll(0, newItems)
} else {
items.addAll(newItems)
}
saveNote()
setupAdapter()
}

View File

@ -89,4 +89,8 @@ class Config(context: Context) : BaseConfig(context) {
var fontSizePercentage: Int
get() = prefs.getInt(FONT_SIZE_PERCENTAGE, 100)
set(fontSizePercentage) = prefs.edit().putInt(FONT_SIZE_PERCENTAGE, fontSizePercentage).apply()
var addNewChecklistItemsTop: Boolean
get() = prefs.getBoolean(ADD_NEW_CHECKLIST_ITEMS_TOP, false)
set(addNewCheckListItemsTop) = prefs.edit().putBoolean(ADD_NEW_CHECKLIST_ITEMS_TOP, addNewCheckListItemsTop).apply()
}

View File

@ -37,6 +37,7 @@ const val LAST_CREATED_NOTE_TYPE = "last_created_note_type"
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
const val FONT_SIZE_PERCENTAGE = "font_size_percentage"
const val EXPORT_MIME_TYPE = "text/plain"
const val ADD_NEW_CHECKLIST_ITEMS_TOP = "add_new_checklist_items_top"
// gravity
const val GRAVITY_LEFT = 0

View File

@ -32,5 +32,12 @@
android:paddingBottom="@dimen/medium_margin"
android:src="@drawable/ic_plus_vector" />
<com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/settings_add_checklist_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/add_to_the_top"
android:visibility="gone" />
</LinearLayout>
</ScrollView>