Search in sources :

Example 1 with UnsafeAction

use of com.simplecity.amp_library.rx.UnsafeAction in project Shuttle by timusus.

the class MainController method onResume.

@Override
public void onResume() {
    super.onResume();
    if (delayHandler != null) {
        delayHandler.removeCallbacksAndMessages(null);
    }
    delayHandler = new Handler();
    disposables.add(navigationEventRelay.getEvents().observeOn(AndroidSchedulers.mainThread()).filter(NavigationEventRelay.NavigationEvent::isActionable).subscribe(navigationEvent -> {
        switch(navigationEvent.type) {
            case NavigationEventRelay.NavigationEvent.Type.LIBRARY_SELECTED:
                popToRootViewController();
                break;
            case NavigationEventRelay.NavigationEvent.Type.FOLDERS_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(FolderFragment.newInstance(getString(R.string.folders_title), false), "FolderFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SLEEP_TIMER_SELECTED:
                UnsafeAction showToast = () -> Toast.makeText(getContext(), R.string.sleep_timer_started, Toast.LENGTH_SHORT).show();
                SleepTimer.getInstance().getDialog(getContext(), () -> SleepTimer.getInstance().showMinutesDialog(getContext(), showToast), showToast).show();
                break;
            case NavigationEventRelay.NavigationEvent.Type.EQUALIZER_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(EqualizerFragment.newInstance(), "EqualizerFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SETTINGS_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_headers, R.string.settings), "Settings Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SUPPORT_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_support, R.string.pref_title_support), "Support Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.PLAYLIST_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(PlaylistDetailFragment.newInstance((Playlist) navigationEvent.data), "PlaylistDetailFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ARTIST:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                AlbumArtist albumArtist = (AlbumArtist) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(ArtistDetailFragment.newInstance(albumArtist, null), "ArtistDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ALBUM:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Album album = (Album) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(AlbumDetailFragment.newInstance(album, null), "AlbumDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_GENRE:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Genre genre = (Genre) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(GenreDetailFragment.newInstance(genre), "GenreDetailFragment");
                }, 250);
                break;
        }
    }));
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(MusicService.InternalIntents.SERVICE_CONNECTED);
    intentFilter.addAction(MusicService.InternalIntents.QUEUE_CHANGED);
    disposables.add(RxBroadcast.fromBroadcast(getContext(), intentFilter).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> toggleBottomSheetVisibility(true, true)));
    DrawerLockManager.getInstance().setDrawerLockController(this);
}
Also used : R(com.simplecity.amp_library.R) Genre(com.simplecity.amp_library.model.Genre) Bundle(android.os.Bundle) SettingsParentFragment(com.simplecity.amp_library.ui.settings.SettingsParentFragment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) Handler(android.os.Handler) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CustomMultiSheetView(com.simplecity.amp_library.ui.views.multisheet.CustomMultiSheetView) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) GenreDetailFragment(com.simplecity.amp_library.ui.detail.GenreDetailFragment) ViewGroup(android.view.ViewGroup) MusicUtils(com.simplecity.amp_library.utils.MusicUtils) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Nullable(android.support.annotation.Nullable) ArtistDetailFragment(com.simplecity.amp_library.ui.detail.ArtistDetailFragment) Album(com.simplecity.amp_library.model.Album) ButterKnife(butterknife.ButterKnife) AlbumDetailFragment(com.simplecity.amp_library.ui.detail.AlbumDetailFragment) DrawerLockManager(com.simplecity.amp_library.ui.drawer.DrawerLockManager) NonNull(android.support.annotation.NonNull) DrawerLockController(com.simplecity.amp_library.ui.drawer.DrawerLockController) UpNextView(com.simplecity.amp_library.ui.views.UpNextView) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) SleepTimer(com.simplecity.amp_library.utils.SleepTimer) Toast(android.widget.Toast) DrawerLayout(android.support.v4.widget.DrawerLayout) MiniPlayerLockManager(com.simplecity.amp_library.ui.drawer.MiniPlayerLockManager) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) DrawerProvider(com.simplecity.amp_library.ui.drawer.DrawerProvider) NavigationEventRelay(com.simplecity.amp_library.ui.drawer.NavigationEventRelay) ShuttleApplication(com.simplecity.amp_library.ShuttleApplication) MusicService(com.simplecity.amp_library.playback.MusicService) Pair(android.support.v4.util.Pair) PlaylistDetailFragment(com.simplecity.amp_library.ui.detail.PlaylistDetailFragment) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) BaseNavigationController(test.com.androidnavigation.fragment.BaseNavigationController) FragmentTransaction(android.support.v4.app.FragmentTransaction) IntentFilter(android.content.IntentFilter) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) Playlist(com.simplecity.amp_library.model.Playlist) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) Handler(android.os.Handler) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Album(com.simplecity.amp_library.model.Album) Genre(com.simplecity.amp_library.model.Genre) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 2 with UnsafeAction

use of com.simplecity.amp_library.rx.UnsafeAction in project Shuttle by timusus.

the class MainController method onResume.

@Override
public void onResume() {
    super.onResume();
    if (delayHandler != null) {
        delayHandler.removeCallbacksAndMessages(null);
    }
    delayHandler = new Handler();
    disposables.add(navigationEventRelay.getEvents().observeOn(AndroidSchedulers.mainThread()).filter(NavigationEventRelay.NavigationEvent::isActionable).subscribe(navigationEvent -> {
        switch(navigationEvent.type) {
            case NavigationEventRelay.NavigationEvent.Type.LIBRARY_SELECTED:
                popToRootViewController();
                break;
            case NavigationEventRelay.NavigationEvent.Type.FOLDERS_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(FolderFragment.newInstance(getString(R.string.folders_title), false), "FolderFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SLEEP_TIMER_SELECTED:
                UnsafeAction showToast = () -> Toast.makeText(getContext(), R.string.sleep_timer_started, Toast.LENGTH_SHORT).show();
                SleepTimer.getInstance().getDialog(getContext(), () -> SleepTimer.getInstance().showMinutesDialog(getContext(), showToast), showToast).show();
                break;
            case NavigationEventRelay.NavigationEvent.Type.EQUALIZER_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(EqualizerFragment.newInstance(), "EqualizerFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SETTINGS_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_headers, R.string.settings), "Settings Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.SUPPORT_SELECTED:
                delayHandler.postDelayed(() -> multiSheetEventRelay.sendEvent(new MultiSheetEventRelay.MultiSheetEvent(MultiSheetEventRelay.MultiSheetEvent.Action.HIDE, MultiSheetView.Sheet.FIRST)), 100);
                delayHandler.postDelayed(() -> pushViewController(SettingsParentFragment.newInstance(R.xml.settings_support, R.string.pref_title_support), "Support Fragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.PLAYLIST_SELECTED:
                delayHandler.postDelayed(() -> pushViewController(PlaylistDetailFragment.Companion.newInstance((Playlist) navigationEvent.data), "PlaylistDetailFragment"), 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ARTIST:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                AlbumArtist albumArtist = (AlbumArtist) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(ArtistDetailFragment.Companion.newInstance(albumArtist, null), "ArtistDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_ALBUM:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Album album = (Album) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(AlbumDetailFragment.Companion.newInstance(album, null), "AlbumDetailFragment");
                }, 250);
                break;
            case NavigationEventRelay.NavigationEvent.Type.GO_TO_GENRE:
                multiSheetView.goToSheet(MultiSheetView.Sheet.NONE);
                Genre genre = (Genre) navigationEvent.data;
                delayHandler.postDelayed(() -> {
                    popToRootViewController();
                    pushViewController(GenreDetailFragment.Companion.newInstance(genre), "GenreDetailFragment");
                }, 250);
                break;
        }
    }));
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(InternalIntents.SERVICE_CONNECTED);
    intentFilter.addAction(InternalIntents.QUEUE_CHANGED);
    disposables.add(RxBroadcast.fromBroadcast(getContext(), intentFilter).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(intent -> {
        toggleBottomSheetVisibility(true, true);
    }));
    DrawerLockManager.getInstance().setDrawerLockController(this);
}
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) MiniPlayerFragment(com.simplecity.amp_library.ui.screens.miniplayer.MiniPlayerFragment) PlayerFragment(com.simplecity.amp_library.ui.screens.nowplaying.PlayerFragment) PlaylistDetailFragment(com.simplecity.amp_library.ui.screens.playlist.detail.PlaylistDetailFragment) SettingsParentFragment(com.simplecity.amp_library.ui.settings.SettingsParentFragment) AlbumDetailFragment(com.simplecity.amp_library.ui.screens.album.detail.AlbumDetailFragment) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) DrawerLockController(com.simplecity.amp_library.ui.screens.drawer.DrawerLockController) UpNextView(com.simplecity.amp_library.ui.screens.upnext.UpNextView) Handler(android.os.Handler) QueueFragment(com.simplecity.amp_library.ui.screens.queue.QueueFragment) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) LogUtils(com.simplecity.amp_library.utils.LogUtils) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Playlist(com.simplecity.amp_library.model.Playlist) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) FragmentInfo(test.com.androidnavigation.fragment.FragmentInfo) CustomMultiSheetView(com.simplecity.amp_library.ui.views.multisheet.CustomMultiSheetView) RxBroadcast(com.cantrowitz.rxbroadcast.RxBroadcast) DrawerProvider(com.simplecity.amp_library.ui.screens.drawer.DrawerProvider) ViewGroup(android.view.ViewGroup) SettingsManager(com.simplecity.amp_library.utils.SettingsManager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) List(java.util.List) Nullable(android.support.annotation.Nullable) MiniPlayerLockManager(com.simplecity.amp_library.ui.screens.drawer.MiniPlayerLockManager) Context(android.content.Context) Album(com.simplecity.amp_library.model.Album) ButterKnife(butterknife.ButterKnife) NonNull(android.support.annotation.NonNull) ArtistDetailFragment(com.simplecity.amp_library.ui.screens.artist.detail.ArtistDetailFragment) Inject(javax.inject.Inject) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) GenreDetailFragment(com.simplecity.amp_library.ui.screens.genre.detail.GenreDetailFragment) SleepTimer(com.simplecity.amp_library.utils.SleepTimer) Toast(android.widget.Toast) PlayerPresenter(com.simplecity.amp_library.ui.screens.nowplaying.PlayerPresenter) DrawerLayout(android.support.v4.widget.DrawerLayout) MediaManager(com.simplecity.amp_library.playback.MediaManager) MultiSheetView(com.simplecity.multisheetview.ui.view.MultiSheetView) LayoutInflater(android.view.LayoutInflater) AndroidSupportInjection(dagger.android.support.AndroidSupportInjection) FolderFragment(com.simplecity.amp_library.ui.screens.folders.FolderFragment) InternalIntents(com.simplecity.amp_library.playback.constants.InternalIntents) DrawerLockManager(com.simplecity.amp_library.ui.screens.drawer.DrawerLockManager) MultiSheetSlideEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetSlideEventRelay) Pair(android.support.v4.util.Pair) EqualizerFragment(com.simplecity.amp_library.ui.screens.equalizer.EqualizerFragment) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist) BaseNavigationController(test.com.androidnavigation.fragment.BaseNavigationController) FragmentTransaction(android.support.v4.app.FragmentTransaction) IntentFilter(android.content.IntentFilter) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) Playlist(com.simplecity.amp_library.model.Playlist) MultiSheetEventRelay(com.simplecity.amp_library.ui.views.multisheet.MultiSheetEventRelay) Handler(android.os.Handler) BackPressHandler(test.com.androidnavigation.fragment.BackPressHandler) Album(com.simplecity.amp_library.model.Album) Genre(com.simplecity.amp_library.model.Genre) AlbumArtist(com.simplecity.amp_library.model.AlbumArtist)

Example 3 with UnsafeAction

use of com.simplecity.amp_library.rx.UnsafeAction in project Shuttle by timusus.

the class SleepTimer method showMinutesDialog.

public void showMinutesDialog(Context context, UnsafeAction timerStarted) {
    @SuppressLint("InflateParams") View customView = LayoutInflater.from(context).inflate(R.layout.dialog_minutes_picker, null);
    EditText editText = customView.findViewById(R.id.editText);
    new MaterialDialog.Builder(context).title(R.string.sleep_timer_set_minutes).customView(customView, false).positiveText(R.string.button_ok).negativeText(R.string.cancel).autoDismiss(false).onPositive((materialDialog, dialogAction) -> {
        if (!TextUtils.isEmpty(editText.getText())) {
            start(Integer.parseInt(editText.getText().toString()) * 60, playToEnd);
            timerStarted.run();
            materialDialog.dismiss();
        }
    }).onNegative((materialDialog, dialogAction) -> {
        materialDialog.dismiss();
    }).show();
    new Handler().post(() -> {
        InputMethodManager inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    });
}
Also used : EditText(android.widget.EditText) R(com.simplecity.amp_library.R) Context(android.content.Context) BackpressureStrategy(io.reactivex.BackpressureStrategy) LayoutInflater(android.view.LayoutInflater) BehaviorSubject(io.reactivex.subjects.BehaviorSubject) TextUtils(android.text.TextUtils) InputMethodManager(android.view.inputmethod.InputMethodManager) TimeUnit(java.util.concurrent.TimeUnit) SuppressLint(android.annotation.SuppressLint) Flowable(io.reactivex.Flowable) Handler(android.os.Handler) View(android.view.View) Observable(io.reactivex.Observable) MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) UnsafeAction(com.simplecity.amp_library.rx.UnsafeAction) EditText(android.widget.EditText) SuppressLint(android.annotation.SuppressLint) Handler(android.os.Handler) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View)

Aggregations

Handler (android.os.Handler)3 LayoutInflater (android.view.LayoutInflater)3 View (android.view.View)3 R (com.simplecity.amp_library.R)3 UnsafeAction (com.simplecity.amp_library.rx.UnsafeAction)3 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 Nullable (android.support.annotation.Nullable)2 Fragment (android.support.v4.app.Fragment)2 FragmentTransaction (android.support.v4.app.FragmentTransaction)2 Pair (android.support.v4.util.Pair)2 DrawerLayout (android.support.v4.widget.DrawerLayout)2 ViewGroup (android.view.ViewGroup)2 Toast (android.widget.Toast)2 BindView (butterknife.BindView)2 ButterKnife (butterknife.ButterKnife)2 RxBroadcast (com.cantrowitz.rxbroadcast.RxBroadcast)2 Album (com.simplecity.amp_library.model.Album)2