Search in sources :

Example 1 with SettingsManager

use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.

the class LibraryController method setupViewPager.

private void setupViewPager() {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext());
    CategoryItem.getCategoryItems(sharedPreferences);
    if (pagerAdapter != null && refreshPagerAdapter) {
        pagerAdapter.removeAllChildFragments();
        refreshPagerAdapter = false;
        pager.setAdapter(null);
    }
    int defaultPage = 1;
    pagerAdapter = new PagerAdapter(getChildFragmentManager());
    List<CategoryItem> categoryItems = Stream.of(CategoryItem.getCategoryItems(sharedPreferences)).filter(categoryItem -> categoryItem.isChecked).toList();
    int defaultPageType = settingsManager.getDefaultPageType();
    for (int i = 0; i < categoryItems.size(); i++) {
        CategoryItem categoryItem = categoryItems.get(i);
        pagerAdapter.addFragment(categoryItem.getFragment(getContext()));
        if (categoryItem.type == defaultPageType) {
            defaultPage = i;
        }
    }
    int currentPage = Math.min(defaultPage, pagerAdapter.getCount());
    pager.setAdapter(pagerAdapter);
    pager.setOffscreenPageLimit(pagerAdapter.getCount() - 1);
    pager.setCurrentItem(currentPage);
    slidingTabLayout.setupWithViewPager(pager);
    pager.postDelayed(() -> {
        if (pager != null) {
            new RatingSnackbar(settingsManager, analyticsManager).show(pager, () -> {
                ShuttleUtils.openShuttleLink(getActivity(), getActivity().getPackageName(), getActivity().getPackageManager());
                return Unit.INSTANCE;
            });
        }
    }, 1000);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) NavigationEventRelay(com.simplecity.amp_library.ui.screens.drawer.NavigationEventRelay) Bundle(android.os.Bundle) PlaylistDetailFragment(com.simplecity.amp_library.ui.screens.playlist.detail.PlaylistDetailFragment) AlbumDetailFragment(com.simplecity.amp_library.ui.screens.album.detail.AlbumDetailFragment) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) CategoryItem(com.simplecity.amp_library.model.CategoryItem) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) BindView(butterknife.BindView) Aesthetic(com.afollestad.aesthetic.Aesthetic) View(android.view.View) ViewCompat(android.support.v4.view.ViewCompat) Transition(android.transition.Transition) PreferenceManager(android.preference.PreferenceManager) Unbinder(butterknife.Unbinder) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CastManager(com.simplecity.amp_library.cast.CastManager) AlbumListFragment(com.simplecity.amp_library.ui.screens.album.list.AlbumListFragment) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) AppCompatActivity(android.support.v7.app.AppCompatActivity) ViewGroup(android.view.ViewGroup) BaseFragment(com.simplecity.amp_library.ui.common.BaseFragment) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Unit(kotlin.Unit) SearchFragment(com.simplecity.amp_library.ui.screens.search.SearchFragment) ContextualToolbarHost(com.simplecity.amp_library.ui.views.ContextualToolbarHost) Nullable(android.support.annotation.Nullable) AppBarLayout(android.support.design.widget.AppBarLayout) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) ButterKnife(butterknife.ButterKnife) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) ViewPager(android.support.v4.view.ViewPager) NonNull(android.support.annotation.NonNull) ArtistDetailFragment(com.simplecity.amp_library.ui.screens.artist.detail.ArtistDetailFragment) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) TabLayout(android.support.design.widget.TabLayout) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) GenreDetailFragment(com.simplecity.amp_library.ui.screens.genre.detail.GenreDetailFragment) GenreListFragment(com.simplecity.amp_library.ui.screens.genre.list.GenreListFragment) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) CastButtonFactory(com.google.android.gms.cast.framework.CastButtonFactory) PlaylistListFragment(com.simplecity.amp_library.ui.screens.playlist.list.PlaylistListFragment) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) ToolbarListener(com.simplecity.amp_library.ui.common.ToolbarListener) SuggestedFragment(com.simplecity.amp_library.ui.screens.suggested.SuggestedFragment) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Pair(android.support.v4.util.Pair) TransitionInflater(android.transition.TransitionInflater) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) AlbumArtistListFragment(com.simplecity.amp_library.ui.screens.artist.list.AlbumArtistListFragment) SharedPreferences(android.content.SharedPreferences) PagerAdapter(com.simplecity.amp_library.ui.adapters.PagerAdapter) CategoryItem(com.simplecity.amp_library.model.CategoryItem) RatingSnackbar(com.simplecity.amp_library.ui.views.RatingSnackbar)

Example 2 with SettingsManager

use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.

the class FolderFragment method changeDir.

@SuppressLint("CheckResult")
public void changeDir(File newDir) {
    disposables.add(Single.zip(whitelistRepository.getWhitelistItems(songsRepository).first(Collections.emptyList()), blacklistRepository.getBlacklistItems(songsRepository).first(Collections.emptyList()), Single.fromCallable(() -> {
        final String path = FileHelper.getPath(newDir);
        if (TextUtils.isEmpty(path)) {
            return new ArrayList<>();
        }
        currentDir = path;
        return fileBrowser.loadDir(new File(path));
    }), (Function3<List<InclExclItem>, List<InclExclItem>, List<BaseFileObject>, List<ViewModel>>) (whitelist, blacklist, baseFileObjects) -> {
        List<ViewModel> items = Stream.of(baseFileObjects).map(baseFileObject -> {
            // Look for an existing FolderView wrapping the BaseFileObject, we'll reuse it if it exists.
            FolderView folderView = (FolderView) Stream.of(adapter.items).filter(viewModel -> viewModel instanceof FolderView && (((FolderView) viewModel).baseFileObject.equals(baseFileObject))).findFirst().orElse(null);
            if (folderView == null) {
                folderView = new FolderView(baseFileObject, whitelistRepository, blacklistRepository, settingsManager, Stream.of(whitelist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)), Stream.of(blacklist).anyMatch(inclExclItem -> inclExclItem.path.equals(baseFileObject.path)));
                folderView.setShowWhitelist(isShowingWhitelist);
                folderView.setShowBlacklist(isShowingBlacklist);
                folderView.setClickListener(FolderFragment.this);
            }
            return folderView;
        }).collect(Collectors.toList());
        if (showBreadcrumbsInList && breadcrumbsView != null) {
            breadcrumbsView.setBreadcrumbsPath(currentDir);
            breadcrumbsView.setListener(FolderFragment.this);
            items.add(0, breadcrumbsView);
        }
        return items;
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(adaptableItems -> {
        if (adapter != null) {
            analyticsManager.dropBreadcrumb(TAG, "setItems()");
            setItemsDisposable = adapter.setItems(adaptableItems);
        }
        if (breadcrumb != null) {
            breadcrumb.changeBreadcrumbPath(currentDir);
        }
        if (adapter != null) {
            changeBreadcrumbPath();
        }
        updateMenuItems();
    }, error -> LogUtils.logException(TAG, "Error changing dir", error)));
}
Also used : R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) PlaylistManager(com.simplecity.amp_library.utils.playlists.PlaylistManager) Rx.onErrorLogAndRethrow(com.afollestad.aesthetic.Rx.onErrorLogAndRethrow) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) AnalyticsManager(com.simplecity.amp_library.utils.AnalyticsManager) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Song(com.simplecity.amp_library.model.Song) Aesthetic(com.afollestad.aesthetic.Aesthetic) CheckBox(android.widget.CheckBox) SongInfoDialog(com.simplecity.amp_library.ui.dialog.SongInfoDialog) TaggerDialog(com.simplecity.amp_library.ui.screens.tagger.TaggerDialog) View(android.view.View) RingtoneManager(com.simplecity.amp_library.utils.RingtoneManager) Schedulers(io.reactivex.schedulers.Schedulers) Unbinder(butterknife.Unbinder) BackPressListener(test.com.androidnavigation.fragment.BackPressListener) LogUtils(com.simplecity.amp_library.utils.LogUtils) ContextualToolbarHelper(com.simplecity.amp_library.utils.ContextualToolbarHelper) FileHelper(com.simplecity.amp_library.utils.FileHelper) PopupMenu(android.support.v7.widget.PopupMenu) ViewGroup(android.view.ViewGroup) Breadcrumb(com.simplecity.amp_library.interfaces.Breadcrumb) BaseFragment(com.simplecity.amp_library.ui.common.BaseFragment) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) SongExtKt(com.simplecity.amp_library.utils.extensions.SongExtKt) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) List(java.util.List) Unit(kotlin.Unit) NotNull(org.jetbrains.annotations.NotNull) InclExclItem(com.simplecity.amp_library.model.InclExclItem) IntStream(com.annimon.stream.IntStream) BreadcrumbListener(com.simplecity.amp_library.interfaces.BreadcrumbListener) FileType(com.simplecity.amp_library.interfaces.FileType) AppBarLayout(android.support.design.widget.AppBarLayout) Stream(com.annimon.stream.Stream) ButterKnife(butterknife.ButterKnife) ContextualToolbar(com.simplecity.amp_library.ui.views.ContextualToolbar) RecyclerListener(com.simplecityapps.recycler_adapter.recyclerview.RecyclerListener) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) SelectableViewModel(com.simplecity.amp_library.ui.modelviews.SelectableViewModel) Single(io.reactivex.Single) FolderView(com.simplecity.amp_library.ui.modelviews.FolderView) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) Repository(com.simplecity.amp_library.data.Repository) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) ViewBackgroundAction(com.afollestad.aesthetic.ViewBackgroundAction) BaseFileObject(com.simplecity.amp_library.model.BaseFileObject) Observable(io.reactivex.Observable) Rx.distinctToMainThread(com.afollestad.aesthetic.Rx.distinctToMainThread) Nullable(io.reactivex.annotations.Nullable) MenuUtils(com.simplecity.amp_library.utils.menu.MenuUtils) Collectors(com.annimon.stream.Collectors) FileBrowser(com.simplecity.amp_library.utils.FileBrowser) LayoutInflater(android.view.LayoutInflater) Function3(io.reactivex.functions.Function3) ThemedStatusBarView(com.simplecity.amp_library.ui.views.ThemedStatusBarView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) TextUtils(android.text.TextUtils) SortManager(com.simplecity.amp_library.utils.sorting.SortManager) File(java.io.File) RecyclerView(android.support.v7.widget.RecyclerView) DrawerLockManager(com.simplecity.amp_library.ui.screens.drawer.DrawerLockManager) Toolbar(android.support.v7.widget.Toolbar) BreadcrumbItem(com.simplecity.amp_library.ui.views.BreadcrumbItem) BreadcrumbsView(com.simplecity.amp_library.ui.modelviews.BreadcrumbsView) PlaylistMenuHelper(com.simplecity.amp_library.utils.playlists.PlaylistMenuHelper) FolderMenuUtils(com.simplecity.amp_library.utils.menu.folder.FolderMenuUtils) Collections(java.util.Collections) FolderView(com.simplecity.amp_library.ui.modelviews.FolderView) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) SuppressLint(android.annotation.SuppressLint)

Example 3 with SettingsManager

use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.

the class QueuePagerPresenter method bindView.

@Override
public void bindView(@NonNull QueuePagerView view) {
    super.bindView(view);
    IntentFilter filter = new IntentFilter();
    filter.addAction(InternalIntents.META_CHANGED);
    filter.addAction(InternalIntents.REPEAT_CHANGED);
    filter.addAction(InternalIntents.SHUFFLE_CHANGED);
    filter.addAction(InternalIntents.QUEUE_CHANGED);
    filter.addAction(InternalIntents.SERVICE_CONNECTED);
    addDisposable(RxBroadcast.fromBroadcast(application, filter).startWith(new Intent(InternalIntents.QUEUE_CHANGED)).toFlowable(BackpressureStrategy.LATEST).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> {
        final String action = intent.getAction();
        QueuePagerView queuePagerView = getView();
        if (queuePagerView == null) {
            return;
        }
        if (action != null) {
            switch(action) {
                case InternalIntents.META_CHANGED:
                    queuePagerView.updateQueuePosition(mediaManager.getQueuePosition());
                    break;
                case InternalIntents.REPEAT_CHANGED:
                case InternalIntents.SHUFFLE_CHANGED:
                case InternalIntents.QUEUE_CHANGED:
                case InternalIntents.SERVICE_CONNECTED:
                    List<ViewModel> items = Stream.of(mediaManager.getQueue()).map(queueItem -> new QueuePagerItemView(queueItem.getSong(), requestManager, settingsManager)).collect(Collectors.toList());
                    queuePagerView.loadData(items, mediaManager.getQueuePosition());
                    break;
            }
        }
    }));
}
Also used : QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) BackpressureStrategy(io.reactivex.BackpressureStrategy) Collectors(com.annimon.stream.Collectors) Stream(com.annimon.stream.Stream) MediaManager(com.simplecity.amp_library.playback.MediaManager) IntentFilter(android.content.IntentFilter) Intent(android.content.Intent) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) NonNull(android.support.annotation.NonNull) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) Inject(javax.inject.Inject) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) List(java.util.List) InternalIntents(com.simplecity.amp_library.playback.constants.InternalIntents) RequestManager(com.bumptech.glide.RequestManager) Presenter(com.simplecity.amp_library.ui.common.Presenter) IntentFilter(android.content.IntentFilter) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) Intent(android.content.Intent) List(java.util.List)

Example 4 with SettingsManager

use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.

the class QueuePagerFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_queue_pager, container, false);
    unbinder = ButterKnife.bind(this, rootView);
    LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
    if (ShuttleUtils.isLandscape(getContext())) {
        textProtectionScrim.setVisibility(View.GONE);
    }
    recyclerView.setNestedScrollingEnabled(false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setAdapter(viewModelAdapter);
    SnapHelper snapHelper = new PagerSnapHelper() {

        @Override
        public int findTargetSnapPosition(RecyclerView.LayoutManager layoutManager, int velocityX, int velocityY) {
            int snapPosition = super.findTargetSnapPosition(layoutManager, velocityX, velocityY);
            if (snapPosition < viewModelAdapter.items.size()) {
                Observable.timer(200, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(o -> {
                    if (mediaManager.getQueuePosition() != snapPosition) {
                        mediaManager.setQueuePosition(snapPosition);
                    }
                }, throwable -> LogUtils.logException(TAG, "Error setting queue position", throwable));
            }
            return snapPosition;
        }
    };
    snapHelper.attachToRecyclerView(recyclerView);
    recyclerView.addOnScrollListener(new RecyclerViewPreloader<>(new ListPreloader.PreloadModelProvider<QueuePagerItemView>() {

        @Override
        public List<QueuePagerItemView> getPreloadItems(int position) {
            QueuePagerItemView queuePagerItemView = (QueuePagerItemView) viewModelAdapter.items.get(position);
            return Collections.singletonList(queuePagerItemView);
        }

        @Override
        public GenericRequestBuilder getPreloadRequestBuilder(QueuePagerItemView item) {
            return requestManager.load(item.song).diskCacheStrategy(DiskCacheStrategy.SOURCE).error(PlaceholderProvider.getInstance(getContext()).getPlaceHolderDrawable(item.song.name, true, settingsManager));
        }
    }, (item, adapterPosition, perItemPosition) -> imageSize, 3));
    recyclerView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {

        @Override
        public boolean onPreDraw() {
            // This null check doesn't make sense to me, but there was an NPE here..
            if (recyclerView != null) {
                imageSize = new int[] { recyclerView.getWidth(), recyclerView.getHeight() };
                recyclerView.getViewTreeObserver().removeOnPreDrawListener(this);
            }
            return false;
        }
    });
    return rootView;
}
Also used : R(com.simplecity.amp_library.R) Context(android.content.Context) Bundle(android.os.Bundle) SnapHelper(android.support.v7.widget.SnapHelper) ButterKnife(butterknife.ButterKnife) ViewModelAdapter(com.simplecityapps.recycler_adapter.adapter.ViewModelAdapter) ViewModel(com.simplecityapps.recycler_adapter.model.ViewModel) NonNull(android.support.annotation.NonNull) RequestManagerProvider(com.simplecity.amp_library.ui.common.RequestManagerProvider) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Inject(javax.inject.Inject) GenericRequestBuilder(com.bumptech.glide.GenericRequestBuilder) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RequestManager(com.bumptech.glide.RequestManager) ListPreloader(com.bumptech.glide.ListPreloader) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) View(android.view.View) Observable(io.reactivex.Observable) Unbinder(butterknife.Unbinder) PlaceholderProvider(com.simplecity.amp_library.utils.PlaceholderProvider) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) LogUtils(com.simplecity.amp_library.utils.LogUtils) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) LayoutInflater(android.view.LayoutInflater) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ViewGroup(android.view.ViewGroup) RecyclerViewPreloader(com.simplecity.amp_library.glide.preloader.RecyclerViewPreloader) BaseFragment(com.simplecity.amp_library.ui.common.BaseFragment) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) TimeUnit(java.util.concurrent.TimeUnit) RecyclerView(android.support.v7.widget.RecyclerView) List(java.util.List) ViewTreeObserver(android.view.ViewTreeObserver) Collections(java.util.Collections) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) BindView(butterknife.BindView) View(android.view.View) QueuePagerItemView(com.simplecity.amp_library.ui.modelviews.QueuePagerItemView) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) SnapHelper(android.support.v7.widget.SnapHelper) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) ViewTreeObserver(android.view.ViewTreeObserver)

Example 5 with SettingsManager

use of com.simplecity.amp_library.utils.SettingsManager in project Shuttle by timusus.

the class DeleteDialog method deleteSongsOrShowSafDialog.

@SuppressLint("CheckResult")
void deleteSongsOrShowSafDialog() {
    disposables.add(getSongs().map(songs -> {
        // Keep track of the songs we want to delete, for later.
        Stream.of(songs).forEach(song -> {
            if (SafManager.getInstance(getContext(), settingsManager).requiresPermission(new File(song.path))) {
                songsForSafDeletion.add(song);
            } else {
                songsForNormalDeletion.add(song);
            }
        });
        boolean requiresSafDialog = false;
        if (!songsForSafDeletion.isEmpty()) {
            // We're gonna need SAF access to delete some songs.
            // We may be able to build a list of document files if the user has been here before..
            List<DocumentFile> documentFiles = SafManager.getInstance(getContext(), settingsManager).getWriteableDocumentFiles(Stream.of(songsForSafDeletion).map(song -> new File(song.path)).toList());
            if (documentFiles.size() == songsForSafDeletion.size()) {
                // We have all the document files we need. No need to show SAF dialog.
                this.documentFilesForDeletion.addAll(documentFiles);
            } else {
                // We'll have to show the SAF dialog
                requiresSafDialog = true;
            }
        }
        return requiresSafDialog;
    }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(requiresSafDialog -> {
        if (requiresSafDialog) {
            if (DeleteDialog.this.isAdded()) {
                SafManager.SafDialog.show(DeleteDialog.this);
            } else {
                LogUtils.logException(TAG, "Failed to delete songs.. Couldn't show SAFDialog", null);
                Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
            }
        } else {
            disposables.add(deleteSongs().observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(deletedSongs -> {
                if (DeleteDialog.this.isAdded()) {
                    if (deletedSongs > 0) {
                        Toast.makeText(getContext(), getString(R.string.delete_songs_success_toast, deletedSongs), Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
                    }
                    dismiss();
                }
            }, error -> {
                LogUtils.logException(TAG, "Failed to delete songs", error);
                if (DeleteDialog.this.isAdded()) {
                    Toast.makeText(getContext(), getString(R.string.delete_songs_failure_toast), Toast.LENGTH_SHORT).show();
                }
            }));
        }
    }, error -> LogUtils.logException(TAG, "Failed to delete songs", error)));
}
Also used : ContentProviderOperation(android.content.ContentProviderOperation) R(com.simplecity.amp_library.R) Bundle(android.os.Bundle) Album(com.simplecity.amp_library.model.Album) Stream(com.annimon.stream.Stream) Completable(io.reactivex.Completable) Uri(android.net.Uri) Dialog(android.app.Dialog) RemoteException(android.os.RemoteException) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) DialogFragment(android.support.v4.app.DialogFragment) PlayCountTable(com.simplecity.amp_library.sql.providers.PlayCountTable) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Song(com.simplecity.amp_library.model.Song) SuppressLint(android.annotation.SuppressLint) Repository(com.simplecity.amp_library.data.Repository) Toast(android.widget.Toast) SafManager(com.simplecity.amp_library.saf.SafManager) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) CustomMediaScanner(com.simplecity.amp_library.utils.CustomMediaScanner) Supplier(com.annimon.stream.function.Supplier) LogUtils(com.simplecity.amp_library.utils.LogUtils) Collectors(com.annimon.stream.Collectors) MediaManager(com.simplecity.amp_library.playback.MediaManager) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) File(java.io.File) OperationApplicationException(android.content.OperationApplicationException) Serializable(java.io.Serializable) SongExtKt(com.simplecity.amp_library.utils.extensions.SongExtKt) FragmentManager(android.support.v4.app.FragmentManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) List(java.util.List) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) Nullable(android.support.annotation.Nullable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) Collections(java.util.Collections) DocumentFile(android.support.v4.provider.DocumentFile) AlbumExtKt(com.simplecity.amp_library.utils.extensions.AlbumExtKt) DocumentFile(android.support.v4.provider.DocumentFile) File(java.io.File) DocumentFile(android.support.v4.provider.DocumentFile) SuppressLint(android.annotation.SuppressLint)

Aggregations

SettingsManager (com.simplecity.amp_library.utils.SettingsManager)5 List (java.util.List)5 Inject (javax.inject.Inject)5 Bundle (android.os.Bundle)4 NonNull (android.support.annotation.NonNull)4 Stream (com.annimon.stream.Stream)4 R (com.simplecity.amp_library.R)4 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 ViewGroup (android.view.ViewGroup)3 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)3 SuppressLint (android.annotation.SuppressLint)2 IntentFilter (android.content.IntentFilter)2 Nullable (android.support.annotation.Nullable)2 AppBarLayout (android.support.design.widget.AppBarLayout)2 Toolbar (android.support.v7.widget.Toolbar)2 Menu (android.view.Menu)2 MenuInflater (android.view.MenuInflater)2 MenuItem (android.view.MenuItem)2 BindView (butterknife.BindView)2