introduce song._flags

Adds a new _flags column to the song table which can be used to store bool flags for the song.

Currently, only 1<<0 is used to indicate that a song is outdated (but still valid)
This commit is contained in:
Adrian Ulrich 2018-03-05 10:33:33 +01:00
parent 50b33cfc2b
commit d4062b18dd
4 changed files with 16 additions and 3 deletions

View File

@ -56,6 +56,8 @@ public class MediaLibrary {
public static final int ROLE_COMPOSER = 1; public static final int ROLE_COMPOSER = 1;
public static final int ROLE_ALBUMARTIST = 2; public static final int ROLE_ALBUMARTIST = 2;
public static final int SONG_FLAG_OUTDATED = (1 << 0); // entry in library should get rescanned.
public static final String PREFERENCES_FILE = "_prefs-v1.obj"; public static final String PREFERENCES_FILE = "_prefs-v1.obj";
/** /**
@ -597,6 +599,10 @@ public class MediaLibrary {
* The mtime of this item * The mtime of this item
*/ */
String MTIME = "mtime"; String MTIME = "mtime";
/**
* Various flags of this entry, see SONG_FLAG...
*/
String FLAGS = "_flags";
} }
// Columns of Album entries // Columns of Album entries

View File

@ -35,7 +35,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
/** /**
* The database version we are using * The database version we are using
*/ */
private static final int DATABASE_VERSION = 20180129; private static final int DATABASE_VERSION = 20180305;
/** /**
* on-disk file to store the database * on-disk file to store the database
*/ */

View File

@ -439,13 +439,14 @@ public class MediaScanner implements Handler.Callback {
return false; return false;
long dbEntryMtime = mBackend.getColumnFromSongId(MediaLibrary.SongColumns.MTIME, 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 songFlags = mBackend.getColumnFromSongId(MediaLibrary.SongColumns.FLAGS, songId);
long fileMtime = file.lastModified(); long fileMtime = file.lastModified();
long playCount = 0; long playCount = 0;
long skipCount = 0; long skipCount = 0;
boolean hasChanged = false; boolean hasChanged = false;
boolean mustInsert = false; boolean mustInsert = false;
if (fileMtime > 0 && dbEntryMtime >= fileMtime) { if (fileMtime > 0 && dbEntryMtime >= fileMtime && (songFlags & MediaLibrary.SONG_FLAG_OUTDATED) == 0) {
return false; // on-disk mtime is older than db mtime and it still exists -> nothing to do return false; // on-disk mtime is older than db mtime and it still exists -> nothing to do
} }
@ -507,6 +508,7 @@ public class MediaScanner implements Handler.Callback {
v.put(MediaLibrary.SongColumns.PLAYCOUNT, playCount); v.put(MediaLibrary.SongColumns.PLAYCOUNT, playCount);
v.put(MediaLibrary.SongColumns.SKIPCOUNT, skipCount); v.put(MediaLibrary.SongColumns.SKIPCOUNT, skipCount);
v.put(MediaLibrary.SongColumns.PATH, path); v.put(MediaLibrary.SongColumns.PATH, path);
v.put(MediaLibrary.SongColumns.FLAGS, (songFlags &~MediaLibrary.SONG_FLAG_OUTDATED));
mBackend.insert(MediaLibrary.TABLE_SONGS, null, v); mBackend.insert(MediaLibrary.TABLE_SONGS, null, v);
v.clear(); v.clear();

View File

@ -35,7 +35,8 @@ public class MediaSchema {
+ MediaLibrary.SongColumns.SKIPCOUNT +" INTEGER NOT NULL DEFAULT 0, " + MediaLibrary.SongColumns.SKIPCOUNT +" INTEGER NOT NULL DEFAULT 0, "
+ MediaLibrary.SongColumns.MTIME +" TIMESTAMP DEFAULT (strftime('%s', CURRENT_TIMESTAMP)), " + MediaLibrary.SongColumns.MTIME +" TIMESTAMP DEFAULT (strftime('%s', CURRENT_TIMESTAMP)), "
+ MediaLibrary.SongColumns.DURATION +" INTEGER NOT NULL, " + MediaLibrary.SongColumns.DURATION +" INTEGER NOT NULL, "
+ MediaLibrary.SongColumns.PATH +" VARCHAR(4096) NOT NULL " + MediaLibrary.SongColumns.PATH +" VARCHAR(4096) NOT NULL, "
+ MediaLibrary.SongColumns.FLAGS +" INTEGER NOT NULL DEFAULT 0 "
+ ");"; + ");";
/** /**
@ -326,6 +327,10 @@ public class MediaSchema {
dbh.execSQL("UPDATE songs SET mtime=1"); dbh.execSQL("UPDATE songs SET mtime=1");
} }
if (oldVersion < 20180305) {
dbh.execSQL("ALTER TABLE "+MediaLibrary.TABLE_SONGS+" ADD COLUMN "+MediaLibrary.SongColumns.FLAGS+" INTEGER NOT NULL DEFAULT 0 ");
}
} }
} }