Skip to content

Commit

Permalink
Merge pull request #201 from TeamPINGLE/feat-my-group
Browse files Browse the repository at this point in the history
  • Loading branch information
HAJIEUN02 authored Mar 1, 2024
2 parents e926d09 + 46cd733 commit 7969101
Show file tree
Hide file tree
Showing 26 changed files with 1,184 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ interface PingleLocalDataSource {
var refreshToken: String
var groupId: Int
var groupName: String
var meetingCount: String
var participantCount: String
var isOwner: Boolean
var groupKeyword: String
var code: String
fun clear(): Unit
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@ class PingleLocalDataSourceImpl @Inject constructor(
get() = pref.getString(GROUP_NAME, "") ?: ""
set(value) = pref.edit { putString(GROUP_NAME, value) }

override var meetingCount: String
get() = pref.getString(MEETING_COUNT, "") ?: ""
set(value) = pref.edit { putString(MEETING_COUNT, value) }

override var participantCount: String
get() = pref.getString(PARTICIPANTS_COUNT, "") ?: ""
set(value) = pref.edit { putString(PARTICIPANTS_COUNT, value) }

override var groupKeyword: String
get() = pref.getString(GROUP_KEYWORD, "") ?: ""
set(value) = pref.edit { putString(GROUP_KEYWORD, value) }

override var isOwner: Boolean
get() = pref.getBoolean(IS_OWNER, false)
set(value) = pref.edit { putBoolean(IS_OWNER, value) }

override var code: String
get() = pref.getString(GROUP_CODE, "") ?: ""
set(value) = pref.edit { putString(GROUP_CODE, value) }

override fun clear() {
pref.edit {
clear()
Expand All @@ -69,5 +89,10 @@ class PingleLocalDataSourceImpl @Inject constructor(
const val REFRESH_TOKEN = "RefreshToken"
const val GROUP_ID = "GroupId"
const val GROUP_NAME = "GroupName"
const val MEETING_COUNT = "MeetingCount"
const val PARTICIPANTS_COUNT = "ParticipantsCount"
const val GROUP_KEYWORD = "GroupKeyWord"
const val IS_OWNER = "IsOwner"
const val GROUP_CODE = "GroupCode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.sopt.pingle.data.model.remote.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.pingle.domain.model.MyGroupEntity

@Serializable
data class ResponseMyGroupDto(
@SerialName("id")
val id: Int,
@SerialName("keyword")
val keyword: String,
@SerialName("name")
val name: String,
@SerialName("meetingCount")
val meetingCount: Int,
@SerialName("participantCount")
val participantCount: Int,
@SerialName("isOwner")
val isOwner: Boolean,
@SerialName("code")
val code: String
) {
fun toResponseMyGroupEntity() = MyGroupEntity(
id = id,
keyword = keyword,
name = name,
meetingCount = meetingCount.toString(),
participantCount = participantCount.toString(),
isOwner = isOwner,
code = code
)
}
11 changes: 11 additions & 0 deletions app/src/main/java/org/sopt/pingle/domain/model/MyGroupEntity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.pingle.domain.model

data class MyGroupEntity(
var id: Int,
val keyword: String,
val name: String,
val meetingCount: String,
val participantCount: String,
val isOwner: Boolean,
val code: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class JoinViewModel @Inject constructor(
runCatching {
getJoinGroupInfoUseCase(teamId = teamId).collect { joinGroupInfo ->
_joinGroupInfoState.value = UiState.Success(joinGroupInfo)
with(localStorage) {
meetingCount = joinGroupInfo.meetingCount.toString()
participantCount = joinGroupInfo.participantCount.toString()
}
}
}.onFailure {
_joinGroupInfoState.value = UiState.Error(it.message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class MoreFragment : BindingFragment<FragmentMoreBinding>(R.layout.fragment_more
collectData()
}

override fun onResume() {
super.onResume()
binding.tvMoreMyGroupContent.text = moreViewModel.getGroupName()
}

private fun initLayout() {
with(binding) {
tvMoreVersionDetail.text = BuildConfig.VERSION_NAME
Expand Down Expand Up @@ -69,55 +74,58 @@ class MoreFragment : BindingFragment<FragmentMoreBinding>(R.layout.fragment_more
}

private fun collectData() {
moreViewModel.logoutState.flowWithLifecycle(viewLifecycleOwner.lifecycle).onEach { logoutState ->
when (logoutState) {
is UiState.Success -> {
moveToSign()
}

is UiState.Error -> {
Timber.d(FAILURE_LOGOUT)
}
moreViewModel.logoutState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { logoutState ->
when (logoutState) {
is UiState.Success -> {
moveToSign()
}

else -> {}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
is UiState.Error -> {
Timber.d(FAILURE_LOGOUT)
}

moreViewModel.withDrawState.flowWithLifecycle(viewLifecycleOwner.lifecycle).onEach { withDrawState ->
when (withDrawState) {
is UiState.Success -> {
kakaoAuthService.withdrawKakao()
moveToSign()
else -> {}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)

moreViewModel.withDrawState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { withDrawState ->
when (withDrawState) {
is UiState.Success -> {
kakaoAuthService.withdrawKakao()
moveToSign()
}

is UiState.Error -> {
when (withDrawState.message) {
FAILURE_OWNER -> {
PingleSnackbar.makeSnackbar(
requireView(),
stringOf(R.string.more_snackbar_failure),
SNACKBAR_BOTTOM_MARGIN,
SnackbarType.WARNING
)
is UiState.Error -> {
when (withDrawState.message) {
FAILURE_OWNER -> {
PingleSnackbar.makeSnackbar(
requireView(),
stringOf(R.string.more_snackbar_failure),
SNACKBAR_BOTTOM_MARGIN,
SnackbarType.WARNING
)
}

else -> Timber.d("$FAILURE_LOGOUT : ${withDrawState.message}")
}

else -> Timber.d("$FAILURE_LOGOUT : ${withDrawState.message}")
}

else -> {}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)

else -> {}
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
moreViewModel.userInfoState.flowWithLifecycle(viewLifecycleOwner.lifecycle)
.onEach { userInfoState ->
when (userInfoState) {
is UiState.Success -> {
binding.tvMoreNickname.text = userInfoState.data.name
}

moreViewModel.userInfoState.flowWithLifecycle(viewLifecycleOwner.lifecycle).onEach { userInfoState ->
when (userInfoState) {
is UiState.Success -> {
binding.tvMoreNickname.text = userInfoState.data.name
else -> Unit
}

else -> Unit
}
}.launchIn(viewLifecycleOwner.lifecycleScope)
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

private fun moveToSign() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,141 @@
package org.sopt.pingle.presentation.ui.mygroup

import android.content.Intent
import android.os.Bundle
import android.view.View
import androidx.activity.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.sopt.pingle.R
import org.sopt.pingle.databinding.ActivityMyGroupBinding
import org.sopt.pingle.domain.model.MyGroupEntity
import org.sopt.pingle.presentation.type.SnackbarType
import org.sopt.pingle.presentation.ui.onboarding.OnBoardingActivity
import org.sopt.pingle.util.base.BindingActivity
import org.sopt.pingle.util.component.PingleSnackbar
import org.sopt.pingle.util.context.PINGLE_PLAY_STORE_LINK
import org.sopt.pingle.util.context.PINGLE_SHARE_CODE
import org.sopt.pingle.util.context.copyGroupCode
import org.sopt.pingle.util.context.sharePingle
import org.sopt.pingle.util.context.stringOf
import timber.log.Timber

@AndroidEntryPoint
class MyGroupActivity : BindingActivity<ActivityMyGroupBinding>(R.layout.activity_my_group) {

private val viewModel by viewModels<MyGroupViewModel>()
private lateinit var adapter: MyGroupAdapter

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

binding.myGroupviewModel = viewModel

initLayout()
addListeners()
collectData()
}

override fun onDestroy() {
binding.rvMyGroupSelected.adapter = null
super.onDestroy()
}

private fun initLayout() {
viewModel.getGroupList()
binding.toolbarMyGroup.text = stringOf(R.string.my_group_title)

runCatching {
adapter = MyGroupAdapter(this@MyGroupActivity::showChangeGroupModal)
binding.rvMyGroupSelected.adapter = adapter
adapter.submitList(viewModel.filteredGroupList.value)
}.onFailure { throwable -> Timber.e(throwable.message) }
}

private fun addListeners() {
with(binding) {
toolbarMyGroup.ivAllTopbarArrowWithTitleArrowLeft.setOnClickListener { finish() }
tvMyGroupMoveSelectedGroup.setOnClickListener { navigateToNewGroupInfo() }
ivMyGroupSelectedMenu.setOnClickListener { showMyGroupMenu() }
root.setOnClickListener { layoutMyGroupSelectedMenu.visibility = View.INVISIBLE }
layoutMyGroupSelectedMenuCopy.setOnClickListener { copyGroupCode() }
layoutMyGroupSelectedMenuShare.setOnClickListener { shareGroupCode() }
}
}

private fun collectData() {
viewModel.filteredGroupList.flowWithLifecycle(lifecycle).onEach { filteredList ->
adapter.submitList(filteredList)
}.launchIn(lifecycleScope)

viewModel.selectedMyGroup.flowWithLifecycle(lifecycle).onEach { selectedMyGroup ->
binding.ivMyGroupSelectedOwner.visibility = if (selectedMyGroup?.isOwner == true) View.VISIBLE else View.INVISIBLE
}.launchIn(lifecycleScope)
}

private fun showMyGroupMenu() {
with(binding) {
if (layoutMyGroupSelectedMenu.visibility == View.VISIBLE) {
layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
} else {
layoutMyGroupSelectedMenu.visibility = View.VISIBLE
}
}
}

private fun showChangeGroupModal(clickedEntity: MyGroupEntity) {
binding.layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
MyGroupModalDialogFragment(
title = getString(
R.string.my_group_modal_move_question,
clickedEntity.name
),
buttonText = stringOf(R.string.my_group_modal_change),
textButtonText = stringOf(R.string.my_group_modal_back),
clickBtn = { chageToNewGroup(clickedEntity) },
clickTextBtn = { }
).show(supportFragmentManager, CHANGE_MODAL)
}

private fun chageToNewGroup(clickedEntity: MyGroupEntity) {
viewModel.changeGroupList(clickedEntity)

PingleSnackbar.makeSnackbar(
view = binding.root,
message = stringOf(R.string.my_group_snack_bar_chage_group_complete),
bottomMarin = SNACKBAR_BOTTOM_MARGIN,
snackbarType = SnackbarType.GUIDE
)
}

private fun copyGroupCode() {
binding.layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
copyGroupCode(viewModel.getGroupCode())
PingleSnackbar.makeSnackbar(
view = binding.root,
message = stringOf(R.string.my_group_snack_bar_code_copy_complete),
bottomMarin = SNACKBAR_BOTTOM_MARGIN,
snackbarType = SnackbarType.GUIDE
)
}

private fun shareGroupCode() {
// TODO 콘텐츠 내용 알려주면 ContextExt와 함께 수정
binding.layoutMyGroupSelectedMenu.visibility = View.INVISIBLE
this.sharePingle(getString(R.string.my_group_share_pingle, viewModel.getGroupName(), PINGLE_SHARE_CODE, viewModel.getGroupCode(), PINGLE_PLAY_STORE_LINK))
}

private fun navigateToNewGroupInfo() {
Intent(this, OnBoardingActivity::class.java).apply {
startActivity(this)
}
}

companion object {
private const val CHANGE_MODAL = "ChangeGroupModal"
private const val SNACKBAR_BOTTOM_MARGIN = 57
}
}
Loading

0 comments on commit 7969101

Please sign in to comment.