TeamAVChatVoiceMuteDialog.java 3.91 KB
Newer Older
konghaorui committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
package com.yidianling.avchatkit.teamavchat;

import android.content.Context;
import android.util.Pair;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.LinearLayout;

import com.yidianling.avchatkit.AVChatKit;
import com.yidianling.im.R;
import com.yidianling.avchatkit.common.dialog.CustomAlertDialog;
import com.yidianling.avchatkit.teamavchat.adapter.TeamAVChatVoiceMuteAdapter;
import com.yidianling.avchatkit.teamavchat.module.TeamAVChatVoiceMuteItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by hzchenkang on 2017/5/9.
 */

public class TeamAVChatVoiceMuteDialog extends CustomAlertDialog {

    private TeamAVChatVoiceMuteAdapter adapter;
    private TeamVoiceMuteListener listener;
    private List<Pair<String, Boolean>> beforeMutes;

    public TeamAVChatVoiceMuteDialog(Context context, String teamId, List<Pair<String, Boolean>> voiceMutes) {
        super(context, voiceMutes == null ? 0 : voiceMutes.size());
        beforeMutes = voiceMutes;
        if (voiceMutes == null) {
            return;
        }
        setTitle("屏蔽音频");
        setCanceledOnTouchOutside(false);

        List<TeamAVChatVoiceMuteItem> data = new ArrayList<>();
        for (Pair<String, Boolean> voiceMute : voiceMutes) {
            TeamAVChatVoiceMuteItem item = new TeamAVChatVoiceMuteItem();
            item.setAccount(voiceMute.first);
            item.setMute(voiceMute.second);
            item.setDisplayName(AVChatKit.getTeamDataProvider().getTeamMemberDisplayName(teamId, item.getAccount()));
            data.add(item);
        }
        adapter = new TeamAVChatVoiceMuteAdapter(context, data);
        setAdapter(adapter, new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //
                TeamAVChatVoiceMuteItem item = (TeamAVChatVoiceMuteItem) adapter.getItem(position);
                if (item == null) {
                    return;
                }
                item.setMute(!item.isMute());

                adapter.notifyDataSetChanged();
            }
        });
    }

    public void setTeamVoiceMuteListener(TeamVoiceMuteListener listener) {
        this.listener = listener;
    }

    public interface TeamVoiceMuteListener {
        void onVoiceMuteChange(List<Pair<String, Boolean>> voiceMuteAccounts);
    }

    @Override
    protected void addFootView(LinearLayout parent) {
konghaorui committed
72
        View footView = getLayoutInflater().inflate(R.layout.im_nim_easy_alert_dialog_bottom_button, null);
konghaorui committed
73 74
        Button positiveButton = (Button) footView.findViewById(R.id.easy_dialog_positive_btn);
        positiveButton.setVisibility(View.VISIBLE);
konghaorui committed
75
        positiveButton.setText(getContext().getString(R.string.im_save));
konghaorui committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

        Button negativeButton = (Button) footView.findViewById(R.id.easy_dialog_negative_btn);
        negativeButton.setVisibility(View.VISIBLE);

        positiveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null) {
                    List<Pair<String, Boolean>> items = new ArrayList<>();
                    List<TeamAVChatVoiceMuteItem> afterItems = adapter.getItems();

                    for (int i = 0; i < afterItems.size(); i++) {
                        if (afterItems.get(i).isMute() != beforeMutes.get(i).second) {
                            items.add(new Pair<>(beforeMutes.get(i).first, !beforeMutes.get(i).second));
                        }
                    }

                    listener.onVoiceMuteChange(items);
                }
                dismiss();
            }
        });
        negativeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        parent.addView(footView);
    }
}