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

전남대 Android_이민서_6주차 과제_Step 1 #53

Open
wants to merge 4 commits into
base: leeminseo00
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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# android-map-notification
## Step 1. Splash Screen
### 구현 기능 목록

1. 초기 진입 화면 추가
2. Firebase의 Remote Config 설정
- 서비스 상태 나타내는 매개변수 각각 등록
- 매개변수 이름: serviceState, serviceMessage
3. 매개변수 serviceState 값 = ON_SERVICE
- 초기 진입 화면 -> 지도 화면
4. 매개변수 serviceState 값 != ON_SERVICE
- 지도 화면 진입 X
- serviceMessage 값 -> 초기 진입 화면 하단에 표시
5. 상태 관리
- 서버 상태
- UI 로딩
6. MVVM 아키텍처 패턴 적용
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
android:theme="@style/Theme.Map"
tools:targetApi="31">
<activity
android:name=".view.MainActivity"
android:name=".view.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -27,6 +27,7 @@
</intent-filter>
</activity>
<activity android:name=".view.MainActivity"/>
<activity android:name=".view.MapActivity"/>
</application>

</manifest>
46 changes: 46 additions & 0 deletions app/src/main/java/campus/tech/kakao/map/view/SplashActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package campus.tech.kakao.map.view

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import campus.tech.kakao.map.viewmodel.SplashViewModel
import campus.tech.kakao.map.databinding.ActivitySplashBinding
import com.google.firebase.ktx.Firebase
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfig
import com.google.firebase.remoteconfig.ktx.remoteConfigSettings

class SplashActivity : AppCompatActivity() {

private val viewModel: SplashViewModel by viewModels()
private lateinit var binding: ActivitySplashBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivitySplashBinding.inflate(layoutInflater)
setContentView(binding.root)

val remoteConfig: FirebaseRemoteConfig = Firebase.remoteConfig
val configSettings = remoteConfigSettings {
minimumFetchIntervalInSeconds = 0
}
remoteConfig.setConfigSettingsAsync(configSettings)

viewModel.fetchRemoteConfig(remoteConfig)

viewModel.fetchSuccess.observe(this, Observer { success ->
if (success) {
if (viewModel.serviceState.value == "ON_SERVICE") {
startActivity(Intent(this, MapActivity::class.java))
finish()
} else {
Log.d("SplashActivity", "Observed serviceMessage: ${viewModel.serviceMessage.value}")
binding.serviceMessageTextView.text = viewModel.serviceMessage.value
}
}
})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package campus.tech.kakao.map.viewmodel

import android.app.Application
import android.util.Log
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.google.firebase.remoteconfig.FirebaseRemoteConfig

class SplashViewModel(application: Application) : AndroidViewModel(application) {

private val _serviceState = MutableLiveData<String>()
val serviceState: LiveData<String> get() = _serviceState

private val _serviceMessage = MutableLiveData<String>()
val serviceMessage: LiveData<String> get() = _serviceMessage

private val _fetchSuccess = MutableLiveData<Boolean>()
val fetchSuccess: LiveData<Boolean> get() = _fetchSuccess

fun fetchRemoteConfig(remoteConfig: FirebaseRemoteConfig) {
remoteConfig.fetchAndActivate()

Choose a reason for hiding this comment

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

ViewModel에서 안드로이드에 의존적인 코드를 최대한 덜어내보세요.
이 로직의 역할을 담당하는 컴포넌트를 만들고 추상화하여 사용해보셔요.

.addOnCompleteListener { task ->
if (task.isSuccessful) {
val serviceStateValue = remoteConfig.getString("serviceState")
val serviceMessageValue = remoteConfig.getString("serviceMessage")

Log.d("SplashViewModel", "serviceState: $serviceStateValue")
Log.d("SplashViewModel", "serviceMessage: $serviceMessageValue")

_serviceState.value = serviceStateValue
_serviceMessage.value = serviceMessageValue
_fetchSuccess.value = true
} else {
_fetchSuccess.value = false
}
}
}
}
Binary file added app/src/main/res/drawable/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions app/src/main/res/layout/activity_splash.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".view.SplashActivity">

<data>
<variable
name="viewModel"
type="campus.tech.kakao.map.viewmodel.SplashViewModel" />
<import type="android.view.View"/>
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/splashLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ImageView
android:id="@+id/logoImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:src="@drawable/splash"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>

<TextView
android:id="@+id/serviceMessageTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/darker_gray"
app:layout_constraintTop_toBottomOf="@id/logoImage"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginTop="150dp"
android:text="@{viewModel.serviceMessage}" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>