diff --git a/checklistview/src/main/java/it/feio/android/checklistview/Settings.java b/checklistview/src/main/java/it/feio/android/checklistview/Settings.java index 86fe241..de7f1ab 100644 --- a/checklistview/src/main/java/it/feio/android/checklistview/Settings.java +++ b/checklistview/src/main/java/it/feio/android/checklistview/Settings.java @@ -24,6 +24,7 @@ public class Settings { private boolean showHintItem = Constants.SHOW_HINT_ITEM; private String newEntryHint = ""; private int moveCheckedOnBottom = CHECKED_HOLD; + private boolean moveNewItemOnTop = Constants.NEW_ITEM_TOP; private boolean dragEnabled = Constants.DRAG_ENABLED; private boolean dragVibrationEnabled = Constants.DRAG_VIBRATION_ENABLED; private int dragVibrationDuration = Constants.DRAG_VIBRATION_DURATION; @@ -98,6 +99,14 @@ public void setMoveCheckedOnBottom (int moveCheckedOnBottom) { this.moveCheckedOnBottom = moveCheckedOnBottom; } + public boolean getMoveNewItemOnTop () { + return moveNewItemOnTop; + } + + + public void setMoveNewItemOnTop (boolean moveNewItemOnTop) { + this.moveNewItemOnTop = moveNewItemOnTop; + } public boolean getDragEnabled () { return dragEnabled; diff --git a/checklistview/src/main/java/it/feio/android/checklistview/interfaces/Constants.java b/checklistview/src/main/java/it/feio/android/checklistview/interfaces/Constants.java index 604e25a..413d176 100644 --- a/checklistview/src/main/java/it/feio/android/checklistview/interfaces/Constants.java +++ b/checklistview/src/main/java/it/feio/android/checklistview/interfaces/Constants.java @@ -20,6 +20,10 @@ public interface Constants { * Keep cheched items when converting back to simple text. Otherwise they will be removed. */ boolean KEEP_CHECKED = true; + /** + * Add Item to the top of list. + */ + boolean NEW_ITEM_TOP = false; /** * Shows or not checks when converting back to simple text */ diff --git a/checklistview/src/main/java/it/feio/android/checklistview/models/CheckListView.java b/checklistview/src/main/java/it/feio/android/checklistview/models/CheckListView.java index 69d65cb..dd86c36 100644 --- a/checklistview/src/main/java/it/feio/android/checklistview/models/CheckListView.java +++ b/checklistview/src/main/java/it/feio/android/checklistview/models/CheckListView.java @@ -34,6 +34,7 @@ public class CheckListView extends LinearLayout implements Constants, CheckListE private boolean showHintItem = Constants.SHOW_HINT_ITEM; private String newEntryHint = ""; private int moveCheckedOnBottom = Settings.CHECKED_HOLD; + private boolean moveNewItemOnTop = Constants.NEW_ITEM_TOP; private WeakReference mContext; private CheckListChangedListener mCheckListChangedListener; @@ -62,6 +63,12 @@ void setMoveCheckedOnBottom (int moveCheckedOnBottom) { this.moveCheckedOnBottom = moveCheckedOnBottom; } + /** + * Declare if a checked item must be moved on bottom of the list or not + */ + void setMoveNewItemOnTop (boolean moveNewItemOnTop) { + this.moveNewItemOnTop = moveNewItemOnTop; + } /** * Set if show or not a delete icon at the end of the line. Default true. @@ -371,6 +378,11 @@ public void addHintItem () { } } + // To add new item at the top of list + if (moveNewItemOnTop != Constants.NEW_ITEM_TOP) { + hintItemPosition = 0; + } + // To avoid dropping here the dragged checklist items mCheckListViewItem.setOnDragListener(new OnDragListener() { @Override diff --git a/checklistview/src/main/java/it/feio/android/checklistview/models/ChecklistManager.java b/checklistview/src/main/java/it/feio/android/checklistview/models/ChecklistManager.java index bfc8718..e8ed377 100644 --- a/checklistview/src/main/java/it/feio/android/checklistview/models/ChecklistManager.java +++ b/checklistview/src/main/java/it/feio/android/checklistview/models/ChecklistManager.java @@ -92,6 +92,20 @@ public ChecklistManager moveCheckedOnBottom (int moveCheckedOnBottom) { } + public boolean getMoveNewItemOnTop () { + return App.getSettings().getMoveNewItemOnTop(); + } + + + /** + * If set to true an Item is added to the top of list + */ + public ChecklistManager moveNewItemOnTop (boolean moveNewItemOnTop) { + App.getSettings().setMoveNewItemOnTop(moveNewItemOnTop); + return this; + } + + /** * Set if an empty line on bottom of the checklist must be shown or not */ @@ -197,6 +211,7 @@ private View convert (EditText v) { this.originalView = v; mCheckListView = new CheckListView(mContext); mCheckListView.setMoveCheckedOnBottom(App.getSettings().getMoveCheckedOnBottom()); + mCheckListView.setMoveNewItemOnTop(App.getSettings().getMoveNewItemOnTop()); mCheckListView.setUndoBarEnabled(undoBarEnabled); mCheckListView.setUndoBarContainerView(undoBarContainerView); mCheckListView.setShowDeleteIcon(App.getSettings().getShowDeleteIcon()); diff --git a/checklistview_demo/src/main/java/it/feio/android/checklistview/demo/MainActivity.java b/checklistview_demo/src/main/java/it/feio/android/checklistview/demo/MainActivity.java index 0062c81..2c6691b 100644 --- a/checklistview_demo/src/main/java/it/feio/android/checklistview/demo/MainActivity.java +++ b/checklistview_demo/src/main/java/it/feio/android/checklistview/demo/MainActivity.java @@ -129,7 +129,11 @@ private void toggleCheckList() { mChecklistManager.moveCheckedOnBottom(Integer.parseInt(prefs.getString("settings_checked_items_behavior", String.valueOf(Settings.CHECKED_HOLD)))); - // Is also possible to set a general changes listener + // Add new items on top + mChecklistManager.moveNewItemOnTop(prefs.getBoolean("settings_new_item_on_top", + Constants.NEW_ITEM_TOP)); + + // Is also possible tlinesSeparatoro set a general changes listener mChecklistManager.setCheckListChangedListener(this); diff --git a/checklistview_demo/src/main/res/values/strings.xml b/checklistview_demo/src/main/res/values/strings.xml index 79a0fc8..03371a8 100644 --- a/checklistview_demo/src/main/res/values/strings.xml +++ b/checklistview_demo/src/main/res/values/strings.xml @@ -23,5 +23,7 @@ Checks symbols Show checks symbols when converting back to simple text (parsed also for converting again into checklist with previously edited checks) Info + Add new Item on top of the list + New Item on top \ No newline at end of file diff --git a/checklistview_demo/src/main/res/xml/settings.xml b/checklistview_demo/src/main/res/xml/settings.xml index 56fe1fe..06a9f85 100644 --- a/checklistview_demo/src/main/res/xml/settings.xml +++ b/checklistview_demo/src/main/res/xml/settings.xml @@ -52,6 +52,11 @@ android:key="settings_show_checks" android:summary="@string/settings_show_checks_summary" android:title="@string/settings_show_checks" /> +