Implement bulk saving of playlists

This commit is contained in:
Martin Disch 2018-05-27 13:33:59 +02:00
commit 7e4f7162ca
No known key found for this signature in database
GPG key ID: DB6C1FF7E550D904
2 changed files with 22 additions and 0 deletions

View file

@ -14,6 +14,7 @@ import android.widget.Toast;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.helper.M3UWriter;
import com.kabouzeid.gramophone.loader.PlaylistLoader;
import com.kabouzeid.gramophone.model.Playlist;
import com.kabouzeid.gramophone.model.PlaylistSong;
import com.kabouzeid.gramophone.model.Song;
@ -248,6 +249,25 @@ public class PlaylistsUtil {
return M3UWriter.write(context, new File(Environment.getExternalStorageDirectory(), "Playlists"), playlist);
}
public static String saveAllPlaylists(Context context) {
int successes = 0, failures = 0;
File dir = new File(Environment.getExternalStorageDirectory(), "Playlists");
List<Playlist> playlists = PlaylistLoader.getAllPlaylists(context);
for (Playlist playlist : playlists) {
try {
savePlaylist(context, playlist);
successes++;
} catch (IOException ignored) {
failures++;
}
}
return failures == 0
? String.format(context.getString(R.string.saved_x_playlists_to_x), successes, dir)
: String.format(context.getString(R.string.saved_x_playlists_to_x_failed_to_save_x), successes, dir, failures);
}
private static boolean doesPlaylistExist(@NonNull Context context, @NonNull final String selection, @NonNull final String[] values) {
Cursor cursor = context.getContentResolver().query(EXTERNAL_CONTENT_URI,
new String[]{}, selection, values, null);

View file

@ -234,6 +234,8 @@
<string name="folders">Folders</string>
<string name="saved_playlist_to">Saved playlist to %s.</string>
<string name="failed_to_save_playlist">Failed to save playlist (%s).</string>
<string name="saved_x_playlists_to_x">Saved %1$d playlists to %2$s.</string>
<string name="saved_x_playlists_to_x_failed_to_save_x">Saved %1$d playlists to %2$s, failed to save %3$d.</string>
<string name="not_listed_in_media_store"><![CDATA[<b>%s</b> is not listed in the media store.]]></string>
<string name="some_files_are_not_listed_in_the_media_store">Some files are not listed in the media store.</string>
<string name="nothing_to_scan">Nothing to scan.</string>