-
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주차 과제 Step1 #17
Changes from 5 commits
04c907f
8b097b3
6b8ac02
cacee4b
cb73f1e
6bd8cf7
0fc0da3
f94b9b8
a400cbd
60e50ab
36ad032
0644db3
de2036d
8dcc8a7
3959c94
c03af09
bbf77e9
e708df9
39de52b
1c5d9c2
a68d784
2f45b6c
e3818d0
3521161
ab8d218
7b38ee9
10c77c6
8d65dd3
9e07bf4
8702f3b
b3231a9
113daff
b954413
0f3c880
9652c65
9238189
918d3fd
f87982e
ce0ab32
f6cb344
767bc4a
dac7bca
afa34b0
d88c1a5
13d7133
97ee6d1
dd9b3a1
b44783b
f14be70
1d481b2
cec88cf
02b9df4
08879d8
305453d
53769af
bf7f411
4aceb24
634700d
eea98eb
202da6c
ec78710
cac1aaa
3b8c2ca
3ca355a
05d33a7
bd0c9ba
fff84fb
ba997ca
55d7ed5
9cf280f
5b541c7
712d413
8e28f65
f79cab4
59c928d
5aaa878
348dcb9
dc1329a
da573e2
5d71bef
9bdaa2f
6ce455d
592cdc5
9141ee4
261f6a3
a8910a9
c2115ed
2b423ce
0f87216
618db5c
de13d90
890bf2b
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 | ||
# 맵 위치 검색 안드로이드 앱 | ||
- 카테캠 Step2 Week6 | ||
- 장소 검색 및 장소 저장이 가능한 안드로이드 앱 | ||
|
||
## 기능 | ||
**1. 초기 진입 화면 추가** | ||
- firebase의 Remote Config 설정 | ||
- serviceState 값이 ON_SERVICE 일 때 | ||
- 지도 화면으로 진입 | ||
- serviceState 값이 ON_SERVICE가 아닐 때 | ||
- serviceMessage를 초기 진입 화면 하단에 표시 | ||
- 지도 화면으로 진입하지 않음 | ||
|
||
|
||
## 실행 | ||
- SplashActivity.kt 에서 시작 | ||
|
||
## 환경 | ||
- Kotlin | ||
- Android Studio |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package campus.tech.kakao.map.ui | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.util.Log | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import androidx.activity.viewModels | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.Observer | ||
import campus.tech.kakao.map.R | ||
import campus.tech.kakao.map.databinding.ActivitySplashBinding | ||
|
||
class SplashActivity : AppCompatActivity() { | ||
|
||
private val splashViewModel: SplashViewModel by viewModels() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val binding: ActivitySplashBinding = DataBindingUtil.setContentView(this, R.layout.activity_splash) | ||
binding.lifecycleOwner = this | ||
binding.viewModel = splashViewModel | ||
|
||
splashViewModel.serviceState.observe(this, Observer { state -> | ||
if (state == "ON_SERVICE") { | ||
startActivity(Intent(this, MapActivity::class.java)) | ||
finish() | ||
} else { | ||
binding.tvServiceMessage.visibility = TextView.VISIBLE | ||
} | ||
}) | ||
|
||
splashViewModel.serviceMessage.observe(this, Observer { message -> | ||
Log.d("SplashActivity", "serviceMessage: $message") | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package campus.tech.kakao.map.ui | ||
|
||
import android.app.Application | ||
import androidx.lifecycle.AndroidViewModel | ||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig | ||
import com.google.firebase.remoteconfig.remoteConfigSettings | ||
|
||
class SplashViewModel(application: Application) : AndroidViewModel(application) { | ||
|
||
Comment on lines
+9
to
+11
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. hilt를 통해 의존성 주입을 받고자 한다면, 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 val _serviceState = MutableLiveData<String>() | ||
val serviceState: LiveData<String> = _serviceState | ||
|
||
private val _serviceMessage = MutableLiveData<String>() | ||
val serviceMessage: LiveData<String> = _serviceMessage | ||
|
||
init { | ||
remoteConfigValues() | ||
} | ||
|
||
private fun remoteConfigValues() { | ||
val remoteConfig: FirebaseRemoteConfig = FirebaseRemoteConfig.getInstance() | ||
val configSettings = remoteConfigSettings { | ||
minimumFetchIntervalInSeconds = 0 | ||
} | ||
remoteConfig.setConfigSettingsAsync(configSettings) | ||
|
||
remoteConfig.fetchAndActivate().addOnCompleteListener { task -> | ||
if (task.isSuccessful) { | ||
_serviceState.value = remoteConfig.getString("serviceState") | ||
_serviceMessage.value = remoteConfig.getString("serviceMessage") | ||
} else { | ||
_serviceMessage.value = "Failed to fetch remote config values" | ||
} | ||
} | ||
} | ||
Comment on lines
+18
to
+37
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로 데이터를 조회하고, LiveData를 통해 Activity에 전달해주는 코드는 훌륭하게 작성하셨습니다. 조금 개선하면 좋을 부분이요. RemoteConfig 또한 원격 저장소에서 데이터를 조회하는 동작이라 network 및 data layer (model) 쪽에 속한다고 볼 수 있습니다. 따라서 repository혹은 remote 와 관련된 클래스를 만들고, 그 클래스에서 리모트컨피그 값을 조회하도록 하는것이 조금더 좋을것 같습니다! 그 클래스는 hilt module에 선언한 후 SplashViewModel의 생성자를 통해 주입받는거죠 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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.ui.SplashViewModel" /> | ||
</data> | ||
|
||
<androidx.constraintlayout.widget.ConstraintLayout | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.SplashActivity"> | ||
|
||
<ImageView | ||
android:id="@+id/ivInitialIcon" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
android:src="@drawable/map" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent"/> | ||
|
||
<TextView | ||
android:id="@+id/tvServiceMessage" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@{viewModel.serviceMessage}" | ||
app:layout_constraintTop_toBottomOf="@+id/ivInitialIcon" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
android:visibility="gone"/> | ||
|
||
</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.
profileDao의 insertAll도 suspend function으로 선언되어 있죠?
그렇다면, withContext로 Dispatcher를 전환해주지 않아도 괜찮습니다. Room 내부에서 비동기로 처리되게 해주기 때문이죠. 혹여나 필요하다면
viewModelScope.launch(Dispatchers.IO)
이렇게 넣어주면 withContext 단계를 생략할 수 있을듯 합니다