Search in sources :

Example 1 with Predicate

use of com.annimon.stream.function.Predicate in project Shuttle by timusus.

the class MusicService method openFile.

/**
     * Opens a file and prepares it for playback
     *
     * @param path The path of the file to open
     */
public void openFile(String path, @Nullable Action0 completion) {
    synchronized (this) {
        if (path == null) {
            return;
        }
        Uri uri = Uri.parse(path);
        long id = -1;
        try {
            id = Long.valueOf(uri.getLastPathSegment());
        } catch (NumberFormatException ignored) {
        }
        Predicate<Song> predicate;
        long finalId = id;
        if (finalId != -1 && (path.startsWith(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI.toString()) || path.startsWith(MediaStore.Files.getContentUri("external").toString()))) {
            predicate = song -> song.id == finalId;
        } else {
            if (uri != null && path.startsWith("content://")) {
                path = uri.getPath();
            }
            String finalPath = path;
            predicate = song -> song.path.contains(finalPath);
        }
        DataManager.getInstance().getSongsRelay().first().map(songs -> Stream.of(songs).filter(predicate).collect(Collectors.toList())).subscribe(songs -> {
            if (!songs.isEmpty()) {
                currentSong = songs.get(0);
                open(currentSong);
                if (completion != null) {
                    completion.call();
                }
            }
        });
    }
}
Also used : R(com.simplecity.amp_library.R) WidgetProviderSmall(com.simplecity.amp_library.ui.widgets.WidgetProviderSmall) Bundle(android.os.Bundle) WebImage(com.google.android.gms.common.images.WebImage) PackageManager(android.content.pm.PackageManager) CrashlyticsCore(com.crashlytics.android.core.CrashlyticsCore) PlaylistUtils(com.simplecity.amp_library.utils.PlaylistUtils) Uri(android.net.Uri) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Random(java.util.Random) PendingIntent(android.app.PendingIntent) MediaSessionCompat(android.support.v4.media.session.MediaSessionCompat) Action1(rx.functions.Action1) Drawable(android.graphics.drawable.Drawable) IBinder(android.os.IBinder) WakeLock(android.os.PowerManager.WakeLock) Song(com.simplecity.amp_library.model.Song) Manifest(android.Manifest) SQLiteException(android.database.sqlite.SQLiteException) PowerManager(android.os.PowerManager) MediaMetadataCompat(android.support.v4.media.MediaMetadataCompat) Handler(android.os.Handler) Looper(android.os.Looper) MediaStore(android.provider.MediaStore) Map(java.util.Map) Schedulers(rx.schedulers.Schedulers) PreferenceManager(android.preference.PreferenceManager) PlaybackStateCompat(android.support.v4.media.session.PlaybackStateCompat) Log(android.util.Log) WidgetProviderLarge(com.simplecity.amp_library.ui.widgets.WidgetProviderLarge) RemoteViews(android.widget.RemoteViews) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) NotificationManager(android.app.NotificationManager) Service(android.app.Service) IntentFilter(android.content.IntentFilter) ContextCompat(android.support.v4.content.ContextCompat) MediaStatus(com.google.android.gms.cast.MediaStatus) MediaButtonIntentReceiver(com.simplecity.amp_library.utils.MediaButtonIntentReceiver) NoConnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.NoConnectionException) BuildConfig(com.simplecity.amp_library.BuildConfig) VideoCastManager(com.google.android.libraries.cast.companionlibrary.cast.VideoCastManager) BroadcastReceiver(android.content.BroadcastReceiver) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) List(java.util.List) Action0(rx.functions.Action0) WidgetProviderMedium(com.simplecity.amp_library.ui.widgets.WidgetProviderMedium) Notification(android.app.Notification) GlideUtils(com.simplecity.amp_library.glide.utils.GlideUtils) ContentValues(android.content.ContentValues) Nullable(android.support.annotation.Nullable) BluetoothDevice(android.bluetooth.BluetoothDevice) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DrawableUtils(com.simplecity.amp_library.utils.DrawableUtils) Intent(android.content.Intent) SystemClock(android.os.SystemClock) AudioManager(android.media.AudioManager) ApplicationMetadata(com.google.android.gms.cast.ApplicationMetadata) HttpServer(com.simplecity.amp_library.http.HttpServer) ArrayList(java.util.ArrayList) Observable(rx.Observable) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SuppressLint(android.annotation.SuppressLint) BluetoothHeadset(android.bluetooth.BluetoothHeadset) Toast(android.widget.Toast) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) BluetoothA2dp(android.bluetooth.BluetoothA2dp) Build(android.os.Build) VideoCastConsumerImpl(com.google.android.libraries.cast.companionlibrary.cast.callbacks.VideoCastConsumerImpl) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) TransientNetworkDisconnectionException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.TransientNetworkDisconnectionException) EqualizerService(com.simplecity.amp_library.services.EqualizerService) Collectors(com.annimon.stream.Collectors) AlarmManager(android.app.AlarmManager) WidgetProviderExtraLarge(com.simplecity.amp_library.ui.widgets.WidgetProviderExtraLarge) ComponentName(android.content.ComponentName) MediaInfo(com.google.android.gms.cast.MediaInfo) TextUtils(android.text.TextUtils) CastException(com.google.android.libraries.cast.companionlibrary.cast.exceptions.CastException) AppWidgetManager(android.appwidget.AppWidgetManager) RemoteControlClient(android.media.RemoteControlClient) Glide(com.bumptech.glide.Glide) SharedPreferences(android.content.SharedPreferences) TreeMap(java.util.TreeMap) HandlerThread(android.os.HandlerThread) Bitmap(android.graphics.Bitmap) Crashlytics(com.crashlytics.android.Crashlytics) DataManager(com.simplecity.amp_library.utils.DataManager) OnAudioFocusChangeListener(android.media.AudioManager.OnAudioFocusChangeListener) Predicate(com.annimon.stream.function.Predicate) MediaMetadata(com.google.android.gms.cast.MediaMetadata) Collections(java.util.Collections) ContentUris(android.content.ContentUris) Song(com.simplecity.amp_library.model.Song) Uri(android.net.Uri)

Aggregations

Manifest (android.Manifest)1 SuppressLint (android.annotation.SuppressLint)1 AlarmManager (android.app.AlarmManager)1 Notification (android.app.Notification)1 NotificationManager (android.app.NotificationManager)1 PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 AppWidgetManager (android.appwidget.AppWidgetManager)1 BluetoothA2dp (android.bluetooth.BluetoothA2dp)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 BluetoothHeadset (android.bluetooth.BluetoothHeadset)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ComponentName (android.content.ComponentName)1 ContentUris (android.content.ContentUris)1 ContentValues (android.content.ContentValues)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1