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 Item on top feature #25

Open
wants to merge 1 commit into
base: develop
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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Context> mContext;
private CheckListChangedListener mCheckListChangedListener;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);


Expand Down
2 changes: 2 additions & 0 deletions checklistview_demo/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@
<string name="settings_show_checks">Checks symbols</string>
<string name="settings_show_checks_summary">Show checks symbols when converting back to simple text (parsed also for converting again into checklist with previously edited checks)</string>
<string name="settings_info">Info</string>
<string name="settings_new_item_on_top_summary">Add new Item on top of the list</string>
<string name="settings_new_item_on_top">New Item on top</string>

</resources>
5 changes: 5 additions & 0 deletions checklistview_demo/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
android:key="settings_show_checks"
android:summary="@string/settings_show_checks_summary"
android:title="@string/settings_show_checks" />
<CheckBoxPreference
android:defaultValue="false"
android:key="settings_new_item_on_top"
android:summary="@string/settings_new_item_on_top_summary"
android:title="@string/settings_new_item_on_top" />

<Preference android:title="@string/settings_info">
<intent
Expand Down