package cgeo.geocaching.command;

import cgeo.geocaching.storage.DataStore;
import cgeo.geocaching.models.Geocache;
import cgeo.geocaching.R;
import cgeo.geocaching.list.StoredList;

import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;

import rx.functions.Action1;

import android.app.Activity;

import java.util.Collection;

public abstract class MoveToListCommand extends AbstractCachesCommand {

    private final int currentListId;
    private int newListId;

    protected MoveToListCommand(final Activity context, @NonNull final Collection<Geocache> caches, final int currentListId) {
        super(context, caches, R.string.command_move_caches_progress);
        this.currentListId = currentListId;
    }

    @Override
    public void execute() {
        // as we cannot show the dialog inside the background doCommand, we override execute to ask in the UI thread
        new StoredList.UserInterface(getContext()).promptForListSelection(R.string.cache_menu_move_list, new Action1<Integer>() {


            @Override
            public void call(final Integer newListId) {
                MoveToListCommand.this.newListId = newListId;
                final String newListName = StoredList.getListById(newListId).getTitle();
                setProgressMessage(getContext().getString(R.string.command_move_caches_progress, newListName));
                MoveToListCommand.super.execute();
            }
        }, true, currentListId);
    }

    @Override
    protected void doCommand() {
        DataStore.moveToList(getCaches(), newListId);
    }

    @Override
    protected void undoCommand() {
        DataStore.moveToList(getCaches(), currentListId);
    }

    @Override
    @Nullable
    protected String getResultMessage() {
        final int size = getCaches().size();
        return getContext().getResources().getQuantityString(R.plurals.command_move_caches_result, size, size);
    }
}

@@ -54,25 +54,51 @@
 ing.
-storage.DataStore
+R;%0Aimport cgeo.geocaching.list.AbstractList
 ;%0Aim
@@ -122,23 +122,23 @@
 ing.
-models.Geocache
+list.StoredList
 ;%0Aim
@@ -150,33 +150,47 @@
 cgeo.geocaching.
-R
+models.Geocache
 ;%0Aimport cgeo.ge
@@ -198,31 +198,33 @@
 caching.
-list.StoredList
+storage.DataStore
 ;%0A%0Aimpor
@@ -310,38 +310,8 @@
 e;%0A%0A
-import rx.functions.Action1;%0A%0A
 impo
@@ -366,16 +366,46 @@
 ction;%0A%0A
+import rx.functions.Action1;%0A%0A
 public a
@@ -1240,62 +1240,152 @@
 nal 
-String newListName = StoredList.getListById(newListId)
+AbstractList list = AbstractList.getListById(newListId);%0A                if (list != null) %7B%0A                    final String newListName = list
 .get
@@ -1389,24 +1389,28 @@
 getTitle();%0A
+    
             
@@ -1517,32 +1517,36 @@
                 
+    
 MoveToListComman
@@ -1560,24 +1560,42 @@
 .execute();%0A
+                %7D%0A
             

fix null analysis violation