Move deleteMedia into PlaybackService
This commit is contained in:
parent
6cdaf3787d
commit
d17df425cd
@ -559,13 +559,12 @@ public class LibraryActivity extends PlaybackActivity implements AdapterView.OnI
|
|||||||
int type = intent.getIntExtra("type", 1);
|
int type = intent.getIntExtra("type", 1);
|
||||||
long id = intent.getLongExtra("id", -1);
|
long id = intent.getLongExtra("id", -1);
|
||||||
|
|
||||||
ContentResolver resolver = getContentResolver();
|
|
||||||
if (type == MediaUtils.TYPE_PLAYLIST) {
|
if (type == MediaUtils.TYPE_PLAYLIST) {
|
||||||
Playlist.deletePlaylist(resolver, id);
|
Playlist.deletePlaylist(getContentResolver(), id);
|
||||||
String message = getResources().getString(R.string.playlist_deleted, intent.getStringExtra("title"));
|
String message = getResources().getString(R.string.playlist_deleted, intent.getStringExtra("title"));
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||||
} else {
|
} else {
|
||||||
int count = MediaUtils.deleteMedia(this, type, id);
|
int count = PlaybackService.get(this).deleteMedia(type, id);
|
||||||
String message = getResources().getQuantityString(R.plurals.deleted, count, count);
|
String message = getResources().getQuantityString(R.plurals.deleted, count, count);
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,9 @@
|
|||||||
package org.kreed.vanilla;
|
package org.kreed.vanilla;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import java.io.File;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -189,43 +187,6 @@ public class MediaUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete all the songs in the given media set. Should be run on a
|
|
||||||
* background thread.
|
|
||||||
*
|
|
||||||
* @param context A context to use.
|
|
||||||
* @param type One of the TYPE_* constants, excluding playlists.
|
|
||||||
* @param id The MediaStore id of the media to delete.
|
|
||||||
* @return The number of songs deleted.
|
|
||||||
*/
|
|
||||||
public static int deleteMedia(Context context, int type, long id)
|
|
||||||
{
|
|
||||||
int count = 0;
|
|
||||||
|
|
||||||
ContentResolver resolver = context.getContentResolver();
|
|
||||||
String[] projection = new String [] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA };
|
|
||||||
Cursor cursor = buildQuery(type, id, projection, null).runQuery(resolver);
|
|
||||||
|
|
||||||
if (cursor != null) {
|
|
||||||
PlaybackService service = PlaybackService.hasInstance() ? PlaybackService.get(context) : null;
|
|
||||||
|
|
||||||
while (cursor.moveToNext()) {
|
|
||||||
if (new File(cursor.getString(1)).delete()) {
|
|
||||||
long songId = cursor.getLong(0);
|
|
||||||
String where = MediaStore.Audio.Media._ID + '=' + songId;
|
|
||||||
resolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, where, null);
|
|
||||||
if (service != null)
|
|
||||||
service.removeSong(songId);
|
|
||||||
++count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the MediaStore to determine the id of the genre the song belongs
|
* Query the MediaStore to determine the id of the genre the song belongs
|
||||||
* to.
|
* to.
|
||||||
|
@ -22,21 +22,17 @@
|
|||||||
|
|
||||||
package org.kreed.vanilla;
|
package org.kreed.vanilla;
|
||||||
|
|
||||||
import java.io.DataInputStream;
|
|
||||||
import java.io.DataOutputStream;
|
|
||||||
import java.io.EOFException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
|
import android.database.Cursor;
|
||||||
import android.media.AudioManager;
|
import android.media.AudioManager;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -51,6 +47,12 @@ import android.telephony.PhoneStateListener;
|
|||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.EOFException;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public final class PlaybackService extends Service implements Handler.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, SharedPreferences.OnSharedPreferenceChangeListener, SongTimeline.Callback {
|
public final class PlaybackService extends Service implements Handler.Callback, MediaPlayer.OnCompletionListener, MediaPlayer.OnErrorListener, SharedPreferences.OnSharedPreferenceChangeListener, SongTimeline.Callback {
|
||||||
/**
|
/**
|
||||||
@ -949,15 +951,36 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove the song with the given id from the timeline and advance to the
|
* Delete all the songs in the given media set. Should be run on a
|
||||||
* next song if the given song is currently playing.
|
* background thread.
|
||||||
*
|
*
|
||||||
* @param id The MediaStore id of the song to remove.
|
* @param type One of the TYPE_* constants, excluding playlists.
|
||||||
* @see SongTimeline#removeSong(long)
|
* @param id The MediaStore id of the media to delete.
|
||||||
|
* @return The number of songs deleted.
|
||||||
*/
|
*/
|
||||||
public void removeSong(long id)
|
public int deleteMedia(int type, long id)
|
||||||
{
|
{
|
||||||
mTimeline.removeSong(id);
|
int count = 0;
|
||||||
|
|
||||||
|
ContentResolver resolver = getContentResolver();
|
||||||
|
String[] projection = new String [] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA };
|
||||||
|
Cursor cursor = MediaUtils.buildQuery(type, id, projection, null).runQuery(resolver);
|
||||||
|
|
||||||
|
if (cursor != null) {
|
||||||
|
while (cursor.moveToNext()) {
|
||||||
|
if (new File(cursor.getString(1)).delete()) {
|
||||||
|
long songId = cursor.getLong(0);
|
||||||
|
String where = MediaStore.Audio.Media._ID + '=' + songId;
|
||||||
|
resolver.delete(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, where, null);
|
||||||
|
mTimeline.removeSong(songId);
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user