diff --git a/app/src/main/java/com/example/sprout/refactor/activity/RoomCreateActivity.java b/app/src/main/java/com/example/sprout/refactor/activity/RoomCreateActivity.java index 4d853aa..746e6f1 100644 --- a/app/src/main/java/com/example/sprout/refactor/activity/RoomCreateActivity.java +++ b/app/src/main/java/com/example/sprout/refactor/activity/RoomCreateActivity.java @@ -8,47 +8,68 @@ import com.example.sprout.R; import com.example.sprout.databinding.RfActivityRoomCreateBinding; -import com.example.sprout.refactor.common.ActivityEvent; -import com.example.sprout.refactor.contract.ViewContract; import com.example.sprout.refactor.viewmodel.RoomCreateViewModel; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.schedulers.Schedulers; + /** * ルーム作成のActivity * * @author matsumoto_k */ -public class RoomCreateActivity extends AppCompatActivity implements ViewContract { +public class RoomCreateActivity extends AppCompatActivity { + + private CompositeDisposable subscriptions = null; + private RoomCreateViewModel roomCreateViewModel = null; + private RfActivityRoomCreateBinding binding = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - RfActivityRoomCreateBinding binding = DataBindingUtil.setContentView(this, R.layout.rf_activity_room_create); - RoomCreateViewModel roomCreateViewModel = new RoomCreateViewModel((ViewContract) this); + binding = DataBindingUtil.setContentView(this, R.layout.rf_activity_room_create); + roomCreateViewModel = new RoomCreateViewModel(); binding.setViewModel(roomCreateViewModel); getLifecycle().addObserver(roomCreateViewModel); } @Override - public void startActivity(ActivityEvent event) { - switch (event) { - case ROOM_MAIN: - startActivity(new Intent(RoomCreateActivity.this, RoomMainActivity.class)); - break; - } + protected void onResume() { + super.onResume(); + subscribe(); } - @Override - public void finishActivity() { - finish(); - } - - @Override - public void showShortToast(String message) { - Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); - } - - @Override - public void showLongToast(String message) { - Toast.makeText(this, message, Toast.LENGTH_LONG).show(); + private void subscribe() { + subscriptions = new CompositeDisposable(); + // トーストの購読 + subscriptions.add( + roomCreateViewModel.getToastMessanger() + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(toastMessage -> { + switch (toastMessage.getLength()) { + case SHORT: + Toast.makeText(this, toastMessage.getMessage(), Toast.LENGTH_SHORT).show(); + break; + case LONG: + Toast.makeText(this, toastMessage.getMessage(), Toast.LENGTH_LONG).show(); + break; + } + }) + ); + // 画面遷移の購読 + subscriptions.add( + roomCreateViewModel.getNavigationMessenger() + .observeOn(Schedulers.computation()) + .subscribe(navigationMessage -> { + switch (navigationMessage.getType()) { + case Start: + startActivity(new Intent(RoomCreateActivity.this, navigationMessage.getClazz())); + break; + case Finsih: + finish(); + } + }) + ); } }