-
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주차 과제_Step 1 #53
Open
LEEMINSEO00
wants to merge
4
commits into
kakao-tech-campus-2nd-step2:leeminseo00
Choose a base branch
from
LEEMINSEO00:step1
base: leeminseo00
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4b3e151
docs: README.md
LEEMINSEO00 0bfc0ad
feat: Firebase Remote Config and splash screen
LEEMINSEO00 24dc83e
refactor: change package structure_SplashActivity.kt and SplashViewModel
LEEMINSEO00 12b791c
refactor: modify SplashActivity.kt_use Kotlin DSL style for Remote Co…
LEEMINSEO00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 아키텍처 패턴 적용 |
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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/campus/tech/kakao/map/view/SplashActivity.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,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 | ||
} | ||
} | ||
}) | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/campus/tech/kakao/map/viewmodel/SplashViewModel.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,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() | ||
.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 | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ViewModel에서 안드로이드에 의존적인 코드를 최대한 덜어내보세요.
이 로직의 역할을 담당하는 컴포넌트를 만들고 추상화하여 사용해보셔요.