Search in sources :

Example 41 with Theme

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);
}
Also used : BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) Theme(net.iGap.module.Theme) TextView(android.widget.TextView) ImageView(android.widget.ImageView) HelperFragment(net.iGap.helper.HelperFragment) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Aggregations

Theme (net.iGap.module.Theme)41 View (android.view.View)22 TextView (android.widget.TextView)21 HelperFragment (net.iGap.helper.HelperFragment)17 LinearLayout (android.widget.LinearLayout)15 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)13 Bundle (android.os.Bundle)12 ViewGroup (android.view.ViewGroup)12 Nullable (androidx.annotation.Nullable)12 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 ArrayList (java.util.ArrayList)12 R (net.iGap.R)11 NonNull (androidx.annotation.NonNull)10 LayoutInflater (android.view.LayoutInflater)9 HelperError (net.iGap.helper.HelperError)9 ParamWithAvatarType (net.iGap.helper.avatar.ParamWithAvatarType)9 Drawable (android.graphics.drawable.Drawable)8 FrameLayout (android.widget.FrameLayout)8 ProgressBar (android.widget.ProgressBar)8 Fragment (androidx.fragment.app.Fragment)8