preserve playcounts during updates
This commit is contained in:
parent
50ae82446e
commit
4f509303de
@ -366,7 +366,7 @@ public class MediaLibrary {
|
||||
|
||||
ArrayList<ContentValues> bulk = new ArrayList<>();
|
||||
for (Long id : ids) {
|
||||
if (getBackend(context).getSongMtime(id) == 0)
|
||||
if (getBackend(context).getColumnFromSongId(MediaLibrary.SongColumns.MTIME, id) == 0) // no mtime? song does not exist.
|
||||
continue;
|
||||
|
||||
ContentValues v = new ContentValues();
|
||||
|
@ -90,14 +90,15 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the modification time of a song, 0 if the song does not exist
|
||||
* Returns the `long' value stored in the column of the given id.
|
||||
*
|
||||
* @param column the column to return of `id'
|
||||
* @param id the song id to query
|
||||
* @return the modification time of this song
|
||||
* @return the value of `column'
|
||||
*/
|
||||
long getSongMtime(long id) {
|
||||
long getColumnFromSongId(String column, long id) {
|
||||
long mtime = 0;
|
||||
Cursor cursor = query(false, MediaLibrary.TABLE_SONGS, new String[]{ MediaLibrary.SongColumns.MTIME }, MediaLibrary.SongColumns._ID+"="+Long.toString(id), null, null, null, null, "1");
|
||||
Cursor cursor = query(false, MediaLibrary.TABLE_SONGS, new String[]{ column }, MediaLibrary.SongColumns._ID+"="+Long.toString(id), null, null, null, null, "1");
|
||||
if (cursor.moveToFirst())
|
||||
mtime = cursor.getLong(0);
|
||||
cursor.close();
|
||||
|
@ -416,8 +416,10 @@ public class MediaScanner implements Handler.Callback {
|
||||
if (isBlacklisted(file))
|
||||
return false;
|
||||
|
||||
long dbEntryMtime = mBackend.getSongMtime(songId) * 1000; // this is in unixtime -> convert to 'ms'
|
||||
long dbEntryMtime = mBackend.getColumnFromSongId(MediaLibrary.SongColumns.MTIME, songId) * 1000; // this is in unixtime -> convert to 'ms'
|
||||
long fileMtime = file.lastModified();
|
||||
long playCount = 0;
|
||||
long skipCount = 0;
|
||||
boolean hasChanged = false;
|
||||
boolean mustInsert = true;
|
||||
|
||||
@ -427,7 +429,9 @@ public class MediaScanner implements Handler.Callback {
|
||||
|
||||
if (dbEntryMtime != 0) {
|
||||
// DB entry exists but is outdated - drop current entry and maybe re-insert it
|
||||
// fixme: drops play counts :-(
|
||||
// this tries to preserve play and skipcounts of the song
|
||||
playCount = mBackend.getColumnFromSongId(MediaLibrary.SongColumns.PLAYCOUNT, songId);
|
||||
skipCount = mBackend.getColumnFromSongId(MediaLibrary.SongColumns.SKIPCOUNT, songId);
|
||||
mBackend.delete(MediaLibrary.TABLE_SONGS, MediaLibrary.SongColumns._ID+"="+songId, null);
|
||||
hasChanged = true;
|
||||
}
|
||||
@ -479,6 +483,8 @@ public class MediaScanner implements Handler.Callback {
|
||||
v.put(MediaLibrary.SongColumns.SONG_NUMBER, tags.getFirst(MediaMetadataExtractor.TRACK_NUMBER));
|
||||
v.put(MediaLibrary.SongColumns.DISC_NUMBER, discNumber);
|
||||
v.put(MediaLibrary.SongColumns.YEAR, tags.getFirst(MediaMetadataExtractor.YEAR));
|
||||
v.put(MediaLibrary.SongColumns.PLAYCOUNT, playCount);
|
||||
v.put(MediaLibrary.SongColumns.SKIPCOUNT, skipCount);
|
||||
v.put(MediaLibrary.SongColumns.PATH, path);
|
||||
mBackend.insert(MediaLibrary.TABLE_SONGS, null, v);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user