-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#35 한판승부생성 화면전환 기능 구현 #54
Changes from 7 commits
3368e42
85d5ffa
7a13ed0
f949a96
19df0fd
3d2406e
3db274e
7401344
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package sopt.uni.presentation.entity | ||
|
||
import android.os.Parcelable | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@Parcelize | ||
data class MissionIdPosition( | ||
val id: Int, | ||
val position: Int | ||
) | ||
val position: Int, | ||
) : Parcelable |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,26 @@ | ||
package sopt.uni.presentation.shortgame | ||
package sopt.uni.presentation.shortgame.createshortgame | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.graphics.Rect | ||
import android.os.Bundle | ||
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 | ||
|
@@ -22,10 +29,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) | ||
|
@@ -37,6 +53,7 @@ class CreateShortGameActivity : | |
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
binding.viewModel = viewModel | ||
setViewModelObserve() | ||
setAdapter() | ||
setClickListener() | ||
} | ||
|
@@ -62,22 +79,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 = [email protected](R.string.create_short_game_exit_dialog_title) | ||
bodyText = [email protected](R.string.create_short_game_exit_dialog_body) | ||
confirmButtonText = [email protected](R.string.create_short_game_exit_dialog_exit) | ||
dismissButtonText = [email protected](R.string.dialog_cancel_text) | ||
confirmClickListener = { | ||
finish() | ||
this.dismiss() | ||
} | ||
dismissClickListener = { | ||
this.dismiss() | ||
} | ||
}.show(supportFragmentManager, "") | ||
} | ||
|
||
private fun createDialog() { | ||
CreateShortGameDialogFragment().apply { | ||
titleText = [email protected](R.string.create_short_game_create_dialog_title) | ||
bodyText = [email protected](R.string.create_short_game_create_dialog_body) | ||
confirmButtonText = [email protected](R.string.create_short_game_create_dialog_create) | ||
dismissButtonText = [email protected](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) | ||
|
@@ -89,7 +151,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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 수정하겟슴둥 |
||
} else { | ||
view.setTextColor(view.context.getColor(R.color.Gray_200)) | ||
|
@@ -100,7 +162,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) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package sopt.uni.presentation.shortgame.createshortgame.dialog | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import sopt.uni.R | ||
import sopt.uni.databinding.TitleAction2DialogBinding | ||
import sopt.uni.presentation.BindingDialogFragment | ||
|
||
class CreateShortGameDialogFragment : | ||
BindingDialogFragment<TitleAction2DialogBinding>(R.layout.title_action2_dialog) { | ||
|
||
var titleText: String? = null | ||
var bodyText: String? = null | ||
var confirmButtonText: String? = null | ||
var dismissButtonText: String? = null | ||
var confirmClickListener: (() -> Unit)? = null | ||
var dismissClickListener: (() -> Unit)? = null | ||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
initView() | ||
} | ||
|
||
private fun initView() { | ||
titleText?.let { | ||
binding.dialogTitle.visibility = View.VISIBLE | ||
binding.dialogTitle.text = it | ||
} ?: kotlin.run { | ||
binding.dialogTitle.visibility = View.GONE | ||
} | ||
bodyText?.let { | ||
binding.dialogBody.visibility = View.VISIBLE | ||
binding.dialogBody.text = it | ||
} ?: kotlin.run { | ||
binding.dialogBody.visibility = View.GONE | ||
} | ||
confirmButtonText?.let { | ||
binding.btnRight.text = it | ||
} | ||
dismissButtonText?.let { | ||
binding.btnLeft.text = it | ||
} | ||
|
||
confirmClickListener?.let { | ||
binding.btnRight.visibility = View.VISIBLE | ||
binding.btnRight.setOnClickListener { | ||
confirmClickListener?.invoke() | ||
} | ||
} ?: kotlin.run { | ||
binding.btnRight.visibility = View.GONE | ||
} | ||
|
||
dismissClickListener?.let { | ||
binding.btnLeft.visibility = View.VISIBLE | ||
binding.btnLeft.setOnClickListener { | ||
dismissClickListener?.invoke() | ||
} | ||
} ?: run { | ||
binding.btnLeft.visibility = View.GONE | ||
} | ||
Comment on lines
+24
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 스코프 함수 장인이네요 ㅎㄷㄷ |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package sopt.uni.presentation.shortgame.missiondetailcreate | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import sopt.uni.R | ||
import sopt.uni.databinding.ActivityMissionDetailCreateBinding | ||
import sopt.uni.presentation.entity.MissionIdPosition | ||
import sopt.uni.presentation.shortgame.createshortgame.CreateShortGameActivity | ||
import sopt.uni.util.binding.BindingActivity | ||
import sopt.uni.util.extension.parcelable | ||
import sopt.uni.util.extension.setOnSingleClickListener | ||
|
||
class MissionDetailCreateActivity : BindingActivity<ActivityMissionDetailCreateBinding>(R.layout.activity_mission_detail_create) { | ||
|
||
private val viewModel: MissionDetailCreateViewModel by viewModels() | ||
|
||
private lateinit var idPosition: MissionIdPosition | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
idPosition = intent.parcelable<MissionIdPosition>(MISSION_ID_POSITION)!! | ||
binding.missionDetailCreateViewModel = viewModel | ||
setClickListener() | ||
} | ||
|
||
private fun setClickListener() { | ||
binding.missionDetailCreateMissionBtnPick.setOnSingleClickListener { | ||
val intent = Intent(this, CreateShortGameActivity::class.java) | ||
intent.putExtra(MISSION_ID_POSITION, idPosition) | ||
setResult(RESULT_OK, intent) | ||
finish() | ||
} | ||
binding.missionDetailCreateBack.setOnSingleClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
companion object { | ||
const val MISSION_ID_POSITION = "MISSION_ID_POSITION" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package sopt.uni.presentation.shortgame.missiondetailcreate | ||
|
||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.SavedStateHandle | ||
import androidx.lifecycle.ViewModel | ||
import sopt.uni.data.entity.shortgame.MissionDetail | ||
import sopt.uni.data.entity.shortgame.MissionExample | ||
import sopt.uni.presentation.entity.MissionIdPosition | ||
|
||
class MissionDetailCreateViewModel(savedStateHandle: SavedStateHandle) : ViewModel() { | ||
val missionId = savedStateHandle.get<MissionIdPosition>(MissionDetailCreateActivity.MISSION_ID_POSITION) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 한번 설명할게연 |
||
|
||
private val _missionDetail = MutableLiveData<MissionDetail>() | ||
val missionDetail = _missionDetail | ||
|
||
init { | ||
setMissionDetail() | ||
} | ||
|
||
fun setMissionDetail() { | ||
_missionDetail.value = MissionDetail( | ||
1, | ||
"금지어 말하지 않기", | ||
"금지이름 말하지 않는 게임입니다", | ||
"본인에게 할당된 주제의 답변을 상대방이 맞춰야 하는 게임입니다.\n" + "단순 주제가 나와있는 미션이라면, 상대의 입장에서 해당 주제에 대한 답을 해주세요.\n" + "2지선다로 이루어진 미션이라면, 상대가 어떤 선지를 더 좋아할지에 대해 예상하여 답을 해주세요.", | ||
"요리조리 피해보세요", | ||
"https://github.com/U-is-Ni-in-Korea/Android-United/assets/50603273/8c345eb3-d688-42bd-8585-a02f1016e213", | ||
listOf(MissionExample(1, "헐"), MissionExample(2, "대박")), | ||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이렇게 바꿔도 되지 않나욤?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 맞네 감사요