package org.ntlab.irisclient; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; import com.google.android.material.snackbar.Snackbar; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; import androidx.lifecycle.ViewModelProvider; import org.ntlab.irisclient.entities.RoomJson; import org.ntlab.irisclient.models.Member; import org.ntlab.irisclient.resources.RoomsRest; import org.ntlab.irisclient.viewmodels.RoomViewModel; import java.util.ArrayList; import java.util.Collections; import java.util.List; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.jackson.JacksonConverterFactory; public class OwnerRoomActivity extends AppCompatActivity { //フィールド ArrayList<String> viewMembers = new ArrayList<>(); ArrayList<String> oldMembers = new ArrayList<>(); String roomId = "null"; String myName = "null"; //String nickname; String belongs; Boolean isMaster; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_owner_room); myName = ((Iris) getApplication()).getNickname(); roomId = ((Iris) getApplication()).getRid(); //自分のなまえ //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); ListView membersList = (ListView) findViewById(R.id.MembersList); BaseAdapter adapter = new MemberListAdapter(this.getApplicationContext(), R.layout.member_list_layout, viewMembers); membersList.setAdapter(adapter); //LiveData(List<Member>)への購読 roomViewModel.getMembersLiveData().observe(this, new Observer<List<Member>>() { private List<Member> members; @Override public void onChanged(List<Member> irisMembers) { viewMembers.clear(); irisMembers.forEach(m -> viewMembers.add(m.getNickname())); BaseAdapter adapter = new MemberListAdapter(getApplicationContext(), R.layout.member_list_layout, viewMembers); membersList.setAdapter(adapter); } }); //各ボタン処理 ArrayList<String> members = new ArrayList<>(); 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); //OwnerRoom専用ボタン Button randomButton = (Button) findViewById(R.id.random); Button startButton = (Button) findViewById(R.id.start); //チームと役職の変更 //赤チーム・スパイマスター redMasterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { roomViewModel.changeBelongsAndMaster(roomId, myName,"r",true); } }); //赤チーム・諜報員 redSpyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { roomViewModel.changeBelongsAndMaster(roomId, myName,"r",false); } }); //青チーム・スパイマスター blueMasterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { roomViewModel.changeBelongsAndMaster(roomId, myName,"b",true); } }); //青チーム・諜報員 blueSpyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { roomViewModel.changeBelongsAndMaster(roomId, myName,"b",false); } }); //コピーボタン copyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Snackbar.make(v, "コピーしました", Snackbar.LENGTH_LONG).show(); } }); //ランダムボタン randomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Retrofit retrofit = new Retrofit.Builder() .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") .addConverterFactory(JacksonConverterFactory.create()) .build(); final RoomsRest roomsRest = retrofit.create(RoomsRest.class); } }); //スタートボタン startButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { roomViewModel.startDrawing(roomId, myName); Intent intent = new Intent(OwnerRoomActivity.this,DrawingActivity.class); startActivity(intent); } }); //--------------------------------------------------------------- //settings情報 String s = "設定\\nお絵描き"; TextView settingsText = findViewById(R.id.settings); settingsText.setText(s); //--------------------------------------------------------------- //部屋ID情報 TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(roomId); roomViewModel.start(500,(Iris)getApplication()); } }