Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
norohind committed Apr 13, 2024
1 parent 9670e4d commit 2e774aa
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
33 changes: 33 additions & 0 deletions app/src/main/java/github/daneren2005/dsub/domain/Scrobble.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package github.daneren2005.dsub.domain;

public class Scrobble {
private final String serverKey;
private final String serverId;
private final long time;
private final boolean isSubmission;

public Scrobble(String serverKey, String serverId, long time, boolean isSubmission) {
this.serverKey = serverKey;
this.serverId = serverId;
this.time = time;
this.isSubmission = isSubmission;
}


public String getServerKey() {
return serverKey;
}

public String getServerId() {
return serverId;
}

public long getTime() {
return time;
}

public boolean isSubmission() {
return isSubmission;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,10 @@ public void scrobble(String id, boolean submission, Context context, ProgressLis
public void scrobble(String id, boolean submission, long time, Context context, ProgressListener progressListener) throws Exception {
checkServerVersion(context, "1.5", "Scrobbling not supported.");
Reader reader;
Scrobble scrobble = new Scrobble(String.valueOf(Util.getActiveServer(context)), id, time, submission);

SongDBHandler.getHandler(context).addScrobble(scrobble);

if(time > 0){
checkServerVersion(context, "1.8", "Scrobbling with a time not supported.");
reader = getReader(context, progressListener, "scrobble", Arrays.asList("id", "submission", "time"), Arrays.<Object>asList(id, submission, time));
Expand Down
39 changes: 36 additions & 3 deletions app/src/main/java/github/daneren2005/dsub/util/SongDBHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import java.util.List;

import github.daneren2005.dsub.domain.MusicDirectory;
import github.daneren2005.dsub.domain.Scrobble;
import github.daneren2005.dsub.service.DownloadFile;

public class SongDBHandler extends SQLiteOpenHelper {
private static final String TAG = SongDBHandler.class.getSimpleName();
private static SongDBHandler dbHandler;

private static final int DATABASE_VERSION = 2;
private static final int DATABASE_VERSION = 3;
public static final String DATABASE_NAME = "SongsDB";

public static final String TABLE_SONGS = "RegisteredSongs";
Expand All @@ -43,6 +44,10 @@ public class SongDBHandler extends SQLiteOpenHelper {
public static final String SONGS_LAST_PLAYED = "lastPlayed";
public static final String SONGS_LAST_COMPLETED = "lastCompleted";

public static final String SCROBBLES_TABLE = "scrobbles";
public static final String SCROBBLES_TIMESTAMP = "timestamp";
public static final String SCROBBLES_SUBMISSION = "submission";

private Context context;

private SongDBHandler(Context context) {
Expand All @@ -60,14 +65,42 @@ public void onCreate(SQLiteDatabase db) {
SONGS_LAST_PLAYED + " INTEGER, " +
SONGS_LAST_COMPLETED + " INTEGER, " +
"UNIQUE(" + SONGS_SERVER_KEY + ", " + SONGS_SERVER_ID + "))");

createScrobblesTable(db);
}

private void createScrobblesTable(SQLiteDatabase db) {
db.execSQL("CREATE TABLE " + SCROBBLES_TABLE + " ( " +
SONGS_SERVER_KEY + " INTEGER NOT NULL, " +
SONGS_SERVER_ID + " TEXT NOT NULL, " +
SCROBBLES_TIMESTAMP + " INT, " +
SCROBBLES_SUBMISSION + " INTEGER NOT NULL, " +
"primary key(" + SONGS_SERVER_KEY + ", " + SONGS_SERVER_ID + ", " + SCROBBLES_TIMESTAMP + ", " + SCROBBLES_SUBMISSION + " ))");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SONGS);
this.onCreate(db);
if (oldVersion == 2 && newVersion == 3) {
createScrobblesTable(db);
}
}

@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 3 && newVersion == 2) {
db.execSQL("drop table " + SCROBBLES_TABLE + ";");
}
}

public synchronized void addScrobble(Scrobble scrobble) {
ContentValues values = new ContentValues();
values.put(SONGS_SERVER_KEY, scrobble.getServerKey());
values.put(SONGS_SERVER_ID, scrobble.getServerId());
values.put(SCROBBLES_TIMESTAMP, scrobble.getTime());
values.put(SCROBBLES_SUBMISSION, scrobble.isSubmission());
SQLiteDatabase db = getWritableDatabase();
db.insert(SCROBBLES_TABLE, null, values);
}
public synchronized void addSong(DownloadFile downloadFile) {
addSong(Util.getMostRecentActiveServer(context), downloadFile);
}
Expand Down

0 comments on commit 2e774aa

Please sign in to comment.