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

[feat] #172 popup #173

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions core/designsystem/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@
<string name="home_user_clip">๋‹˜์˜ ํด๋ฆฝ</string>
<string name="home_this_week_link">์ด์ฃผ์˜ ๋งํฌ</string>
<string name="home_this_week_recommend">์ด์ฃผ์˜ ์ถ”์ฒœ ์‚ฌ์ดํŠธ</string>
<string name="home_survey_title">1๋ถ„ ์„ค๋ฌธ์กฐ์‚ฌ ์ฐธ์—ฌํ•˜๊ณ \n์Šคํƒ€๋ฒ…์Šค ๊ธฐํ”„ํ‹ฐ์ฝ˜ ๋ฐ›๊ธฐ</string>
<string name="home_survey_subtitle">ํ† ์Šคํ„ฐ ์‚ฌ์šฉ ํ”ผ๋“œ๋ฐฑ์„ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด\n์ถ”์ฒจ์„ ํ†ตํ•ด ๊ธฐํ”„ํ‹ฐ์ฝ˜์„ ๋“œ๋ ค์š”!</string>
<string name="home_survey_button">์ฐธ์—ฌํ•˜๊ธฐ</string>
<string name="home_survey_skip"><u>์ผ์ฃผ์ผ๊ฐ„ ๋ณด์ง€ ์•Š๊ธฐ</u></string>


<!-- error -->
<string name="error_clip_length">ํด๋ฆฝ์˜ ์ด๋ฆ„์€ ์ตœ๋Œ€ 15์ž๊นŒ์ง€ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•ด์š”</string>
Expand Down
9 changes: 9 additions & 0 deletions core/model/src/main/java/org/sopt/model/home/PopupInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.model.home

data class PopupInfo(
val popupId: Int,
val popupImage: String,
val popupActiveStartDate: String,
val popupActiveEndDate: String,
val popupLinkUrl: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.sopt.model.home

data class PopupInvisible(
val popupId: Int,
val popupHideUntil: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.remote.home.api

import org.sopt.network.model.response.base.BaseResponse
import org.sopt.remote.home.request.RequestPopupInvisibleDto
import org.sopt.remote.home.response.ResponsePopupInfoDto
import org.sopt.remote.home.response.ResponsePopupInvisibleDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.PATCH

interface PopupService {
companion object {
const val API = "api"
const val V2 = "v2"
const val POPUP = "popup"
}

@PATCH("/$API/$V2/$POPUP")
suspend fun patchPopupInvisible(
@Body requestPopupInvisibleDto: RequestPopupInvisibleDto,
): BaseResponse<ResponsePopupInvisibleDto>

@GET("/$API/$V2/$POPUP")
suspend fun getPopupInfo(): BaseResponse<ResponsePopupInfoDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.sopt.remote.home.datasource

import org.sopt.home.datasource.RemotePopupDataSource
import org.sopt.model.home.PopupInfo
import org.sopt.model.home.PopupInvisible
import org.sopt.remote.home.api.PopupService
import org.sopt.remote.home.request.RequestPopupInvisibleDto
import org.sopt.remote.home.response.toCoreModel
import javax.inject.Inject

class RemotePopupDatasourceImpl @Inject constructor(
private val popupService: PopupService,
) : RemotePopupDataSource {
override suspend fun patchPopupInvisible(popupId: Long, hideDate: Long): PopupInvisible =
popupService.patchPopupInvisible(RequestPopupInvisibleDto(popupId, hideDate)).data!!.toCoreModel()

override suspend fun getPopupInfo(): List<PopupInfo> =
popupService.getPopupInfo().data!!.popupList.map { it.toCoreModel() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.home.datasource.RemoteHomeDataSource
import org.sopt.home.datasource.RemotePopupDataSource
import org.sopt.remote.home.datasource.RemoteHomeDataSourceImpl
import org.sopt.remote.home.datasource.RemotePopupDatasourceImpl
import javax.inject.Singleton

@Module
Expand All @@ -16,4 +18,10 @@ abstract class HomeDataSourceModule {
abstract fun bindRemoteHomeDatasource(
remoteHomeDataSourceImpl: RemoteHomeDataSourceImpl,
): RemoteHomeDataSource

@Singleton
@Binds
abstract fun bindRemotePopupDataSource(
remotePopupDataSourceImpl: RemotePopupDatasourceImpl,
): RemotePopupDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.network.di.AuthLinkMindRetrofit
import org.sopt.remote.home.api.HomeService
import org.sopt.remote.home.api.PopupService
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object HomeServiceModule {
Expand All @@ -16,4 +18,9 @@ object HomeServiceModule {
@Provides
fun provideHomeService(@AuthLinkMindRetrofit retrofit: Retrofit): HomeService =
retrofit.create(HomeService::class.java)

@Singleton
@Provides
fun providePopupService(@AuthLinkMindRetrofit retrofit: Retrofit): PopupService =
retrofit.create(PopupService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.remote.home.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class RequestPopupInvisibleDto(
@SerialName("popupId")
val popupId: Long,
@SerialName("hideDate")
val hideDate: Long,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.sopt.remote.home.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.model.home.PopupInfo

@Serializable
data class ResponsePopupInfoDto(
@SerialName("popupList")
val popupList: List<ResponsePopupInfo>,
)

@Serializable
data class ResponsePopupInfo(
@SerialName("id")
val id: Int,
@SerialName("image")
val image: String,
@SerialName("activeStartDate")
val activeStartDate: String,
@SerialName("activeEndDate")
val activeEndDate: String,
@SerialName("linkUrl")
val linkUrl: String,
)

internal fun ResponsePopupInfoDto.toCoreModel() = popupList.map {
it.toCoreModel()
}

internal fun ResponsePopupInfo.toCoreModel() = PopupInfo(
popupId = id,
popupImage = image,
popupActiveStartDate = activeStartDate,
popupActiveEndDate = activeEndDate,
popupLinkUrl = linkUrl,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.remote.home.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.model.home.PopupInvisible

@Serializable
data class ResponsePopupInvisibleDto(
@SerialName("popupId")
val popupId: Int,
@SerialName("hideUntil")
val hideUntil: String,
)

internal fun ResponsePopupInvisibleDto.toCoreModel() = PopupInvisible(
popupId = popupId,
popupHideUntil = hideUntil,
)
Comment on lines +15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

internal ์„ ์“ฐ์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์šฅ!?

Copy link
Author

Choose a reason for hiding this comment

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

๋งคํ•‘ํ•จ์ˆ˜๋‹ˆ๊นŒ data-remote ๋ชจ๋“ˆ ์•ˆ์—์„œ๋งŒ ์‚ฌ์šฉ๋˜๊ฒŒ ํ•˜๋ ค๊ณ  ํ–ˆ์Šต๋‹ˆ๋‹ค

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.home.datasource

import org.sopt.model.home.PopupInfo
import org.sopt.model.home.PopupInvisible

interface RemotePopupDataSource {
suspend fun patchPopupInvisible(popupId: Long, hideDate: Long): PopupInvisible
suspend fun getPopupInfo(): List<PopupInfo>
}
8 changes: 8 additions & 0 deletions data/home/src/main/java/org/sopt/home/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.home.repository.HomeRepoImpl
import org.sopt.home.repository.HomeRepository
import org.sopt.home.repository.PopupRepoImpl
import org.sopt.home.repository.PopupRepository
import javax.inject.Singleton

@Module
Expand All @@ -16,4 +18,10 @@ abstract class RepositoryModule {
abstract fun bindHomeRepository(
homeRepoImpl: HomeRepoImpl,
): HomeRepository

@Singleton
@Binds
abstract fun bindPopupRepository(
popupRepoImpl: PopupRepoImpl,
): PopupRepository
}
16 changes: 16 additions & 0 deletions data/home/src/main/java/org/sopt/home/repository/PopupRepoImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.home.repository

import org.sopt.home.datasource.RemotePopupDataSource
import org.sopt.model.home.PopupInfo
import org.sopt.model.home.PopupInvisible
import javax.inject.Inject

class PopupRepoImpl @Inject constructor(
private val remotePopupDataSource: RemotePopupDataSource,
) : PopupRepository {
override suspend fun patchPopupInvisible(popupId: Long, hideDate: Long): Result<PopupInvisible> =
runCatching { remotePopupDataSource.patchPopupInvisible(popupId, hideDate) }

override suspend fun getPopupInfo(): Result<List<PopupInfo>> =
runCatching { remotePopupDataSource.getPopupInfo() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.home.repository

import org.sopt.model.home.PopupInfo
import org.sopt.model.home.PopupInvisible

interface PopupRepository {
suspend fun patchPopupInvisible(popupId: Long, hideDate: Long): Result<PopupInvisible>
suspend fun getPopupInfo(): Result<List<PopupInfo>>
}
11 changes: 11 additions & 0 deletions domain/home/src/main/java/org/sopt/home/usecase/GetPopupInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.home.usecase

import org.sopt.home.repository.PopupRepository
import org.sopt.model.home.PopupInfo
import javax.inject.Inject

class GetPopupInfo @Inject constructor(
private val popupRepository: PopupRepository,
) {
suspend operator fun invoke(): Result<List<PopupInfo>> = popupRepository.getPopupInfo()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.home.usecase

import org.sopt.home.repository.PopupRepository
import org.sopt.model.home.PopupInvisible
import javax.inject.Inject

class PatchPopupInvisible @Inject constructor(
private val popupRepository: PopupRepository,
) {
suspend operator fun invoke(popupId: Long, hideDate: Long): Result<PopupInvisible> =
popupRepository.patchPopupInvisible(popupId, hideDate)
}
3 changes: 3 additions & 0 deletions feature/home/src/main/java/org/sopt/home/HomeContract.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.sopt.home

import org.sopt.model.category.Category
import org.sopt.model.home.PopupInfo
import org.sopt.model.home.RecommendLink
import org.sopt.model.home.WeekBestLink

Expand All @@ -14,6 +15,7 @@ data class HomeState(
val url: String = "",
val categoryId: Long? = 0,
val categoryName: String? = "์ „์ฒด ํด๋ฆฝ",
val popupList: List<PopupInfo> = emptyList(),
Comment on lines 15 to +18
Copy link
Contributor

Choose a reason for hiding this comment

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

emptyList๋ฅผ ์“ด ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”?

Copy link
Author

Choose a reason for hiding this comment

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

๊ธฐ๋ณธ๊ฐ’์„ null๋กœ ๋‘๊ฒŒ๋˜๋ฉด state๋ฅผ ํ™•์ธํ•  ๋•Œ๋งˆ๋‹ค null ์ฒดํฌ๋ฅผ ํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์—, emtpyList๋กœ ๋‘์–ด popupList๊ฐ€ ์ดˆ๊ธฐํ™” ๋˜์ง€ ์•Š์•˜๋”๋ผ๊ณ  ์ ‘๊ทผ์ด ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•ด์•ผํ•œ๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์Šต๋‹ˆ๋‹ค์ž‰.

) {
fun calculateProgress(): Int {
if (readToastNum > allToastNum) return 0
Expand All @@ -31,4 +33,5 @@ sealed interface HomeSideEffect {
data object NavigateClipLink : HomeSideEffect
data object NavigateWebView : HomeSideEffect
data object ShowBottomSheet : HomeSideEffect
data object ShowPopupInfo : HomeSideEffect
}
20 changes: 20 additions & 0 deletions feature/home/src/main/java/org/sopt/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.sopt.home.adapter.HomeWeekLinkAdapter
import org.sopt.home.adapter.HomeWeekRecommendLinkAdapter
import org.sopt.home.adapter.ItemDecoration
import org.sopt.home.databinding.FragmentHomeBinding
import org.sopt.model.home.PopupInfo
import org.sopt.ui.base.BindingFragment
import org.sopt.ui.nav.DeepLinkUtil
import org.sopt.ui.view.onThrottleClick
Expand Down Expand Up @@ -62,13 +63,16 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
is HomeSideEffect.NavigateClipLink -> navigateToDestination(
"featureSaveLink://ClipLinkFragment/${viewModel.container.stateFlow.value.categoryId}/${viewModel.container.stateFlow.value.categoryName}",
)

is HomeSideEffect.ShowBottomSheet -> showHomeBottomSheet()
is HomeSideEffect.NavigateWebView -> {
val encodedURL = URLEncoder.encode(viewModel.container.stateFlow.value.url, StandardCharsets.UTF_8.toString())
navigateToDestination(
"featureSaveLink://webViewFragment/${0}/${false}/${false}/$encodedURL",
)
}

is HomeSideEffect.ShowPopupInfo -> showPopupInfo(viewModel.container.stateFlow.value.popupList)
}
}

Expand All @@ -80,8 +84,10 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
getMainPageUserClip()
getRecommendSite()
getWeekBestLink()
getPopupListInfo()
}
}

private fun navigateToSetting() {
binding.ivHomeSetting.onThrottleClick {
viewModel.navigateSetting()
Expand Down Expand Up @@ -154,4 +160,18 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>({ FragmentHomeBinding.
}
}
}

private fun showPopupInfo(popupList: List<PopupInfo>) {
popupList.forEach {
if (viewModel.checkPopupDate(it.popupActiveStartDate, it.popupActiveEndDate)
) {
val surveyDialog = SurveyDialogFragment.newInstance(
it.popupImage,
{ viewModel.navigateWebview(it.popupLinkUrl) },
{ viewModel.patchPopupInvisible(it.popupId.toLong(), 7) },
)
surveyDialog.show(parentFragmentManager, this.tag)
}
}
}
}
Loading
Loading