-
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.
feat: add splash screen implementation
- Loading branch information
1 parent
a1d5c7b
commit dbc164e
Showing
9 changed files
with
152 additions
and
16 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 was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
app/src/main/java/campus/tech/kakao/map/model/splashscreen/Service.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,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" | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/campus/tech/kakao/map/repository/splashscreen/FirebaseModule.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.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 | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/campus/tech/kakao/map/repository/splashscreen/FirebaseRepository.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,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 | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
app/src/main/java/campus/tech/kakao/map/view/splashscreen/SplashScreenActivity.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,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 | ||
} | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/campus/tech/kakao/map/viewmodel/splashscreen/SplashScreenViewModel.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,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() | ||
} | ||
} | ||
} |