Skip to content
This repository has been archived by the owner on Jan 26, 2025. It is now read-only.

Commit

Permalink
replaced old loader, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearfog committed Apr 20, 2024
1 parent e736a12 commit daa445d
Show file tree
Hide file tree
Showing 45 changed files with 1,305 additions and 1,753 deletions.
77 changes: 37 additions & 40 deletions app/src/main/java/org/nuclearfog/apollo/loaders/AlbumLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,59 +28,56 @@
* Used to return the albums on a user's device.
*
* @author Andrew Neal ([email protected])
* @author nuclearfog
*/
public class AlbumLoader extends WrappedAsyncTaskLoader<List<Album>> {
public class AlbumLoader extends AsyncExecutor<Void, List<Album>> {

private static final String TAG = "AlbumLoader";

private ExcludeStore exclude_db;

/**
* Constructor of <code>AlbumLoader</code>
*
* @param context The {@link Context} to use
*/
public AlbumLoader(Context context) {
super(context);
exclude_db = ExcludeStore.getInstance(context);

}

/**
* {@inheritDoc}
*/
@Override
public List<Album> loadInBackground() {
protected List<Album> doInBackground(Void v) {
List<Album> result = new LinkedList<>();
Set<Long> excludedIds = exclude_db.getIds(Type.ALBUM);
try {
// Create the Cursor
Cursor mCursor = CursorFactory.makeAlbumCursor(getContext());
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the album id
long id = mCursor.getLong(0);
// Copy the album name
String albumName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// Copy the release year
String year = mCursor.getString(4);
// check if album is excluded from viewing
boolean visible = !excludedIds.contains(id);
// Create a new album
Album album = new Album(id, albumName, artist, songCount, year, visible);
// Add everything up
result.add(album);
} while (mCursor.moveToNext());
Context context = getContext();
if (context != null) {
ExcludeStore exclude_db = ExcludeStore.getInstance(context);
try {
// init filter list
Set<Long> excludedIds = exclude_db.getIds(Type.ALBUM);
// Create the Cursor
Cursor mCursor = CursorFactory.makeAlbumCursor(context);
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the album id
long id = mCursor.getLong(0);
// Copy the album name
String albumName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// Copy the release year
String year = mCursor.getString(4);
// check if album is excluded from viewing
boolean visible = !excludedIds.contains(id);
// Create a new album
Album album = new Album(id, albumName, artist, songCount, year, visible);
// Add everything up
result.add(album);
} while (mCursor.moveToNext());
}
mCursor.close();
}
mCursor.close();
} catch (Exception exception) {
Log.e(TAG, "error loading albums", exception);
}
} catch (Exception exception) {
Log.e(TAG, "error loading albums", exception);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,51 @@
* Used to query Audio and return the Song for a particular album.
*
* @author Andrew Neal ([email protected])
* @author nuclearfog
*/
public class AlbumSongLoader extends WrappedAsyncTaskLoader<List<Song>> {
public class AlbumSongLoader extends AsyncExecutor<Long, List<Song>> {

private static final String TAG = "AlbumSongLoader";

/**
* The Id of the album the songs belong to.
*/
private Long mAlbumID;

/**
* Constructor of <code>AlbumSongHandler</code>
*
* @param context The {@link Context} to use.
* @param albumId The Id of the album the songs belong to.
*/
public AlbumSongLoader(Context context, long albumId) {
public AlbumSongLoader(Context context) {
super(context);
mAlbumID = albumId;
}

/**
* {@inheritDoc}
*/

@Override
public List<Song> loadInBackground() {
protected List<Song> doInBackground(Long param) {
List<Song> result = new LinkedList<>();
try {
// Create the Cursor
Cursor mCursor = CursorFactory.makeAlbumSongCursor(getContext(), mAlbumID);
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the song Id
long id = mCursor.getLong(0);
// Copy the song name
String songName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the album name
String album = mCursor.getString(3);
// Copy the duration
long duration = mCursor.getLong(4);
// Create a new song
Song song = new Song(id, songName, artist, album, duration);
// Add everything up
result.add(song);
} while (mCursor.moveToNext());
Context context = getContext();
if (context != null && param != null) {
try {
// Create the Cursor
Cursor mCursor = CursorFactory.makeAlbumSongCursor(context, param);
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the song Id
long id = mCursor.getLong(0);
// Copy the song name
String songName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the album name
String album = mCursor.getString(3);
// Copy the duration
long duration = mCursor.getLong(4);
// Create a new song
Song song = new Song(id, songName, artist, album, duration);
// Add everything up
result.add(song);
} while (mCursor.moveToNext());
}
mCursor.close();
}
mCursor.close();
} catch (Exception exception) {
Log.e(TAG, "error loading songs from album", exception);
}
} catch (Exception exception) {
Log.e(TAG, "error loading songs from album", exception);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,60 +25,51 @@
* Used to return the albums for a particular artist.
*
* @author Andrew Neal ([email protected])
* @author nuclearfog
*/
public class ArtistAlbumLoader extends WrappedAsyncTaskLoader<List<Album>> {
public class ArtistAlbumLoader extends AsyncExecutor<Long, List<Album>> {

private static final String TAG = "ArtistAlbumLoader";

/**
* The Id of the artist the albums belong to.
*/
private long mArtistID;

/**
* Constructor of <code>ArtistAlbumHandler</code>
*
* @param context The {@link Context} to use.
* @param artistId The Id of the artist the albums belong to.
*/
public ArtistAlbumLoader(Context context, Long artistId) {
public ArtistAlbumLoader(Context context) {
super(context);
mArtistID = artistId;
}

/**
* {@inheritDoc}
*/

@Override
public List<Album> loadInBackground() {
protected List<Album> doInBackground(Long param) {
List<Album> result = new LinkedList<>();
try {
// Create the Cursor
Cursor mCursor = CursorFactory.makeArtistAlbumCursor(getContext(), mArtistID);
// Gather the dataS
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the album id
long id = mCursor.getLong(0);
// Copy the album name
String albumName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// Copy the release year
String year = mCursor.getString(4);
// Create a new album
Album album = new Album(id, albumName, artist, songCount, year, true);
// Add everything up
result.add(album);
} while (mCursor.moveToNext());
Context context = getContext();
if (context != null && param != null) {
try {
// Create the Cursor
Cursor mCursor = CursorFactory.makeArtistAlbumCursor(context, param);
// Gather the dataS
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the album id
long id = mCursor.getLong(0);
// Copy the album name
String albumName = mCursor.getString(1);
// Copy the artist name
String artist = mCursor.getString(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// Copy the release year
String year = mCursor.getString(4);
// Create a new album
Album album = new Album(id, albumName, artist, songCount, year, true);
// Add everything up
result.add(album);
} while (mCursor.moveToNext());
}
mCursor.close();
}
mCursor.close();
} catch (Exception exception) {
Log.e(TAG, "error loading albums from artist", exception);
}
} catch (Exception exception) {
Log.e(TAG, "error loading albums from artist", exception);
}
return result;
}
Expand Down
65 changes: 34 additions & 31 deletions app/src/main/java/org/nuclearfog/apollo/loaders/ArtistLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,57 +28,60 @@
* Used to return the artists on a user's device.
*
* @author Andrew Neal ([email protected])
* @author nuclearfog
*/
public class ArtistLoader extends WrappedAsyncTaskLoader<List<Artist>> {
public class ArtistLoader extends AsyncExecutor<Void, List<Artist>> {

private static final String TAG = "ArtistLoader";

private ExcludeStore exclude_db;

/**
* Constructor of <code>ArtistLoader</code>
*
* @param context The {@link Context} to use
*/
public ArtistLoader(Context context) {
super(context);
exclude_db = ExcludeStore.getInstance(context);
}

/**
* {@inheritDoc}
*/
@Override
public List<Artist> loadInBackground() {
protected List<Artist> doInBackground(Void v) {
List<Artist> result = new LinkedList<>();
try {
Set<Long> excluded_ids = exclude_db.getIds(Type.ARTIST);
// Create the Cursor
Cursor mCursor = CursorFactory.makeArtistCursor(getContext());
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the artist id
long id = mCursor.getLong(0);
// Copy the artist name
String artistName = mCursor.getString(1);
// Copy the number of albums
int albumCount = mCursor.getInt(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// visibility of the artist
boolean visible = !excluded_ids.contains(id);
// Create a new artist
Artist artist = new Artist(id, artistName, songCount, albumCount, visible);
// Add everything up
result.add(artist);
} while (mCursor.moveToNext());
Context context = getContext();
if (context != null) {
ExcludeStore exclude_db = ExcludeStore.getInstance(context);
try {
// init filter list
Set<Long> excluded_ids = exclude_db.getIds(Type.ARTIST);
// Create the Cursor
Cursor mCursor = CursorFactory.makeArtistCursor(context);
// Gather the data
if (mCursor != null) {
if (mCursor.moveToFirst()) {
do {
// Copy the artist id
long id = mCursor.getLong(0);
// Copy the artist name
String artistName = mCursor.getString(1);
// Copy the number of albums
int albumCount = mCursor.getInt(2);
// Copy the number of songs
int songCount = mCursor.getInt(3);
// visibility of the artist
boolean visible = !excluded_ids.contains(id);
// Create a new artist
Artist artist = new Artist(id, artistName, songCount, albumCount, visible);
// Add everything up
result.add(artist);
} while (mCursor.moveToNext());
}
mCursor.close();
}
mCursor.close();
} catch (Exception exception) {
Log.e(TAG, "error loading artists", exception);
}
} catch (Exception exception) {
Log.e(TAG, "error loading artists", exception);
}
return result;
}
Expand Down
Loading

0 comments on commit daa445d

Please sign in to comment.