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

[AN] 비회원 관리 #595

Merged
merged 8 commits into from
Nov 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class GuestViewModel @Inject constructor(
private val _refreshState: MutableLiveData<Boolean> = MutableLiveData<Boolean>()
val refreshState: LiveData<Boolean> get() = _refreshState

fun refresh() {
_refreshState.value = true
fun updateRefreshState(isRefreshed: Boolean) {
_refreshState.value = isRefreshed
}

fun signUp(token: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ class LoginBottomSheetFragment :
setClickEventOnLoginButton()
}

override fun onDestroyView() {
super.onDestroyView()

if (guestViewModel.signUpState.value != SUCCESS) {
guestViewModel.updateRefreshState(false)
}
}

private fun initBinding() {
binding.lifecycleOwner = viewLifecycleOwner
}
Expand All @@ -72,7 +80,7 @@ class LoginBottomSheetFragment :
when (onBoardingDoneState) {
is OnBoardingDoneState.Success -> {
if (onBoardingDoneState.isDone) {
guestViewModel.refresh()
guestViewModel.updateRefreshState(true)
this.dismiss()
if (parentFragment is BottomSheetListener) {
(parentFragment as BottomSheetListener).onBottomSheetClosed()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import javax.inject.Inject

@HiltViewModel
class HomeViewModel @Inject constructor(
private val homeRepository: HomeRepository
private val homeRepository: HomeRepository,
) : ViewModel() {

private val _userStudyUiState: MutableStateFlow<UserStudyState> = MutableStateFlow(Idle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.created.team201.presentation.chat.ChatFragment
import com.created.team201.presentation.common.BindingActivity
import com.created.team201.presentation.guest.GuestFragment
import com.created.team201.presentation.guest.GuestViewModel
import com.created.team201.presentation.guest.bottomSheet.LoginBottomSheetFragment
import com.created.team201.presentation.home.HomeFragment
import com.created.team201.presentation.main.MainActivity.FragmentType.CHAT
import com.created.team201.presentation.main.MainActivity.FragmentType.GUEST
Expand Down Expand Up @@ -51,7 +52,7 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
Toast.makeText(
this@MainActivity,
getString(R.string.main_toast_back_pressed),
Toast.LENGTH_SHORT
Toast.LENGTH_SHORT,
).show()
} else {
finish()
Expand All @@ -65,29 +66,34 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
val itemId = binding.bnvMain.selectedItemId
val fragmentType = FragmentType.valueOf(itemId)
showFragment(fragmentType)
} else {
binding.bnvMain.selectedItemId = R.id.menu_study_list
}
}
}

private fun setBottomNavigationView() {
binding.bnvMain.setOnItemSelectedListener(::displayFragment)
binding.bnvMain.selectedItemId = R.id.menu_home
binding.bnvMain.selectedItemId = when (mainViewModel.isGuest) {
true -> R.id.menu_study_list
false -> R.id.menu_home
}
}

private fun displayFragment(item: MenuItem): Boolean {
when (FragmentType.valueOf(item.itemId)) {
HOME -> showOriginOrGuest(HOME)
HOME -> showOriginOrLogin(HOME)
STUDY_LIST -> showFragment(STUDY_LIST)
CHAT -> showOriginOrGuest(CHAT)
MY_PAGE -> showOriginOrGuest(MY_PAGE)
CHAT -> showOriginOrLogin(CHAT)
MY_PAGE -> showOriginOrLogin(MY_PAGE)
else -> throw IllegalStateException()
}
return true
}

private fun showOriginOrGuest(type: FragmentType) {
private fun showOriginOrLogin(type: FragmentType) {
when (mainViewModel.isGuest) {
true -> showFragment(GUEST)
true -> showLoginBottomSheetDialog()
false -> showFragment(type)
}
}
Expand Down Expand Up @@ -141,6 +147,13 @@ class MainActivity : BindingActivity<ActivityMainBinding>(R.layout.activity_main
}
}

private fun showLoginBottomSheetDialog() {
LoginBottomSheetFragment().show(
Copy link
Collaborator

Choose a reason for hiding this comment

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

얘는 매번 생성안하고 한번만 생성해도 되지 않나요? 진짜궁금

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

엇 그렇네요.
굳이 안해줘도 되네요.
인스턴스 한번만 생성하게 바꿨습니다 ~

supportFragmentManager,
LoginBottomSheetFragment.TAG_LOGIN_BOTTOM_SHEET,
)
}

private enum class FragmentType(@IdRes private val resId: Int) {
GUEST(-1),
HOME(R.id.menu_home),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.created.team201.presentation.main.MainViewModel
import com.created.team201.presentation.studyDetail.StudyDetailActivity
import com.created.team201.presentation.studyList.adapter.StudyListAdapter
import com.created.team201.presentation.studyList.model.StudyListFilter
import com.created.team201.presentation.studyList.model.StudyListFilter.Companion.isGuestOnly
import com.created.team201.util.FirebaseLogUtil
import com.created.team201.util.FirebaseLogUtil.SCREEN_STUDY_LIST
import com.google.android.material.chip.ChipGroup
Expand All @@ -39,6 +40,7 @@ class StudyListFragment :
private val studyListAdapter: StudyListAdapter by lazy {
StudyListAdapter(studyListClickListener())
}
private val loginBottomSheetFragment: LoginBottomSheetFragment = LoginBottomSheetFragment()

override fun onResume() {
super.onResume()
Expand Down Expand Up @@ -179,7 +181,7 @@ class StudyListFragment :

private fun showLoginBottomSheetDialog() {
removeAllFragment()
LoginBottomSheetFragment().show(
loginBottomSheetFragment.show(
childFragmentManager,
LoginBottomSheetFragment.TAG_LOGIN_BOTTOM_SHEET,
)
Expand Down Expand Up @@ -235,9 +237,6 @@ class StudyListFragment :

private fun setupStudyList() {
studyListViewModel.initPage()
binding.tvGuestInformation.setOnClickListener {
showLoginBottomSheetDialog()
}
}

private fun studyListClickListener() = object : StudyListClickListener {
Expand All @@ -256,6 +255,9 @@ class StudyListFragment :
studyListViewModel.updateIsGuest(mainViewModel.isGuest)
val filter = getStudyListFilter(group)
studyListViewModel.loadFilteredPage(filter)
if (mainViewModel.isGuest and filter.isGuestOnly()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

오 ㅋ and 연산자쓰는사람 처음봄 mz하네요

Copy link
Collaborator

Choose a reason for hiding this comment

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

이런게 있었어?!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

요즘 python 많이 썻더니..

showLoginBottomSheetDialog()
}
}

private fun getStudyListFilter(group: ChipGroup): StudyListFilter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.created.domain.model.Page
import com.created.domain.model.Role
import com.created.domain.repository.StudyListRepository
import com.created.team201.presentation.studyList.model.StudyListFilter
import com.created.team201.presentation.studyList.model.StudyListFilter.Companion.isGuestOnly
import com.created.team201.presentation.studyList.model.StudySummaryUiModel
import com.created.team201.presentation.studyList.model.StudySummaryUiModel.Companion.toUiModel
import com.created.team201.util.NonNullLiveData
Expand Down Expand Up @@ -116,8 +117,7 @@ class StudyListViewModel @Inject constructor(

fun loadFilteredPage(filter: StudyListFilter) {
filterStatus = filter
_isGuestMode.value =
((filterStatus == StudyListFilter.WAITING_APPLICANT) or (filterStatus == StudyListFilter.WAITING_MEMBER)) and isGuest
_isGuestMode.value = filter.isGuestOnly() and isGuest
refreshPage()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.created.team201.presentation.studyList.model

enum class StudyListFilter {
ALL, RECRUITING, PROCESSING, WAITING_APPLICANT, WAITING_MEMBER
ALL, RECRUITING, PROCESSING, WAITING_APPLICANT, WAITING_MEMBER;

companion object {
fun StudyListFilter.isGuestOnly(): Boolean {
return this == WAITING_MEMBER || this == WAITING_APPLICANT
}
}
}
17 changes: 15 additions & 2 deletions android/app/src/main/res/layout/fragment_guest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:onClick="@{() -> onClickViewListener.invoke()}">
android:layout_height="match_parent">

<ImageView
android:id="@+id/iv_home_logo"
Expand All @@ -38,5 +37,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:onClick="@{() -> onClickViewListener.invoke()}"
android:text="@string/guest_login_button"
android:textAppearance="@style/subtitle_r20"
android:textColor="@color/white"
app:layout_constraintEnd_toEndOf="@id/tv_home_no_study"
app:layout_constraintStart_toStartOf="@id/tv_home_no_study"
app:layout_constraintTop_toBottomOf="@id/tv_home_no_study" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<!-- 비회원 뷰 -->
<string name="guest_information_title">로그인이 필요한 서비스입니다.</string>
<string name="guest_toast_can_not_report">비회원은 신고할 수 없습니다</string>
<string name="guest_login_button">로그인하러 가기 ></string>

<!-- 로그인 바텀 시트 다이얼로그 뷰 -->
<string name="loginBottomSheetFragment_information_title">로그인 이후 서비스 이용이 가능합니다.</string>
Expand Down