use of net.iGap.module.Theme in project iGap-Android by KianIranian-STDG.
the class BeepTunesFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
viewModel.onCreateFragment(this);
new HelperFragment(getFragmentManager(), new BeepTunesMainFragment().getInstance(fromAlbumAdapter, toAlbumAdapter)).setResourceContainer(R.id.fl_beepTunes_Container).setAddToBackStack(false).setReplace(false).load();
TextView artistNameTv = rootView.findViewById(R.id.tv_btBehavior_artistName);
TextView songNameTv = rootView.findViewById(R.id.tv_btBehavior_songName);
TextView playIconTv = rootView.findViewById(R.id.tv_btBehavior_playIcon);
ImageView songImageIv = rootView.findViewById(R.id.iv_btBehavior_image);
ImageView hidePlayerIv = rootView.findViewById(R.id.iv_btPlayer_hide);
TextView playerToolBarPlayerTv = rootView.findViewById(R.id.tv_btPlayer_toolBarTitle);
TextView behaviorPlayerTime = rootView.findViewById(R.id.tv_btBehavior_timeDuration);
LinearLayout playerLayout = rootView.findViewById(R.id.cl_beepTunesPlayer);
progressBar = rootView.findViewById(R.id.pb_btBehavior_behavior);
bottomPlayerCl = rootView.findViewById(R.id.cl_btPlayer_behavior);
playerToolBarCl = rootView.findViewById(R.id.cl_btPlayer_toolBar);
beepTunesPlayer = BeepTunesPlayer.getInstance(toAlbumAdapter, viewModel.getProgressDurationLiveData(), viewModel.getMediaPlayerStatusLiveData());
behavior = BottomSheetBehavior.from(playerLayout);
behavior.setState(BottomSheetBehavior.STATE_HIDDEN);
viewModel.getPlayingSongViewLiveData().observe(getViewLifecycleOwner(), playingSong -> {
if (playingSong != null) {
toAlbumAdapter.postValue(playingSong);
artistNameTv.setText(playingSong.getArtistName());
songNameTv.setText(playingSong.getTitle());
songImageIv.setImageBitmap(playingSong.getBitmap());
if (playingSong.isPlay()) {
playIconTv.setText(getContext().getResources().getString(R.string.icon_pause));
} else {
playIconTv.setText(getContext().getResources().getString(R.string.icon_beeptunes_play));
}
behavior.setState(playingSong.getBehaviorStatus());
new HelperFragment(getFragmentManager(), beepTunesPlayer).setResourceContainer(R.id.fl_btPlayer_container).setAddToBackStack(false).setReplace(true).load();
playerToolBarPlayerTv.setText(playingSong.getTitle());
}
});
playerLayout.setOnClickListener(v -> behavior.setState(BottomSheetBehavior.STATE_EXPANDED));
playIconTv.setOnClickListener(v -> {
if (viewModel.getPlayingSongViewLiveData().getValue() != null) {
viewModel.getPlayingSongViewLiveData().getValue().setBehaviorStatus(BottomSheetBehavior.STATE_COLLAPSED);
viewModel.onPlaySongClicked(viewModel.getPlayingSongViewLiveData().getValue(), getContext());
}
});
fromAlbumAdapter.observe(getViewLifecycleOwner(), playingSong -> viewModel.onPlaySongClicked(playingSong, getContext()));
viewModel.getProgressDurationLiveData().observe(getViewLifecycleOwner(), progressDuration -> {
if (progressDuration != null && viewModel.getPlayingSongViewLiveData().getValue() != null) {
if (viewModel.getPlayingSongViewLiveData().getValue().getSongId() == progressDuration.getId()) {
progressBar.setProgress(progressDuration.getCurrent());
progressBar.setMax(progressDuration.getTotal());
behaviorPlayerTime.setText(progressDuration.getCurrentTime() + " | " + progressDuration.getTotalTime());
}
}
});
beepTunesPlayer.getSongFromPlayerLiveData().observe(getViewLifecycleOwner(), playingSong -> viewModel.onPlaySongClicked(playingSong, getContext()));
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View view, int status) {
switch(status) {
case BottomSheetBehavior.STATE_COLLAPSED:
playerToolBarCl.setVisibility(View.GONE);
bottomPlayerCl.setVisibility(View.VISIBLE);
break;
case BottomSheetBehavior.STATE_DRAGGING:
playerToolBarCl.setVisibility(View.VISIBLE);
bottomPlayerCl.setVisibility(View.GONE);
break;
case BottomSheetBehavior.STATE_HIDDEN:
playerToolBarCl.setVisibility(View.GONE);
bottomPlayerCl.setVisibility(View.VISIBLE);
break;
case BottomSheetBehavior.STATE_EXPANDED:
playerToolBarCl.setVisibility(View.VISIBLE);
bottomPlayerCl.setVisibility(View.GONE);
break;
}
}
@Override
public void onSlide(@NonNull View view, float v) {
}
});
hidePlayerIv.setOnClickListener(v -> {
if (behavior.getState() == BottomSheetBehavior.STATE_EXPANDED) {
behavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
});
beepTunesPlayer.getPlayingSongSeekBarLiveData().observe(getViewLifecycleOwner(), progress -> {
if (progress != null)
viewModel.seekBarProgressChanged(progress);
});
progressBar.getProgressDrawable().setColorFilter(new Theme().getAccentColor(progressBar.getContext()), PorterDuff.Mode.SRC_IN);
}
Aggregations