Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.
Open
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 @@ -90,6 +90,17 @@ public enum UndoStyle {

}

/**
* Defines the strings shown inside the undo popup.
* use {@link #setPopupString(de.timroes.android.listview.EnhancedListView.PopupStrings, int)}
*/
public enum PopupStrings {
UNDO,
UNDO_ALL,
ITEM_DELETED,
N_ITEMS_DELETED
}

/**
* Defines the direction in which list items can be swiped out to delete them.
* Use {@link #setSwipeDirection(de.timroes.android.listview.EnhancedListView.SwipeDirection)}
Expand Down Expand Up @@ -309,6 +320,12 @@ public void handleMessage(Message msg) {
private int mMaxFlingVelocity;
private long mAnimationTime;

// Popup window string resources
private int mUndoStringResource;
private int mUndoAllStringResource;
private int mItemDeletedStringResource;
private int mNItemsDeletedStringResource;

private final Object[] mAnimationLock = new Object[0];

// Swipe-To-Dismiss
Expand Down Expand Up @@ -400,12 +417,40 @@ public boolean onTouch(View v, MotionEvent event) {
mUndoPopup.setAnimationStyle(R.style.elv_fade_animation);

mScreenDensity = getResources().getDisplayMetrics().density;
// Set the initial popup strings
setPopupString(PopupStrings.UNDO, R.string.elv_undo);
setPopupString(PopupStrings.UNDO_ALL, R.string.elv_undo_all);
setPopupString(PopupStrings.ITEM_DELETED, R.string.elv_item_deleted);
setPopupString(PopupStrings.N_ITEMS_DELETED, R.string.elv_n_items_deleted);
// END initialize undo popup

setOnScrollListener(makeScrollListener());

}

/**
* Sets a string resource for the undo popup (see {@link de.timroes.android.listview.EnhancedListView.PopupStrings} for possible strings).
*
* @param string The string to be set
* @param stringResource Resource pointer to the desired string
*/
public void setPopupString(PopupStrings string, int stringResource) {
switch (string) {
case UNDO:
mUndoStringResource = stringResource;
break;
case UNDO_ALL:
mUndoAllStringResource = stringResource;
break;
case ITEM_DELETED:
mItemDeletedStringResource = stringResource;
break;
case N_ITEMS_DELETED:
mNItemsDeletedStringResource = stringResource;
break;
}
}

/**
* Enables the <i>Swipe to Dismiss</i> feature for this list. This allows users to swipe out
* an list item element to delete it from the list. Every time the user swipes out an element
Expand Down Expand Up @@ -883,14 +928,14 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {
private void changePopupText() {
String msg = null;
if(mUndoActions.size() > 1) {
msg = getResources().getString(R.string.elv_n_items_deleted, mUndoActions.size());
msg = getResources().getString(mNItemsDeletedStringResource, mUndoActions.size());
} else if(mUndoActions.size() >= 1) {
// Set title from single undoable or when no multiple deletion string
// is given
msg = mUndoActions.get(mUndoActions.size() - 1).getTitle();

if(msg == null) {
msg = getResources().getString(R.string.elv_item_deleted);
msg = getResources().getString(mItemDeletedStringResource);
}
}
mUndoPopupTextView.setText(msg);
Expand All @@ -902,9 +947,9 @@ private void changePopupText() {
private void changeButtonLabel() {
String msg;
if(mUndoActions.size() > 1 && mUndoStyle == UndoStyle.COLLAPSED_POPUP) {
msg = getResources().getString(R.string.elv_undo_all);
msg = getResources().getString(mUndoAllStringResource);
} else {
msg = getResources().getString(R.string.elv_undo);
msg = getResources().getString(mUndoStringResource);
}
mUndoButton.setText(msg);
}
Expand Down