Newer
Older
IrisClient / app / src / main / java / org / ntlab / irisclient / MemberRoomActivity.java
package org.ntlab.irisclient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;

import org.ntlab.irisclient.entities.RoomJson;
import org.ntlab.irisclient.models.Member;
import org.ntlab.irisclient.viewmodels.RoomViewModel;

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


public class MemberRoomActivity extends AppCompatActivity {

    //RoomViewModel roomViewModel = new ViewModelProvider(this).get(RoomViewModel.class);

    //フィールド
    ArrayList<String> members = new ArrayList<>();
    String r = "roomid";
    String myName = "null";




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member_room);

        String roomId = ((Iris) getApplication()).getRid();
        String nickname = ((Iris) getApplication()).getNickname();

        //自分のなまえ
        //Intent intentMain = getIntent();
        //myName = intentMain.getStringExtra("nickname");

        //--------------------------------------------------------------------------



        //--------------------------------------------------------------------------
        //各ボタン処理
        buttonProcesses();

        //--------------------------------------------------------------------------
        //メンバー表示
        Member m1 = new Member("m1");
        m1.setBelongs("r");
        m1.setMaster(true);

        Member m2 = new Member("m2");
        m2.setBelongs("b");
        m2.setMaster(true);

        Member m3 = new Member("m3");
        m2.setBelongs("r");
        m2.setMaster(false);
        Member m4 = new Member("m4");
        m2.setBelongs("b");
        m2.setMaster(false);
        Member m5 = new Member("m5");
        m2.setBelongs("r");
        m2.setMaster(false);

        members.add(m1.getNickname());
        members.add(m2.getNickname());
        members.add(m3.getNickname());
        members.add(m4.getNickname());
        members.add(m5.getNickname());

        ListView membersList = (ListView) findViewById(R.id.MembersList);

        //ArrayAdapter<String> adapter = new MemberListAdapter(this.getApplicationContext());
        //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, members);
        /*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getApplicationContext(),
                R.layout.member_list_layout, members);*/
        /*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getApplicationContext(),
                android.R.layout.simple_list_item_1, members);*/

        BaseAdapter adapter = new MemberListAdapter(this.getApplicationContext(),
                R.layout.member_list_layout, members);
        membersList.setAdapter(adapter);



        //---------------------------------------------------------------
        //settings情報
        String s = "設定されている内容がここに表示されるはずです";
        TextView settingsText = findViewById(R.id.settings);
        settingsText.setText(s);

        //---------------------------------------------------------------
        //部屋ID情報
        TextView RoomIdText = findViewById(R.id.roomID);
        RoomIdText.setText(roomId);

        /*roomViewModel.getMembersLiveData().observe(this, new Observer<List<Member>>() {
            private List<Member> members;
            @Override
            public void onChanged(List<Member> members) {

            }
        });

        roomViewModel.start(500);*/

    }

    /*
    // 初期化
    private void init() {
        setContentView(R.layout.activity_member_room);
        startObserve();
    }

    //-----------------------------------------------------------------
    // VMの監視開始
    private void startObserve() {
        roomViewModel = new ViewModelProvider(this).get(RoomViewModel.class);
        roomViewModel.getRoomLiveData().observe(this, new Observer<RoomJson>() {
            @Override
            public void onChanged(RoomJson roomData) {
                //新しいroomDataの処理
            }
        });
    }*/

    /*private getMemberInformation(){

    }*/

    /*private void addMemberToMemberList(String m){
        members.add(m);
    }*/

    public void buttonProcesses(){
        Button redMasterButton = (Button) findViewById(R.id.beRedMaster);
        Button redSpyButton = (Button) findViewById(R.id.beRedSpy);
        Button blueMasterButton = (Button) findViewById(R.id.beBlueMaster);
        Button blueSpyButton = (Button) findViewById(R.id.beBlueSpy);
        ImageButton copyButton = (ImageButton) findViewById(R.id.copyButton);
        ImageButton homeButton = (ImageButton) findViewById(R.id.homeButton);

        redMasterButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = "赤マスターボタン検知しました";
                TextView RoomIdText = findViewById(R.id.roomID);
                RoomIdText.setText(r);
            }
        });

        redSpyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = "赤諜報員ボタン検知しました";
                TextView RoomIdText = findViewById(R.id.roomID);
                RoomIdText.setText(r);
            }
        });

        blueMasterButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = "青マスターボタン検知しました";
                TextView RoomIdText = findViewById(R.id.roomID);
                RoomIdText.setText(r);
            }
        });

        blueSpyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = "青諜報員ボタン検知しました";
                TextView RoomIdText = findViewById(R.id.roomID);
                RoomIdText.setText(r);
            }
        });

        homeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                r = "ホームボタン検知しました";
                TextView RoomIdText = findViewById(R.id.roomID);
                RoomIdText.setText(r);
            }
        });

        copyButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Snackbar.make(v, "コピーしました", Snackbar.LENGTH_LONG).show();
            }
        });
    }
}