/*
 * Copyright (C) 2016 Yaroslav Mytkalyk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.doctoror.fuckoffmusicplayer.queue;

import com.doctoror.fuckoffmusicplayer.data.media.MediaManagerMediaStore;
import com.doctoror.fuckoffmusicplayer.data.util.Log;
import com.doctoror.fuckoffmusicplayer.domain.playback.PlaybackData;
import com.doctoror.fuckoffmusicplayer.domain.queue.Media;
import com.doctoror.fuckoffmusicplayer.domain.playback.PlaybackServiceControl;

import android.content.ContentResolver;
import android.support.annotation.NonNull;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

/**
 * Queue utils
 */
public final class QueueUtils {

    private static final String TAG = "QueueUtils";

    private QueueUtils() {
        throw new UnsupportedOperationException();
    }

    /**
     * @deprecated use {@link com.doctoror.fuckoffmusicplayer.domain.playback.initializer.PlaybackInitializer}
     */
    @Deprecated
    public static void play(
            @NonNull final PlaybackServiceControl control,
            @NonNull final PlaybackData playbackData,
            @NonNull final List<Media> mediaList) {
        if (mediaList.isEmpty()) {
            throw new IllegalArgumentException("Will not play empty playlist");
        }
        play(control, playbackData, mediaList, 0);
    }

    /**
     * @deprecated use {@link com.doctoror.fuckoffmusicplayer.domain.playback.initializer.PlaybackInitializer}
     */
    @Deprecated
    public static void play(
            @NonNull final PlaybackServiceControl control,
            @NonNull final PlaybackData playbackData,
            @NonNull final List<Media> mediaList,
            final int position) {
        playbackData.setMediaPosition(0);
        playbackData.setPlayQueuePosition(position);
        playbackData.setPlayQueue(mediaList);
        playbackData.persistAsync();

        control.play();
    }

    public static void removeAlbumFromCurrentQueue(
            @NonNull final ContentResolver contentResolver,
            @NonNull final PlaybackData playbackData,
            final long albumId) {
        final long[] ids;
        try {
            ids = MediaManagerMediaStore.getAlbumMediaIds(contentResolver, albumId);
        } catch (IOException e) {
            Log.w(TAG, "Will not remove album from current queue", e);
            return;
        }
        removeMediasFromCurrentQueue(playbackData, ids);
    }

    public static void removeMediasFromCurrentQueue(
            @NonNull final PlaybackData playbackData,
            @NonNull final long... mediaIds) {
        final List<Media> queue = playbackData.getQueue();
        boolean modified = false;
        if (queue != null) {
            for (final long id : mediaIds) {
                modified |= removeFromQueue(queue, id);
            }
        }
        if (modified) {
            playbackData.setPlayQueue(queue);
        }
    }

    private static boolean removeFromQueue(@NonNull final List<Media> queue,
            final long id) {
        final Iterator<Media> i = queue.iterator();
        while (i.hasNext()) {
            if (i.next().getId() == id) {
                i.remove();
                return true;
            }
        }
        return false;
    }
}

@@ -906,87 +906,8 @@
 dia;
-%0Aimport com.doctoror.fuckoffmusicplayer.domain.playback.PlaybackServiceControl;
 %0A%0Aim
@@ -1265,1107 +1265,8 @@
  %7D%0A%0A
-    /**%0A     * @deprecated use %7B@link com.doctoror.fuckoffmusicplayer.domain.playback.initializer.PlaybackInitializer%7D%0A     */%0A    @Deprecated%0A    public static void play(%0A            @NonNull final PlaybackServiceControl control,%0A            @NonNull final PlaybackData playbackData,%0A            @NonNull final List%3CMedia%3E mediaList) %7B%0A        if (mediaList.isEmpty()) %7B%0A            throw new IllegalArgumentException(%22Will not play empty playlist%22);%0A        %7D%0A        play(control, playbackData, mediaList, 0);%0A    %7D%0A%0A    /**%0A     * @deprecated use %7B@link com.doctoror.fuckoffmusicplayer.domain.playback.initializer.PlaybackInitializer%7D%0A     */%0A    @Deprecated%0A    public static void play(%0A            @NonNull final PlaybackServiceControl control,%0A            @NonNull final PlaybackData playbackData,%0A            @NonNull final List%3CMedia%3E mediaList,%0A            final int position) %7B%0A        playbackData.setMediaPosition(0);%0A        playbackData.setPlayQueuePosition(position);%0A        playbackData.setPlayQueue(mediaList);%0A        playbackData.persistAsync();%0A%0A        control.play();%0A    %7D%0A%0A
     

Remove QueueUtils.play methods.