-
Notifications
You must be signed in to change notification settings - Fork 30
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주차 과제_1단계 #33
Changes from 8 commits
04c907f
8b097b3
1e95da9
4a7f9a8
42afbd1
517f77f
7ce9207
97252e2
de8235e
c09822b
6648952
f768d06
4667bef
34d7f19
af00889
4696833
270aa41
d8b123a
ba8c9e9
d87066d
14eab04
bbf77e9
566e065
9761014
a8018be
83e4264
d55b398
0a8dbb8
72262c9
6199ae0
a1ea940
5ad8740
923a0e6
ed5c86b
9d0cb76
1ad92d6
c4d7d2c
789b398
200828c
e2799c0
8969b8d
ecfb8d4
491fd21
6547a98
779e8bf
1012e1c
8668c0b
5387bbc
39c2aca
cdc82a9
f5f422f
3355c00
649ec19
964fa52
7f38d89
b251102
d636f3f
2ddc919
ebf3aa5
a799aac
e4daf88
59f842d
2c127ca
078fd2e
2623c4d
3a508e5
305453d
95bf427
706f113
b0126f0
2105f5b
f515e0f
19241e0
44b0c8b
2a48e98
27fdfc3
bc60c27
2f197c3
a9d021d
1426ecf
f410091
8b53376
df98574
a326fb9
f64ef36
5ef4c73
58f0b7c
10d4af5
0ef011a
2fe82cb
dd6806c
5f276af
a8d7d08
d876e3d
bd802f4
f34c050
fb20a77
80e3e32
f99f9a8
e8f6ef1
4efd28f
c9b3deb
b1a01df
b119c29
397118a
b2cd4d4
519b7a4
cd214ea
5c15df7
ff3f7cb
a1e9ada
93a7ed4
1744a99
68a8288
02d1ed4
faf35d9
7ca97f5
77fd1dc
1947208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
# android-map-notification | ||
|
||
## Step1 | ||
|
||
### 📜 Description | ||
|
||
카카오맵 클론 코딩 _ 알림-파이어베이 | ||
|
||
|
||
### 🎯 Tasks | ||
|
||
- Main 기능 : **Splash Screen** | ||
|
||
- 초기 진입 화면 추가 | ||
- Firebase의 Remote Config 설정 | ||
- 서비스 상태를 나타내는 매개변수 각각 등록 | ||
- 매개변수 이름 : serviceState, serviceMessage | ||
- 매개변수 serviceState 값이 ON_SERVICE일 때만 초기 진입 화면이 지도 화면으로 넘어감 | ||
- 매개변수 serviceState 값이 ON_SERVICE이 아닌 경우, serviceMessage 값을 초기 진입 화면 하단에 표시하고 지도 화면으로 진입하지 않음 | ||
- 서버 상태, UI 로딩 등에 대한 상태 관리 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package campus.tech.kakao.map.ui | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.util.Log | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import campus.tech.kakao.map.R | ||
import campus.tech.kakao.map.databinding.ActivitySplashScreenBinding | ||
import campus.tech.kakao.map.viewmodel.SplashScreenViewModel | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class SplashScreenActivity : AppCompatActivity() { | ||
|
||
private val viewModel: SplashScreenViewModel by viewModels() | ||
private lateinit var binding: ActivitySplashScreenBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = DataBindingUtil.setContentView(this, R.layout.activity_splash_screen) | ||
binding.lifecycleOwner = this | ||
binding.viewModel = viewModel | ||
|
||
viewModel.serviceState.observe(this) { state -> | ||
if (state == "ON_SERVICE") { | ||
navigateToMapActivity() | ||
} else { | ||
showServiceMessage() | ||
} | ||
} | ||
} | ||
|
||
private fun navigateToMapActivity() { | ||
Log.d("SplashScreen", "Success") | ||
Handler(Looper.getMainLooper()).postDelayed({ | ||
startActivity(Intent(this, MapActivity::class.java)) | ||
finish() | ||
}, 3000) | ||
} | ||
|
||
private fun showServiceMessage() { | ||
Log.d("SplashScreen", "Failed") | ||
binding.tvServiceMessage.text = viewModel.serviceMessage.value | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package campus.tech.kakao.map.viewmodel | ||
|
||
import android.util.Log | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.remoteConfigSettings | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class SplashScreenViewModel @Inject constructor( | ||
private val remoteConfig: FirebaseRemoteConfig | ||
) : ViewModel() { | ||
|
||
private val _serviceState = MutableLiveData<String>() | ||
val serviceState: LiveData<String> = _serviceState | ||
|
||
private val _serviceMessage = MutableLiveData<String>() | ||
val serviceMessage: LiveData<String> = _serviceMessage | ||
|
||
init { | ||
setupRemoteConfig() | ||
fetchRemoteConfig() | ||
} | ||
|
||
private fun setupRemoteConfig() { | ||
val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = 0 | ||
} | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
} | ||
|
||
private fun fetchRemoteConfig() { | ||
viewModelScope.launch { | ||
remoteConfig.fetchAndActivate() | ||
.addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
handleRemoteConfig() | ||
} else { | ||
Log.d("SplashScreenViewModel", "Fetch failed") | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+25
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remoteConfig 에서 값을 가져와서 처리하는 로직은 정상적으로 작성해주셨습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 감사합니다! 그런 부분까지 생각하지 못했는데 새로운 관점을 알게 되었네요!! 적용해보겠습니다. |
||
|
||
private fun handleRemoteConfig() { | ||
_serviceState.value = remoteConfig.getString("serviceState") | ||
_serviceMessage.value = remoteConfig.getString("serviceMessage") | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?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.viewmodel.SplashScreenViewModel" /> | ||
<import type="android.view.View"/> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.SplashScreenActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/ivMap" | ||
android:layout_width="150dp" | ||
android:layout_height="150dp" | ||
android:src="@drawable/map" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
android:contentDescription="@string/splashscreenmapicon" /> | ||
|
||
<TextView | ||
android:id="@+id/tvServiceMessage" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@{viewModel.serviceMessage}" | ||
android:textColor="#999999" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
android:gravity="center" | ||
android:layout_marginBottom="50dp" | ||
android:visibility="@{viewModel.serviceState.equals(`ON_SERVICE`) ? View.GONE : View.VISIBLE}"/> | ||
Comment on lines
+30
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. text를 넣어주는 코드는 Activity의 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. state가 ON_SERVICE가 아닐 때, showServiceMessage()가 호출되며 로그를 띄우는 등의 기능을 하니까 Activity에서 하도록 통일해보려고 합니다 ... !! |
||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> | ||
|
||
</layout> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MapActivity를 띄우는데 handler로 3초 딜레이를 주신 이유가 있을까요.
약간 늦게 뜨는걸 의도한 것이라면,
ViewModelScope.launch
수행할때 RemoteConfig 값을 조금 늦게 확인하도록 하는방법이 어덜까 합니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저에게는 가끔 에뮬레이터가 버벅이며 늦게 실행되어서 Splash Screen에 아이콘이 잘 들어왔는지, 메시지가 잘 처리되었는지 확인되기도 전에 MapActivity로 갑자기 휙 넘어가는 경우가 있어 지연을 주고싶었습니다.
구글링을 통해 해당 방법을 찾았는데, 더 좋은 방법을 알려주셔서 감사합니다!
(이 부분 작성할 때 제가 찾았던 자료도 살짝쿵 첨부하고 갑니다 ㅎㅎ)
https://dailycoding365.tistory.com/entry/%EC%95%88%EB%93%9C%EB%A1%9C%EC%9D%B4%EB%93%9C-Splash-%ED%99%94%EB%A9%B4-%EA%B5%AC%ED%98%84%ED%95%98%EA%B8%B0