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

#30 [feat] 설정 뷰 + 공통 바텀시트 #35

Merged
merged 16 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 15 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: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.setting.SettingActivity"
android:exported="false"
android:screenOrientation="portrait" />

</application>

Expand Down

This file was deleted.

72 changes: 72 additions & 0 deletions app/src/main/java/com/sopetit/softie/ui/setting/SettingActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.sopetit.softie.ui.setting

import android.os.Bundle
import androidx.activity.viewModels
import androidx.fragment.app.Fragment
import com.sopetit.softie.R
import com.sopetit.softie.databinding.ActivitySettingBinding
import com.sopetit.softie.util.binding.BindingActivity

class SettingActivity : BindingActivity<ActivitySettingBinding>(R.layout.activity_setting) {

private val viewModel by viewModels<SettingViewModel>()

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

initMakeInitFragment()
initChangeFragment()
}

private fun initMakeInitFragment() {
val currentFragment = supportFragmentManager.findFragmentById(R.id.fcv_setting)
if (currentFragment == null) {
supportFragmentManager.beginTransaction()
.add(R.id.fcv_setting, SettingInitFragment())
.commit()
}
}

private fun initChangeFragment() {
viewModel.settingFragment.observe(this) { clickSetting ->
when (clickSetting) {
USER_SECURITY -> changeFragment(SettingUserSecurityFragment())
USER_EXIT -> changeFragment(SettingUserExitFragment())
// TODO 다른 세부 설정 화면 추가
}
}
}

private fun changeFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.replace(R.id.fcv_setting, fragment)
.addToBackStack(FRAGMENT_STACK_TAG).commitAllowingStateLoss()

setClickBackBtnInDetailView(fragment)
}

private fun setClickBackBtnInDetailView(fragment: Fragment) {
binding.btnSettingBack.setOnClickListener {
backInitView(fragment)
}
}

fun backInitView(fragment: Fragment) {
with(supportFragmentManager) {
beginTransaction().remove(fragment).commit()
popBackStack()
}
viewModel.setSettingFragment(SETTING_INIT)
}

companion object {
const val SETTING_INIT = "설정"
const val USER_SECURITY = "개인정보 처리방침"
const val DOCUMENT = "서비스 이용 약관"
const val GUIDE = "서비스 이용 가이드"
const val FEEDBACK = "피드백"
const val USER_EXIT = "회원 탈퇴"
const val FRAGMENT_STACK_TAG = "BACK_STACK_TAG"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.sopetit.softie.ui.setting

import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModelProvider
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentSettingInitBinding
import com.sopetit.softie.ui.setting.SettingActivity.Companion.USER_EXIT
import com.sopetit.softie.ui.setting.SettingActivity.Companion.USER_SECURITY
import com.sopetit.softie.util.binding.BindingBottomSheet
import com.sopetit.softie.util.binding.BindingFragment

class SettingInitFragment :
BindingFragment<FragmentSettingInitBinding>(R.layout.fragment_setting_init) {

private lateinit var viewModel: SettingViewModel

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewModel = ViewModelProvider(requireActivity()).get(SettingViewModel::class.java)
binding.viewModel = viewModel

initChangeFragment()
}

private fun initChangeFragment() {
clickUserSecurity()
clickLogOut()
clickUserExit()
}

private fun clickUserSecurity() {
binding.clSettingUserSecurity.setOnClickListener {
viewModel.setSettingFragment(USER_SECURITY)
}
}

private fun clickDocument() {
// TODO 서비스 이용 약관
}

private fun clickGuide() {
// TODO 서비스 이용 가이드
}

private fun clickFeedback() {
// TODO 피드백
}

private fun clickLogOut() {
binding.btnSettingInitLogout.setOnClickListener {
BindingBottomSheet.Builder().build(
isDrawable = true,
imageDrawable = R.drawable.ic_bear_face_crying,
imageUri = "",
title = "제목",
content = "내용",
isContentVisible = true,
contentColor = R.color.gray300,
backBtnContent = "돌아가기",
doBtnContent = "그냥 해",
doBtnColor = R.drawable.shape_red_fill_12_rect,
backBtnAction = {},
doBtnAction = {}
).show(parentFragmentManager, BOTTOM_SHEET_TAG)
}
}

private fun clickUserExit() {
binding.btnSettingInitUserExit.setOnClickListener {
viewModel.setSettingFragment(USER_EXIT)
}
}

companion object {
const val BOTTOM_SHEET_TAG = "BOTTOM SHEET TAG"
Copy link
Member

Choose a reason for hiding this comment

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

이게 바텀시트 올라오는 오브젝트인가요??

Copy link
Contributor

Choose a reason for hiding this comment

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

요거는 그냥 TAG입니다! 스트링 값!

Copy link
Collaborator

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,60 @@
package com.sopetit.softie.ui.setting

import android.os.Bundle
import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.view.View
import androidx.core.content.ContextCompat
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentSettingUserExitBinding
import com.sopetit.softie.util.binding.BindingFragment

class SettingUserExitFragment :
BindingFragment<FragmentSettingUserExitBinding>(R.layout.fragment_setting_user_exit) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

initSetSpeechText()
initSetClickBackBtn()
}

private fun initSetSpeechText() {
binding.tvUserExitSpeech.text =
SpannableStringBuilder(getString(R.string.user_exit_title)).apply {
setSpan(
ForegroundColorSpan(
ContextCompat.getColor(
requireActivity(),
R.color.red
)
),
SETTING_SPAN_START,
SETTING_SPAN_END,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
)
Comment on lines +24 to +36
Copy link
Contributor

Choose a reason for hiding this comment

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

좋아요~ 애용하시는군요

}
}

private fun initSetBear() {
// TODO bear type 받아서 bear 이미지 띄우기
}
Comment on lines +40 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

제가 홈에서 보내드리겠습니닷

Copy link
Member Author

Choose a reason for hiding this comment

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

감사합니닷


private fun initSetClickBackBtn() {
binding.btnUserExitBack.setOnClickListener {
(activity as SettingActivity).backInitView(this)
}
}

private fun initSetClickExitBtn() {
binding.btnUserExitExit.setOnClickListener {
// TODO 회원탈퇴 로직 추가
}
}

companion object {
const val SETTING_SPAN_START = 8
const val SETTING_SPAN_END = 10
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sopetit.softie.ui.setting

import android.os.Bundle
import android.view.View
import com.sopetit.softie.R
import com.sopetit.softie.databinding.FragmentSettingUserSecurityBinding
import com.sopetit.softie.util.binding.BindingFragment

class SettingUserSecurityFragment :
BindingFragment<FragmentSettingUserSecurityBinding>(R.layout.fragment_setting_user_security) {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.sopetit.softie.ui.setting

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sopetit.softie.ui.setting.SettingActivity.Companion.SETTING_INIT

class SettingViewModel : ViewModel() {

private val _settingFragment: MutableLiveData<String> = MutableLiveData(SETTING_INIT)
val settingFragment: LiveData<String>
get() = _settingFragment

fun setSettingFragment(clickFragment: String) {
_settingFragment.value = clickFragment
}
}
72 changes: 72 additions & 0 deletions app/src/main/java/com/sopetit/softie/util/OriginalBottomSheet.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.sopetit.softie.util

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.sopetit.softie.databinding.FragmentBottomsheetBinding
import com.sopetit.softie.util.binding.BindingAdapter.setImage
import com.sopetit.softie.util.binding.BindingBottomSheet

class OriginalBottomSheet : BindingBottomSheet() {
Copy link
Member

Choose a reason for hiding this comment

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

유틸로 만들어두셧군요 👍


private val binding: FragmentBottomsheetBinding
get() = requireNotNull(_binding as FragmentBottomsheetBinding)

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = FragmentBottomsheetBinding.inflate(inflater, container, false)
return binding.root
}

override fun setImage() {
if (isDrawable == true) {
imageDrawable?.let { binding.ivBottomSheet.setImageResource(it) }
} else {
binding.ivBottomSheet.setImage(imageUri)
}
}

override fun setTitle() {
binding.tvBottomSheetTitle.text = title
}

override fun setContent() {
binding.tvBottomSheetContent.text = content
}

override fun setContentVisible() {
if (isContentVisible == true) {
binding.tvBottomSheetContent.visibility = View.VISIBLE
} else {
binding.tvBottomSheetContent.visibility = View.INVISIBLE
}
}

override fun setContentColor() {
contentColor?.let { binding.tvBottomSheetContent.setTextColor(it) }
}

override fun setBackBtnContent() {
binding.btnBottomSheetBack.text = backBtnContent
}

override fun setDoBtnContent() {
binding.btnBottomSheetDo.text = doBtnContent
}

override fun setDoBtnColor() {
doBtnColor?.let { binding.btnBottomSheetDo.setBackgroundResource(it) }
}

override fun setBackBtnClick(action: () -> Unit) {
binding.btnBottomSheetBack.setOnClickListener { action() }
}

override fun setDoBtnClick(action: () -> Unit) {
binding.btnBottomSheetDo.setOnClickListener { action() }
}
}
Loading