-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[경북대 Android 류지원] 6주차 과제_STEP1 (#16)
* init: load previous codes 이전 코드 불러오기 * refactor: implement databinding on ErrorActivity 전주 피드백 사항인 ErrorActivity databinding 추가 적용 * docs: edit README * feat: implement SplashView splashview 구현 * feat: implement loading serviceConfig in layer mvvm 패턴에 알맞게 데이터 레이어에 serviceConfig 불러오도록 구현 * init: load previous codes 이전 코드 불러오기 * refactor: implement databinding on ErrorActivity 전주 피드백 사항인 ErrorActivity databinding 추가 적용 * feat: implement SplashView splashview 구현 * feat: implement loading serviceConfig in layer mvvm 패턴에 알맞게 데이터 레이어에 serviceConfig 불러오도록 구현 * refactor: add coroutines for async 비동기 작업을 위해 코루틴 추가
- Loading branch information
Showing
16 changed files
with
266 additions
and
8 deletions.
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
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
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
13 changes: 13 additions & 0 deletions
13
app/src/main/java/campus/tech/kakao/map/data/ConfigRepositoryImpl.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,13 @@ | ||
package campus.tech.kakao.map.data | ||
|
||
import campus.tech.kakao.map.data.datasource.Local.Entity.toVO | ||
import campus.tech.kakao.map.data.datasource.Remote.ConfigService | ||
import campus.tech.kakao.map.domain.ConfigRepository | ||
import campus.tech.kakao.map.domain.vo.Config | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import javax.inject.Inject | ||
|
||
class ConfigRepositoryImpl @Inject constructor(private val configService: ConfigService) : ConfigRepository{ | ||
override suspend fun getConfig(): Config = withContext(Dispatchers.IO){ configService.getConfig().toVO() } | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/campus/tech/kakao/map/data/datasource/Local/Entity/ConfigEntity.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,23 @@ | ||
package campus.tech.kakao.map.data.datasource.Local.Entity | ||
|
||
import campus.tech.kakao.map.domain.vo.Config | ||
import campus.tech.kakao.map.domain.vo.ServiceState | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig.DEFAULT_VALUE_FOR_STRING | ||
|
||
data class ConfigEntity( | ||
val serviceState : String, | ||
val serviceMessage : String | ||
) | ||
|
||
fun ConfigEntity.toVO() : Config = | ||
Config( | ||
mapServiceState(serviceState), | ||
if(serviceMessage != DEFAULT_VALUE_FOR_STRING) serviceMessage else "unknown" | ||
) | ||
|
||
fun mapServiceState(serviceState: String): ServiceState = | ||
when(serviceState) { | ||
"ON_SERVICE" -> ServiceState.ON_SERVICE | ||
"OUT_OF_ORDER" -> ServiceState.OUT_OF_ORDER | ||
else -> ServiceState.ELSE | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/java/campus/tech/kakao/map/data/datasource/Remote/ConfigService.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,33 @@ | ||
package campus.tech.kakao.map.data.datasource.Remote | ||
|
||
import campus.tech.kakao.map.R | ||
import campus.tech.kakao.map.data.datasource.Local.Entity.ConfigEntity | ||
import campus.tech.kakao.map.domain.vo.ServiceState | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings | ||
import com.google.firebase.remoteconfig.remoteConfig | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.tasks.asDeferred | ||
import kotlinx.coroutines.tasks.await | ||
import kotlinx.coroutines.withContext | ||
|
||
class ConfigService { | ||
private val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig | ||
private val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = 0 | ||
} | ||
|
||
init{ | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
} | ||
|
||
suspend fun getConfig() : ConfigEntity = withContext(Dispatchers.IO){ | ||
remoteConfig.fetchAndActivate().await() | ||
ConfigEntity( | ||
remoteConfig.getString("serviceState"), | ||
remoteConfig.getString("serviceMessage") | ||
) | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/campus/tech/kakao/map/data/di/ConfigModule.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 campus.tech.kakao.map.data.di | ||
|
||
import android.content.SharedPreferences | ||
import campus.tech.kakao.map.data.ConfigRepositoryImpl | ||
import campus.tech.kakao.map.data.PlaceRepositoryImpl | ||
import campus.tech.kakao.map.data.datasource.Local.DB.RoomDB | ||
import campus.tech.kakao.map.data.datasource.Remote.ConfigService | ||
import campus.tech.kakao.map.data.datasource.Remote.RemoteService | ||
import campus.tech.kakao.map.data.datasource.Remote.RetrofitService | ||
import campus.tech.kakao.map.domain.ConfigRepository | ||
import campus.tech.kakao.map.domain.PlaceRepository | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ConfigModule { | ||
|
||
@Provides | ||
@Singleton | ||
fun provideConfigRepository( | ||
configService: ConfigService | ||
) : ConfigRepository = | ||
ConfigRepositoryImpl(configService) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideConfigService() : ConfigService = ConfigService() | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/campus/tech/kakao/map/domain/ConfigRepository.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,7 @@ | ||
package campus.tech.kakao.map.domain | ||
|
||
import campus.tech.kakao.map.domain.vo.Config | ||
|
||
interface ConfigRepository { | ||
suspend fun getConfig() : Config | ||
} |
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,6 @@ | ||
package campus.tech.kakao.map.domain.vo | ||
|
||
data class Config( | ||
val serviceState : ServiceState, | ||
val serviceMessage : String | ||
) |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/campus/tech/kakao/map/domain/vo/ServiceState.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,5 @@ | ||
package campus.tech.kakao.map.domain.vo | ||
|
||
enum class ServiceState { | ||
ON_SERVICE,LOADING,OUT_OF_ORDER,ELSE | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/main/java/campus/tech/kakao/map/presenter/view/SplashActivity.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,45 @@ | ||
package campus.tech.kakao.map.presenter.view | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.databinding.DataBindingUtil | ||
import campus.tech.kakao.map.R | ||
import campus.tech.kakao.map.databinding.ActivitySplashBinding | ||
import campus.tech.kakao.map.domain.vo.ServiceState | ||
import campus.tech.kakao.map.presenter.viewModel.MapViewModel | ||
import campus.tech.kakao.map.presenter.viewModel.SplashViewModel | ||
import com.google.firebase.Firebase | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.get | ||
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings | ||
import com.google.firebase.remoteconfig.remoteConfig | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class SplashActivity : AppCompatActivity() { | ||
private val viewModel: SplashViewModel by viewModels() | ||
private lateinit var binding: ActivitySplashBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_splash) | ||
|
||
binding = DataBindingUtil.setContentView(this, R.layout.activity_splash) | ||
binding.lifecycleOwner = this | ||
binding.viewModel = viewModel | ||
|
||
viewModel.config.observe(this){ | ||
if(it.serviceState == ServiceState.ON_SERVICE){ | ||
startActivity(Intent(this,MapActivity::class.java)) | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/campus/tech/kakao/map/presenter/viewModel/SplashViewModel.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 campus.tech.kakao.map.presenter.viewModel | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import campus.tech.kakao.map.domain.ConfigRepository | ||
import campus.tech.kakao.map.domain.vo.Config | ||
import campus.tech.kakao.map.domain.vo.ServiceState | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashViewModel @Inject constructor( | ||
private val configRepository: ConfigRepository | ||
) : ViewModel() { | ||
private val _config: MutableLiveData<Config> = MutableLiveData( | ||
Config(serviceState = ServiceState.LOADING, serviceMessage = "Loading...") | ||
) | ||
val config: LiveData<Config> = _config | ||
|
||
init { | ||
viewModelScope.launch { | ||
_config.postValue(configRepository.getConfig()) | ||
} | ||
} | ||
} |
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,38 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<layout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<data> | ||
<variable | ||
name="viewModel" | ||
type="campus.tech.kakao.map.presenter.viewModel.SplashViewModel" /> | ||
</data> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".presenter.view.SplashActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/img" | ||
android:layout_width="200dp" | ||
android:layout_height="200dp" | ||
android:src="@drawable/place_image" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
<TextView | ||
android:id="@+id/errorText" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:textSize="@dimen/normal_100" | ||
splashErrorVisible="@{viewModel.config.serviceState}" | ||
text="@{viewModel.config.serviceMessage}" | ||
app:layout_constraintTop_toBottomOf="@+id/img" | ||
app:layout_constraintLeft_toLeftOf="parent" | ||
app:layout_constraintRight_toRightOf="parent"/> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
</layout> |
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,11 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<defaults> | ||
<entry> | ||
<key>serviceMessage</key> | ||
<value>서버 점검 중입니다. 나중에 다시 시도해 주세요.</value> | ||
</entry> | ||
<entry> | ||
<key>serviceState</key> | ||
<value>ON_SERVICE</value> | ||
</entry> | ||
</defaults> |
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