Skip to content

Commit

Permalink
Merge pull request #71 from Team-Umbba/feat/#66
Browse files Browse the repository at this point in the history
[Feat/#66] 선택 질문 뷰 이동 로직 생성
  • Loading branch information
yeoncheong authored Jul 17, 2023
2 parents 9bf2d78 + 13b2e31 commit c00015f
Show file tree
Hide file tree
Showing 25 changed files with 676 additions and 91 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize" />
<activity
android:name=".presentation.onboarding.QuestActivity"
android:name=".presentation.onboarding.quest.QuestActivity"
android:exported="false"
android:screenOrientation="portrait" />
<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.sopt.umbba_android.data.model

import com.google.firebase.BuildConfig
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import com.sopt.umbba_android.BuildConfig
import com.sopt.umbba_android.data.service.HomeService
import com.sopt.umbba_android.data.service.ListService
import com.sopt.umbba_android.data.service.OnBoardingService
Expand All @@ -15,14 +15,17 @@ import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit

object ApiFactory {

const val UMBBA_URL = BuildConfig.UMBBA_BASE_URL

private val client by lazy {
OkHttpClient.Builder().addInterceptor(
AuthInterceptor()
).build()
}
val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl("d")
.baseUrl(UMBBA_URL)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.client(client)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.View
import androidx.activity.viewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivityInputInfoBinding
import com.sopt.umbba_android.presentation.onboarding.quest.QuestActivity
import com.sopt.umbba_android.presentation.onboarding.viewmodel.InputInfoViewModel
import com.sopt.umbba_android.util.binding.BindingActivity
import java.util.regex.Pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.core.content.ContextCompat
import com.google.android.material.snackbar.Snackbar
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivityNotifyTimeBinding
import com.sopt.umbba_android.presentation.onboarding.quest.QuestActivity
import com.sopt.umbba_android.util.binding.BindingActivity

class NotifyTimeActivity :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ class OnboardingFinishActivity : BindingActivity<ActivityOnboardingFinishBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

goBack()
animateFadeBackground()
goMainActivity()
}

private fun goBack() {
binding.btnBack2.setOnClickListener {
finish()
}
}

private fun animateFadeBackground() {
Handler(Looper.getMainLooper()).postDelayed({
val fadeOutAnim = AnimationUtils.loadAnimation(this, R.anim.fadeout)
Expand All @@ -32,7 +39,7 @@ class OnboardingFinishActivity : BindingActivity<ActivityOnboardingFinishBinding
startAnimation(fadeInAnim)
visibility = View.VISIBLE
}
},2000)
},1000)

}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.view.View
import androidx.activity.viewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivitySelectFamilyBinding
import com.sopt.umbba_android.presentation.onboarding.quest.QuestActivity
import com.sopt.umbba_android.presentation.onboarding.viewmodel.SelectFamilyViewModel
import com.sopt.umbba_android.util.binding.BindingActivity

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package com.sopt.umbba_android.presentation.onboarding.quest

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.viewModels
import com.sopt.umbba_android.R
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.commit
import com.sopt.umbba_android.databinding.ActivityQuestBinding
import com.sopt.umbba_android.presentation.onboarding.NotifyTimeActivity
import com.sopt.umbba_android.presentation.onboarding.SetTimeActivity
import com.sopt.umbba_android.util.binding.BindingActivity

class QuestActivity : BindingActivity<ActivityQuestBinding>(R.layout.activity_quest),
View.OnClickListener {

private val viewModel by viewModels<QuestViewModel>()
private var count = 0
private var quest = arrayOfNulls<String>(5)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.viewmodel = viewModel
binding.clickListener = this

initFragment(QuestOneFragment())
checkNextButtonEnabled()
clickNextButton()
}

override fun onClick(view: View?) {
when (view?.id) {
R.id.iv_basic_back -> {
if (count in 1..4) {
supportFragmentManager.popBackStack("$count", FragmentManager.POP_BACK_STACK_INCLUSIVE)
binding.progressBar.progress -= 20
count -= 1
initChip()
setBeforeButtonClick(count)
} else {
finish()
}
}
}
}

private fun setBeforeButtonClick(count: Int) {
when (quest[count].toString()) {
"" -> viewModel.isClickedYes.value = true
"아니" -> viewModel.isClickedNo.value = true
"애매해" -> viewModel.isClickedAmbiguous.value = true
}
Log.d("viewmodel", "pop stack : ${count}번 : ${quest[count].toString()}")
}

private fun initFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.add(R.id.fragment_question, fragment)
.addToBackStack("$count")
.commit()
}

private fun changeFragment(fragment: Fragment) {
supportFragmentManager.commit {
replace(R.id.fragment_question, fragment)
.addToBackStack("$count")
}
}

private fun checkNextButtonEnabled() {
viewModel.isClickedComplete.observe(this) {
binding.btnNext.isEnabled = true
}
}

private fun clickNextButton() {
binding.btnNext.setOnClickListener {
Log.d("viewmodel", "chipText : ${viewModel.clickedChipText.value.toString()}")
Log.d("viewmodel", "count : ${count}")
quest[count] = viewModel.clickedChipText.value.toString()
Log.d("viewmodel", "배열 값 : ${quest[count]}")
initChip()
count += 1
when (count) {
0 -> changeFragment(QuestOneFragment())
1 -> changeFragment(QuestTwoFragment())
2 -> changeFragment(QuestThreeFragment())
3 -> changeFragment(QuestFourFragment())
4 -> changeFragment(QuestFiveFragment())
5 -> {
goNextActivity()
count = 4
}
}
binding.progressBar.progress += 20
}
}

private fun initChip() {
with(viewModel) {
isClickedYes.value = false
isClickedNo.value = false
isClickedAmbiguous.value = false
}
}

private fun goNextActivity() {
if (true) { //초대하는 측
startActivity(Intent(this, SetTimeActivity::class.java))
} else { //초대받는 측
startActivity(Intent(this, NotifyTimeActivity::class.java))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sopt.umbba_android.presentation.onboarding.quest

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentQuestFiveBinding
import com.sopt.umbba_android.util.binding.BindingFragment

class QuestFiveFragment : BindingFragment<FragmentQuestFiveBinding>(R.layout.fragment_quest_five) {
private val viewModel by activityViewModels<QuestViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewmodel = viewModel

checkButtonComplete()
}

private fun checkButtonComplete() {
viewModel.isClickedYes.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer1.text.toString()
}
viewModel.isClickedNo.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer2.text.toString()
}
viewModel.isClickedAmbiguous.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer3.text.toString()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.sopt.umbba_android.presentation.onboarding.quest

import android.os.Bundle
import android.view.View
import androidx.fragment.app.activityViewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentQuestFourBinding
import com.sopt.umbba_android.util.binding.BindingFragment

class QuestFourFragment : BindingFragment<FragmentQuestFourBinding>(R.layout.fragment_quest_four) {
private val viewModel by activityViewModels<QuestViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewmodel = viewModel

checkButtonComplete()
}

private fun checkButtonComplete() {
viewModel.isClickedYes.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer1.text.toString()
}
viewModel.isClickedNo.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer2.text.toString()
}
viewModel.isClickedAmbiguous.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer3.text.toString()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.sopt.umbba_android.presentation.onboarding.quest

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.FragmentQuestOneBinding
import com.sopt.umbba_android.util.binding.BindingFragment

class QuestOneFragment : BindingFragment<FragmentQuestOneBinding>(R.layout.fragment_quest_one) {

private val viewModel by activityViewModels<QuestViewModel>()
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.viewmodel = viewModel

checkButtonComplete()
}

private fun checkButtonComplete() {
viewModel.isClickedYes.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer1.text.toString()
}
viewModel.isClickedNo.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer2.text.toString()
}
viewModel.isClickedAmbiguous.observe(viewLifecycleOwner) {
viewModel.checkButtonComplete()
viewModel.clickedChipText.value = binding.btnAnswer3.text.toString()

}
}
}
Loading

0 comments on commit c00015f

Please sign in to comment.