diff --git a/app/src/main/java/com/example/sprout/refactor/activity/RoomListActivity.java b/app/src/main/java/com/example/sprout/refactor/activity/RoomListActivity.java index 00c00eb..a53406d 100644 --- a/app/src/main/java/com/example/sprout/refactor/activity/RoomListActivity.java +++ b/app/src/main/java/com/example/sprout/refactor/activity/RoomListActivity.java @@ -9,53 +9,77 @@ import com.example.sprout.R; import com.example.sprout.databinding.RfActivityRoomListBinding; import com.example.sprout.refactor.adapter.RoomListAdapter; -import com.example.sprout.refactor.common.ActivityEvent; import com.example.sprout.refactor.contract.ViewContract; import com.example.sprout.refactor.viewmodel.RoomListViewModel; +import io.reactivex.android.schedulers.AndroidSchedulers; +import io.reactivex.disposables.CompositeDisposable; +import io.reactivex.schedulers.Schedulers; + /** * ルーム一覧のActivity * * @author matsumoto_k */ -public class RoomListActivity extends AppCompatActivity implements ViewContract { +public class RoomListActivity extends AppCompatActivity { + + private RfActivityRoomListBinding binding = null; + private RoomListViewModel roomListViewModel = null; + private CompositeDisposable subscriptions = new CompositeDisposable(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - RfActivityRoomListBinding binding = DataBindingUtil.setContentView(this, R.layout.rf_activity_room_list); - RoomListViewModel roomMainViewModel = new RoomListViewModel(new RoomListAdapter(this), (ViewContract) this); - binding.setViewModel(roomMainViewModel); - getLifecycle().addObserver(roomMainViewModel); + binding = DataBindingUtil.setContentView(this, R.layout.rf_activity_room_list); + roomListViewModel = new RoomListViewModel(new RoomListAdapter(this)); + binding.setViewModel(roomListViewModel); + getLifecycle().addObserver(roomListViewModel); } @Override - public void startActivity(ActivityEvent event) { - switch (event) { - case CREATE_ROOM: - startActivity(new Intent(RoomListActivity.this, RoomCreateActivity.class)); - break; - case ROOM_MAIN: - startActivity(new Intent(RoomListActivity.this, RoomMainActivity.class)); - break; - case INPUT_KEY: - startActivity(new Intent(RoomListActivity.this, RoomInputKeyActivity.class)); - break; - } + protected void onResume() { + super.onResume(); + subscribe(); } @Override - public void finishActivity() { - + protected void onPause() { + super.onPause(); + dispose(); } - @Override - public void showShortToast(String message) { - Toast.makeText(this, message, Toast.LENGTH_SHORT).show(); + private void subscribe() { + subscriptions.add( + roomListViewModel.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( + roomListViewModel.getNavigationMessenger() + .observeOn(Schedulers.computation()) + .subscribe(navigationMessage -> { + switch (navigationMessage.getType()) { + case Start: + startActivity(new Intent(RoomListActivity.this, navigationMessage.getClazz())); + break; + case Finsih: + finish(); + } + }) + ); } - @Override - public void showLongToast(String message) { - Toast.makeText(this, message, Toast.LENGTH_LONG).show(); + private void dispose() { + subscriptions.dispose(); } }