Display durations in albums tab (#857)
This commit is contained in:
1 parent
6ab4e137ac
commit
17eea6c868
3 files changed
+20
-7
No files matched your search
@@ -35,7 +35,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
|
||||
/**
|
||||
* The database version we are using
|
||||
*/
|
||||
private static final int DATABASE_VERSION = 20180416;
|
||||
private static final int DATABASE_VERSION = 20181021;
|
||||
/**
|
||||
* on-disk file to store the database
|
||||
*/
|
||||
|
||||
@@ -191,9 +191,13 @@ public class MediaSchema {
|
||||
* View which includes album and artist information
|
||||
*/
|
||||
private static final String VIEW_CREATE_ALBUMS_ARTISTS = "CREATE VIEW "+ MediaLibrary.VIEW_ALBUMS_ARTISTS+ " AS "
|
||||
+ "SELECT *, " + VIEW_ARTIST_SELECT + " FROM " + MediaLibrary.TABLE_ALBUMS
|
||||
+ "SELECT " + MediaLibrary.TABLE_ALBUMS + ".*, " + VIEW_ARTIST_SELECT + ", SUM(" + MediaLibrary.SongColumns.DURATION + ")" + " AS " + MediaLibrary.SongColumns.DURATION
|
||||
+" FROM " + MediaLibrary.TABLE_ALBUMS
|
||||
+" LEFT JOIN "+MediaLibrary.TABLE_CONTRIBUTORS+" AS _artist"
|
||||
+" ON _artist."+MediaLibrary.ContributorColumns._ID+" = "+MediaLibrary.TABLE_ALBUMS+"."+MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID
|
||||
+" LEFT JOIN " + MediaLibrary.TABLE_SONGS
|
||||
+" ON " + MediaLibrary.TABLE_SONGS + "." + MediaLibrary.SongColumns.ALBUM_ID + " = " + MediaLibrary.TABLE_ALBUMS + "." + MediaLibrary.AlbumColumns._ID
|
||||
+" GROUP BY " + MediaLibrary.TABLE_ALBUMS + "." + MediaLibrary.AlbumColumns._ID
|
||||
+" ;";
|
||||
|
||||
/**
|
||||
@@ -340,6 +344,11 @@ public class MediaSchema {
|
||||
dbh.execSQL("DROP TABLE _migrate");
|
||||
}
|
||||
|
||||
if (oldVersion < 20181021) {
|
||||
// Recreate view to include album duration
|
||||
dbh.execSQL("DROP VIEW " + MediaLibrary.VIEW_ALBUMS_ARTISTS);
|
||||
dbh.execSQL(VIEW_CREATE_ALBUMS_ARTISTS);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -32,7 +32,6 @@ import android.database.DatabaseUtils;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.TextUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -192,7 +191,7 @@ public class MediaAdapter
|
||||
break;
|
||||
case MediaUtils.TYPE_ALBUM:
|
||||
mSource = MediaLibrary.VIEW_ALBUMS_ARTISTS;
|
||||
mFields = new String[] { MediaLibrary.AlbumColumns.ALBUM, MediaLibrary.ContributorColumns.ARTIST };
|
||||
mFields = new String[] { MediaLibrary.AlbumColumns.ALBUM, MediaLibrary.ContributorColumns.ARTIST, MediaLibrary.SongColumns.DURATION };
|
||||
mFieldKeys = new String[] { MediaLibrary.AlbumColumns.ALBUM_SORT, MediaLibrary.ContributorColumns.ARTIST_SORT };
|
||||
mSortEntries = new int[] { R.string.title, R.string.artist_album, R.string.year, R.string.date_added };
|
||||
mAdapterSortValues = new String[] { MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s", MediaLibrary.ContributorColumns.ARTIST_SORT+" %1$s,"+MediaLibrary.AlbumColumns.ALBUM_SORT+" %1$s",
|
||||
@@ -496,7 +495,7 @@ public class MediaAdapter
|
||||
|
||||
row.setDraggerOnClickListener(this);
|
||||
row.showDragger(mExpandable);
|
||||
row.showDuration(!mExpandable);
|
||||
row.showDuration(!mExpandable || mType == MediaUtils.TYPE_ALBUM);
|
||||
} else {
|
||||
row = (DraggableRow)convertView;
|
||||
holder = (ViewHolder)row.getTag();
|
||||
@@ -513,8 +512,13 @@ public class MediaAdapter
|
||||
line1 = (line1 == null ? DB_NULLSTRING_FALLBACK : line1);
|
||||
line2 = (line2 == null ? DB_NULLSTRING_FALLBACK : line2);
|
||||
|
||||
if (mProjection.length >= 5)
|
||||
line2 += ", " + cursor.getString(4);
|
||||
if (mProjection.length >= 5) {
|
||||
if (mType == MediaUtils.TYPE_ALBUM) {
|
||||
duration = cursor.getLong(4);
|
||||
} else {
|
||||
line2 += ", " + cursor.getString(4);
|
||||
}
|
||||
}
|
||||
|
||||
if (mProjection.length >= 6)
|
||||
duration = cursor.getLong(5);
|
||||
|
||||
Reference in new issue
Block a user