diff --git a/app/src/main/java/org/ntlab/irisclient/CreateRoomActivity.java b/app/src/main/java/org/ntlab/irisclient/CreateRoomActivity.java index f47a29f..ed6e445 100644 --- a/app/src/main/java/org/ntlab/irisclient/CreateRoomActivity.java +++ b/app/src/main/java/org/ntlab/irisclient/CreateRoomActivity.java @@ -16,6 +16,15 @@ import android.app.AlertDialog; import android.widget.EditText; +import org.ntlab.irisclient.entities.RoomJson; +import org.ntlab.irisclient.resources.RoomsRest; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; +import retrofit2.converter.jackson.JacksonConverterFactory; + public class CreateRoomActivity extends AppCompatActivity { @Override @@ -23,6 +32,15 @@ super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_room); + //---------------------------------------------------------------------------------------------------------------------------------- + //サーバーとの通信の初期化 + Retrofit retrofit = new Retrofit.Builder() + .baseUrl("http://nitta-lab-www.is.konan-u.ac.jp/iris/") + .addConverterFactory(JacksonConverterFactory.create()) + .build(); + final RoomsRest roomRest = retrofit.create(RoomsRest.class); + + //------------------------------------------------------------------------------------------------------------------------------------------ //アクションバーの非表示 ActionBar actionBar = getSupportActionBar(); @@ -44,18 +62,34 @@ //ボタンをクリックすると、部屋を作る次の画面に遷移 Button nextButton = findViewById(R.id.CreateRoomButton); - EditText text = (EditText) findViewById(R.id.nicknameEditText); nextButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { + EditText text = (EditText) findViewById(R.id.nicknameEditText); + String nickname = text.getText().toString(); - //ニックネームが入力されていない場合エラーメッセージを表示する + //ニックネームが入力されていない場合エラーメッセージを表示する if (text.getText().toString().isEmpty()) { text.setError("ニックネームを入力されていません"); //ニックネームが入力されていれば次の画面へ } else { - Intent intent = new Intent(CreateRoomActivity.this,OwnerRoomActivity.class); - startActivity(intent); + //サーバーとの通信のために呼び出す + Call call = roomRest.makeRooms(nickname); + call.enqueue(new Callback() { + //onResponseで成功 + public void onResponse(Call call, Response response) { + if (response.isSuccessful()) { + //iris.setPreferenceName(nickname); + //次の画面へ遷移 + Intent intent = new Intent(CreateRoomActivity.this,OwnerRoomActivity.class); + startActivity(intent); + } + } + //onFailureで失敗 + public void onFailure(Call call, Throwable t) { + } + }); + } } });