use of android.support.annotation.WorkerThread in project bugzy by cpunq.
the class SearchSuggestionRepository method insertDefaultSearchSuggestions.
@WorkerThread
public void insertDefaultSearchSuggestions() {
List<SearchSuggestion> suggestions = new ArrayList<>();
List<String> orderingOptions = getOrderringOptions();
for (String option : orderingOptions) {
String text = "orderBy:" + option;
String id = "orderby:" + option;
suggestions.add(new SearchSuggestion(id, text, SearchSuggestionType.ORDER_BY));
}
for (int i = 1; i < 8; i++) {
String text = "priority:" + i;
suggestions.add(new SearchSuggestion(text, text, SearchSuggestionType.PRIORITY));
}
for (String option : getLastEditOptions()) {
String text = "lastEdited:" + option;
String id = "lastedited:" + option.replace("'", "");
suggestions.add(new SearchSuggestion(id, text, SearchSuggestionType.LAST_EDITED));
}
for (String option : getLastEditOptions()) {
String text = "opened:" + option;
String id = "opened:" + option.replace("'", "");
suggestions.add(new SearchSuggestion(id, text, SearchSuggestionType.OPENED));
}
for (String option : getLastEditOptions()) {
String text = "closed:" + option;
String id = "closed:" + option.replace("'", "");
suggestions.add(new SearchSuggestion(id, text, SearchSuggestionType.CLOSED));
}
String text = "status:active";
suggestions.add(new SearchSuggestion(text, text, SearchSuggestionType.STATUS));
text = "status:closed";
suggestions.add(new SearchSuggestion(text, text, SearchSuggestionType.STATUS));
text = "status:open";
suggestions.add(new SearchSuggestion(text, text, SearchSuggestionType.STATUS));
text = "status:resolved";
suggestions.add(new SearchSuggestion(text, text, SearchSuggestionType.STATUS));
db.miscDao().insertSearchSuggestions(suggestions);
}
use of android.support.annotation.WorkerThread in project PainlessMusicPlayer by Doctoror.
the class QueueActivity method onPlaybackStateChanged.
@WorkerThread
private void onPlaybackStateChanged(@NonNull final PlaybackState state) {
final Media media = state == PlaybackState.STATE_PLAYING ? currentMediaProvider.getCurrentMedia() : null;
// noinspection WrongThread
runOnUiThread(() -> onNowPlayingMediaChanged(media));
}
use of android.support.annotation.WorkerThread in project PainlessMusicPlayer by Doctoror.
the class MediaStoreMediaProvider method loadMediaList.
@NonNull
@WorkerThread
private List<Media> loadMediaList(@NonNull final Uri contentUri, @Nullable final String selection, @Nullable final String[] selectionArgs, @Nullable final String orderBy, @Nullable final Integer limit) {
List<Media> result = null;
final StringBuilder order = new StringBuilder(128);
if (orderBy != null) {
order.append(orderBy);
}
if (limit != null) {
if (order.length() == 0) {
throw new IllegalArgumentException("Cannot use LIMIT without ORDER BY");
}
order.append(" LIMIT ").append(limit);
}
final Cursor c = mContentResolver.query(contentUri, MediaQuery.PROJECTION, selection, selectionArgs, order.length() == 0 ? null : order.toString());
if (c != null) {
result = new ArrayList<>(c.getCount());
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
result.add(mediaFromCursor(c));
}
c.close();
}
return result == null ? new ArrayList<>() : result;
}
use of android.support.annotation.WorkerThread in project PainlessMusicPlayer by Doctoror.
the class QueueProviderTracksMediaStore method queueFromTracksSearch.
@NonNull
@WorkerThread
private List<Media> queueFromTracksSearch(@Nullable final String query) {
final List<Long> ids = new ArrayList<>(15);
final StringBuilder sel = new StringBuilder(256);
sel.append(MediaStoreTracksProvider.SELECTION_NON_HIDDEN_MUSIC);
if (!TextUtils.isEmpty(query)) {
final String likeQuery = " LIKE " + SqlUtils.escapeAndWrapForLikeArgument(query);
sel.append(" AND (").append(MediaStore.Audio.Media.TITLE).append(likeQuery);
sel.append(" OR ").append(MediaStore.Audio.Media.ARTIST).append(likeQuery);
sel.append(" OR ").append(MediaStore.Audio.Media.ALBUM).append(likeQuery);
sel.append(')');
}
final List<Media> fromProvider = mMediaProvider.load(sel.toString(), null, MediaStore.Audio.Media.ALBUM + ',' + MediaStore.Audio.Media.TRACK, QueueConfig.MAX_QUEUE_SIZE).take(1).blockingFirst();
for (final Media media : fromProvider) {
ids.add(media.getId());
}
if (!TextUtils.isEmpty(query) && fromProvider.size() < QueueConfig.MAX_QUEUE_SIZE) {
// Search in genres for tracks with media ids that do not match found ids
Cursor c = mContentResolver.query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI, new String[] { BaseColumns._ID }, MediaStore.Audio.Genres.NAME + "=?", new String[] { StringUtils.capWords(query) }, null);
Long genreId = null;
if (c != null) {
try {
if (c.moveToFirst()) {
genreId = c.getLong(0);
}
} finally {
c.close();
}
}
if (genreId != null) {
fromProvider.addAll(mMediaProvider.load(MediaStore.Audio.Genres.Members.getContentUri(MediaStoreVolumeNames.EXTERNAL, genreId), SelectionUtils.notInSelection(MediaStore.Audio.Media._ID, ids), null, "RANDOM()", QueueConfig.MAX_QUEUE_SIZE - ids.size()).take(1).blockingFirst());
}
}
return fromProvider;
}
use of android.support.annotation.WorkerThread in project PainlessMusicPlayer by Doctoror.
the class PlaybackDataImpl method storeToRecentAlbums.
/**
* Finds albums in queue and stores them in recently played albums.
* Album is a sequence of tracks with the same album id.
* Single playlist can be a concatination of multiple albums.
*
* @param queue The queue to process
*/
@WorkerThread
private void storeToRecentAlbums(@Nullable final List<Media> queue) {
if (queue != null && !queue.isEmpty()) {
final Set<Long> albums = new LinkedHashSet<>();
// number of items per single album
final long THRESHOLD = 4;
long prevAlbumId = -1;
int sequence = 1;
boolean first = true;
for (final Media item : queue) {
if (first) {
first = false;
prevAlbumId = item.getAlbumId();
} else {
final long albumId = item.getAlbumId();
if (albumId == prevAlbumId) {
sequence++;
} else {
if (sequence >= THRESHOLD) {
albums.add(prevAlbumId);
}
sequence = 1;
prevAlbumId = albumId;
}
}
}
if (sequence >= THRESHOLD) {
albums.add(prevAlbumId);
}
mRecentActivityManager.onAlbumsPlayed(albums);
}
}
Aggregations