package com.nf2m;
import android.content.Context;
import android.support.annotation.NonNull;
import com.nf2m.preferences.Preferences;
import com.nf2m.service.MediaPlayerService;
import java.util.ArrayList;
import java.util.HashMap;
public class RandomSong {
@NonNull
public static ArrayList<Integer> randomPosList = new ArrayList<>();
@NonNull
public static final HashMap<Integer, Integer> randomPosMap = new HashMap<>();
private static Preferences preferences;
@NonNull
public static RandomSong newInstance(@NonNull Context context) {
preferences = Preferences.newInstance(context);
return new RandomSong();
}
public int getRandomPos() {
int songPos = preferences.getPrefSongPosition();
randomPosList.add(songPos);
int pos;
java.util.Random random = new java.util.Random();
do {
if (MediaPlayerService.songsCursor.getCount() == 1) {
pos = 0;
break;
}
pos = random.nextInt(MediaPlayerService.songsCursor.getCount());
} while (pos == songPos);
if (pos >= MediaPlayerService.songsCursor.getCount() || pos < 0) {
pos = 0;
}
return pos;
}
}