Added Nullity Annotations
This commit is contained in:
parent
1dcc447e52
commit
5317c51400
102 changed files with 772 additions and 404 deletions
|
|
@ -5,25 +5,29 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class AlbumJSONStore extends SQLiteOpenHelper {
|
||||
|
||||
public static final String DATABASE_NAME = "albums_last_fm.db";
|
||||
private static final int VERSION = 1;
|
||||
@Nullable
|
||||
private static AlbumJSONStore sInstance = null;
|
||||
|
||||
public AlbumJSONStore(final Context context) {
|
||||
super(context, DATABASE_NAME, null, VERSION);
|
||||
}
|
||||
|
||||
public static synchronized AlbumJSONStore getInstance(final Context context) {
|
||||
@Nullable
|
||||
public static synchronized AlbumJSONStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new AlbumJSONStore(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void addAlbumJSON(final String albumAndArtistName, final String json) {
|
||||
public void addAlbumJSON(@Nullable final String albumAndArtistName, @Nullable final String json) {
|
||||
if (albumAndArtistName == null || json == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -41,7 +45,8 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
database.endTransaction();
|
||||
}
|
||||
|
||||
public String getJSONData(final String albumAndArtistName) {
|
||||
@Nullable
|
||||
public String getJSONData(@Nullable final String albumAndArtistName) {
|
||||
if (albumAndArtistName == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -68,7 +73,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void removeAlbumJSON(final String albumAndArtistName) {
|
||||
public void removeAlbumJSON(@NonNull final String albumAndArtistName) {
|
||||
final SQLiteDatabase database = getReadableDatabase();
|
||||
database.delete(AlbumJSONColumns.NAME, AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " = ?", new String[]{
|
||||
albumAndArtistName.trim().toLowerCase()
|
||||
|
|
@ -83,7 +88,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + AlbumJSONColumns.NAME +
|
||||
" (" + AlbumJSONColumns.ALBUM_PLUS_ARTIST_NAME + " TEXT NOT NULL," +
|
||||
AlbumJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
||||
|
|
@ -92,7 +97,7 @@ public class AlbumJSONStore extends SQLiteOpenHelper {
|
|||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + AlbumJSONColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,25 +5,29 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class ArtistJSONStore extends SQLiteOpenHelper {
|
||||
|
||||
public static final String DATABASE_NAME = "artists_last_fm.db";
|
||||
private static final int VERSION = 1;
|
||||
@Nullable
|
||||
private static ArtistJSONStore sInstance = null;
|
||||
|
||||
public ArtistJSONStore(final Context context) {
|
||||
super(context, DATABASE_NAME, null, VERSION);
|
||||
}
|
||||
|
||||
public static synchronized ArtistJSONStore getInstance(final Context context) {
|
||||
@Nullable
|
||||
public static synchronized ArtistJSONStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new ArtistJSONStore(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public void addArtistJSON(final String artistName, final String json) {
|
||||
public void addArtistJSON(@Nullable final String artistName, @Nullable final String json) {
|
||||
if (artistName == null || json == null) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -41,7 +45,8 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
database.endTransaction();
|
||||
}
|
||||
|
||||
public String getArtistJSON(final String artistName) {
|
||||
@Nullable
|
||||
public String getArtistJSON(@Nullable final String artistName) {
|
||||
if (artistName == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -68,7 +73,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void removeArtistJSON(final String artistName) {
|
||||
public void removeArtistJSON(@NonNull final String artistName) {
|
||||
final SQLiteDatabase database = getReadableDatabase();
|
||||
database.delete(ArtistJSONColumns.NAME, ArtistJSONColumns.ARTIST_NAME + "=?", new String[]{
|
||||
artistName.trim().toLowerCase()
|
||||
|
|
@ -83,7 +88,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + ArtistJSONColumns.NAME +
|
||||
" (" + ArtistJSONColumns.ARTIST_NAME + " TEXT NOT NULL," +
|
||||
ArtistJSONColumns.JSON_DATA + " TEXT NOT NULL);"
|
||||
|
|
@ -92,7 +97,7 @@ public class ArtistJSONStore extends SQLiteOpenHelper {
|
|||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ArtistJSONColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ import android.database.sqlite.SQLiteDatabase;
|
|||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore.Audio.AudioColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.Song;
|
||||
|
|
@ -34,6 +36,7 @@ import java.util.ArrayList;
|
|||
* This keeps track of the music playback and history state of the playback service
|
||||
*/
|
||||
public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
||||
@Nullable
|
||||
private static MusicPlaybackQueueStore sInstance = null;
|
||||
public static final String DATABASE_NAME = "music_playback_state.db";
|
||||
public static final String PLAYING_QUEUE_TABLE_NAME = "playing_queue";
|
||||
|
|
@ -50,12 +53,12 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
createTable(db, PLAYING_QUEUE_TABLE_NAME);
|
||||
createTable(db, ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
}
|
||||
|
||||
private void createTable(final SQLiteDatabase db, final String tableName) {
|
||||
private void createTable(@NonNull final SQLiteDatabase db, final String tableName) {
|
||||
//noinspection StringBufferReplaceableByString
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("CREATE TABLE IF NOT EXISTS ");
|
||||
|
|
@ -93,7 +96,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
// not necessary yet
|
||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
|
|
@ -101,7 +104,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// If we ever have downgrade, drop the table to be safe
|
||||
db.execSQL("DROP TABLE IF EXISTS " + PLAYING_QUEUE_TABLE_NAME);
|
||||
db.execSQL("DROP TABLE IF EXISTS " + ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
|
|
@ -112,14 +115,15 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
* @param context The {@link Context} to use
|
||||
* @return A new instance of this class.
|
||||
*/
|
||||
public static synchronized MusicPlaybackQueueStore getInstance(final Context context) {
|
||||
@Nullable
|
||||
public static synchronized MusicPlaybackQueueStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MusicPlaybackQueueStore(context.getApplicationContext());
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void saveQueues(final ArrayList<Song> playingQueue, final ArrayList<Song> originalPlayingQueue) {
|
||||
public synchronized void saveQueues(@NonNull final ArrayList<Song> playingQueue, @NonNull final ArrayList<Song> originalPlayingQueue) {
|
||||
saveQueue(PLAYING_QUEUE_TABLE_NAME, playingQueue);
|
||||
saveQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME, originalPlayingQueue);
|
||||
}
|
||||
|
|
@ -130,7 +134,7 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
*
|
||||
* @param queue the queue to save
|
||||
*/
|
||||
private synchronized void saveQueue(final String tableName, final ArrayList<Song> queue) {
|
||||
private synchronized void saveQueue(final String tableName, @NonNull final ArrayList<Song> queue) {
|
||||
final SQLiteDatabase database = getWritableDatabase();
|
||||
database.beginTransaction();
|
||||
|
||||
|
|
@ -170,15 +174,18 @@ public class MusicPlaybackQueueStore extends SQLiteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ArrayList<Song> getSavedPlayingQueue() {
|
||||
return getQueue(PLAYING_QUEUE_TABLE_NAME);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ArrayList<Song> getSavedOriginalPlayingQueue() {
|
||||
return getQueue(ORIGINAL_PLAYING_QUEUE_TABLE_NAME);
|
||||
}
|
||||
|
||||
private ArrayList<Song> getQueue(final String tableName) {
|
||||
@NonNull
|
||||
private ArrayList<Song> getQueue(@NonNull final String tableName) {
|
||||
Cursor cursor = getReadableDatabase().query(tableName, null,
|
||||
null, null, null, null, null);
|
||||
return SongLoader.getSongs(cursor);
|
||||
|
|
|
|||
|
|
@ -21,12 +21,15 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
public class RecentlyPlayedStore extends SQLiteOpenHelper {
|
||||
private static final int MAX_ITEMS_IN_DB = 100;
|
||||
|
||||
public static final String DATABASE_NAME = "recently_played.db";
|
||||
private static final int VERSION = 1;
|
||||
@Nullable
|
||||
private static RecentlyPlayedStore sInstance = null;
|
||||
|
||||
public RecentlyPlayedStore(final Context context) {
|
||||
|
|
@ -34,25 +37,26 @@ public class RecentlyPlayedStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
db.execSQL("CREATE TABLE IF NOT EXISTS " + RecentStoreColumns.NAME + " ("
|
||||
+ RecentStoreColumns.ID + " LONG NOT NULL," + RecentStoreColumns.TIME_PLAYED
|
||||
+ " LONG NOT NULL);");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onUpgrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + RecentStoreColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
public static synchronized RecentlyPlayedStore getInstance(final Context context) {
|
||||
@Nullable
|
||||
public static synchronized RecentlyPlayedStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new RecentlyPlayedStore(context.getApplicationContext());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ import android.content.Context;
|
|||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
|
|
@ -29,12 +31,14 @@ import android.view.animation.Interpolator;
|
|||
* the top played tracks as well as the playlist images
|
||||
*/
|
||||
public class SongPlayCountStore extends SQLiteOpenHelper {
|
||||
@Nullable
|
||||
private static SongPlayCountStore sInstance = null;
|
||||
|
||||
public static final String DATABASE_NAME = "song_play_count.db";
|
||||
private static final int VERSION = 1;
|
||||
|
||||
// interpolator curve applied for measuring the curve
|
||||
@NonNull
|
||||
private static Interpolator sInterpolator = new AccelerateInterpolator(1.5f);
|
||||
|
||||
// how many weeks worth of playback to track
|
||||
|
|
@ -51,6 +55,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
@SuppressWarnings("FieldCanBeLocal")
|
||||
private static int ONE_WEEK_IN_MS = 1000 * 60 * 60 * 24 * 7;
|
||||
|
||||
@NonNull
|
||||
private static String WHERE_ID_EQUALS = SongPlayCountColumns.ID + "=?";
|
||||
|
||||
// number of weeks since epoch time
|
||||
|
|
@ -69,7 +74,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(final SQLiteDatabase db) {
|
||||
public void onCreate(@NonNull final SQLiteDatabase db) {
|
||||
// create the play count table
|
||||
// WARNING: If you change the order of these columns
|
||||
// please update getColumnIndexForWeek
|
||||
|
|
@ -95,13 +100,13 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
public void onUpgrade(@NonNull final SQLiteDatabase db, final int oldVersion, final int newVersion) {
|
||||
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
||||
onCreate(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
public void onDowngrade(@NonNull SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// If we ever have downgrade, drop the table to be safe
|
||||
db.execSQL("DROP TABLE IF EXISTS " + SongPlayCountColumns.NAME);
|
||||
onCreate(db);
|
||||
|
|
@ -111,7 +116,8 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* @param context The {@link Context} to use
|
||||
* @return A new instance of this class.
|
||||
*/
|
||||
public static synchronized SongPlayCountStore getInstance(final Context context) {
|
||||
@Nullable
|
||||
public static synchronized SongPlayCountStore getInstance(@NonNull final Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new SongPlayCountStore(context.getApplicationContext());
|
||||
}
|
||||
|
|
@ -138,7 +144,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* @param database a write able database
|
||||
* @param songId the id of the track
|
||||
*/
|
||||
private void createNewPlayedEntry(final SQLiteDatabase database, final long songId) {
|
||||
private void createNewPlayedEntry(@NonNull final SQLiteDatabase database, final long songId) {
|
||||
// no row exists, create a new one
|
||||
float newScore = getScoreMultiplierForWeek(0);
|
||||
int newPlayCount = 1;
|
||||
|
|
@ -160,7 +166,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* @param id the id of the track to bump
|
||||
* @param bumpCount whether to bump the current's week play count by 1 and adjust the score
|
||||
*/
|
||||
private void updateExistingRow(final SQLiteDatabase database, final long id, boolean bumpCount) {
|
||||
private void updateExistingRow(@NonNull final SQLiteDatabase database, final long id, boolean bumpCount) {
|
||||
String stringId = String.valueOf(id);
|
||||
|
||||
// begin the transaction
|
||||
|
|
@ -329,7 +335,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* @param database database to use
|
||||
* @param stringId id to delete
|
||||
*/
|
||||
private void deleteEntry(final SQLiteDatabase database, final String stringId) {
|
||||
private void deleteEntry(@NonNull final SQLiteDatabase database, final String stringId) {
|
||||
database.delete(SongPlayCountColumns.NAME, WHERE_ID_EQUALS, new String[]{stringId});
|
||||
}
|
||||
|
||||
|
|
@ -340,7 +346,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* where playCounts[N] is the # of times it was played N weeks ago
|
||||
* @return the score
|
||||
*/
|
||||
private static float calculateScore(final int[] playCounts) {
|
||||
private static float calculateScore(@Nullable final int[] playCounts) {
|
||||
if (playCounts == null) {
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -359,6 +365,7 @@ public class SongPlayCountStore extends SQLiteOpenHelper {
|
|||
* @param week number
|
||||
* @return the column name
|
||||
*/
|
||||
@NonNull
|
||||
private static String getColumnNameForWeek(final int week) {
|
||||
return SongPlayCountColumns.WEEK_PLAY_COUNT + String.valueOf(week);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue