327 lines
13 KiB
Java
327 lines
13 KiB
Java
package com.xscm.modulemain.dialog;
|
||
|
||
|
||
import android.content.Context;
|
||
import android.os.Bundle;
|
||
import android.view.Gravity;
|
||
import android.view.View;
|
||
import android.view.Window;
|
||
import android.view.WindowManager;
|
||
import android.widget.CompoundButton;
|
||
import android.widget.SeekBar;
|
||
|
||
import androidx.fragment.app.FragmentManager;
|
||
import androidx.recyclerview.widget.GridLayoutManager;
|
||
|
||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||
import com.xscm.modulemain.R;
|
||
import com.xscm.modulemain.adapter.TunerListAdapter;
|
||
import com.xscm.modulemain.activity.room.contacts.WheatContacts;
|
||
import com.xscm.modulemain.databinding.RoomDialogTunerBinding;
|
||
import com.xscm.modulemain.activity.room.presenter.WheatPresenter;
|
||
import com.luck.picture.lib.decoration.GridSpacingItemDecoration;
|
||
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
||
import com.xscm.moduleutil.bean.MixerResp;
|
||
import com.xscm.moduleutil.bean.room.RoomApplyListBean;
|
||
import com.xscm.moduleutil.rtc.AgoraManager;
|
||
import com.xscm.moduleutil.rtc.RtcConstants;
|
||
import com.xscm.moduleutil.rtc.VolumeManager;
|
||
import com.xscm.moduleutil.utils.SpUtil;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
|
||
/**
|
||
* 调音台弹窗
|
||
*/
|
||
public class TunerDialogFragment extends BaseMvpDialogFragment<WheatPresenter, RoomDialogTunerBinding> implements WheatContacts.View {
|
||
|
||
private static final String TAG = "TunerSheetDialog";
|
||
|
||
private Context mContext;
|
||
|
||
|
||
private String roomId;
|
||
private int tunerType;
|
||
private TunerListAdapter tunerAdapter;
|
||
private TunerListAdapter tunerAdapter2;
|
||
|
||
|
||
public static void show(String id, FragmentManager fragmentManager) {
|
||
TunerDialogFragment dialogFragment = new TunerDialogFragment();
|
||
Bundle args = new Bundle();
|
||
args.putString("roomId", id); // 可选:传递参数
|
||
dialogFragment.setArguments(args);
|
||
dialogFragment.show(fragmentManager, "SoundEffectsDialogFragment");
|
||
}
|
||
@Override
|
||
public void onStart() {
|
||
super.onStart();
|
||
Window window = getDialog().getWindow();
|
||
if (window != null) {
|
||
// 设置固定高度为 500dp
|
||
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
||
int heightInDp = (int) (screenHeight * 0.5f);;
|
||
// int heightInPx = (int) (heightInDp * getResources().getDisplayMetrics().density);
|
||
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, heightInDp);
|
||
|
||
// 可选:设置动画样式(从底部弹出)
|
||
window.setWindowAnimations(com.xscm.moduleutil.R.style.CommonShowDialogBottom);
|
||
}
|
||
}
|
||
@Override
|
||
protected void initDialogStyle(Window window) {
|
||
super.initDialogStyle(window);
|
||
window.setGravity(Gravity.BOTTOM);
|
||
}
|
||
@Override
|
||
public int getLayoutId() {
|
||
return R.layout.room_dialog_tuner;
|
||
}
|
||
|
||
|
||
@Override
|
||
public void initView() {
|
||
// mBinding.rvEffectStyleList.setLayoutManager(new GridLayoutManager(mContext, 4));
|
||
// mBinding.rvEffectStyleList.setAdapter(tunerAdapter = new TunerListAdapter());
|
||
// mBinding.rvEffectStyleList.addItemDecoration(new GridSpacingItemDecoration(4, 30, true));
|
||
// tunerAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||
// @Override
|
||
// public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||
// MixerResp item = tunerAdapter.getItem(position);
|
||
// tunerAdapter.setIndex(position);
|
||
// MvpPre.setUserMixer(roomId, item.getId());
|
||
// RtcManager.getInstance().setTone(item.getId());
|
||
// }
|
||
// });
|
||
|
||
// 初始化音量管理器
|
||
VolumeManager volumeManager = VolumeManager.getInstance();
|
||
String currentUserId = SpUtil.getUserId() + "";
|
||
volumeManager.setCurrentUserId(currentUserId);
|
||
|
||
mBinding.swMonitoring.setChecked(SpUtil.getAuricularBack() == 1 ? true : false);//设置耳返开启还是关闭
|
||
mBinding.swMonitoring.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||
@Override
|
||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||
AgoraManager.getInstance().enableHeadphoneMonitor(b);
|
||
//耳返设置完保存本地
|
||
SpUtil.setAuricularBack(b ? 1 : 0);
|
||
}
|
||
});
|
||
// int progress = SpUtil.getMusicVolume();
|
||
// if (progress == 0) {
|
||
// progress = 100;
|
||
// }
|
||
// mBinding.seekBar1.setProgress(progress);
|
||
// 设置 seekBar1 的默认进度为 100
|
||
// mBinding.seekBar1.setProgress(100);
|
||
// 更新对应的 TextView 显示内容
|
||
// mBinding.tvSeekbarValue.setText("人声" + progress + "%");
|
||
|
||
|
||
// 获取新演唱者的音量设置
|
||
int[] volumes = volumeManager.getUserVolumes(currentUserId);
|
||
int musicVolume = volumes[0];
|
||
int playoutVolume = volumes[1];
|
||
updateVolumeUI(musicVolume, playoutVolume);
|
||
|
||
mBinding.seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||
|
||
@Override
|
||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||
// 转换为百分比显示 (200代表100%,100代表50%)
|
||
int percentage = (int) ((progress / 200.0) * 100);
|
||
mBinding.tvSeekbarValue.setText("人声" + percentage + "%");
|
||
SpUtil.setMusicVolume(progress); // 保存原始值(0-200)
|
||
AgoraManager.getInstance().setMusicVolume(progress); // 使用原始值(0-200)
|
||
// 保存当前用户的音量设置
|
||
volumeManager.saveCurrentVolumes(
|
||
mBinding.seekBar1.getProgress(),
|
||
mBinding.seekBar2.getProgress()
|
||
);
|
||
}
|
||
|
||
@Override
|
||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||
|
||
}
|
||
});
|
||
// int progress2 = SpUtil.gettPlayoutVolume();
|
||
// if (progress2 == 0) {
|
||
// progress2 = 100;
|
||
// }
|
||
// // 设置 seekBar1 的默认进度为 100
|
||
// mBinding.seekBar2.setProgress(progress2);
|
||
// // 更新对应的 TextView 显示内容
|
||
// mBinding.tvSeekbarValue2.setText("伴奏" + progress2 + "%");
|
||
|
||
mBinding.seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||
@Override
|
||
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
|
||
mBinding.tvSeekbarValue2.setText("伴奏" + progress + "%");
|
||
SpUtil.settPlayoutVolume(progress);
|
||
AgoraManager.getInstance().setPlayoutVolume(progress);
|
||
// 保存当前用户的音量设置
|
||
volumeManager.saveCurrentVolumes(
|
||
mBinding.seekBar1.getProgress(),
|
||
mBinding.seekBar2.getProgress()
|
||
);
|
||
}
|
||
|
||
@Override
|
||
public void onStartTrackingTouch(SeekBar seekBar) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||
|
||
}
|
||
});
|
||
mBinding.rvEffectStyleList.setLayoutManager(new GridLayoutManager(mContext, 5));
|
||
mBinding.rvEffectStyleList.setAdapter(tunerAdapter = new TunerListAdapter(1));
|
||
mBinding.rvEffectStyleList.addItemDecoration(new GridSpacingItemDecoration(5, 11, true));
|
||
tunerAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||
@Override
|
||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||
// 取消之前选中的项
|
||
// if (tunerAdapter.get() >= 0) {
|
||
// tunerAdapter.notifyItemChanged(tunerAdapter.getIndex());
|
||
// }
|
||
|
||
// 设置当前项为选中状态
|
||
tunerAdapter.setIndex(position);
|
||
tunerAdapter.notifyItemChanged(position);
|
||
|
||
// 执行选中项的操作
|
||
MixerResp item = tunerAdapter.getItem(position);
|
||
// MvpPre.setUserMixer(roomId, item.getId());
|
||
// RtcManager.getInstance().setTone(item.getId());
|
||
AgoraManager.getInstance().setTone(item.getId());
|
||
}
|
||
});
|
||
|
||
mBinding.rvEffectStyleList2.setLayoutManager(new GridLayoutManager(mContext, 5));
|
||
mBinding.rvEffectStyleList2.setAdapter(tunerAdapter2 = new TunerListAdapter(2));
|
||
mBinding.rvEffectStyleList2.addItemDecoration(new GridSpacingItemDecoration(5, 20, true));
|
||
tunerAdapter2.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
|
||
@Override
|
||
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
|
||
// 取消之前选中的项
|
||
// if (tunerAdapter.get() >= 0) {
|
||
// tunerAdapter.notifyItemChanged(tunerAdapter.getIndex());
|
||
// }
|
||
// 设置当前项为选中状态
|
||
tunerAdapter2.setIndex(position);
|
||
tunerAdapter2.notifyItemChanged(position);
|
||
// 设置当前项为选中状态
|
||
|
||
// 执行选中项的操作
|
||
MixerResp item = tunerAdapter2.getItem(position);
|
||
AgoraManager.getInstance().setTone(item.getId());
|
||
// MvpPre.setUserMixer(roomId, item.getId());
|
||
// RtcManager.getInstance().setTone(item.getId());
|
||
}
|
||
});
|
||
|
||
|
||
}
|
||
|
||
/**
|
||
* 更新音量UI显示
|
||
* @param musicVolume 人声音量
|
||
* @param playoutVolume 伴奏音量
|
||
*/
|
||
public void updateVolumeUI(int musicVolume, int playoutVolume) {
|
||
// 更新人声音量
|
||
int musicPercentage = (int) ((musicVolume / 200.0) * 100);
|
||
mBinding.seekBar1.setMax(200);
|
||
mBinding.seekBar1.setProgress(musicVolume);
|
||
mBinding.tvSeekbarValue.setText("人声" + musicPercentage + "%");
|
||
AgoraManager.getInstance().setMusicVolume(musicVolume); // 使用原始值(0-200)
|
||
// 更新伴奏音量
|
||
mBinding.seekBar2.setProgress(playoutVolume);
|
||
// int playoutPercentage = (int) ((playoutVolume / 200.0) * 100);
|
||
mBinding.tvSeekbarValue2.setText("伴奏" + playoutVolume + "%");
|
||
AgoraManager.getInstance().setPlayoutVolume(playoutVolume);
|
||
}
|
||
|
||
@Override
|
||
protected WheatPresenter bindPresenter() {
|
||
return new WheatPresenter(this, getActivity());
|
||
}
|
||
|
||
@Override
|
||
public void initData() {
|
||
// roomId = getArguments().getString("roomId");
|
||
// tunerType = getArguments().getInt("tunerType");
|
||
|
||
List<MixerResp> mixerResps = new ArrayList<>();
|
||
mixerResps.add(new MixerResp(RtcConstants.AUDIO_EFFECT_OFF, "原生", com.xscm.moduleutil.R.mipmap.yuansheng));
|
||
mixerResps.add(new MixerResp(RtcConstants.AUDIO_EFFECT_CPJ, "唱片机", com.xscm.moduleutil.R.mipmap.changpian));
|
||
// mixerResps.add(new MixerResp(RtcConstants.AUDIO_EFFECT_3W, "3维声音", com.qxcm.moduleutil.R.mipmap.sanwei));
|
||
// mixerResps.add(new MixerResp(RtcConstants.AUDIO_EFFECT_XN, "虚拟环绕", com.qxcm.moduleutil.R.mipmap.xuni));
|
||
mixerResps.add(new MixerResp(RtcConstants.AUDIO_EFFECT_KTV, "KTV", com.xscm.moduleutil.R.mipmap.ktv));
|
||
tunerAdapter.setNewData(mixerResps);
|
||
tunerAdapter.setIndex(0);
|
||
|
||
List<MixerResp> mixerResps2 = new ArrayList<>();
|
||
mixerResps2.add(new MixerResp(RtcConstants.SOUNDEFFECTTYPE_CHANGE_VOICE1, "老人", com.xscm.moduleutil.R.mipmap.laoren));
|
||
mixerResps2.add(new MixerResp(RtcConstants.SOUNDEFFECTTYPE_CHANGE_VOICE2, "猪八戒", com.xscm.moduleutil.R.mipmap.zubj));
|
||
mixerResps2.add(new MixerResp(RtcConstants.SOUNDEFFECTTYPE_CHANGE_VOICE3, "叔叔", com.xscm.moduleutil.R.mipmap.dashu));
|
||
mixerResps2.add(new MixerResp(RtcConstants.SOUNDEFFECTTYPE_CHANGE_VOICE4, "姐姐", com.xscm.moduleutil.R.mipmap.yujie));
|
||
mixerResps2.add(new MixerResp(RtcConstants.SOUNDEFFECTTYPE_CHANGE_VOICE5, "女孩", com.xscm.moduleutil.R.mipmap.nvhai));
|
||
tunerAdapter2.setNewData(mixerResps2);
|
||
}
|
||
|
||
@Override
|
||
public void roomApplyListBean(RoomApplyListBean roomApplyListBeans) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void clearApply() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void agreePit() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void applyPit() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void giveGift() {
|
||
|
||
}
|
||
|
||
|
||
// @Override
|
||
// protected void initDialogStyle(Window window) {
|
||
// super.initDialogStyle(window);
|
||
// window.setGravity(Gravity.BOTTOM);
|
||
// WindowManager.LayoutParams lp = window.getAttributes();
|
||
// lp.dimAmount = 0.4f;
|
||
// window.setAttributes(lp);
|
||
// window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
|
||
// }
|
||
|
||
|
||
// @Override
|
||
// public void setMixerData(List<MixerResp> mixerResps) {
|
||
// tunerAdapter.setNewData(mixerResps);
|
||
// tunerAdapter.setIndex(tunerType);
|
||
// }
|
||
|
||
} |