Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

bug fixed #812. #833

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions app/src/main/java/com/kabouzeid/gramophone/util/PlaylistsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
import android.os.Environment;
import android.provider.BaseColumns;
import android.provider.MediaStore;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.widget.Toast;

import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.helper.M3UWriter;
import com.kabouzeid.gramophone.loader.PlaylistSongLoader;
import com.kabouzeid.gramophone.model.Playlist;
import com.kabouzeid.gramophone.model.PlaylistSong;
import com.kabouzeid.gramophone.model.Song;
Expand Down Expand Up @@ -111,7 +114,21 @@ public static void addToPlaylist(@NonNull final Context context, @NonNull final
final Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId);
Cursor cursor = null;
int base = 0;

List<PlaylistSong> previousSong = PlaylistSongLoader.getPlaylistSongList(context, playlistId);
List<Song> newSongs = new ArrayList<>();
for (Song song : songs) {
boolean flag = false;
for (Song previous : previousSong) {
if (song.id == previous.id) {
flag = true;
break;
}
}
if (!flag) {
newSongs.add(song);
}
}
final int newSize = newSongs.size();
try {
try {
cursor = resolver.query(uri, projection, null, null, null);
Expand All @@ -126,12 +143,11 @@ public static void addToPlaylist(@NonNull final Context context, @NonNull final
}

int numInserted = 0;
for (int offSet = 0; offSet < size; offSet += 1000)
numInserted += resolver.bulkInsert(uri, makeInsertItems(songs, offSet, 1000, base));

for (int offSet = 0; offSet < newSize; offSet += 1000)
numInserted += resolver.bulkInsert(uri, makeInsertItems(newSongs, offSet, 1000, base));
if (showToastOnFinish) {
Toast.makeText(context, context.getResources().getString(
R.string.inserted_x_songs_into_playlist_x, numInserted, getNameForPlaylist(context, playlistId)), Toast.LENGTH_SHORT).show();
R.string.inserted_x_songs_into_playlist_x, numInserted, getNameForPlaylist(context, playlistId), size - numInserted), Toast.LENGTH_SHORT).show();
}
} catch (SecurityException ignored) {
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<string name="action_remove_from_playlist">Remove from playlist</string>
<string name="action_grid_size">Grid size</string>
<string name="action_grid_size_land">Grid size (land)</string>
<string name="inserted_x_songs_into_playlist_x">Inserted %1$d songs into the playlist %2$s.</string>
<string name="inserted_x_songs_into_playlist_x">Inserted %1$d songs into the playlist %2$s, %3$d of selected songs existed in this playlist.</string>
<string name="created_playlist_x">Created playlist %1$s.</string>
<string name="deleted_x_songs">Deleted %1$d songs.</string>
<string name="playlist_exists">Playlist %1$s already exists.</string>
Expand Down