Skip to content
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

Merged
merged 8 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.MissionDetailCreateActivity"
android:name=".presentation.shortgame.missiondetailcreate.MissionDetailCreateActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
Expand All @@ -92,7 +92,7 @@
android:exported="false"
android:screenOrientation="portrait" />
<activity
android:name=".presentation.shortgame.CreateShortGameActivity"
android:name=".presentation.shortgame.createshortgame.CreateShortGameActivity"
android:exported="false"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
Expand Down

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
Expand Up @@ -5,7 +5,7 @@ import dagger.hilt.android.AndroidEntryPoint
import sopt.uni.R
import sopt.uni.databinding.ActivityHomeBinding
import sopt.uni.presentation.history.HistoryActivity
import sopt.uni.presentation.shortgame.CreateShortGameActivity
import sopt.uni.presentation.shortgame.createshortgame.CreateShortGameActivity
import sopt.uni.presentation.wish.WishActivity
import sopt.uni.util.binding.BindingActivity
import sopt.uni.util.extension.setOnSingleClickListener
Expand Down
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
Expand All @@ -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)
Expand All @@ -37,6 +53,7 @@ class CreateShortGameActivity :
super.onCreate(savedInstanceState)
setContentView(binding.root)
binding.viewModel = viewModel
setViewModelObserve()
setAdapter()
setClickListener()
}
Expand All @@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (it == true) {
if (it) {

이렇게 바꿔도 되지 않나욤?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 맞네 감사요

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)
Expand All @@ -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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 수정하겟슴둥

} else {
view.setTextColor(view.context.getColor(R.color.Gray_200))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sopt.uni.presentation.shortgame
package sopt.uni.presentation.shortgame.createshortgame

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -9,6 +9,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 +21,9 @@ class CreateShortGameViewModel : ViewModel() {
it.length
}

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

init {
setDummyList()
}
Expand All @@ -31,12 +37,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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sopt.uni.presentation.shortgame
package sopt.uni.presentation.shortgame.createshortgame

import android.view.LayoutInflater
import android.view.ViewGroup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package sopt.uni.presentation.shortgame
package sopt.uni.presentation.shortgame.createshortgame

import androidx.recyclerview.widget.RecyclerView
import coil.load
Expand Down
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

savedStateHadle 좀 알려줘잉

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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, "대박")),
)
}
}
Loading
Loading