add skipcount column
This commit is contained in:
parent
8beb95c79a
commit
0c360bb5c2
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
* Copyright (C) 2014-2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -31,13 +31,14 @@ public class PlayCountsHelper extends SQLiteOpenHelper {
|
|||||||
* SQL constants and CREATE TABLE statements used by
|
* SQL constants and CREATE TABLE statements used by
|
||||||
* this java class
|
* this java class
|
||||||
*/
|
*/
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int DATABASE_VERSION = 2;
|
||||||
private static final String DATABASE_NAME = "playcounts.db";
|
private static final String DATABASE_NAME = "playcounts.db";
|
||||||
private static final String TABLE_PLAYCOUNTS = "playcounts";
|
private static final String TABLE_PLAYCOUNTS = "playcounts";
|
||||||
private static final String DATABASE_CREATE = "CREATE TABLE "+TABLE_PLAYCOUNTS + " ("
|
private static final String DATABASE_CREATE = "CREATE TABLE "+TABLE_PLAYCOUNTS + " ("
|
||||||
+ "type INTEGER, "
|
+ "type INTEGER, "
|
||||||
+ "type_id BIGINT, "
|
+ "type_id BIGINT, "
|
||||||
+ "playcount INTEGER);";
|
+ "playcount INTEGER, "
|
||||||
|
+ "skipcount INTEGER);";
|
||||||
private static final String INDEX_UNIQUE_CREATE = "CREATE UNIQUE INDEX idx_uniq ON "+TABLE_PLAYCOUNTS
|
private static final String INDEX_UNIQUE_CREATE = "CREATE UNIQUE INDEX idx_uniq ON "+TABLE_PLAYCOUNTS
|
||||||
+ " (type, type_id);";
|
+ " (type, type_id);";
|
||||||
private static final String INDEX_TYPE_CREATE = "CREATE INDEX idx_type ON "+TABLE_PLAYCOUNTS
|
private static final String INDEX_TYPE_CREATE = "CREATE INDEX idx_type ON "+TABLE_PLAYCOUNTS
|
||||||
@ -59,18 +60,22 @@ public class PlayCountsHelper extends SQLiteOpenHelper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpgrade(SQLiteDatabase dbh, int oldVersion, int newVersion) {
|
public void onUpgrade(SQLiteDatabase dbh, int oldVersion, int newVersion) {
|
||||||
// first db -> nothing to upgrade
|
if (oldVersion < 2) {
|
||||||
|
dbh.execSQL("ALTER TABLE "+TABLE_PLAYCOUNTS+" ADD COLUMN skipcount INTEGER");
|
||||||
|
dbh.execSQL("UPDATE "+TABLE_PLAYCOUNTS+" SET skipcount=0");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Counts this song object as 'played'
|
* Counts this song object as 'played' or 'skipped'
|
||||||
*/
|
*/
|
||||||
public void countSong(Song song) {
|
public void countSong(Song song, boolean played) {
|
||||||
long id = Song.getId(song);
|
long id = Song.getId(song);
|
||||||
|
final String column = played ? "playcount" : "skipcount";
|
||||||
|
|
||||||
SQLiteDatabase dbh = getWritableDatabase();
|
SQLiteDatabase dbh = getWritableDatabase();
|
||||||
dbh.execSQL("INSERT OR IGNORE INTO "+TABLE_PLAYCOUNTS+" (type, type_id, playcount) VALUES ("+MediaUtils.TYPE_SONG+", "+id+", 0);"); // Creates row if not exists
|
dbh.execSQL("INSERT OR IGNORE INTO "+TABLE_PLAYCOUNTS+" (type, type_id, playcount, skipcount) VALUES ("+MediaUtils.TYPE_SONG+", "+id+", 0, 0);"); // Creates row if not exists
|
||||||
dbh.execSQL("UPDATE "+TABLE_PLAYCOUNTS+" SET playcount=playcount+1 WHERE type="+MediaUtils.TYPE_SONG+" AND type_id="+id+";");
|
dbh.execSQL("UPDATE "+TABLE_PLAYCOUNTS+" SET "+column+"="+column+"+1 WHERE type="+MediaUtils.TYPE_SONG+" AND type_id="+id+";");
|
||||||
dbh.close();
|
dbh.close();
|
||||||
|
|
||||||
performGC(MediaUtils.TYPE_SONG);
|
performGC(MediaUtils.TYPE_SONG);
|
||||||
|
@ -1544,7 +1544,7 @@ public final class PlaybackService extends Service
|
|||||||
break;
|
break;
|
||||||
case MSG_UPDATE_PLAYCOUNTS:
|
case MSG_UPDATE_PLAYCOUNTS:
|
||||||
Song song = (Song)message.obj;
|
Song song = (Song)message.obj;
|
||||||
mPlayCounts.countSong(song);
|
mPlayCounts.countSong(song, true);
|
||||||
// Update the playcounts playlist in ~20% of all cases if enabled
|
// Update the playcounts playlist in ~20% of all cases if enabled
|
||||||
if (mAutoPlPlaycounts > 0 && Math.random() > 0.8) {
|
if (mAutoPlPlaycounts > 0 && Math.random() > 0.8) {
|
||||||
ContentResolver resolver = getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user