Skip to content
Snippets Groups Projects
Commit 274531c7 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Snackbars now use Runnable for cancel action

parent 2f3f7054
No related branches found
No related tags found
No related merge requests found
......@@ -162,16 +162,16 @@ public class PlaylistAdapter extends RecyclerView.Adapter<PlaylistAdapter.ViewHo
String message = String.format(VLCApplication.getAppResources().getString(R.string.remove_playlist_item), media.getTitle());
if (mAudioPlayer instanceof Fragment){
View v = ((Fragment) mAudioPlayer).getView();
View.OnClickListener cancelAction = new View.OnClickListener() {
Runnable cancelAction = new Runnable() {
@Override
public void onClick(View v) {
public void run() {
mDataSet.add(position, media);
mOriginalDataSet.add(position, media);
notifyItemInserted(position);
mService.insertItem(position, media);
}
};
UiTools.snackerWithCancel(v, message, cancelAction);
UiTools.snackerWithCancel(v, message, null, cancelAction);
} else if (mAudioPlayer instanceof Context){
Toast.makeText((Context) mAudioPlayer, message, Toast.LENGTH_SHORT).show();
}
......
......@@ -65,12 +65,7 @@ public class UiTools {
}
/** Print an on-screen message to alert the user, with undo action */
public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final View.OnClickListener cancelAction) {
snackerWithCancel(view, message, null, cancelAction);
}
/** Print an on-screen message to alert the user, with undo action */
public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final Runnable action, @Nullable final View.OnClickListener cancelAction) {
public static void snackerWithCancel(@NonNull View view, @NonNull String message, @NonNull final Runnable action, @Nullable final Runnable cancelAction) {
Snackbar.make(view, message, DELETE_DURATION)
.setAction(android.R.string.cancel, new View.OnClickListener() {
@Override
......@@ -78,7 +73,7 @@ public class UiTools {
if (action != null)
sHandler.removeCallbacks(action);
if (cancelAction != null)
cancelAction.onClick(v);
cancelAction.run();
}
})
.show();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment