Skip to content

Commit

Permalink
feat: add splash screen implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
kimseongyu committed Jul 31, 2024
1 parent a1d5c7b commit dbc164e
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 16 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".view.splashscreen.SplashScreenActivity"
android:exported="false" />
<activity
android:name=".view.kakaomap.KakaoMapActivity"
android:exported="false" />
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/campus/tech/kakao/map/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package campus.tech.kakao.map

import android.content.Context
import android.content.SharedPreferences
import campus.tech.kakao.map.model.search.SearchKeywordDao
import campus.tech.kakao.map.repository.kakaomap.LastPositionRepository
import campus.tech.kakao.map.repository.search.KakaoSearchKeywordAPI
import campus.tech.kakao.map.repository.search.SavedSearchKeywordRepository
import campus.tech.kakao.map.repository.search.SearchRepository
import campus.tech.kakao.map.repository.splashscreen.FirebaseRepository
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

Expand All @@ -32,4 +32,9 @@ object AppModule {
@Singleton
fun provideLastPositionRepository(sharedPreferences: SharedPreferences) =
LastPositionRepository(sharedPreferences)

@Provides
@Singleton
fun provideFirebaseRepository(remoteConfig: FirebaseRemoteConfig) =
FirebaseRepository(remoteConfig)
}
13 changes: 0 additions & 13 deletions app/src/main/java/campus/tech/kakao/map/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package campus.tech.kakao.map.model.splashscreen

data class Service(
var state: String,
var msg: String
)

object ServiceRemoteConfig {
const val SERVICE_STATE = "serviceState"
const val SERVICE_MESSAGE = "serviceMessage"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package campus.tech.kakao.map.repository.splashscreen

import android.content.Context
import com.google.firebase.Firebase
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.remoteConfig
import com.google.firebase.remoteconfig.remoteConfigSettings
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object FirebaseModule {

@Provides
@Singleton
fun provideRemoteConfig(@ApplicationContext context: Context): FirebaseRemoteConfig {
val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 0
}
remoteConfig.setConfigSettingsAsync(configSettings)
return remoteConfig
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package campus.tech.kakao.map.repository.splashscreen

import campus.tech.kakao.map.model.splashscreen.Service
import campus.tech.kakao.map.model.splashscreen.ServiceRemoteConfig.SERVICE_MESSAGE
import campus.tech.kakao.map.model.splashscreen.ServiceRemoteConfig.SERVICE_STATE
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import kotlinx.coroutines.tasks.await
import javax.inject.Inject

private const val ON_SERIVCE = "ON_SERVICE"

class FirebaseRepository @Inject constructor(
private val remoteConfig: FirebaseRemoteConfig
) {

suspend fun getService(): Service {
val service = Service("", "")
remoteConfig.fetchAndActivate().await()
service.state = remoteConfig.getString(SERVICE_STATE)
if (service.state != ON_SERIVCE)
service.msg = remoteConfig.getString(SERVICE_MESSAGE)
return service
}
}
3 changes: 2 additions & 1 deletion app/src/main/java/campus/tech/kakao/map/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import campus.tech.kakao.map.R
import campus.tech.kakao.map.view.kakaomap.KakaoMapActivity
import campus.tech.kakao.map.view.splashscreen.SplashScreenActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val intent = Intent(this, KakaoMapActivity::class.java)
val intent = Intent(this, SplashScreenActivity::class.java)
startActivity(intent)
finish()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package campus.tech.kakao.map.view.splashscreen

import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import campus.tech.kakao.map.R
import campus.tech.kakao.map.databinding.ActivitySplashScreenBinding
import campus.tech.kakao.map.view.kakaomap.KakaoMapActivity
import campus.tech.kakao.map.viewmodel.splashscreen.SplashScreenViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch

@AndroidEntryPoint
class SplashScreenActivity : AppCompatActivity() {

private lateinit var binding: ActivitySplashScreenBinding
private val viewModel: SplashScreenViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_splash_screen)

viewModel.getService()
displaySplashScreen()
}

private fun displaySplashScreen() {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.service.collect { service ->
if (service.state == "ON_SERVICE") {
Handler(Looper.getMainLooper()).postDelayed({
val intent =
Intent(this@SplashScreenActivity, KakaoMapActivity::class.java)
startActivity(intent)
finish()
}, 2000)
}
binding.service = service
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package campus.tech.kakao.map.viewmodel.splashscreen

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import campus.tech.kakao.map.model.splashscreen.Service
import campus.tech.kakao.map.repository.splashscreen.FirebaseRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SplashScreenViewModel @Inject constructor(
private var firebaseRepository: FirebaseRepository
) : ViewModel() {

private val _service = MutableStateFlow<Service>(Service("", ""))
val service: StateFlow<Service> get() = _service

fun getService() {
viewModelScope.launch {
_service.value = firebaseRepository.getService()
}
}
}

0 comments on commit dbc164e

Please sign in to comment.