Skip to content

Commit

Permalink
Merge pull request #595 from woowacourse-teams/AN/feature/574-guest
Browse files Browse the repository at this point in the history
[AN] ๋น„ํšŒ์› ๊ด€๋ฆฌ
  • Loading branch information
RightHennessy authored Nov 2, 2023
2 parents 6ebdf72 + 7e93f14 commit 5e1221d
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 20 deletions.
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(
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()) {
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

0 comments on commit 5e1221d

Please sign in to comment.