-
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
Feature/#102 refactor createshortgame #115
Changes from all commits
7305c43
56d2ee8
11121ab
40fba79
4e2ce03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,31 @@ | ||
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.Button | ||
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.presentation.shortgame.missiondetailcreate.MissionDetailCreateFragment | ||
import sopt.uni.util.binding.BindingActivity | ||
import sopt.uni.util.extension.parcelable | ||
import sopt.uni.util.extension.setOnSingleClickListener | ||
|
||
@AndroidEntryPoint | ||
class CreateShortGameActivity : | ||
BindingActivity<ActivityCreateShortGameBinding>(R.layout.activity_create_short_game) { | ||
|
||
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 shortGameFragment by lazy { ShortGameFragment.newInstance() } | ||
private val missionDetailCreateFragment by lazy { MissionDetailCreateFragment.newInstance() } | ||
|
||
private val missionAdapter by lazy { | ||
MissionCategoryAdapter( | ||
goToMissionDetailClickListener = { missionIdPosition -> | ||
val intent = Intent(this, MissionDetailCreateActivity::class.java) | ||
intent.putExtra(MissionDetailCreateActivity.MISSION_ID_POSITION, missionIdPosition) | ||
activityLauncher.launch(intent) | ||
}, | ||
selectMissionClickListener = { missionIdPosition -> | ||
selectItem(missionIdPosition.id, missionIdPosition.position) | ||
}, | ||
) | ||
} | ||
private val viewModel: CreateShortGameViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
binding.viewModel = viewModel | ||
setViewModelObserve() | ||
setAdapter() | ||
setClickListener() | ||
changeFragment(getString(R.string.label_short_game)) | ||
} | ||
|
||
// ํ๋ฉด ํด๋ฆญํ์ฌ ํค๋ณด๋ ์จ๊ธฐ๊ธฐ ๋ฐ ํฌ์ปค์ค ์ ๊ฑฐ | ||
|
@@ -79,115 +46,29 @@ class CreateShortGameActivity : | |
return super.dispatchTouchEvent(event) | ||
} | ||
|
||
override fun onBackPressed() { | ||
exitDialog() | ||
} | ||
fun changeFragment(tag: String) { | ||
val fragmentManager = supportFragmentManager | ||
val fragment = fragmentManager.findFragmentByTag(tag) ?: when (tag) { | ||
getString(R.string.label_mission_detail) -> missionDetailCreateFragment | ||
getString(R.string.label_short_game) -> shortGameFragment | ||
else -> null | ||
} ?: return | ||
|
||
private fun setAdapter() { | ||
binding.rvMission.adapter = missionAdapter | ||
binding.rvMission.addItemDecoration(ItemDecorations(0, 9, 0, 9)) | ||
} | ||
if (fragment.isVisible) return | ||
|
||
private fun setViewModelObserve() { | ||
viewModel.missionList.observe(this) { | ||
missionAdapter.submitList(it) | ||
} | ||
viewModel.isCreateSuccess.observe(this) { | ||
if (it) { | ||
MissionRecordActivity.start( | ||
this, | ||
viewModel.roundGameId.value | ||
?: return@observe, | ||
) | ||
finish() | ||
} | ||
} | ||
} | ||
val transaction = fragmentManager.beginTransaction() | ||
|
||
private fun setClickListener() { | ||
binding.apply { | ||
ivClose.setOnSingleClickListener { | ||
exitDialog() | ||
fragmentManager.fragments.filter { it.isVisible } | ||
.forEach { | ||
transaction.hide(it) | ||
} | ||
btnCreate.setOnSingleClickListener { | ||
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) | ||
} | ||
|
||
companion object { | ||
private const val MAX_LENGTH = 54 | ||
|
||
@JvmStatic | ||
@BindingAdapter("setContentLength") | ||
fun setContentLength(view: TextView, length: Int) { | ||
if (length > MAX_LENGTH) { | ||
view.setTextColor(view.context.getColor(R.color.Red_500)) | ||
} else { | ||
view.setTextColor(view.context.getColor(R.color.Gray_200)) | ||
} | ||
view.text = "$length/$MAX_LENGTH" | ||
if (fragment.isAdded) { | ||
transaction.show(fragment) | ||
} else { | ||
transaction.add(R.id.fcv_create_short_game, fragment, tag) | ||
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. replace๊ฐ ์๋ hide & add ๋ฐฉ์์ ์ฌ์ฉํ ์ด์ ๊ฐ ์์๊น์? ๋ก์ง ์ค๋ช ํด์ฃผ์๋ฉด ๋๋ฌด๋๋ฌด ๊ฐ์ฌํ๊ฒ ์ต๋๋ค :) 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. replace์ add ์ฐจ์ด๋ฅผ ๋ณด์๋ฉด replace๋ ์ด์ ํ๋๊ทธ๋จผํธ๋ฅผ ์ญ์ ํ๊ณ ์๋ก์ด ํ๋๊ทธ๋จผํธ๋ฅผ ์ถ๊ฐํ๋ ๊ฒ๊ณผ ๋ฌ๋ฆฌ add์ ๊ฒฝ์ฐ์๋ ํ๋๊ทธ๋จผํธ๋ฅผ ์ญ์ ํ์ง์์ต๋๋ค. ํํ์น๋ถ์์ฑ์์ ๋ฏธ์ ์นดํ ๊ณ ๋ฆฌ๋ทฐ๋ก ์์ฃผ ์ด๋์ ํด์ผํ ๊ฑฐ๋ผ๊ณ ์๊ฐํด์ ๊ตณ์ด ๋งค๋ฒ ํ๋๊ทธ๋จผํธ๋ฅผ ์ญ์ ํ ํ์์๋ค๊ณ ์๊ฐํด์ ์ด๋ ๊ฒ ๊ตฌํํ์ต๋๋ค! 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. ์ ํฌ ์ํฉ์์๋ add๋ก show/hide๋ฅผ ํ๋ ๊ฒ ๋ง๊ฒ ๊ตฐ์..! ์ํ๋ฅผ ๋ณด์กดํด์ผ ๋๊ธฐ๋ ํ๋๊น |
||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("setContentLength") | ||
fun setWishContent(view: EditText, length: Int) { | ||
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) | ||
} | ||
} | ||
|
||
@JvmStatic | ||
@BindingAdapter("setContentLength") | ||
fun setButtonEnable(view: Button, length: Int) { | ||
view.isEnabled = length <= MAX_LENGTH | ||
} | ||
transaction.commit() | ||
} | ||
} |
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.
์ถ์ฒ ์๊ฐ์ด null์ผ ์๋ ์๋์..? ํ๊ฑฑ
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.
์ผ๋จ ์๋ฒ๊ฐ ๋ด๋ ค์ฃผ๋๊ฒ nullableํ๊ฒ ๋ด๋ ค์ค๋๋ค...ใ ใ