Skip to content

Commit

Permalink
#35 / Update CreateShortGame
Browse files Browse the repository at this point in the history
나가기 다이얼로그 기능 구현
한판승부 생성 기능 구현
미션상세 이동 기능 구현
  • Loading branch information
rkdmf1026 committed Jul 18, 2023
1 parent 12c849c commit 64ea8ca
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
package sopt.uni.presentation.shortgame.createshortgame

import android.content.Context
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.util.Log
import android.view.MotionEvent
import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.TextView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.databinding.BindingAdapter
import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.databinding.ActivityCreateShortGameBinding
import sopt.uni.presentation.entity.MissionIdPosition
import sopt.uni.presentation.shortgame.createshortgame.dialog.CreateShortGameDialogFragment
import sopt.uni.presentation.shortgame.missiondetailcreate.MissionDetailCreateActivity
import sopt.uni.presentation.shortgame.missionrecord.MissionRecordActivity
import sopt.uni.util.ItemDecorations
import sopt.uni.util.binding.BindingActivity
import sopt.uni.util.extension.parcelable
import sopt.uni.util.extension.setOnSingleClickListener

@AndroidEntryPoint
Expand All @@ -22,10 +30,19 @@ class CreateShortGameActivity :

private val viewModel: CreateShortGameViewModel by viewModels()

private val activityLauncher = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
if (it.resultCode == RESULT_OK) {
val data = it.data?.parcelable<MissionIdPosition>(MissionDetailCreateActivity.MISSION_ID_POSITION) as MissionIdPosition
selectItem(data.id, data.position)
}
}

private val missionAdapter by lazy {
MissionCategoryAdapter(
goToMissionDetailClickListener = { missionIdPosition ->
// TODO : 미션상세뷰 이동
val intent = Intent(this, MissionDetailCreateActivity::class.java)
intent.putExtra(MissionDetailCreateActivity.MISSION_ID_POSITION, missionIdPosition)
activityLauncher.launch(intent)
},
selectMissionClickListener = { missionIdPosition ->
selectItem(missionIdPosition.id, missionIdPosition.position)
Expand All @@ -37,6 +54,7 @@ class CreateShortGameActivity :
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.viewModel = viewModel
setViewModelObserve()
setAdapter()
setClickListener()
}
Expand All @@ -62,22 +80,67 @@ class CreateShortGameActivity :
private fun setAdapter() {
binding.rvMission.adapter = missionAdapter
binding.rvMission.addItemDecoration(ItemDecorations(0, 9, 0, 9))
}

private fun setViewModelObserve() {
viewModel.missionList.observe(this) {
missionAdapter.submitList(it)
}
viewModel.isCreateSuccess.observe(this) {
if (it == true) {
MissionRecordActivity.start(
this,
viewModel.roundGameId.value
?: return@observe,
)
finish()
}
}
}

private fun setClickListener() {
binding.apply {
ivClose.setOnSingleClickListener {
// TODO : 종료 다이얼로그
exitDialog()
}
btnCreate.setOnSingleClickListener {
// TODO : 생성 다이얼로그 + 미션 기록 액티비티 이동
createDialog()
}
}
}

private fun exitDialog() {
CreateShortGameDialogFragment().apply {
titleText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_exit_dialog_title)
bodyText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_exit_dialog_body)
confirmButtonText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_exit_dialog_exit)
dismissButtonText = this@CreateShortGameActivity.resources.getString(R.string.dialog_cancel_text)
confirmClickListener = {
finish()
this.dismiss()
}
dismissClickListener = {
this.dismiss()
}
}.show(supportFragmentManager, "")
}

private fun createDialog() {
CreateShortGameDialogFragment().apply {
titleText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_create_dialog_title)
bodyText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_create_dialog_body)
confirmButtonText = this@CreateShortGameActivity.resources.getString(R.string.create_short_game_create_dialog_create)
dismissButtonText = this@CreateShortGameActivity.resources.getString(R.string.dialog_cancel_text)
confirmClickListener = {
viewModel.createShortGame()
this.dismiss()
}
dismissClickListener = {
this.dismiss()
}
}.show(supportFragmentManager, "")
}

private fun selectItem(id: Int, position: Int) {
missionAdapter.setSelectedItem(position)
viewModel.setSelectedMissionId(id)
Expand All @@ -89,7 +152,7 @@ class CreateShortGameActivity :
@JvmStatic
@BindingAdapter("setContentLength")
fun setContentLength(view: TextView, length: Int) {
if (length >= MAX_LENGTH) {
if (length > MAX_LENGTH) {
view.setTextColor(view.context.getColor(R.color.Red_500))
} else {
view.setTextColor(view.context.getColor(R.color.Gray_200))
Expand All @@ -100,7 +163,7 @@ class CreateShortGameActivity :
@JvmStatic
@BindingAdapter("setContentLength")
fun setWishContent(view: EditText, length: Int) {
if (length >= MAX_LENGTH && view.isFocused) {
if (length > MAX_LENGTH && view.isFocused) {
view.background = view.context.getDrawable(R.drawable.bg_wish_edit_text_error)
} else {
view.background = view.context.getDrawable(R.drawable.bg_wish_edit_text)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sopt.uni.presentation.shortgame.createshortgame

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
Expand All @@ -9,6 +10,9 @@ class CreateShortGameViewModel : ViewModel() {
private val _selectedMissionId = MutableLiveData<Int>()
val selectedMissionId = _selectedMissionId

private val _roundGameId = MutableLiveData<Int>()
val roundGameId = _roundGameId

private val _missionList = MutableLiveData<List<Mission>>()
val missionList = _missionList

Expand All @@ -18,6 +22,9 @@ class CreateShortGameViewModel : ViewModel() {
it.length
}

private val _isCreateSuccess = MutableLiveData<Boolean>(false)
val isCreateSuccess = _isCreateSuccess

init {
setDummyList()
}
Expand All @@ -31,12 +38,17 @@ class CreateShortGameViewModel : ViewModel() {
image = "https://github.com/U-is-Ni-in-Korea/Android-United/assets/50603273/8c345eb3-d688-42bd-8585-a02f1016e213",
title = "$i",
id = i,
)
),
)
}
_missionList.value = missionList
}

fun createShortGame() {
_isCreateSuccess.postValue(true)
_roundGameId.value = 1
}

fun setSelectedMissionId(missionId: Int) {
_selectedMissionId.value = missionId
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_create_short_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@
android:background="@drawable/bg_wish_edit_text"
android:gravity="top"
android:hint="@string/create_short_game_wish_content_hint"
android:imeOptions="actionDone"
android:importantForAutofill="no"
android:inputType="textMultiLine"
android:maxLength="54"
android:maxLength="60"
android:maxLines="3"
android:padding="10dp"
android:text="@={viewModel.wishContent}"
Expand Down

0 comments on commit 64ea8ca

Please sign in to comment.