0

I have two array list, the first called que and the second list shuffledQue which is a shuffled que.I have an integer indicating to the current position of the item in the que called currentTrackIndex, so when I assign the que to shuffledQue and shuffle the list I look for the new position of the current item and assign it to currentShuffledTrackIndex. But what I get afterwards is that que changes the position of it's items.

                    List<TrackModel> que = new ArrayList<>();
                    List <TrackModel> shuffledQue = new ArrayList<>();
                    /*
                     some code where I add items to the que
                     */
                        boolean shuffle = intent.getBooleanExtra("isOn", true);
                        TrackModel currentTrack3 = que.get(currentTrackIndex);
                        if(shuffle) {
                            for(int i =0; i < que.size(); i++){
                                TrackModel model = que.get(i);
                                String trackname = model.getaName();
                                Log.i("TAG", "que " + trackname);
                            }
                            shuffledQue = que;
                            Collections.shuffle(shuffledQue);
                            for(int i = 0; i < shuffledQue.size(); i++)
                            {
                                TrackModel trackModel = shuffledQue.get(i);
                                if(trackModel.getID() == currentTrack3.getID()){
                                    currentShuffledTrackIndex = shuffledQue.indexOf(trackModel);
                                }
                            }

                            for(int i =0; i < que.size(); i++){
                                TrackModel model = que.get(i);
                                String trackname = model.getaName();
                                Log.i("TAG", "que2 " + trackname);
                            }
                            preferences.edit().putInt("selected_track", currentShuffledTrackIndex).apply();
                            json = gson.toJson(shuffledQue);
                            preferences.edit().putString("shuffledQueJSON", json).apply();
                        }

logcat

   12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que Frank Sinatra Fly Me To The Moon
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que Marshmello - Alone (Official Music Video)
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que [Electro] - Laszlo - Supernova [Monstercat Release
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que Louis Armstrong - What A Wonderful World [HQ]
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que Chris Brown - Turn Up the Music
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que Vangelis - Alpha
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que2 Louis Armstrong - What A Wonderful World [HQ]
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que2 [Electro] - Laszlo - Supernova [Monstercat Release
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que2 Vangelis - Alpha
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que2 Chris Brown - Turn Up the Music
12-19 21:11:34.277 14704-14704/com.sparidapps.musicplayer I/TAG: que2 Frank Sinatra Fly Me To The Moon
12-19 21:11:34.278 14704-14704/com.sparidapps.musicplayer I/TAG: que2 Marshmello - Alone (Official Music Video)

As you see in the logcat the items of the que list change their position, and I couldn't figure out why. Thanks in advance!

0 Answers0