Search in sources :

Example 86 with WorkerThread

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);
}
Also used : SearchSuggestion(in.bugzy.data.model.SearchSuggestion) ArrayList(java.util.ArrayList) WorkerThread(android.support.annotation.WorkerThread)

Example 87 with WorkerThread

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));
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) WorkerThread(android.support.annotation.WorkerThread)

Example 88 with WorkerThread

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;
}
Also used : Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 89 with WorkerThread

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;
}
Also used : ArrayList(java.util.ArrayList) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) Cursor(android.database.Cursor) WorkerThread(android.support.annotation.WorkerThread) NonNull(android.support.annotation.NonNull)

Example 90 with WorkerThread

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Media(com.doctoror.fuckoffmusicplayer.domain.queue.Media) WorkerThread(android.support.annotation.WorkerThread)

Aggregations

WorkerThread (android.support.annotation.WorkerThread)152 Cursor (android.database.Cursor)37 ArrayList (java.util.ArrayList)36 NonNull (android.support.annotation.NonNull)34 File (java.io.File)20 HashMap (java.util.HashMap)17 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)15 StorIOException (com.pushtorefresh.storio.StorIOException)15 IOException (java.io.IOException)13 ContentValues (android.content.ContentValues)11 Resources (android.content.res.Resources)10 Bitmap (android.graphics.Bitmap)10 Context (android.content.Context)8 Intent (android.content.Intent)7 SharedPreferences (android.content.SharedPreferences)7 Uri (android.net.Uri)7 Nullable (android.support.annotation.Nullable)7 VisibleForTesting (android.support.annotation.VisibleForTesting)7 Media (com.doctoror.fuckoffmusicplayer.domain.queue.Media)7 DashboardCategory (com.android.settingslib.drawer.DashboardCategory)6