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.Button; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; import android.widget.TextView; 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 { //フィールド String r = "部屋ID " + "123456"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_owner_room); String nickname = ((Iris) getApplication()).getNickname(); String rid = ((Iris) getApplication()).getRid(); //RoomViewModelへのアクセス RoomViewModel roomViewModel = new ViewModelProvider(this).get(RoomViewModel.class); //LiveData(List<Member>)への購読 roomViewModel.getMembersLiveData().observe(this, new Observer<List<Member>>() { private List<Member> members; @Override public void onChanged(List<Member> members) { } }); //-------------------------------------------------------------------------- //各ボタン処理 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); Button randomButton = (Button) findViewById(R.id.random); Button startButton = (Button) findViewById(R.id.start); ImageButton copyButton = (ImageButton) findViewById(R.id.copyButton); //--------------------------------------------------------------------------- //メンバーリスト ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, members); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); redMasterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "red"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.clear(); members.add("マスターのRedさん"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); } }); redSpyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "red"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("スパイのRedさん"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); } }); blueMasterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "blue"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("マスターのBlueさん"); listView.setBackgroundColor(Color.parseColor("#e83a48")); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); } }); blueSpyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "red"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("スパイのBlueさん"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setBackgroundColor(Color.parseColor("#3a5fe8")); listView.setAdapter(adapter); } }); randomButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "random"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("ランダムさん"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); 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) { r = "部屋ID " + "start"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("スタートさん"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); } }); copyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { r = "部屋ID " + "copy"; TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); members.add("コピーしました"); ListView listView = (ListView)findViewById(R.id.MembersList); listView.setAdapter(adapter); } }); //-------------------------------------------------------------------------- //メンバー表示 //members.add("1さん"); //--------------------------------------------------------------- //settings情報 String s = "設定\\nお絵描き"; TextView settingsText = findViewById(R.id.settings); settingsText.setText(s); //--------------------------------------------------------------- //部屋ID情報 TextView RoomIdText = findViewById(R.id.roomID); RoomIdText.setText(r); //スタートボタンをクリックすると、(絵を描く?)次の画面に遷移 Button nextButton = (Button)findViewById(R.id.start); nextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { /* //ニックネームが入力されていない場合エラーメッセージを表示する if (text.getText().toString().isEmpty()) { text.setError("ニックネームを入力されていません"); //ニックネームが入力されていれば次の画面へ } else { */ //サーバーとの通信のために呼び出す /* Call<RoomJson> call = roomRest.makeRooms(nickname); call.enqueue(new Callback<RoomJson>() { //onResponseで成功 public void onResponse(Call<RoomJson> call, Response<RoomJson> response) { if (response.isSuccessful()) { //ridとnicknameをIrisへ String rid = response.body().getRid(); ((Iris) getApplication()).setRid(rid); ((Iris) getApplication()).setNickname(nickname); */ //次の画面へ遷移 Intent intent = new Intent(OwnerRoomActivity.this,DrawingActivity.class); startActivity(intent); } /* } //onFailureで失敗 public void onFailure(Call<RoomJson> call, Throwable t) { } }); //} } */ }); roomViewModel.start(500); } /*private getMemberInformation(){ }*/ /*private void addMemberToMemberList(String m){ members.add(m); }*/ }