Skip to content

Commit

Permalink
use MediaUtils.TYPE_SONG
Browse files Browse the repository at this point in the history
  • Loading branch information
adrian-bl committed Apr 16, 2014
1 parent 6a97ef8 commit 37e26c8
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/ch/blinkenlights/android/vanilla/PlayCountsHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

public class PlayCountsHelper extends SQLiteOpenHelper {

/**
* Value of 'type' field
*/
private static final int TYPE_SONG = 1;

/**
* SQL constants and CREATE TABLE statements used by
* this java class
Expand Down Expand Up @@ -68,12 +63,11 @@ public void onUpgrade(SQLiteDatabase dbh, int oldVersion, int newVersion) {
* Counts this song object as 'played'
*/
public void countSong(Song song) {
int type = TYPE_SONG;
long id = Song.getId(song);

SQLiteDatabase dbh = this.getWritableDatabase();
dbh.execSQL("INSERT OR IGNORE INTO "+TABLE_PLAYCOUNTS+" (type, type_id, playcount) VALUES ("+type+", "+id+", 0);"); // Creates row if not exists
dbh.execSQL("UPDATE "+TABLE_PLAYCOUNTS+" SET playcount=playcount+1 WHERE type="+type+" AND type_id="+id+";");
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("UPDATE "+TABLE_PLAYCOUNTS+" SET playcount=playcount+1 WHERE type="+MediaUtils.TYPE_SONG+" AND type_id="+id+";");
dbh.close();
}

Expand All @@ -83,7 +77,7 @@ public void countSong(Song song) {
public ArrayList<Long> getTopSongs() {
ArrayList<Long> payload = new ArrayList<Long>();
SQLiteDatabase dbh = this.getReadableDatabase();
Cursor c = dbh.rawQuery("SELECT type_id FROM "+TABLE_PLAYCOUNTS+" WHERE TYPE="+TYPE_SONG+" ORDER BY playcount DESC limit 4096", null);
Cursor c = dbh.rawQuery("SELECT type_id FROM "+TABLE_PLAYCOUNTS+" WHERE type="+MediaUtils.TYPE_SONG+" ORDER BY playcount DESC limit 4096", null);

while (c.moveToNext()) {
payload.add(c.getLong(0));
Expand Down

0 comments on commit 37e26c8

Please sign in to comment.