Skip to content

Commit

Permalink
๐Ÿ› ๏ธ ๊ฐ•์ œ ์—…๋ฐ์ดํŠธ ๊ธฐ๋Šฅ (#47)
Browse files Browse the repository at this point in the history
* Add ForceUpdate Min Version API

* Add DI Modules | Repository & Datasource & Service

* Add ForceUpdateDialog

* Add UseCase | GetForceUpdateMinVersionUseCase

* Apply ForceUpdate Check
  • Loading branch information
moondev03 authored Oct 2, 2024
1 parent 5daee5a commit 9e2cfe1
Show file tree
Hide file tree
Showing 14 changed files with 292 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.neverland.data.datasource

import com.neverland.data.remote.model.BaseResponse
import com.neverland.data.remote.model.ForceUpdateMinVersionResponse
import com.neverland.data.remote.model.alarm.AlarmDTO
import retrofit2.Response
import retrofit2.http.PATCH

interface VersionDataSource {

suspend fun getForceUpdateMinVersion(): Response<BaseResponse<ForceUpdateMinVersionResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.neverland.data.datasourceImpl

import com.neverland.data.datasource.AlarmDataSource
import com.neverland.data.datasource.VersionDataSource
import com.neverland.data.remote.model.BaseResponse
import com.neverland.data.remote.model.ForceUpdateMinVersionResponse
import com.neverland.data.remote.model.alarm.AlarmDTO
import com.neverland.data.remote.service.AlarmService
import com.neverland.data.remote.service.VersionService
import retrofit2.Response
import javax.inject.Inject

class VersionDataSourceImpl @Inject constructor(
private val service: VersionService
): VersionDataSource {

override suspend fun getForceUpdateMinVersion(): Response<BaseResponse<ForceUpdateMinVersionResponse>> {
return service.getForceUpdateMinVersion()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import com.neverland.data.datasource.NoticeDataSource
import com.neverland.data.datasource.ReportDataSource
import com.neverland.data.datasource.UnivDataSource
import com.neverland.data.datasource.UserDataSource
import com.neverland.data.datasource.VersionDataSource
import com.neverland.data.datasourceImpl.AlarmDataSourceImpl
import com.neverland.data.datasourceImpl.BookmarkDataSourceImpl
import com.neverland.data.datasourceImpl.KeywordDataSourceImpl
import com.neverland.data.datasourceImpl.NoticeDataSourceImpl
import com.neverland.data.datasourceImpl.ReportDataSourceImpl
import com.neverland.data.datasourceImpl.UnivDataSourceImpl
import com.neverland.data.datasourceImpl.UserDataSourceImpl
import com.neverland.data.datasourceImpl.VersionDataSourceImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -51,4 +53,7 @@ abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindsReportDataSource(impl: ReportDataSourceImpl): ReportDataSource

@Binds
abstract fun bindsVersionDataSource(impl: VersionDataSourceImpl): VersionDataSource
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import com.neverland.data.repository.NoticeRepositoryImpl
import com.neverland.data.repository.ReportRepositoryImpl
import com.neverland.data.repository.UnivRepositoryImpl
import com.neverland.data.repository.UserRepositoryImpl
import com.neverland.data.repository.VersionRepositoryImpl
import com.neverland.domain.repository.AlarmRepository
import com.neverland.domain.repository.BookmarkRepository
import com.neverland.domain.repository.KeywordRepository
import com.neverland.domain.repository.NoticeRepository
import com.neverland.domain.repository.ReportRepository
import com.neverland.domain.repository.UnivRepository
import com.neverland.domain.repository.UserRepository
import com.neverland.domain.repository.VersionRepository
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -51,4 +53,8 @@ abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindsReportRepository(impl: ReportRepositoryImpl): ReportRepository

@Binds
@Singleton
abstract fun bindsVersionRepository(impl: VersionRepositoryImpl): VersionRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import com.neverland.data.remote.service.NoticeService
import com.neverland.data.remote.service.ReportService
import com.neverland.data.remote.service.UnivService
import com.neverland.data.remote.service.UserService
import com.neverland.data.remote.service.VersionService
import com.neverland.domain.repository.VersionRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
Expand Down Expand Up @@ -44,4 +46,8 @@ internal class ServiceModule {
@Provides
fun providesReportService(client: Retrofit): ReportService =
client.create(ReportService::class.java)

@Provides
fun providesVersionService(client: Retrofit): VersionService =
client.create(VersionService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.neverland.data.remote.model

import com.google.gson.annotations.SerializedName

data class ForceUpdateMinVersionResponse(
@SerializedName("versionCode")
val versionCode: String,
@SerializedName("versionName")
val versionName: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.neverland.data.remote.service

import com.neverland.data.remote.model.BaseResponse
import com.neverland.data.remote.model.ForceUpdateMinVersionResponse
import retrofit2.Response
import retrofit2.http.GET

interface VersionService {

@GET("/api/version")
suspend fun getForceUpdateMinVersion(): Response<BaseResponse<ForceUpdateMinVersionResponse>>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.neverland.data.repository

import com.neverland.data.datasource.AlarmDataSource
import com.neverland.data.datasource.VersionDataSource
import com.neverland.data.utils.handleResponse
import com.neverland.domain.model.alarm.Alarm
import com.neverland.domain.repository.AlarmRepository
import com.neverland.domain.repository.VersionRepository
import javax.inject.Inject

class VersionRepositoryImpl @Inject constructor(
private val datasource: VersionDataSource
) : VersionRepository {

override suspend fun getForceUpdateMinVersion(): Result<String> {
return handleResponse(
call = { datasource.getForceUpdateMinVersion() },
onSuccess = { data ->
data?.versionCode ?: "0"
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.neverland.domain.repository

import com.neverland.domain.model.alarm.Alarm

interface VersionRepository {

suspend fun getForceUpdateMinVersion(): Result<String>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.neverland.domain.usecase.version

import com.neverland.domain.repository.VersionRepository
import javax.inject.Inject

class GetForceUpdateMinVersionUseCase @Inject constructor(
private val repository: VersionRepository
) {

suspend operator fun invoke(): Result<String> {
return repository.getForceUpdateMinVersion()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.neverland.thinkerbell.view.home

import android.content.ActivityNotFoundException
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.net.Uri
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.fragment.app.DialogFragment
import com.neverland.domain.model.univ.DeptContact
import com.neverland.thinkerbell.BuildConfig
import com.neverland.thinkerbell.custom.CustomToast
import com.neverland.thinkerbell.databinding.DialogContactBinding
import com.neverland.thinkerbell.databinding.DialogForceUpdateBinding
import com.neverland.thinkerbell.utils.DisplayUtils

class ForceUpdateDialog : DialogFragment() {

companion object {
fun newInstance(): ForceUpdateDialog {
return ForceUpdateDialog()
}
}

private var mBinding: DialogForceUpdateBinding? = null
private val binding get() = mBinding!!

override fun onStart() {
super.onStart()

dialog?.let {
it.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))

val widthInDp = 304f

val widthInPx = DisplayUtils.dpToPx(requireContext(), widthInDp).toInt()

it.window?.setLayout(widthInPx, WRAP_CONTENT)
}

isCancelable = false
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
mBinding = DialogForceUpdateBinding.inflate(requireActivity().layoutInflater)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

binding.btnDialogUpdate.setOnClickListener {
moveToPlayStore()
}
}

private fun moveToPlayStore() {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}")
setPackage("com.android.vending")
}
try {
startActivity(intent)
} catch (e: ActivityNotFoundException) {
val webIntent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse("https://play.google.com/store/apps/details?id=${BuildConfig.APPLICATION_ID}")
}
startActivity(webIntent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package com.neverland.thinkerbell.view.splash
import android.content.Intent
import androidx.activity.viewModels
import com.google.firebase.messaging.FirebaseMessaging
import com.neverland.thinkerbell.BuildConfig
import com.neverland.thinkerbell.R
import com.neverland.thinkerbell.base.BaseActivity
import com.neverland.thinkerbell.databinding.ActivityStartBinding
import com.neverland.thinkerbell.utils.UiState
import com.neverland.thinkerbell.view.HomeActivity
import com.neverland.thinkerbell.view.home.ForceUpdateDialog
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand All @@ -20,11 +22,26 @@ class StartActivity : BaseActivity<ActivityStartBinding>() {
}

setStatusBarColor(R.color.primary2, false)
viewModel.checkForceUpdate(BuildConfig.VERSION_CODE)
}

override fun setObserver() {
super.setObserver()

viewModel.update.observe(this) { state ->
when(state){
is UiState.Loading -> {}
is UiState.Success -> {
if(state.data){
ForceUpdateDialog.newInstance().show(supportFragmentManager, "")
}
}

is UiState.Error -> {}
is UiState.Empty -> {}
}
}

viewModel.fcmState.observe(this) {
when (it) {
is UiState.Loading -> {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.neverland.core.utils.LoggerUtil
import com.neverland.domain.usecase.user.PostUserInfoUseCase
import com.neverland.domain.usecase.version.GetForceUpdateMinVersionUseCase
import com.neverland.thinkerbell.base.ThinkerBellApplication.Companion.application
import com.neverland.thinkerbell.utils.UiState
import dagger.hilt.android.lifecycle.HiltViewModel
Expand All @@ -15,12 +16,16 @@ import javax.inject.Inject

@HiltViewModel
class StartViewModel @Inject constructor(
private val postUserInfoUseCase: PostUserInfoUseCase
private val postUserInfoUseCase: PostUserInfoUseCase,
private val getForceUpdateMinVersionUseCase: GetForceUpdateMinVersionUseCase
) : ViewModel() {

private val _fcmState = MutableLiveData<UiState<Unit>>(UiState.Loading)
val fcmState: LiveData<UiState<Unit>> get() = _fcmState

private val _update = MutableLiveData<UiState<Boolean>>()
val update: LiveData<UiState<Boolean>> get() = _update

@SuppressLint("HardwareIds")
fun saveDeviceInfo(token: String) {
_fcmState.value = UiState.Loading
Expand All @@ -37,4 +42,17 @@ class StartViewModel @Inject constructor(
}
}

fun checkForceUpdate(currentVersion: Int){
_update.value = UiState.Loading

viewModelScope.launch {
getForceUpdateMinVersionUseCase.invoke()
.onSuccess {
LoggerUtil.i("ํ˜„์žฌ ๋ฒ„์ „: $currentVersion | ์ตœ์†Œ ์—…๋ฐ์ดํŠธ ํ•„์š” ๋ฒ„์ „: $it")
_update.value = UiState.Success(currentVersion < it.toInt())
}
.onFailure { _update.value = UiState.Success(false) }
}
}

}
Loading

0 comments on commit 9e2cfe1

Please sign in to comment.