107 lines
3.6 KiB
Java
107 lines
3.6 KiB
Java
package com.example.moduleroom.dialog;
|
|
|
|
import android.annotation.SuppressLint;
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.example.moduleroom.R;
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
|
|
|
/**
|
|
* @author qx
|
|
* @data 2025/6/26
|
|
* @description: 底部弹框,退出房间选择
|
|
*/
|
|
public class ExitRoomBottomSheet extends BottomSheetDialogFragment {
|
|
|
|
public interface OnOptionSelectedListener {
|
|
void onMinimize(); // 最小化
|
|
|
|
void onExitRoom(); // 退出房间
|
|
|
|
void onCancel(); // 取消
|
|
}
|
|
|
|
private OnOptionSelectedListener listener;
|
|
private static final String ARG_SHOW_MINIMIZE = "show_minimize";
|
|
private static final String ARG_SHOW_EXIT = "show_exit";
|
|
private static final String ARG_SHOW_CANCEL = "show_cancel";
|
|
|
|
private boolean showMinimize = true;
|
|
private boolean showExit = true;
|
|
private boolean showCancel = true;
|
|
|
|
public static ExitRoomBottomSheet newInstance(boolean showMinimize, boolean showExit, boolean showCancel) {
|
|
ExitRoomBottomSheet fragment = new ExitRoomBottomSheet();
|
|
Bundle args = new Bundle();
|
|
args.putBoolean(ARG_SHOW_MINIMIZE, showMinimize);
|
|
args.putBoolean(ARG_SHOW_EXIT, showExit);
|
|
args.putBoolean(ARG_SHOW_CANCEL, showCancel);
|
|
fragment.setArguments(args);
|
|
return fragment;
|
|
}
|
|
|
|
public static ExitRoomBottomSheet newInstance() {
|
|
return newInstance(true, true, true);
|
|
}
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if (getArguments() != null) {
|
|
showMinimize = getArguments().getBoolean(ARG_SHOW_MINIMIZE, true);
|
|
showExit = getArguments().getBoolean(ARG_SHOW_EXIT, true);
|
|
showCancel = getArguments().getBoolean(ARG_SHOW_CANCEL, true);
|
|
}
|
|
setStyle(STYLE_NORMAL, com.xscm.moduleutil.R.style.AppBottomSheetDialogTheme); // 自定义样式(可选)
|
|
setCancelable(true); // 点击外部可关闭
|
|
}
|
|
|
|
@SuppressLint("MissingInflatedId")
|
|
@Nullable
|
|
@Override
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
View view = inflater.inflate(R.layout.dialog_exit_room_bottom_sheet, container, false);
|
|
TextView tv_minimize = view.findViewById(R.id.tv_minimize);
|
|
TextView tv_exit_room = view.findViewById(R.id.tv_exit_room);
|
|
TextView tv_cancel = view.findViewById(R.id.tv_cancel);
|
|
|
|
// 根据参数设置按钮可见性
|
|
if (tv_minimize != null) {
|
|
tv_minimize.setVisibility(showMinimize ? View.VISIBLE : View.GONE);
|
|
}
|
|
if (tv_exit_room != null) {
|
|
tv_exit_room.setVisibility(showExit ? View.VISIBLE : View.GONE);
|
|
}
|
|
if (tv_cancel != null) {
|
|
tv_cancel.setVisibility(showCancel ? View.VISIBLE : View.GONE);
|
|
}
|
|
tv_minimize.setOnClickListener(v -> {
|
|
if (listener != null) listener.onMinimize();
|
|
dismiss();
|
|
});
|
|
|
|
tv_exit_room.setOnClickListener(v -> {
|
|
if (listener != null) listener.onExitRoom();
|
|
dismiss();
|
|
});
|
|
|
|
tv_cancel.setOnClickListener(v -> {
|
|
if (listener != null) listener.onCancel();
|
|
dismiss();
|
|
});
|
|
|
|
return view;
|
|
}
|
|
|
|
|
|
public void setOnOptionSelectedListener(OnOptionSelectedListener listener) {
|
|
this.listener = listener;
|
|
}
|
|
}
|