- migrated ids from int
to long
- some cleaning
This commit is contained in:
parent
90bca59192
commit
9e46d74507
58 changed files with 708 additions and 635 deletions
|
@ -34,7 +34,7 @@ public class AutoGeneratedPlaylistBitmap {
|
|||
if (songPlaylist == null) return null;
|
||||
long start = System.currentTimeMillis();
|
||||
// lấy toàn bộ album id, loại bỏ trùng nhau
|
||||
ArrayList<Integer> albumID = new ArrayList<>();
|
||||
List<Long> albumID = new ArrayList<>();
|
||||
for (Song song : songPlaylist) {
|
||||
if (!albumID.contains(song.getAlbumId())) albumID.add(song.getAlbumId());
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ public class AutoGeneratedPlaylistBitmap {
|
|||
long start2 = System.currentTimeMillis() - start;
|
||||
|
||||
// lấy toàn bộ art tồn tại
|
||||
ArrayList<Bitmap> art = new ArrayList<Bitmap>();
|
||||
for (Integer id : albumID) {
|
||||
List<Bitmap> art = new ArrayList<Bitmap>();
|
||||
for (Long id : albumID) {
|
||||
Bitmap bitmap = getBitmapWithAlbumId(context, id);
|
||||
if (bitmap != null) art.add(bitmap);
|
||||
if (art.size() == 6) break;
|
||||
|
@ -168,7 +168,7 @@ public class AutoGeneratedPlaylistBitmap {
|
|||
else return bitmap;
|
||||
}
|
||||
|
||||
private static Bitmap getBitmapWithAlbumId(@NonNull Context context, Integer id) {
|
||||
private static Bitmap getBitmapWithAlbumId(@NonNull Context context, Long id) {
|
||||
try {
|
||||
return Glide.with(context)
|
||||
.load(MusicUtil.INSTANCE.getMediaStoreAlbumCoverUri(id))
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.core.content.FileProvider
|
|||
import androidx.fragment.app.FragmentActivity
|
||||
import code.name.monkey.retromusic.R
|
||||
import code.name.monkey.retromusic.db.SongEntity
|
||||
import code.name.monkey.retromusic.extensions.getLong
|
||||
import code.name.monkey.retromusic.helper.MusicPlayerRemote.removeFromQueue
|
||||
import code.name.monkey.retromusic.model.Artist
|
||||
import code.name.monkey.retromusic.model.Playlist
|
||||
|
@ -85,7 +86,7 @@ object MusicUtil : KoinComponent {
|
|||
return albumArtDir
|
||||
}
|
||||
|
||||
fun deleteAlbumArt(context: Context, albumId: Int) {
|
||||
fun deleteAlbumArt(context: Context, albumId: Long) {
|
||||
val contentResolver = context.contentResolver
|
||||
val localUri = Uri.parse("content://media/external/audio/albumart")
|
||||
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId.toLong()), null, null)
|
||||
|
@ -175,10 +176,9 @@ object MusicUtil : KoinComponent {
|
|||
return lyrics
|
||||
}
|
||||
|
||||
fun getMediaStoreAlbumCoverUri(albumId: Int): Uri {
|
||||
val sArtworkUri =
|
||||
Uri.parse("content://media/external/audio/albumart")
|
||||
return ContentUris.withAppendedId(sArtworkUri, albumId.toLong())
|
||||
fun getMediaStoreAlbumCoverUri(albumId: Long): Uri {
|
||||
val sArtworkUri = Uri.parse("content://media/external/audio/albumart")
|
||||
return ContentUris.withAppendedId(sArtworkUri, albumId)
|
||||
}
|
||||
|
||||
|
||||
|
@ -249,7 +249,7 @@ object MusicUtil : KoinComponent {
|
|||
return "$songCount $songString"
|
||||
}
|
||||
|
||||
fun getSongFileUri(songId: Int): Uri {
|
||||
fun getSongFileUri(songId: Long): Uri {
|
||||
return ContentUris.withAppendedId(
|
||||
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
|
||||
songId.toLong()
|
||||
|
@ -268,18 +268,13 @@ object MusicUtil : KoinComponent {
|
|||
return if (year > 0) year.toString() else "-"
|
||||
}
|
||||
|
||||
fun indexOfSongInList(songs: List<Song>, songId: Int): Int {
|
||||
for (i in songs.indices) {
|
||||
if (songs[i].id == songId) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
fun indexOfSongInList(songs: List<Song>, songId: Long): Int {
|
||||
return songs.indexOfFirst { it.id == songId }
|
||||
}
|
||||
|
||||
fun insertAlbumArt(
|
||||
context: Context,
|
||||
albumId: Int,
|
||||
albumId: Long,
|
||||
path: String?
|
||||
) {
|
||||
val contentResolver = context.contentResolver
|
||||
|
@ -306,7 +301,7 @@ object MusicUtil : KoinComponent {
|
|||
|
||||
fun isFavorite(context: Context, song: Song): Boolean {
|
||||
return PlaylistsUtil
|
||||
.doPlaylistContains(context, getFavoritesPlaylist(context).id.toLong(), song.id)
|
||||
.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id)
|
||||
}
|
||||
|
||||
fun isFavoritePlaylist(
|
||||
|
@ -387,7 +382,7 @@ object MusicUtil : KoinComponent {
|
|||
// as from the album art cache
|
||||
cursor.moveToFirst()
|
||||
while (!cursor.isAfterLast) {
|
||||
val id = cursor.getInt(0)
|
||||
val id = cursor.getLong(BaseColumns._ID)
|
||||
val song: Song = songRepository.song(id)
|
||||
removeFromQueue(song)
|
||||
cursor.moveToNext()
|
||||
|
@ -452,7 +447,7 @@ object MusicUtil : KoinComponent {
|
|||
// as from the album art cache
|
||||
cursor.moveToFirst()
|
||||
while (!cursor.isAfterLast) {
|
||||
val id: Int = cursor.getInt(0)
|
||||
val id = cursor.getLong(BaseColumns._ID)
|
||||
val song: Song = RealSongRepository(context).song(id)
|
||||
removeFromQueue(song)
|
||||
cursor.moveToNext()
|
||||
|
|
|
@ -43,7 +43,7 @@ import static android.provider.MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
|
|||
|
||||
public class PlaylistsUtil {
|
||||
|
||||
public static int createPlaylist(@NonNull final Context context, @Nullable final String name) {
|
||||
public static long createPlaylist(@NonNull final Context context, @Nullable final String name) {
|
||||
int id = -1;
|
||||
if (name != null && name.length() > 0) {
|
||||
try {
|
||||
|
@ -101,13 +101,13 @@ public class PlaylistsUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static void addToPlaylist(@NonNull final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
|
||||
public static void addToPlaylist(@NonNull final Context context, final Song song, final long playlistId, final boolean showToastOnFinish) {
|
||||
List<Song> helperList = new ArrayList<>();
|
||||
helperList.add(song);
|
||||
addToPlaylist(context, helperList, playlistId, showToastOnFinish);
|
||||
}
|
||||
|
||||
public static void addToPlaylist(@NonNull final Context context, @NonNull final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
|
||||
public static void addToPlaylist(@NonNull final Context context, @NonNull final List<Song> songs, final long playlistId, final boolean showToastOnFinish) {
|
||||
final int size = songs.size();
|
||||
final ContentResolver resolver = context.getContentResolver();
|
||||
final String[] projection = new String[]{
|
||||
|
@ -180,7 +180,7 @@ public class PlaylistsUtil {
|
|||
return "";
|
||||
}
|
||||
|
||||
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final Song song, int playlistId) {
|
||||
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final Song song, long playlistId) {
|
||||
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
||||
"external", playlistId);
|
||||
String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID + " =?";
|
||||
|
@ -193,7 +193,7 @@ public class PlaylistsUtil {
|
|||
}
|
||||
|
||||
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final List<PlaylistSong> songs) {
|
||||
final int playlistId = songs.get(0).getPlaylistId();
|
||||
final long playlistId = songs.get(0).getPlaylistId();
|
||||
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
|
||||
"external", playlistId);
|
||||
String[] selectionArgs = new String[songs.size()];
|
||||
|
@ -211,7 +211,7 @@ public class PlaylistsUtil {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean doPlaylistContains(@NonNull final Context context, final long playlistId, final int songId) {
|
||||
public static boolean doPlaylistContains(@NonNull final Context context, final long playlistId, final long songId) {
|
||||
if (playlistId != -1) {
|
||||
try {
|
||||
Cursor c = context.getContentResolver().query(
|
||||
|
@ -229,7 +229,7 @@ public class PlaylistsUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static boolean moveItem(@NonNull final Context context, int playlistId, int from, int to) {
|
||||
public static boolean moveItem(@NonNull final Context context, long playlistId, int from, int to) {
|
||||
return MediaStore.Audio.Playlists.Members.moveItem(context.getContentResolver(),
|
||||
playlistId, from, to);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue