Recently played is now history. Songs are always added to the history but their play count will be only increased if they were played at least half. This makes the top tracks much more accurate.

This commit is contained in:
Karim Abou Zeid 2015-09-12 15:14:01 +02:00
commit cf4ed6d5c0
10 changed files with 163 additions and 31 deletions

View file

@ -24,15 +24,15 @@ import android.database.sqlite.SQLiteOpenHelper;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
public class RecentlyPlayedStore extends SQLiteOpenHelper {
public class HistoryStore extends SQLiteOpenHelper {
private static final int MAX_ITEMS_IN_DB = 100;
public static final String DATABASE_NAME = "recently_played.db";
public static final String DATABASE_NAME = "history.db";
private static final int VERSION = 1;
@Nullable
private static RecentlyPlayedStore sInstance = null;
private static HistoryStore sInstance = null;
public RecentlyPlayedStore(final Context context) {
public HistoryStore(final Context context) {
super(context, DATABASE_NAME, null, VERSION);
}
@ -56,18 +56,23 @@ public class RecentlyPlayedStore extends SQLiteOpenHelper {
}
@NonNull
public static synchronized RecentlyPlayedStore getInstance(@NonNull final Context context) {
public static synchronized HistoryStore getInstance(@NonNull final Context context) {
if (sInstance == null) {
sInstance = new RecentlyPlayedStore(context.getApplicationContext());
sInstance = new HistoryStore(context.getApplicationContext());
}
return sInstance;
}
public void addSongId(final long songId) {
if (songId == -1) {
return;
}
final SQLiteDatabase database = getWritableDatabase();
database.beginTransaction();
try {
// remove previous entries
removeSongId(songId);
// add the entry

View file

@ -35,7 +35,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
private static SongPlayCountStore sInstance = null;
public static final String DATABASE_NAME = "song_play_count.db";
private static final int VERSION = 1;
private static final int VERSION = 2;
// interpolator curve applied for measuring the curve
@NonNull
@ -129,8 +129,8 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
*
* @param songId The song id to increase the play count
*/
public void bumpSongCount(final long songId) {
if (songId < 0) {
public void bumpPlayCount(final long songId) {
if (songId == -1) {
return;
}