-
Notifications
You must be signed in to change notification settings - Fork 1
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
#33 / 초대장 보내기 받기 서버통신 구현 #69
Merged
+275
−33
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c72fba7
#33 / 초대코드 발급 받기 로직 구현
taeheeL 4d7c743
#33 / 상대 연결 확인하기 UI 수정
taeheeL d55830d
#33 / flow 방출 로직 추가
taeheeL 671c980
#33 / 상대 연결 확인하기 서버통신 구현
taeheeL f8d845f
#33 / 초대코드 공유 기능 추가
taeheeL f28e15c
#33 / 초대코드 힌트 수정
taeheeL c5482db
#33 / 연결하기 버튼 안가리게 하기
taeheeL e158a6f
#33 / 상대 연결 확인하기 버튼 디자인 수정
taeheeL b4f27a6
#33 / 상대 연결 확인하기 서버통신 구현
taeheeL 9b4d532
#33 / 코드리뷰 반영
taeheeL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 7 additions & 1 deletion
8
app/src/main/java/sopt/uni/data/repository/onboarding/OnBoardingRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package sopt.uni.data.repository.onboarding | ||
|
||
import retrofit2.Response | ||
|
||
interface OnBoardingRepository { | ||
|
||
suspend fun patchNickName(nickname: String) | ||
|
||
suspend fun postStartDate(startDate: String) | ||
suspend fun postStartDate(startDate: String): String | ||
|
||
suspend fun checkCoupleConnection(): Boolean | ||
|
||
suspend fun postCheckConnection(inviteCode: String): Response<Unit> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/sopt/uni/data/source/remote/request/RequestPostCheckConnectionDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package sopt.uni.data.source.remote.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class RequestPostCheckConnectionDto( | ||
@SerialName("inviteCode") | ||
val inviteCode: String, | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/sopt/uni/data/source/remote/response/ResponseCheckConnectionDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package sopt.uni.data.source.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ResponseCheckConnectionDto( | ||
@SerialName("connection") | ||
val connection: Boolean, | ||
) |
1 change: 1 addition & 0 deletions
1
app/src/main/java/sopt/uni/presentation/common/content/Const.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
package sopt.uni.presentation.common.content | ||
|
||
const val MAX_LENGTH = 10 | ||
const val INVITECODE = "inviteCode" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 38 additions & 2 deletions
40
app/src/main/java/sopt/uni/presentation/invite/EnterInviteCodeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,61 @@ | ||
package sopt.uni.presentation.invite | ||
|
||
import android.os.Bundle | ||
import android.view.View | ||
import androidx.activity.viewModels | ||
import androidx.lifecycle.lifecycleScope | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.launch | ||
import sopt.uni.R | ||
import sopt.uni.databinding.ActivityEnterInviteCodeBinding | ||
import sopt.uni.presentation.home.HomeActivity | ||
import sopt.uni.util.binding.BindingActivity | ||
import sopt.uni.util.extension.setOnSingleClickListener | ||
import sopt.uni.util.extension.showToast | ||
import sopt.uni.util.extension.startActivity | ||
|
||
@AndroidEntryPoint | ||
class EnterInviteCodeActivity : | ||
BindingActivity<ActivityEnterInviteCodeBinding>(R.layout.activity_enter_invite_code) { | ||
private val enterInviteCodeViewModel by viewModels<EnterInviteCodeViewModel>() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
|
||
binding.viewModel = enterInviteCodeViewModel | ||
moveToPrevPage() | ||
checkInviteCode() | ||
changeBoxStrokeColor() | ||
} | ||
|
||
private fun moveToPrevPage() { | ||
binding.ivBackArrow.setOnSingleClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun changeBoxStrokeColor() { | ||
if (binding.etInviteCode.text.isNotBlank()) { | ||
binding.etInviteCode.background = getDrawable(R.drawable.bg_mypage_edit_text) | ||
} | ||
} | ||
|
||
private fun checkInviteCode() { | ||
binding.btnConnect.setOnSingleClickListener { | ||
enterInviteCodeViewModel.checkCoupleConnection() | ||
lifecycleScope.launch { | ||
enterInviteCodeViewModel.connectState.collect { responseCode -> | ||
if (responseCode == "204") { | ||
[email protected](getString(R.string.couple_connect_success)) | ||
binding.etInviteCode.background = getDrawable(R.drawable.bg_mypage_edit_text) | ||
binding.tvInviteCodeErrorMessage.visibility = View.INVISIBLE | ||
startActivity<HomeActivity>() | ||
finishAffinity() | ||
} else { | ||
binding.etInviteCode.background = | ||
getDrawable(R.drawable.bg_mypage_edit_text_error) | ||
binding.tvInviteCodeErrorMessage.visibility = View.VISIBLE | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/sopt/uni/presentation/invite/EnterInviteCodeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package sopt.uni.presentation.invite | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.launch | ||
import sopt.uni.data.repository.onboarding.OnBoardingRepository | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class EnterInviteCodeViewModel @Inject constructor( | ||
private val onBoardingRepository: OnBoardingRepository, | ||
) : ViewModel() { | ||
|
||
val inviteCode = MutableStateFlow("") | ||
val connectState = MutableStateFlow("") | ||
|
||
fun checkCoupleConnection() { | ||
viewModelScope.launch { | ||
kotlin.runCatching { | ||
Timber.d("invite = ${inviteCode.value}") | ||
onBoardingRepository.postCheckConnection(inviteCode = inviteCode.value) | ||
}.fold({ | ||
connectState.emit(it.code().toString()) | ||
}, { | ||
Timber.d(it) | ||
}) | ||
} | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/sopt/uni/presentation/invite/ShareInviteCodeActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,72 @@ | ||
package sopt.uni.presentation.invite | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import androidx.lifecycle.lifecycleScope | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.launch | ||
import sopt.uni.R | ||
import sopt.uni.databinding.ActivityShareInviteCodeBinding | ||
import sopt.uni.presentation.common.content.INVITECODE | ||
import sopt.uni.presentation.home.HomeActivity | ||
import sopt.uni.util.binding.BindingActivity | ||
import sopt.uni.util.extension.setOnSingleClickListener | ||
import sopt.uni.util.extension.showSnackbar | ||
import sopt.uni.util.extension.startActivity | ||
import timber.log.Timber | ||
|
||
@AndroidEntryPoint | ||
class ShareInviteCodeActivity : | ||
BindingActivity<ActivityShareInviteCodeBinding>(R.layout.activity_share_invite_code) { | ||
private val shareInviteCodeViewModel by viewModels<ShareInviteCodeViewModel>() | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
|
||
moveToPrevPage() | ||
getInviteCode() | ||
checkCoupleConnection() | ||
copyInviteCode() | ||
} | ||
|
||
private fun getInviteCode() { | ||
Timber.e(intent.getStringExtra(INVITECODE)) | ||
binding.tvInviteCode.text = intent.getStringExtra(INVITECODE) | ||
} | ||
|
||
private fun moveToPrevPage() { | ||
binding.ivBackArrow.setOnSingleClickListener { | ||
finish() | ||
} | ||
} | ||
|
||
private fun checkCoupleConnection() { | ||
binding.llCheckConnection.setOnSingleClickListener { | ||
shareInviteCodeViewModel.checkCoupleConnection() | ||
lifecycleScope.launch { | ||
shareInviteCodeViewModel.isConnected.collect { isConnected -> | ||
if (isConnected) { | ||
startActivity<HomeActivity>() | ||
finishAffinity() | ||
} else { | ||
showSnackbar(binding.root, getString(R.string.cannot_connect)) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun copyInviteCode() { | ||
binding.btnCopyInviteCode.setOnSingleClickListener { | ||
val sendIntent: Intent = Intent().apply { | ||
action = Intent.ACTION_SEND | ||
putExtra(Intent.EXTRA_TEXT, binding.tvInviteCode.text.toString()) | ||
type = "text/plain" | ||
} | ||
|
||
val shareIntent = Intent.createChooser(sendIntent, null) | ||
startActivity(shareIntent) | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/sopt/uni/presentation/invite/ShareInviteCodeViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package sopt.uni.presentation.invite | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.launch | ||
import sopt.uni.data.repository.onboarding.OnBoardingRepository | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ShareInviteCodeViewModel @Inject constructor( | ||
private val onBoardingRepository: OnBoardingRepository, | ||
) : ViewModel() { | ||
val isConnected = MutableStateFlow<Boolean>(false) | ||
|
||
fun checkCoupleConnection() { | ||
viewModelScope.launch { | ||
kotlin.runCatching { | ||
onBoardingRepository.checkCoupleConnection() | ||
}.fold({ | ||
isConnected.emit(it) | ||
}, { | ||
Timber.d(it) | ||
}) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 내가 쓰는 const value 여기다가 빼야겠다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헤헤 알아봐주셔서 감사합니다