From 0ef1033b2e5c42ab0401cf6374bd22204108c74b Mon Sep 17 00:00:00 2001 From: Jokwanhee Date: Sun, 25 Aug 2024 14:06:54 +0900 Subject: [PATCH] =?UTF-8?q?[feat/#117]=20=EB=94=A5=EB=A7=81=ED=81=AC=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/dpm/spot/di/DataSourceModule.kt | 8 ++ .../java/com/dpm/spot/di/RepositoryModule.kt | 8 ++ buildSrc/src/main/kotlin/Dependencies.kt | 4 + .../com/dpm/data/datasource/AuthDataSource.kt | 5 + .../datasource/local/AuthDataSourceImpl.kt | 13 +++ .../dpm/data/repository/AuthRepositoryImpl.kt | 15 +++ domain/build.gradle.kts | 3 + .../dpm/domain/repository/AuthRepository.kt | 5 + .../com/dpm/domain/usecase/GetTokenUseCase.kt | 12 ++ .../com/dpm/presentation/home/HomeActivity.kt | 16 +++ .../login/ui/KakaoSignupActivity.kt | 27 +++++ .../login/ui/NicknameInputActivity.kt | 27 +++++ .../presentation/login/ui/SignUpActivity.kt | 26 +++++ .../login/ui/SignUpCompleteActivity.kt | 27 +++++ .../login/ui/TeamSelectActivity.kt | 27 +++++ .../dpm/presentation/scheme/SchemeActivity.kt | 104 +++++++++++++++++- .../scheme/viewmodel/SchemeViewModel.kt | 60 ++++++++++ .../viewfinder/StadiumActivity.kt | 7 +- .../viewfinder/StadiumDetailActivity.kt | 12 +- .../viewfinder/compose/StadiumDetailScreen.kt | 5 +- .../main/StadiumDetailPictureTopScreen.kt | 5 +- .../top/StadiumDetailPictureMainScreen.kt | 5 +- .../viewmodel/StadiumDetailViewModel.kt | 1 + 23 files changed, 406 insertions(+), 16 deletions(-) create mode 100644 data/src/main/java/com/dpm/data/datasource/AuthDataSource.kt create mode 100644 data/src/main/java/com/dpm/data/datasource/local/AuthDataSourceImpl.kt create mode 100644 data/src/main/java/com/dpm/data/repository/AuthRepositoryImpl.kt create mode 100644 domain/src/main/java/com/dpm/domain/repository/AuthRepository.kt create mode 100644 domain/src/main/java/com/dpm/domain/usecase/GetTokenUseCase.kt create mode 100644 presentation/src/main/java/com/dpm/presentation/scheme/viewmodel/SchemeViewModel.kt diff --git a/app/src/main/java/com/dpm/spot/di/DataSourceModule.kt b/app/src/main/java/com/dpm/spot/di/DataSourceModule.kt index 21e68040..464b62dc 100644 --- a/app/src/main/java/com/dpm/spot/di/DataSourceModule.kt +++ b/app/src/main/java/com/dpm/spot/di/DataSourceModule.kt @@ -1,11 +1,13 @@ package com.dpm.spot.di +import com.dpm.data.datasource.AuthDataSource import com.dpm.data.datasource.ExampleDataSource import com.dpm.data.datasource.HomeDataSource import com.dpm.data.datasource.SeatReviewDataSource import com.dpm.data.datasource.SignupRemoteDataSource import com.dpm.data.datasource.ViewfinderDataSource import com.dpm.data.datasource.WebSvgDataSource +import com.dpm.data.datasource.local.AuthDataSourceImpl import com.dpm.data.datasource.remote.ExampleDataSourcelmpl import com.dpm.data.datasource.remote.HomeDataSourceImpl import com.dpm.data.datasource.remote.SeatReviewDataSourceImpl @@ -57,4 +59,10 @@ abstract class DataSourceModule { abstract fun bindSignupDataSource( signupDataSourceImpl: SignupRemoteDataSourceImpl, ): SignupRemoteDataSource + + @Binds + @Singleton + abstract fun bindAuthDataSource( + authDataSourceImpl: AuthDataSourceImpl + ): AuthDataSource } diff --git a/app/src/main/java/com/dpm/spot/di/RepositoryModule.kt b/app/src/main/java/com/dpm/spot/di/RepositoryModule.kt index 7caf42c9..bcb4cece 100644 --- a/app/src/main/java/com/dpm/spot/di/RepositoryModule.kt +++ b/app/src/main/java/com/dpm/spot/di/RepositoryModule.kt @@ -1,11 +1,13 @@ package com.dpm.spot.di +import com.dpm.data.repository.AuthRepositoryImpl import com.dpm.data.repository.ExampleRepositoryImpl import com.dpm.data.repository.HomeRepositoryImpl import com.dpm.data.repository.SeatReviewRepositoryImpl import com.dpm.data.repository.SignupRepositoryImpl import com.dpm.data.repository.ViewfinderRepositoryImpl import com.dpm.data.repository.WebSvgRepositoryImpl +import com.dpm.domain.repository.AuthRepository import com.dpm.domain.repository.ExampleRepository import com.dpm.domain.repository.HomeRepository import com.dpm.domain.repository.SeatReviewRepository @@ -57,4 +59,10 @@ abstract class RepositoryModule { abstract fun bindSignupRepository( signupRepositoryImpl: SignupRepositoryImpl, ): SignupRepository + + @Binds + @Singleton + abstract fun bindAuthRepository( + authRepositoryImpl: AuthRepositoryImpl + ): AuthRepository } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index cfa82a2d..3d594e5d 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -8,6 +8,10 @@ object KotlinDependencies { const val dateTime = "org.jetbrains.kotlinx:kotlinx-datetime:${Versions.kotlinDateTimeVersion}" } +object JavaDependencies { + const val javaxInject = "javax.inject:javax.inject:1" +} + object AndroidXDependencies { const val coreKtx = "androidx.core:core-ktx:${Versions.coreKtxVersion}" const val appCompat = "androidx.appcompat:appcompat:${Versions.appCompatVersion}" diff --git a/data/src/main/java/com/dpm/data/datasource/AuthDataSource.kt b/data/src/main/java/com/dpm/data/datasource/AuthDataSource.kt new file mode 100644 index 00000000..93a23dfe --- /dev/null +++ b/data/src/main/java/com/dpm/data/datasource/AuthDataSource.kt @@ -0,0 +1,5 @@ +package com.dpm.data.datasource + +interface AuthDataSource { + suspend fun getToken(): String +} \ No newline at end of file diff --git a/data/src/main/java/com/dpm/data/datasource/local/AuthDataSourceImpl.kt b/data/src/main/java/com/dpm/data/datasource/local/AuthDataSourceImpl.kt new file mode 100644 index 00000000..7a7db878 --- /dev/null +++ b/data/src/main/java/com/dpm/data/datasource/local/AuthDataSourceImpl.kt @@ -0,0 +1,13 @@ +package com.dpm.data.datasource.local + +import com.dpm.data.datasource.AuthDataSource +import com.dpm.domain.preference.SharedPreference +import javax.inject.Inject + +class AuthDataSourceImpl @Inject constructor( + private val sharedPreference: SharedPreference +): AuthDataSource { + override suspend fun getToken(): String { + return sharedPreference.token + } +} \ No newline at end of file diff --git a/data/src/main/java/com/dpm/data/repository/AuthRepositoryImpl.kt b/data/src/main/java/com/dpm/data/repository/AuthRepositoryImpl.kt new file mode 100644 index 00000000..0c75b2cb --- /dev/null +++ b/data/src/main/java/com/dpm/data/repository/AuthRepositoryImpl.kt @@ -0,0 +1,15 @@ +package com.dpm.data.repository + +import com.dpm.data.datasource.AuthDataSource +import com.dpm.domain.repository.AuthRepository +import javax.inject.Inject + +class AuthRepositoryImpl @Inject constructor( + private val authDataSource: AuthDataSource +) : AuthRepository { + override suspend fun getToken(): Result { + return runCatching { + authDataSource.getToken() + } + } +} \ No newline at end of file diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 72f063f4..0c7f966a 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -10,6 +10,9 @@ java { } dependencies { + JavaDependencies.run { + implementation(javaxInject) + } KotlinDependencies.run { implementation(kotlin) implementation(coroutines) diff --git a/domain/src/main/java/com/dpm/domain/repository/AuthRepository.kt b/domain/src/main/java/com/dpm/domain/repository/AuthRepository.kt new file mode 100644 index 00000000..e9fbfbe1 --- /dev/null +++ b/domain/src/main/java/com/dpm/domain/repository/AuthRepository.kt @@ -0,0 +1,5 @@ +package com.dpm.domain.repository + +interface AuthRepository { + suspend fun getToken(): Result +} \ No newline at end of file diff --git a/domain/src/main/java/com/dpm/domain/usecase/GetTokenUseCase.kt b/domain/src/main/java/com/dpm/domain/usecase/GetTokenUseCase.kt new file mode 100644 index 00000000..348ffa58 --- /dev/null +++ b/domain/src/main/java/com/dpm/domain/usecase/GetTokenUseCase.kt @@ -0,0 +1,12 @@ +package com.dpm.domain.usecase + +import com.dpm.domain.repository.AuthRepository +import javax.inject.Inject + +class GetTokenUseCase @Inject constructor( + private val authRepository: AuthRepository +) { + suspend operator fun invoke(): Result { + return authRepository.getToken() + } +} \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/home/HomeActivity.kt b/presentation/src/main/java/com/dpm/presentation/home/HomeActivity.kt index d3f8a9bb..03533e37 100644 --- a/presentation/src/main/java/com/dpm/presentation/home/HomeActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/home/HomeActivity.kt @@ -3,6 +3,7 @@ package com.dpm.presentation.home import ReviewData import android.content.Intent import android.os.Bundle +import android.util.Log import android.view.View import androidx.activity.viewModels import androidx.lifecycle.asLiveData @@ -16,10 +17,13 @@ import com.dpm.domain.entity.response.home.ResponseHomeFeed import com.dpm.domain.entity.response.viewfinder.ResponseStadiums import com.dpm.domain.model.seatreview.ReviewMethod import com.dpm.presentation.extension.dpToPx +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.home.adapter.StadiumAdapter import com.dpm.presentation.home.dialog.LevelDescriptionDialog import com.dpm.presentation.home.dialog.LevelupDialog import com.dpm.presentation.home.viewmodel.HomeGuiViewModel +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState import com.dpm.presentation.seatrecord.SeatRecordActivity import com.dpm.presentation.seatrecord.adapter.LinearSpacingItemDecoration import com.dpm.presentation.seatreview.dialog.ReviewTypeDialog @@ -28,6 +32,7 @@ import com.dpm.presentation.seatreview.dialog.view.ViewUploadDialog import com.dpm.presentation.setting.SettingActivity import com.dpm.presentation.util.Utils import com.dpm.presentation.viewfinder.StadiumActivity +import com.dpm.presentation.viewfinder.StadiumDetailActivity import com.dpm.presentation.viewfinder.StadiumSelectionActivity import dagger.hilt.android.AndroidEntryPoint @@ -69,6 +74,7 @@ class HomeActivity : BaseActivity( initViewStatusBar() homeViewModel.getStadiums() setStadiumAdapter() + handleIntentExtra() } private fun initReviewDialog() { @@ -282,4 +288,14 @@ class HomeActivity : BaseActivity( marginBottom = 94 ).show() } + + private fun handleIntentExtra() { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + Intent(this, StadiumDetailActivity::class.java).apply { + putExtra(SchemeKey.STADIUM_ID, navReview.stadiumId) + putExtra(SchemeKey.BLOCK_CODE, navReview.blockCode) + }.let { startActivity(it) } + } + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/KakaoSignupActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/KakaoSignupActivity.kt index c3d37ad9..40737cf4 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/KakaoSignupActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/KakaoSignupActivity.kt @@ -7,11 +7,14 @@ import androidx.compose.material.MaterialTheme import androidx.lifecycle.asLiveData import com.depromeet.presentation.databinding.FragmentKakaoSignupBinding import com.dpm.core.base.BaseActivity +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.extension.toast import com.dpm.presentation.home.HomeActivity import com.dpm.presentation.login.ui.compose.KakaoSignupScreen import com.dpm.presentation.login.viewmodel.KakaoSignupViewModel import com.dpm.presentation.login.viewmodel.LoginUiState +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState import com.kakao.sdk.auth.model.OAuthToken import com.kakao.sdk.common.model.ClientError import com.kakao.sdk.common.model.ClientErrorCause @@ -73,6 +76,15 @@ class KakaoSignupActivity : BaseActivity({ if (token.isNotEmpty()) { Intent(this, NicknameInputActivity::class.java).apply { putExtra("kakaoToken", token) + when (val data = handleIntentExtra()) { + is SchemeState.NavReview -> { + putExtra(SchemeKey.NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(SchemeKey.NAV_REVIEW_DETAIL, data) + } + else -> Unit + } startActivity(this) } } @@ -93,4 +105,19 @@ class KakaoSignupActivity : BaseActivity({ } } } + + private fun handleIntentExtra(): SchemeState { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + return navReview + } + + val navReviewDetail = intent.getCompatibleParcelableExtra( + SchemeKey.NAV_REVIEW_DETAIL) + if (navReviewDetail != null) { + return navReviewDetail + } + + return SchemeState.Nothing + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt index 4b3a15cf..05ecd695 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/NicknameInputActivity.kt @@ -11,8 +11,11 @@ import androidx.lifecycle.asLiveData import com.depromeet.presentation.R import com.depromeet.presentation.databinding.FragmentNicknameInputBinding import com.dpm.core.base.BaseActivity +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.login.viewmodel.NicknameInputState import com.dpm.presentation.login.viewmodel.NicknameInputViewModel +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -93,6 +96,15 @@ class NicknameInputActivity: BaseActivity({ Intent(this@NicknameInputActivity, TeamSelectActivity::class.java).apply { putExtra("nickname", etProfileEditNickname.text.toString()) putExtra("kakaoToken", intent.getStringExtra("kakaoToken")) + when (val data = handleIntentExtra()) { + is SchemeState.NavReview -> { + putExtra(SchemeKey.NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(SchemeKey.NAV_REVIEW_DETAIL, data) + } + else -> Unit + } startActivity(this) } } @@ -123,4 +135,19 @@ class NicknameInputActivity: BaseActivity({ tvNicknameNextBtn.setBackgroundResource(R.drawable.rect_action_disabled_fill_8) } } + + private fun handleIntentExtra(): SchemeState { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + return navReview + } + + val navReviewDetail = intent.getCompatibleParcelableExtra( + SchemeKey.NAV_REVIEW_DETAIL) + if (navReviewDetail != null) { + return navReviewDetail + } + + return SchemeState.Nothing + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpActivity.kt index 30e84986..22d8ffc5 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpActivity.kt @@ -6,7 +6,10 @@ import androidx.lifecycle.lifecycleScope import com.depromeet.presentation.databinding.ActivitySignupBinding import com.dpm.core.base.BaseActivity import com.dpm.domain.preference.SharedPreference +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.home.HomeActivity +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.delay import kotlinx.coroutines.launch @@ -41,8 +44,31 @@ class SignUpActivity : BaseActivity({ private fun navigateToNextScreen(destinationClass: Class<*>) { Intent(this@SignUpActivity, destinationClass).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + when (val data = handleIntentExtra()) { + is SchemeState.NavReview -> { + putExtra(SchemeKey.NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(SchemeKey.NAV_REVIEW_DETAIL, data) + } + else -> Unit + } startActivity(this) finish() } } + + private fun handleIntentExtra(): SchemeState { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + return navReview + } + + val navReviewDetail = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW_DETAIL) + if (navReviewDetail != null) { + return navReviewDetail + } + + return SchemeState.Nothing + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpCompleteActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpCompleteActivity.kt index d90aec31..2883ceac 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpCompleteActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/SignUpCompleteActivity.kt @@ -8,7 +8,10 @@ import android.text.SpannableString import android.text.style.ForegroundColorSpan import com.depromeet.presentation.databinding.ActivitySignupCompleteBinding import com.dpm.core.base.BaseActivity +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.home.HomeActivity +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState class SignUpCompleteActivity : BaseActivity( { ActivitySignupCompleteBinding.inflate(it) } @@ -59,9 +62,33 @@ class SignUpCompleteActivity : BaseActivity( binding.tvSignupCompleteBtn.setOnClickListener { Intent(this, HomeActivity::class.java).apply { flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + when (val data = handleIntentExtra()) { + is SchemeState.NavReview -> { + putExtra(SchemeKey.NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(SchemeKey.NAV_REVIEW_DETAIL, data) + } + else -> Unit + } startActivity(this) finish() } } } + + private fun handleIntentExtra(): SchemeState { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + return navReview + } + + val navReviewDetail = intent.getCompatibleParcelableExtra( + SchemeKey.NAV_REVIEW_DETAIL) + if (navReviewDetail != null) { + return navReviewDetail + } + + return SchemeState.Nothing + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/login/ui/TeamSelectActivity.kt b/presentation/src/main/java/com/dpm/presentation/login/ui/TeamSelectActivity.kt index ee71c353..06047558 100644 --- a/presentation/src/main/java/com/dpm/presentation/login/ui/TeamSelectActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/login/ui/TeamSelectActivity.kt @@ -9,11 +9,14 @@ import com.depromeet.presentation.databinding.FragmentTeamSelectBinding import com.dpm.core.base.BaseActivity import com.dpm.core.state.UiState import com.dpm.domain.entity.response.home.ResponseBaseballTeam +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.extension.toast import com.dpm.presentation.home.adapter.BaseballTeamAdapter import com.dpm.presentation.home.adapter.GridSpacingItemDecoration import com.dpm.presentation.login.viewmodel.SignUpViewModel import com.dpm.presentation.login.viewmodel.SignupUiState +import com.dpm.presentation.scheme.SchemeKey +import com.dpm.presentation.scheme.viewmodel.SchemeState import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint @@ -44,6 +47,15 @@ class TeamSelectActivity: BaseActivity( is SignupUiState.SignUpSuccess -> { Intent(this, SignUpCompleteActivity::class.java).apply { putExtra("nickname", it.nickname) + when (val data = handleIntentExtra()) { + is SchemeState.NavReview -> { + putExtra(SchemeKey.NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(SchemeKey.NAV_REVIEW_DETAIL, data) + } + else -> Unit + } flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK startActivity(this) finish() @@ -112,4 +124,19 @@ class TeamSelectActivity: BaseActivity( } } } + + private fun handleIntentExtra(): SchemeState { + val navReview = intent.getCompatibleParcelableExtra(SchemeKey.NAV_REVIEW) + if (navReview != null) { + return navReview + } + + val navReviewDetail = intent.getCompatibleParcelableExtra( + SchemeKey.NAV_REVIEW_DETAIL) + if (navReviewDetail != null) { + return navReviewDetail + } + + return SchemeState.Nothing + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/scheme/SchemeActivity.kt b/presentation/src/main/java/com/dpm/presentation/scheme/SchemeActivity.kt index d5e351f3..4c238fe3 100644 --- a/presentation/src/main/java/com/dpm/presentation/scheme/SchemeActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/scheme/SchemeActivity.kt @@ -4,10 +4,31 @@ import android.annotation.SuppressLint import android.content.Intent import android.net.Uri import android.os.Bundle +import android.util.Log +import androidx.activity.viewModels +import androidx.lifecycle.asLiveData import com.dpm.core.base.BaseActivity import com.depromeet.presentation.databinding.ActivitySchemeBinding import com.dpm.presentation.extension.toast +import com.dpm.presentation.home.HomeActivity +import com.dpm.presentation.login.ui.KakaoSignupActivity +import com.dpm.presentation.login.ui.SignUpActivity +import com.dpm.presentation.scheme.SchemeKey.NAV_REVIEW +import com.dpm.presentation.scheme.SchemeKey.NAV_REVIEW_DETAIL +import com.dpm.presentation.scheme.viewmodel.SchemeState +import com.dpm.presentation.scheme.viewmodel.SchemeViewModel +import dagger.hilt.android.AndroidEntryPoint +object SchemeKey { + const val STADIUM_ID = "stadiumId" + const val BLOCK_CODE = "blockCode" + const val REVIEW_ID = "reviewId" + + const val NAV_REVIEW = "nav_review" + const val NAV_REVIEW_DETAIL = "nav_review_detail" +} + +@AndroidEntryPoint class SchemeActivity : BaseActivity(ActivitySchemeBinding::inflate) { companion object { @@ -24,6 +45,8 @@ class SchemeActivity : BaseActivity(ActivitySchemeBinding const val EXAMPLE_KEY = "example_key" } + private val viewModel: SchemeViewModel by viewModels() + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -37,11 +60,11 @@ class SchemeActivity : BaseActivity(ActivitySchemeBinding } private fun handleIntent(intent: Intent) { + initObserve() val appLinkAction = intent.action val appLinkData: Uri? = intent.data if (Intent.ACTION_VIEW == appLinkAction) { - handleQueryParameter(appLinkData, EXAMPLE_KEY) - // handlePathParameter(appLinkData) + handleNavReview(appLinkData) } } @@ -65,4 +88,81 @@ class SchemeActivity : BaseActivity(ActivitySchemeBinding } } } + + private fun initObserve() { + viewModel.state.asLiveData().observe(this) { + when (it) { + is SchemeState.NonLogin<*> -> { + when (val data = it.data) { + is SchemeState.NavReview -> { + navigateToSignUpActivity(data) + } + is SchemeState.NavReviewDetail -> { + navigateToSignUpActivity(data) + } + } + } + is SchemeState.NavReview -> { + navigateToHomeActivity(it) + } + is SchemeState.NavReviewDetail -> { + navigateToHomeActivity(it) + } + is SchemeState.Failed -> { + navigateToSignUpActivity(it) + } + SchemeState.Nothing -> Unit + } + } + } + + private fun handleNavReview( + uri: Uri? + ) { + if (handleQueryParameter(uri, SchemeKey.STADIUM_ID).isNullOrEmpty() + || handleQueryParameter(uri, SchemeKey.BLOCK_CODE).isNullOrEmpty() + ) { + navigateToSignUpActivity() + return + } + + viewModel.navigateToDetailReview(handleQueryParameter(uri, SchemeKey.STADIUM_ID)?.toInt() ?: 0, handleQueryParameter(uri, SchemeKey.BLOCK_CODE) ?: "") + } + + private fun navigateToSignUpActivity() { + finish() + Intent(this, SignUpActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + }.let { startActivity(it) } + } + + private fun navigateToSignUpActivity(data: T) { + finish() + Intent(this, SignUpActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + when (data) { + is SchemeState.NavReview -> { + putExtra(NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(NAV_REVIEW_DETAIL, data) + } + } + }.let { startActivity(it) } + } + + private fun navigateToHomeActivity(data: T) { + finish() + Intent(this, HomeActivity::class.java).apply { + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) + when(data) { + is SchemeState.NavReview -> { + putExtra(NAV_REVIEW, data) + } + is SchemeState.NavReviewDetail -> { + putExtra(NAV_REVIEW_DETAIL, data) + } + } + }.let { startActivity(it) } + } } \ No newline at end of file diff --git a/presentation/src/main/java/com/dpm/presentation/scheme/viewmodel/SchemeViewModel.kt b/presentation/src/main/java/com/dpm/presentation/scheme/viewmodel/SchemeViewModel.kt new file mode 100644 index 00000000..24c01b32 --- /dev/null +++ b/presentation/src/main/java/com/dpm/presentation/scheme/viewmodel/SchemeViewModel.kt @@ -0,0 +1,60 @@ +package com.dpm.presentation.scheme.viewmodel + +import android.os.Parcelable +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.dpm.domain.usecase.GetTokenUseCase +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import kotlinx.parcelize.Parcelize +import javax.inject.Inject + +@HiltViewModel +class SchemeViewModel @Inject constructor( + private val getTokenUseCase: GetTokenUseCase +) : ViewModel() { + private val _state = MutableStateFlow(SchemeState.Nothing) + val state = _state.asStateFlow() + + fun navigateToDetailReview( + stadiumId: Int, + blockCode: String + ) { + viewModelScope.launch { + getTokenUseCase().onSuccess { + if (it.isEmpty()) { + // 비로그인 상태 + _state.value = SchemeState.NonLogin( + SchemeState.NavReview(stadiumId, blockCode) + ) + } else { + // 로그인 상태 + _state.value = SchemeState.NavReview(stadiumId, blockCode) + } + }.onFailure { + _state.value = SchemeState.Failed + } + } + } +} + +sealed interface SchemeState { + @Parcelize + data class NavReview( + val stadiumId: Int, + val blockCode: String + ) : SchemeState, Parcelable + + @Parcelize + data class NavReviewDetail( + val stadiumId: Int, + val blockCode: String, + val reviewId: Int + ) : SchemeState, Parcelable + + data class NonLogin(val data: T) : SchemeState + object Failed: SchemeState + object Nothing : SchemeState +} diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumActivity.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumActivity.kt index 6fb1ab32..f597b78b 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumActivity.kt @@ -34,6 +34,7 @@ import com.dpm.domain.preference.SharedPreference import com.dpm.presentation.extension.setMargins import com.dpm.presentation.extension.toast import com.dpm.presentation.home.HomeActivity +import com.dpm.presentation.scheme.SchemeKey import com.dpm.presentation.util.SpannableStringUtils import com.dpm.presentation.util.Utils import com.dpm.presentation.viewfinder.adapter.StadiumSectionAdapter @@ -62,8 +63,6 @@ class StadiumActivity : BaseActivity({ ActivityStadiumBinding.inflate(it) }) { companion object { - const val STADIUM_ID = "stadium_id" - const val STADIUM_BLOCK_ID = "stadium_block_id" private const val BASE_URL = "file:///android_asset/web/" private const val ENCODING_UTF8 = "UTF-8" private const val MIME_TYPE_TEXT_HTML = "text/html" @@ -488,8 +487,8 @@ class StadiumActivity : BaseActivity({ private fun startToStadiumDetailActivity(id: String) { Intent(this, StadiumDetailActivity::class.java).apply { - putExtra(STADIUM_ID, viewModel.stadiumId) - putExtra(STADIUM_BLOCK_ID, id) + putExtra(SchemeKey.STADIUM_ID, viewModel.stadiumId) + putExtra(SchemeKey.BLOCK_CODE, id) }.let(::startActivity) } diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumDetailActivity.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumDetailActivity.kt index 8a8c3a59..8d092f8c 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumDetailActivity.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/StadiumDetailActivity.kt @@ -13,7 +13,9 @@ import com.dpm.domain.entity.response.viewfinder.ResponseBlockReview import com.depromeet.presentation.R import com.depromeet.presentation.databinding.ActivityStadiumDetailBinding import com.dpm.domain.preference.SharedPreference +import com.dpm.presentation.extension.getCompatibleParcelableExtra import com.dpm.presentation.home.HomeActivity +import com.dpm.presentation.scheme.SchemeKey import com.dpm.presentation.util.KakaoUtils import com.dpm.presentation.util.seatFeed import com.dpm.presentation.util.toEmptyBlock @@ -52,10 +54,11 @@ class StadiumDetailActivity : BaseActivity({ } private fun initView() { - getIdExtra { stadiumId, blockCode -> + getIdExtra { stadiumId, blockCode, reviewId -> viewModel.updateRequestPathVariable(stadiumId, blockCode) viewModel.getBlockReviews(stadiumId, blockCode) viewModel.getBlockRow(stadiumId, blockCode) + viewModel.reviewId = reviewId } initComposeView() } @@ -129,10 +132,11 @@ class StadiumDetailActivity : BaseActivity({ } } - private fun getIdExtra(callback: (stadiumId: Int, blockCode: String) -> Unit) { + private fun getIdExtra(callback: (stadiumId: Int, blockCode: String, reviewId: Int) -> Unit) { callback( - intent?.getIntExtra(StadiumActivity.STADIUM_ID, 0) ?: 0, - intent?.getStringExtra(StadiumActivity.STADIUM_BLOCK_ID) ?: "" + intent?.getIntExtra(SchemeKey.STADIUM_ID, 0) ?: 0, + intent?.getStringExtra(SchemeKey.BLOCK_CODE) ?: "", + intent?.getIntExtra(SchemeKey.REVIEW_ID, 0) ?: 0 ) } diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/StadiumDetailScreen.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/StadiumDetailScreen.kt index 0c8bbad3..51178be4 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/StadiumDetailScreen.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/StadiumDetailScreen.kt @@ -27,6 +27,7 @@ import com.dpm.domain.entity.response.viewfinder.BASE import com.dpm.domain.entity.response.viewfinder.ResponseBlockReview import com.dpm.domain.entity.response.viewfinder.base import com.dpm.presentation.mapper.toKeyword +import com.dpm.presentation.scheme.SchemeKey import com.dpm.presentation.util.KakaoUtils import com.dpm.presentation.util.kakaoShareSeatFeedTitle import com.dpm.presentation.util.seatFeed @@ -178,8 +179,8 @@ fun StadiumDetailScreen( imageUrl = uiState.reviews[index].images.firstOrNull()?.url ?: "", queryParams = mapOf( - "stadiumId" to viewModel.stadiumId.toString(), - "blockCode" to viewModel.blockCode + SchemeKey.STADIUM_ID to viewModel.stadiumId.toString(), + SchemeKey.BLOCK_CODE to viewModel.blockCode ) ), onSuccess = { sharingIntent -> diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/main/StadiumDetailPictureTopScreen.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/main/StadiumDetailPictureTopScreen.kt index 1d7baaa0..27bb8bb6 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/main/StadiumDetailPictureTopScreen.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/main/StadiumDetailPictureTopScreen.kt @@ -14,6 +14,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel +import com.dpm.presentation.scheme.SchemeKey import com.dpm.presentation.util.KakaoUtils import com.dpm.presentation.util.kakaoShareSeatFeedTitle import com.dpm.presentation.util.seatFeed @@ -86,8 +87,8 @@ fun StadiumDetailPictureTopScreen( description = "출처 : ${uiState.reviews[pageIndex].member.nickname}", imageUrl = uiState.reviews[pageIndex].images[imagePosition].url, queryParams = mapOf( - "stadiumId" to stadiumDetailViewModel.stadiumId.toString(), - "blockCode" to stadiumDetailViewModel.blockCode + SchemeKey.STADIUM_ID to stadiumDetailViewModel.stadiumId.toString(), + SchemeKey.BLOCK_CODE to stadiumDetailViewModel.blockCode ) ), onSuccess = { sharingIntent -> diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/top/StadiumDetailPictureMainScreen.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/top/StadiumDetailPictureMainScreen.kt index c6e6c345..8310dff1 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/top/StadiumDetailPictureMainScreen.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/compose/detailpicture/top/StadiumDetailPictureMainScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview import androidx.lifecycle.viewmodel.compose.viewModel +import com.dpm.presentation.scheme.SchemeKey import com.dpm.presentation.util.KakaoUtils import com.dpm.presentation.util.kakaoShareSeatFeedTitle import com.dpm.presentation.util.seatFeed @@ -109,8 +110,8 @@ fun StadiumDetailPictureMainScreen( description = "출처 : ${uiState.reviews[pageIndex].member.nickname}", imageUrl = uiState.reviews[pageIndex].images[imagePosition].url, queryParams = mapOf( - "stadiumId" to stadiumDetailViewModel.stadiumId.toString(), - "blockCode" to stadiumDetailViewModel.blockCode + SchemeKey.STADIUM_ID to stadiumDetailViewModel.stadiumId.toString(), + SchemeKey.BLOCK_CODE to stadiumDetailViewModel.blockCode ) ), onSuccess = { sharingIntent -> diff --git a/presentation/src/main/java/com/dpm/presentation/viewfinder/viewmodel/StadiumDetailViewModel.kt b/presentation/src/main/java/com/dpm/presentation/viewfinder/viewmodel/StadiumDetailViewModel.kt index 965fb723..4a273ddc 100644 --- a/presentation/src/main/java/com/dpm/presentation/viewfinder/viewmodel/StadiumDetailViewModel.kt +++ b/presentation/src/main/java/com/dpm/presentation/viewfinder/viewmodel/StadiumDetailViewModel.kt @@ -23,6 +23,7 @@ class StadiumDetailViewModel @Inject constructor( ) : ViewModel() { var blockCode: String = "" var stadiumId: Int = 0 + var reviewId : Int = 0 private var reset: Boolean = true private var blockRow: ResponseBlockRow? = null