fix code style errors

This commit is contained in:
Adrian Ulrich 2016-12-18 18:27:59 +01:00
parent 2e9de29921
commit 57b88bfef2
4 changed files with 56 additions and 70 deletions

View File

@ -80,7 +80,6 @@ public class MediaLibrary {
/**
* Registers a new content observer for the media library
*
* @param context the context to use
* @param observer the content observer we are going to call on changes
*/
public static void registerContentObserver(ContentObserver observer) {
@ -136,7 +135,6 @@ public class MediaLibrary {
*
* @param context the context to use
* @param id the song id to update
* @return boolean true if song was played, false if skipped
*/
public static void updateSongPlayCounts(Context context, long id, boolean played) {
final String column = played ? MediaLibrary.SongColumns.PLAYCOUNT : MediaLibrary.SongColumns.SKIPCOUNT;
@ -199,7 +197,7 @@ public class MediaLibrary {
pos = cursor.getLong(0) + 1;
cursor.close();
ArrayList<ContentValues> bulk = new ArrayList<ContentValues>();
ArrayList<ContentValues> bulk = new ArrayList<>();
for (Long id : ids) {
if (getBackend(context).getSongMtime(id) == 0)
continue;
@ -336,7 +334,7 @@ public class MediaLibrary {
* @return array with guessed directories
*/
public static File[] discoverMediaPaths() {
ArrayList<File> scanTargets = new ArrayList<File>();
ArrayList<File> scanTargets = new ArrayList<>();
// this should always exist
scanTargets.add(Environment.getExternalStorageDirectory());
@ -354,47 +352,47 @@ public class MediaLibrary {
/**
* The id of this song in the database
*/
public static final String _ID = "_id";
String _ID = "_id";
/**
* The title of this song
*/
public static final String TITLE = "title";
String TITLE = "title";
/**
* The sortable title of this song
*/
public static final String TITLE_SORT = "title_sort";
String TITLE_SORT = "title_sort";
/**
* The position in the album of this song
*/
public static final String SONG_NUMBER = "song_num";
String SONG_NUMBER = "song_num";
/**
* The album where this song belongs to
*/
public static final String ALBUM_ID = "album_id";
String ALBUM_ID = "album_id";
/**
* The year of this song
*/
public static final String YEAR = "year";
String YEAR = "year";
/**
* How often the song was played
*/
public static final String PLAYCOUNT = "playcount";
String PLAYCOUNT = "playcount";
/**
* How often the song was skipped
*/
public static final String SKIPCOUNT = "skipcount";
String SKIPCOUNT = "skipcount";
/**
* The duration of this song
*/
public static final String DURATION = "duration";
String DURATION = "duration";
/**
* The path to the music file
*/
public static final String PATH = "path";
String PATH = "path";
/**
* The mtime of this item
*/
public static final String MTIME = "mtime";
String MTIME = "mtime";
}
// Columns of Album entries
@ -402,31 +400,31 @@ public class MediaLibrary {
/**
* The id of this album in the database
*/
public static final String _ID = SongColumns._ID;
String _ID = SongColumns._ID;
/**
* The title of this album
*/
public static final String ALBUM = "album";
String ALBUM = "album";
/**
* The sortable title of this album
*/
public static final String ALBUM_SORT = "album_sort";
String ALBUM_SORT = "album_sort";
/**
* The disc number of this album
*/
public static final String DISC_NUMBER = "disc_num";
String DISC_NUMBER = "disc_num";
/**
* The primary contributor / artist reference for this album
*/
public static final String PRIMARY_ARTIST_ID = "primary_artist_id";
String PRIMARY_ARTIST_ID = "primary_artist_id";
/**
* The year of this album
*/
public static final String PRIMARY_ALBUM_YEAR = "primary_album_year";
String PRIMARY_ALBUM_YEAR = "primary_album_year";
/**
* The mtime of this item
*/
public static final String MTIME = "mtime";
String MTIME = "mtime";
}
// Columns of Contributors entries
@ -434,31 +432,31 @@ public class MediaLibrary {
/**
* The id of this contributor
*/
public static final String _ID = SongColumns._ID;
String _ID = SongColumns._ID;
/**
* The name of this contributor
*/
public static final String _CONTRIBUTOR = "_contributor";
String _CONTRIBUTOR = "_contributor";
/**
* The sortable title of this contributor
*/
public static final String _CONTRIBUTOR_SORT = "_contributor_sort";
String _CONTRIBUTOR_SORT = "_contributor_sort";
/**
* The mtime of this item
*/
public static final String MTIME = "mtime";
String MTIME = "mtime";
/**
* ONLY IN VIEWS - the artist
*/
public static final String ARTIST = "artist";
String ARTIST = "artist";
/**
* ONLY IN VIEWS - the artist_sort key
*/
public static final String ARTIST_SORT = "artist_sort";
String ARTIST_SORT = "artist_sort";
/**
* ONLY IN VIEWS - the artist id
*/
public static final String ARTIST_ID = "artist_id";
String ARTIST_ID = "artist_id";
}
// Songs <-> Contributor mapping
@ -466,15 +464,15 @@ public class MediaLibrary {
/**
* The role of this entry
*/
public static final String ROLE = "role";
String ROLE = "role";
/**
* the contirbutor id this maps to
*/
public static final String _CONTRIBUTOR_ID = "_contributor_id";
String _CONTRIBUTOR_ID = "_contributor_id";
/**
* the song this maps to
*/
public static final String SONG_ID = "song_id";
String SONG_ID = "song_id";
}
// Columns of Genres entries
@ -482,15 +480,15 @@ public class MediaLibrary {
/**
* The id of this genre
*/
public static final String _ID = SongColumns._ID;
String _ID = SongColumns._ID;
/**
* The name of this genre
*/
public static final String _GENRE = "_genre";
String _GENRE = "_genre";
/**
* The sortable title of this genre
*/
public static final String _GENRE_SORT = "_genre_sort";
String _GENRE_SORT = "_genre_sort";
}
// Songs <-> Contributor mapping
@ -498,11 +496,11 @@ public class MediaLibrary {
/**
* the genre id this maps to
*/
public static final String _GENRE_ID = "_genre_id";
String _GENRE_ID = "_genre_id";
/**
* the song this maps to
*/
public static final String SONG_ID = "song_id";
String SONG_ID = "song_id";
}
// Playlists
@ -510,11 +508,11 @@ public class MediaLibrary {
/**
* The id of this playlist
*/
public static final String _ID = SongColumns._ID;
String _ID = SongColumns._ID;
/**
* The name of this playlist
*/
public static final String NAME = "name";
String NAME = "name";
}
// Song <-> Playlist mapping
@ -522,19 +520,18 @@ public class MediaLibrary {
/**
* The ID of this entry
*/
public static final String _ID = SongColumns._ID;
String _ID = SongColumns._ID;
/**
* The playlist this entry belongs to
*/
public static final String PLAYLIST_ID = "playlist_id";
String PLAYLIST_ID = "playlist_id";
/**
* The song this entry references to
*/
public static final String SONG_ID = "song_id";
String SONG_ID = "song_id";
/**
* The order attribute
*/
public static final String POSITION = "position";
String POSITION = "position";
}
}

View File

@ -19,7 +19,6 @@ package ch.blinkenlights.android.medialibrary;
import android.content.Context;
import android.content.ContentValues;
import android.database.DatabaseUtils;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.Cursor;
@ -41,10 +40,6 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
* on-disk file to store the database
*/
private static final String DATABASE_NAME = "media-library.db";
/**
* The tag to use for log messages
*/
private static final String TAG = "VanillaMediaLibraryBackend";
/**
* Regexp to detect genre queries which we can optimize
*/
@ -57,7 +52,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
/**
* Constructor for the MediaLibraryBackend helper
*
* @param Context the context to use
* @param context the context to use
*/
MediaLibraryBackend(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
@ -260,9 +255,8 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
* @return an SQL string which should return song id's for the queried genre
*/
private String buildSongIdFromGenreSelect(String genreId) {
final String query = "SELECT "+MediaLibrary.GenreSongColumns.SONG_ID+" FROM "+MediaLibrary.TABLE_GENRES_SONGS+" WHERE "
+MediaLibrary.GenreSongColumns._GENRE_ID+"="+genreId+" GROUP BY "+MediaLibrary.GenreSongColumns.SONG_ID;
return query;
return "SELECT "+MediaLibrary.GenreSongColumns.SONG_ID+" FROM "+MediaLibrary.TABLE_GENRES_SONGS+" WHERE "
+MediaLibrary.GenreSongColumns._GENRE_ID+"="+genreId+" GROUP BY "+MediaLibrary.GenreSongColumns.SONG_ID;
}
/**
@ -273,9 +267,8 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
* @return an SQL string
*/
private String buildSongIdFromGenreSelect(String target, String genreSelect) {
final String query = "SELECT "+target+" FROM "+MediaLibrary.VIEW_SONGS_ALBUMS_ARTISTS+" WHERE "
+MediaLibrary.SongColumns._ID+" IN ("+genreSelect+") GROUP BY "+target;
return query;
return "SELECT "+target+" FROM "+MediaLibrary.VIEW_SONGS_ALBUMS_ARTISTS+" WHERE "
+MediaLibrary.SongColumns._ID+" IN ("+genreSelect+") GROUP BY "+target;
}
/**
@ -307,8 +300,8 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
while(dryRun.moveToNext()) {
results++;
}
dryRun.close();
}
dryRun.close();
long tookMs = System.currentTimeMillis() - startAt;
Log.v(LT, "--- finished in "+tookMs+" ms with count="+results);
}

View File

@ -88,10 +88,9 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
* Attempts to populate this instance with tags found in given path
*
* @param path the path to parse
* @return void, but populates `this'
*/
private void extractMetadata(String path) {
if (isEmpty() == false)
if (!isEmpty())
throw new IllegalStateException("Expected to be called on a clean HashMap");
HashMap bastpTags = (new Bastp()).getTags(path);
@ -109,15 +108,15 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
}
// Bastp can not read the duration and bitrates, so we always get it from the system
ArrayList<String> duration = new ArrayList<String>(1);
ArrayList<String> duration = new ArrayList<>(1);
duration.add(mediaTags.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
this.put(DURATION, duration);
ArrayList<String> bitrate = new ArrayList<String>(1);
ArrayList<String> bitrate = new ArrayList<>(1);
bitrate.add(mediaTags.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE));
this.put(BITRATE, bitrate);
ArrayList<String> mime = new ArrayList<String>(1);
ArrayList<String> mime = new ArrayList<>(1);
mime.add(mediaTags.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE));
this.put(MIME_TYPE, mime);
@ -164,7 +163,7 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
// Try to guess YEAR from date field if only DATE was specified
// We expect it to match \d{4}
if (containsKey(YEAR) == false && bastp.containsKey("DATE")) {
if (!containsKey(YEAR) && bastp.containsKey("DATE")) {
addFiltered(sFilterYear, YEAR, (ArrayList<String>)bastp.get("DATE"));
}
@ -204,7 +203,7 @@ public class MediaMetadataExtractor extends HashMap<String, ArrayList<String>> {
* @param data the array list to inspect
*/
private void addFiltered(Pattern filter, String key, ArrayList<String> data) {
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list = new ArrayList<>();
for (String s : data) {
Matcher matcher = filter.matcher(s);
if (matcher.matches()) {

View File

@ -17,11 +17,9 @@
package ch.blinkenlights.android.medialibrary;
import ch.blinkenlights.bastp.Bastp;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
import android.media.MediaMetadataRetriever;
import android.util.Log;
import android.provider.MediaStore;
import android.os.Handler;
@ -32,7 +30,6 @@ import android.os.SystemClock;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.regex.Pattern;
public class MediaScanner implements Handler.Callback {
@ -118,7 +115,7 @@ public class MediaScanner implements Handler.Callback {
boolean changed = addFile(file);
// Notify the observer if this was the last message OR if the deadline was reached
if (mHandler.hasMessages(MSG_ADD_FILE) == false || (mNextNotification != 0 && now >= mNextNotification)) {
if (!mHandler.hasMessages(MSG_ADD_FILE) || (mNextNotification != 0 && now >= mNextNotification)) {
MediaLibrary.notifyObserver();
mNextNotification = 0;
}
@ -155,7 +152,7 @@ public class MediaScanner implements Handler.Callback {
* @param dir the directory to scan
*/
private void scanDirectory(File dir) {
if (dir.isDirectory() == false)
if (!dir.isDirectory())
return;
if (new File(dir, ".nomedia").exists())
@ -214,7 +211,7 @@ public class MediaScanner implements Handler.Callback {
}
MediaMetadataExtractor tags = new MediaMetadataExtractor(path);
if (tags.isTagged() == false) {
if (!tags.isTagged()) {
needsInsert = false; // does not have any useable metadata: wont insert even if it is a playable file
}