com.trello.rxlifecycle.FragmentEvent Java Examples

The following examples show how to use com.trello.rxlifecycle.FragmentEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListTweetFragment.java    From FlowGeek with GNU General Public License v2.0 6 votes vote down vote up
private void initSubscribers() {

        if (mCatalog == TWEET_TYPE_SELF){
            RxBus.with(this)
                    .setEndEvent(FragmentEvent.DESTROY)
                    .setEvent(Events.EventEnum.DELIVER_LOGIN)
                    .onNext((event) -> {
                        mLoginLayout.setVisibility(View.GONE);
                        onLoadingState(BaseListFragment.LOAD_MODE_DEFAULT);
                        getPresenter().requestData(BaseListFragment.LOAD_MODE_DEFAULT, 0);
                    }).create();

            RxBus.with(this)
                    .setEndEvent(FragmentEvent.DESTROY)
                    .setEvent(Events.EventEnum.DELIVER_LOGOUT)
                    .onNext((event) -> {
                        Log.d("thanatosx", "get logout message");
                        mAdapter.clear();
                        mErrorLayout.setVisibility(View.GONE);
                        mSwipeRefreshLayout.setEnabled(false);
                        mLoginLayout.setVisibility(View.VISIBLE);
                        mState = STATE_USER_NOT_LOGIN;
                    }).create();
        }

    }
 
Example #2
Source File: ListTweetCmmFragment.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // 处理请求tweet对象
    RxBus.getInstance().toObservable()
            .compose(bindUntilEvent(FragmentEvent.DESTROY))
            .filter(events -> events.what == Events.EventEnum.DELIVER_TWEET)
            .subscribe(events -> {
                tweet = events.getMessage();
            });
    
    RxBus.getInstance().send(Events.EventEnum.GET_TWEET, Events.EventEnum.DELIVER_TWEET);
    
}
 
Example #3
Source File: SongFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void setupAdapter() {
    if (mRecyclerView == null || mSongs == null) {
        return;
    }

    if (mSongSection != null && mShuffleAllSection != null) {
        mSongSection.setData(mSongs);
        mShuffleAllSection.setData(mSongs);
        mAdapter.notifyDataSetChanged();
    } else {
        mAdapter = new HeterogeneousFastScrollAdapter();
        mAdapter.setHasStableIds(true);
        mRecyclerView.setAdapter(mAdapter);

        mSongSection = new SongSection(mSongs, getContext(),
                mPlayerController, mMusicStore, mPlaylistStore, getFragmentManager(),
                OnSongSelectedListener.defaultImplementation(getActivity(), mPreferenceStore));
        mPlayerController.getNowPlaying()
                .compose(bindUntilEvent(FragmentEvent.DESTROY))
                .subscribe(mSongSection::setCurrentSong, throwable -> {
                    Timber.e(throwable, "Failed to update now playing");
                });

        mShuffleAllSection = new ShuffleAllSection(mSongs, mPreferenceStore, mPlayerController,
                OnSongSelectedListener.defaultImplementation(getActivity(), mPreferenceStore));
        mAdapter.addSection(mShuffleAllSection);
        mAdapter.addSection(mSongSection);
        mAdapter.setEmptyState(new LibraryEmptyState(getActivity(), mMusicStore, mPlaylistStore));
    }
}
 
Example #4
Source File: NowPlayingFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void updateSleepTimerCounter(long endTimestamp) {
    TimeView sleepTimerCounter = mBinding.nowPlayingSleepTimer;
    long sleepTimerValue = endTimestamp - System.currentTimeMillis();

    if (mSleepTimerSubscription != null) {
        mSleepTimerSubscription.unsubscribe();
    }

    if (sleepTimerValue <= 0) {
        sleepTimerCounter.setVisibility(View.GONE);
    } else {
        sleepTimerCounter.setVisibility(View.VISIBLE);
        sleepTimerCounter.setTime((int) sleepTimerValue);

        mSleepTimerSubscription = Observable.interval(500, TimeUnit.MILLISECONDS)
                .subscribeOn(Schedulers.computation())
                .map(tick -> (int) (sleepTimerValue - 500 * tick))
                .observeOn(AndroidSchedulers.mainThread())
                .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(time -> {
                    sleepTimerCounter.setTime(time);
                    if (time <= 0) {
                        mSleepTimerSubscription.unsubscribe();
                        animateOutSleepTimerCounter();
                    }
                }, throwable -> {
                    Timber.e(throwable, "Failed to update sleep timer value");
                });
    }
}
 
Example #5
Source File: NowPlayingFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_now_playing_shuffle:
            toggleShuffle();
            return true;
        case R.id.menu_now_playing_repeat:
            showRepeatMenu();
            return true;
        case R.id.menu_now_playing_sleep_timer:
            mPlayerController.getSleepTimerEndTime()
                    .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                    .take(1)
                    .subscribe(this::showSleepTimerDialog, throwable -> {
                        Timber.e(throwable, "Failed to show sleep timer dialog");
                    });
            return true;
        case R.id.menu_open_equalizer:
            Intent eqIntent = EqualizerActivity.newIntent(getContext(), mPrefStore.getEqualizerEnabled());
            if (eqIntent != null) {
                startActivity(eqIntent);
            }
            return true;
        case R.id.menu_now_playing_save:
            saveQueueAsPlaylist();
            return true;
        case R.id.menu_now_playing_append:
            addQueueToPlaylist();
            return true;
        case R.id.menu_now_playing_clear:
            clearQueue();
            return true;
    }
    return false;
}
 
Example #6
Source File: KeyboardFragment.java    From FlowGeek with GNU General Public License v2.0 5 votes vote down vote up
private void initSubscribers() {
    // register a listener to receive a event that mean user selected a emotion
    RxBus.with(this)
            .setEvent(Events.EventEnum.DELIVER_SELECT_EMOTION)
            .setEndEvent(FragmentEvent.DESTROY)
            .onNext((events -> {
                EmotionRules emotion = events.<EmotionRules>getMessage();
                mDelegatioin.onEmotionItemSelected(emotion);
            })).create();

    // 接受返回事件,如果显示表情面板,隐藏!如果显示软键盘,隐藏!如果显示回复某某某,隐藏!
    RxBus.with(this)
            .setEvent(Events.EventEnum.DELIVER_GO_BACK)
            .setEndEvent(FragmentEvent.DESTROY)
            .onNext((events -> {
                if (mReplyCmm!=null){
                    mInput.setHint(getResources().getString(R.string.please_say_something));
                    mReplyCmm = null;
                    return;
                }
                if(!mDelegatioin.onTurnBack()) return;
                RxBus.getInstance().send(Events.EventEnum.WE_HIDE_ALL, null);
            })).create();

    RxBus.with(this)
            .setEvent(Events.EventEnum.DELIVER_REPLY_SOMEONE)
            .setEndEvent(FragmentEvent.DESTROY)
            .onNext((events -> {
                mReplyCmm = events.getMessage();
                mInput.setHint("回复 @" + mReplyCmm.getAuthor());
            })).create();

    RxBus.with(this)
            .setEvent(Events.EventEnum.DELIVER_CLEAR_IMPUT)
            .setEndEvent(FragmentEvent.DESTROY)
            .onNext((events -> {
                mInput.setHint(getResources().getString(R.string.please_say_something));
                mInput.setText(null);
            })).create();
}
 
Example #7
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onDestroyView() {
    lifecycleSubject.onNext(FragmentEvent.DESTROY_VIEW);
    super.onDestroyView();
}
 
Example #8
Source File: BaseCmmFragment.java    From FlowGeek with GNU General Public License v2.0 4 votes vote down vote up
private void initSubscribers() {
    // 得到目标类型
    RxBus.with(this)
            .setEndEvent(FragmentEvent.DESTROY)
            .setEvent(Events.EventEnum.DELIVER_ARTICLE_CATALOG_FROM_LIST)
            .onNext((events)->{
                mCatalog = events.getMessage();
                switch (mCatalog) {
                    case DetailActivity.DISPLAY_BLOG:
                        break;
                    case DetailActivity.DISPLAY_NEWS:
                        mRemoteCatalog = RespCmmList.CATALOG_NEWS;
                        break;
                    case DetailActivity.DISPLAY_POST:
                        mRemoteCatalog = RespCmmList.CATALOG_POST;
                        break;
                    case DetailActivity.DISPLAY_TWEET:
                        mRemoteCatalog = RespCmmList.CATALOG_TWEET;
                        break;
                    default:
                        Log.d("thanatos", "什么都没有");
                }
            })
            .onError(Throwable::printStackTrace).create();
    RxBus.getInstance().send(Events.EventEnum.GET_ARTICLE_CATALOG,
            Events.EventEnum.DELIVER_ARTICLE_CATALOG_FROM_LIST);

    // 得到目标id
    RxBus.with(this)
            .setEndEvent(FragmentEvent.DESTROY)
            .setEvent(Events.EventEnum.DELIVER_ARTICLE_ID_FROM_LIST)
            .onNext((events)->{
                mArticleId = events.getMessage();
            })
            .onError(Throwable::printStackTrace).create();
    RxBus.getInstance().send(Events.EventEnum.GET_ARTICLE_ID,
            Events.EventEnum.DELIVER_ARTICLE_ID_FROM_LIST);

    // 得到文章所属人id
    RxBus.with(this)
            .setEvent(Events.EventEnum.DELIVER_ARTICLE_OWNER_ID)
            .setEndEvent(FragmentEvent.DESTROY)
            .onNext((events ->
                    mArticleOwnerId = events.getMessage()
            )).create();
    RxBus.getInstance().send(Events.EventEnum.GET_ARTICLE_OWNER_ID,
            Events.EventEnum.DELIVER_ARTICLE_OWNER_ID);

    // 发送评论
    RxBus.with(this)
            .setEndEvent(FragmentEvent.DESTROY)
            .setEvent(Events.EventEnum.DELIVER_SEND_COMMENT)
            .onNext((events) -> {
                Comment comment = events.getMessage();
                String content = comment.getContent();
                int type = mCatalog == DetailActivity.DISPLAY_BLOG ? 1 : 0;

                onPublishing();

                getPresenter().publicComment(mRemoteCatalog, (int)mArticleId, content,
                        comment.getId().intValue(), comment.getAuthorId(), type);
            })
            .onError(Throwable::printStackTrace).create();
}
 
Example #9
Source File: RxBus.java    From FlowGeek with GNU General Public License v2.0 4 votes vote down vote up
public SubscriberBuilder setEndEvent(FragmentEvent event){
    this.mFragmentEndEvent = event;
    return this;
}
 
Example #10
Source File: NowPlayingFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void setupToolbar(Toolbar toolbar) {
    if (getResources().getConfiguration().orientation != ORIENTATION_LANDSCAPE) {
        toolbar.setBackground(new ColorDrawable(Color.TRANSPARENT));
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        toolbar.setElevation(getResources().getDimension(R.dimen.header_elevation));
    }

    toolbar.setTitle("");
    toolbar.setNavigationIcon(R.drawable.ic_clear_24dp);

    toolbar.inflateMenu(R.menu.activity_now_playing);
    toolbar.setOnMenuItemClickListener(this);
    toolbar.setNavigationOnClickListener(v -> {
        getActivity().onBackPressed();
    });

    mCreatePlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_save);
    mAppendToPlaylistMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_append);
    mShuffleMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_shuffle);
    mRepeatMenuItem = toolbar.getMenu().findItem(R.id.menu_now_playing_repeat);

    toolbar.getMenu().findItem(R.id.menu_open_equalizer)
            .setEnabled(EqualizerActivity.newIntent(getContext(), false) != null);

    mPlayerController.getQueue()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .map(this::queueContainsLocalSongs)
            .subscribe(this::updatePlaylistActionEnabled, throwable -> {
                Timber.e(throwable, "Failed to update playlist enabled state");
            });

    mPlayerController.isShuffleEnabled()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::updateShuffleIcon, throwable -> {
                Timber.e(throwable, "Failed to update shuffle icon");
            });

    mPlayerController.getRepeatMode()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::updateRepeatIcon, throwable -> {
                Timber.e(throwable, "Failed to update repeat icon");
            });
}
 
Example #11
Source File: NowPlayingFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                         @Nullable Bundle savedInstanceState) {

    mBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_now_playing,
            container, false);

    mArtworkViewModel = new NowPlayingArtworkViewModel(getContext(), mPlayerController, mPrefStore);
    mBinding.setArtworkViewModel(mArtworkViewModel);

    setupToolbar(mBinding.nowPlayingToolbar);

    mPlayerController.getArtwork()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(mArtworkViewModel::setArtwork,
                    throwable -> Timber.e(throwable, "Failed to set artwork"));

    mPlayerController.isPlaying()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(mArtworkViewModel::setPlaying,
                    throwable -> Timber.e(throwable, "Failed to update playing state"));

    mPlayerController.getSleepTimerEndTime()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::updateSleepTimerCounter, throwable -> {
                Timber.e(throwable, "Failed to update sleep timer end timestamp");
            });

    mPlayerController.getInfo()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::showSnackbar, throwable -> {
                Timber.e(throwable, "Failed to display info message");
            });

    mPlayerController.getError()
            .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
            .subscribe(this::showSnackbar, throwable -> {
                Timber.e(throwable, "Failed to display error message");
            });

    return mBinding.getRoot();
}
 
Example #12
Source File: QueueFragment.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void setupAdapter(List<Song> queue) {
    if (mQueueSection == null) {
        mAdapter = new DragDropAdapter();
        mAdapter.setHasStableIds(true);
        mAdapter.attach(mRecyclerView);

        mRecyclerView.setItemAnimator(new QueueAnimator());
        mQueueSection = new QueueSection(queue, getFragmentManager(), mMusicStore,
                mPlaylistStore, mPlayerController, null);
        mAdapter.setDragSection(mQueueSection);

        // Wait for a layout pass before calculating bottom spacing since it is dependent on the
        // height of the RecyclerView (which has not been computed yet)
        if (isAdded()) mRecyclerView.post(this::setupSpacers);

        mAdapter.setEmptyState(new LibraryEmptyState(getActivity(), mMusicStore, mPlaylistStore) {
            @Override
            public String getEmptyMessage() {
                return getString(R.string.empty_queue);
            }

            @Override
            public String getEmptyMessageDetail() {
                return getString(R.string.empty_queue_detail);
            }

            @Override
            public String getEmptyAction1Label() {
                return "";
            }

            @Override
            public String getEmptyAction2Label() {
                return "";
            }
        });

        mPlayerController.getQueuePosition()
                .take(1)
                .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(this::setQueuePosition, throwable -> {
                    Timber.e(throwable, "Failed to scroll to queue position");
                });

        mPlayerController.getQueuePosition()
                .skip(1)
                .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(this::onQueuePositionChanged, throwable -> {
                    Timber.e(throwable, "Failed to scroll to queue position");
                });

        mPlayerController.getQueuePosition()
                .compose(bindUntilEvent(FragmentEvent.DESTROY))
                .subscribe(mQueueSection::setCurrentSongIndex, throwable -> {
                    Timber.e(throwable, "Failed to update current song");
                });

    } else if (!mQueueSection.getData().equals(queue)) {
        mQueueSection.setData(queue);
        mAdapter.notifyDataSetChanged();

        mPlayerController.getQueuePosition()
                .skip(1)
                .take(1)
                .compose(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
                .subscribe(this::setQueuePosition, throwable -> {
                    Timber.e(throwable, "Failed to scroll to queue position");
                });
    }
}
 
Example #13
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onDetach() {
    lifecycleSubject.onNext(FragmentEvent.DETACH);
    super.onDetach();
}
 
Example #14
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onDestroy() {
    lifecycleSubject.onNext(FragmentEvent.DESTROY);
    super.onDestroy();
}
 
Example #15
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
public final Observable<FragmentEvent> lifecycle() {
    return lifecycleSubject.asObservable();
}
 
Example #16
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onStop() {
    lifecycleSubject.onNext(FragmentEvent.STOP);
    super.onStop();
}
 
Example #17
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onPause() {
    lifecycleSubject.onNext(FragmentEvent.PAUSE);
    super.onPause();
}
 
Example #18
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onResume() {
    super.onResume();
    lifecycleSubject.onNext(FragmentEvent.RESUME);
}
 
Example #19
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onStart() {
    super.onStart();
    lifecycleSubject.onNext(FragmentEvent.START);
}
 
Example #20
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    lifecycleSubject.onNext(FragmentEvent.CREATE_VIEW);
}
 
Example #21
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    lifecycleSubject.onNext(FragmentEvent.CREATE);
}
 
Example #22
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onAttach(Context context) {
    super.onAttach(context);
    lifecycleSubject.onNext(FragmentEvent.ATTACH);
}
 
Example #23
Source File: RxFragment.java    From ApiClient with Apache License 2.0 4 votes vote down vote up
@Override
public final <T> Observable.Transformer<T, T> bindUntilEvent(FragmentEvent event) {
    return RxLifecycle.bindUntilFragmentEvent(lifecycleSubject, event);
}