240 lines
8.4 KiB
Java
240 lines
8.4 KiB
Java
package com.xscm.modulemain.dialog;
|
|
|
|
import static com.xscm.moduleutil.utils.ImageUtils.copyAssetToFile;
|
|
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.os.Environment;
|
|
import android.view.Gravity;
|
|
import android.view.View;
|
|
import android.view.Window;
|
|
import android.view.WindowManager;
|
|
import android.widget.Button;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.core.content.ContextCompat;
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
import com.xscm.modulemain.R;
|
|
import com.xscm.modulemain.activity.room.contacts.WheatContacts;
|
|
import com.xscm.modulemain.activity.room.presenter.WheatPresenter;
|
|
import com.xscm.modulemain.adapter.RoomOnlineAdapter;
|
|
import com.xscm.modulemain.databinding.FragmentSoundDialogBinding;
|
|
import com.xscm.moduleutil.base.BaseMvpDialogFragment;
|
|
import com.xscm.moduleutil.bean.room.RoomApplyListBean;
|
|
import com.xscm.moduleutil.color.ThemeableDrawableUtils;
|
|
import com.xscm.moduleutil.rtc.AgoraManager;
|
|
import com.xscm.moduleutil.utils.ColorManager;
|
|
|
|
import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
/**
|
|
*@author qx
|
|
*@data 2025/6/17
|
|
*@description: 音效弹框
|
|
*/
|
|
public class SoundEffectsDialogFragment extends BaseMvpDialogFragment<WheatPresenter, FragmentSoundDialogBinding> implements
|
|
WheatContacts.View {
|
|
private int page;
|
|
private RoomOnlineAdapter roomOnlineAdapter;
|
|
@Override
|
|
protected WheatPresenter bindPresenter() {
|
|
return new WheatPresenter(this, getActivity());
|
|
}
|
|
public static SoundEffectsDialogFragment show(String id, FragmentManager fragmentManager) {
|
|
SoundEffectsDialogFragment dialogFragment = new SoundEffectsDialogFragment();
|
|
Bundle args = new Bundle();
|
|
args.putString("roomId", id); // 可选:传递参数
|
|
dialogFragment.setArguments(args);
|
|
dialogFragment.show(fragmentManager, "SoundEffectsDialogFragment");
|
|
return dialogFragment;
|
|
}
|
|
@Override
|
|
protected void initData() {
|
|
// MvpPre.getRoomOnline(getArguments().getString("roomId"), "1", "10");
|
|
}
|
|
@Override
|
|
public void onStart() {
|
|
super.onStart();
|
|
Window window = getDialog().getWindow();
|
|
if (window != null) {
|
|
// 设置固定高度为 500dp
|
|
int screenHeight = getResources().getDisplayMetrics().heightPixels;
|
|
int heightInDp = (int) (screenHeight * 0.4f);;
|
|
// int heightInPx = (int) (heightInDp * getResources().getDisplayMetrics().density);
|
|
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, heightInDp);
|
|
|
|
// 可选:设置动画样式(从底部弹出)
|
|
window.setWindowAnimations(com.xscm.moduleutil.R.style.CommonShowDialogBottom);
|
|
}
|
|
}
|
|
|
|
// 用于记录选中的位置
|
|
private int selectedPosition = -1;
|
|
|
|
// 所有点击项的集合
|
|
private final List<View> clickableViews = new ArrayList<>();
|
|
|
|
// 背景资源
|
|
private static final int BG_DEFAULT = com.xscm.moduleutil.R.mipmap.suound_bj;
|
|
private static final int BG_SELECTED = com.xscm.moduleutil.R.mipmap.suound_bjs;
|
|
private static final int BTN_BG_SELECTED = com.xscm.moduleutil.R.mipmap.y_won;
|
|
private static final int BTN_BG_DEFAULT = com.xscm.moduleutil.R.mipmap.y_w;
|
|
|
|
private static final int TEXT_COLOR_SELECTED = com.xscm.moduleutil.R.color.color_FF333333;
|
|
private static final int TEXT_COLOR_DEFAULT = com.xscm.moduleutil.R.color.white;
|
|
|
|
private final List<Button> buttonList = new ArrayList<>();
|
|
private final List<TextView> textViewList = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
protected void initView() {
|
|
// 添加所有点击项到集合中
|
|
clickableViews.add(mBinding.cl1);
|
|
clickableViews.add(mBinding.cl2);
|
|
clickableViews.add(mBinding.cl3);
|
|
clickableViews.add(mBinding.cl4);
|
|
clickableViews.add(mBinding.cl5);
|
|
|
|
// 初始化 Button 和 TextView 列表
|
|
buttonList.add(mBinding.bottom1);
|
|
buttonList.add(mBinding.bottom2);
|
|
buttonList.add(mBinding.bottom3);
|
|
buttonList.add(mBinding.bottom4);
|
|
buttonList.add(mBinding.bottom5);
|
|
|
|
textViewList.add(mBinding.tv1);
|
|
textViewList.add(mBinding.tv2);
|
|
textViewList.add(mBinding.tv3);
|
|
textViewList.add(mBinding.tv4);
|
|
textViewList.add(mBinding.tv5);
|
|
|
|
// 设置统一点击监听
|
|
for (int i = 0; i < clickableViews.size(); i++) {
|
|
final int position = i;
|
|
clickableViews.get(i).setOnClickListener(v -> handleItemClick(position));
|
|
}
|
|
|
|
mBinding.tvSure.setOnClickListener(v -> {
|
|
if (selectedPosition != -1){
|
|
if (selectedPosition == 0){
|
|
AgoraManager.getInstance().potexao(new File(getSavePath() + "xs.mp3").getPath());
|
|
}else if (selectedPosition == 1){
|
|
AgoraManager.getInstance().potexao(new File(getSavePath() + "hh.mp3").getPath());
|
|
}else if (selectedPosition == 2){
|
|
AgoraManager.getInstance().potexao(new File(getSavePath() + "gg.mp3").getPath());
|
|
}else if (selectedPosition == 3){
|
|
AgoraManager.getInstance().potexao(new File(getSavePath() + "zs.mp3").getPath());
|
|
}else if (selectedPosition == 4){
|
|
AgoraManager.getInstance().potexao(new File(getSavePath() + "mmd.mp3").getPath());
|
|
}
|
|
}
|
|
|
|
});
|
|
|
|
copyAssetToFile("gg.mp3", getSavePath(), "gg.mp3");
|
|
copyAssetToFile("hh.mp3", getSavePath(), "hh.mp3");
|
|
copyAssetToFile("mmd.mp3", getSavePath(), "mmd.mp3");
|
|
copyAssetToFile("xs.mp3", getSavePath(), "xs.mp3");
|
|
copyAssetToFile("zs.mp3", getSavePath(), "zs.mp3");
|
|
|
|
ThemeableDrawableUtils.setThemeableRoundedBackground(mBinding.tvSure, ColorManager.getInstance().getPrimaryColorInt(),53);
|
|
mBinding.tvSure.setTextColor(ColorManager.getInstance().getButtonColorInt());
|
|
}
|
|
|
|
private String getSavePath() {
|
|
String path;
|
|
if (Build.VERSION.SDK_INT > 29) {
|
|
path = getActivity().getExternalFilesDir(null).getAbsolutePath() + "/app/effects/";
|
|
} else {
|
|
path = Environment.getExternalStorageDirectory().getPath() + "/app/effects/";
|
|
}
|
|
return path;
|
|
}
|
|
/**
|
|
* 处理点击事件
|
|
*/
|
|
private void handleItemClick(int position) {
|
|
if (selectedPosition == position) {
|
|
// 再次点击已选项,取消选择
|
|
selectedPosition = -1;
|
|
resetBackgrounds();
|
|
} else {
|
|
// 更新选中项
|
|
selectedPosition = position;
|
|
updateBackgrounds(position);
|
|
}
|
|
}
|
|
/**
|
|
* 更新所有项的背景状态
|
|
*/
|
|
private void updateBackgrounds(int selectedPos) {
|
|
for (int i = 0; i < clickableViews.size(); i++) {
|
|
View view = clickableViews.get(i);
|
|
Button btn = buttonList.get(i);
|
|
TextView tv = textViewList.get(i);
|
|
if (i == selectedPos) {
|
|
view.setBackgroundResource(BG_SELECTED);
|
|
btn.setBackgroundResource(BTN_BG_SELECTED);
|
|
tv.setTextColor(ContextCompat.getColor(requireContext(), TEXT_COLOR_SELECTED));
|
|
} else {
|
|
view.setBackgroundResource(BG_DEFAULT);
|
|
btn.setBackgroundResource(BTN_BG_DEFAULT);
|
|
tv.setTextColor(ContextCompat.getColor(requireContext(), TEXT_COLOR_DEFAULT));
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 恢复所有项为默认背景
|
|
*/
|
|
private void resetBackgrounds() {
|
|
for (int i = 0; i < clickableViews.size(); i++) {
|
|
View view = clickableViews.get(i);
|
|
Button btn = buttonList.get(i);
|
|
TextView tv = textViewList.get(i);
|
|
|
|
view.setBackgroundResource(BG_DEFAULT);
|
|
btn.setBackgroundResource(BTN_BG_DEFAULT);
|
|
tv.setTextColor(ContextCompat.getColor(requireContext(), TEXT_COLOR_DEFAULT));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void initDialogStyle(Window window) {
|
|
super.initDialogStyle(window);
|
|
window.setGravity(Gravity.BOTTOM);
|
|
}
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.fragment_sound_dialog;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void roomApplyListBean(RoomApplyListBean roomApplyListBeans) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void clearApply() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void agreePit() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void applyPit() {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void giveGift() {
|
|
|
|
}
|
|
} |