diff --git a/app/src/main/java/org/ntlab/irisclient/MemberRoomActivity.java b/app/src/main/java/org/ntlab/irisclient/MemberRoomActivity.java index 2ea9bba..b9c3a37 100644 --- a/app/src/main/java/org/ntlab/irisclient/MemberRoomActivity.java +++ b/app/src/main/java/org/ntlab/irisclient/MemberRoomActivity.java @@ -32,7 +32,8 @@ //RoomViewModel roomViewModel = new ViewModelProvider(this).get(RoomViewModel.class); //フィールド - ArrayList members = new ArrayList<>(); + ArrayList viewMembers = new ArrayList<>(); + ArrayList oldMembers = new ArrayList<>(); String r = "roomid"; String myName = "null"; @@ -47,25 +48,69 @@ String roomId = ((Iris) getApplication()).getRid(); String nickname = ((Iris) getApplication()).getNickname(); + + //自分のなまえ Intent intentMain = getIntent(); myName = intentMain.getStringExtra("nickname"); //-------------------------------------------------------------------------- + //メンバー表示 + Member mn = new Member(myName); + mn.setBelongs("g"); + mn.setMaster(false); + + viewMembers.add(mn.getNickname()); + + //-------------------------------------------------------------------------- //RoomViewModelへのアクセス RoomViewModel roomViewModel = new ViewModelProvider(this).get(RoomViewModel.class); roomViewModel.setRid(roomId); + /*memberList = roomViewModel.getMembersLiveData().getValue(); + + memberList.forEach(m -> members.add(m.getNickname()));*/ + + ListView membersList = (ListView) findViewById(R.id.MembersList); + + BaseAdapter adapter = new MemberListAdapter(this.getApplicationContext(), R.layout.member_list_layout, viewMembers); + membersList.setAdapter(adapter); //LiveData(List)への購読 - roomViewModel.getMembersLiveData().observe(this, new Observer>() { - private List members; + /*roomViewModel.getMembersLiveData().observe(this, new Observer>() { + //private List members; @Override - public void onChanged(List members) { + public void onChanged(List irisMembers) { + int i = 0; + if(irisMembers.size() == oldMembers.size()) { + + do { + if (irisMembers.get(i).getNickname().equals(oldMembers.get(i))) { + i++; + } else { + viewMembers.clear(); + irisMembers.forEach(m -> viewMembers.add(m.getNickname())); + System.arraycopy(viewMembers, 0, oldMembers, 0, viewMembers.size()); + + BaseAdapter adapter = new MemberListAdapter(getApplicationContext(), R.layout.member_list_layout, viewMembers); + membersList.setAdapter(adapter); + + break; + } + + } while (i < oldMembers.size()); + } else { + viewMembers.clear(); + irisMembers.forEach(m -> viewMembers.add(m.getNickname())); + System.arraycopy(viewMembers, 0, oldMembers, 0, viewMembers.size()); + + BaseAdapter adapter = new MemberListAdapter(getApplicationContext(), R.layout.member_list_layout, viewMembers); + membersList.setAdapter(adapter); + } } - }); + });*/ roomViewModel.getStateLiveData().observe(this, new Observer() { @Override @@ -82,39 +127,6 @@ //各ボタン処理 buttonProcesses(); - //-------------------------------------------------------------------------- - //メンバー表示 - Member m1 = new Member("m1"); - m1.setBelongs("r"); - m1.setMaster(true); - - Member m2 = new Member("m2"); - m2.setBelongs("b"); - m2.setMaster(true); - - Member mn = new Member(myName); - mn.setBelongs("g"); - mn.setMaster(false); - - members.add(m1.getNickname()); - members.add(m2.getNickname()); - - members.add(mn.getNickname()); - - - ListView membersList = (ListView) findViewById(R.id.MembersList); - - //ArrayAdapter adapter = new MemberListAdapter(this.getApplicationContext()); - //ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, members); - /*ArrayAdapter adapter = new ArrayAdapter(this.getApplicationContext(), - R.layout.member_list_layout, members);*/ - /*ArrayAdapter adapter = new ArrayAdapter(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); - //---------------------------------------------------------------