Skip to content

Commit

Permalink
feat: BeginAdventureActivity에서 진행중인 게임이 있는지 판단하는 기능 구현 (#277)
Browse files Browse the repository at this point in the history
* design: 로딩을 위한 스켈레톤 UI 생성

* feat: 진행중인 상태의 게임을 받아오고 로딩하는 과정을 추가

* feat: 작업중

* rename: 로티 파일 이름 변경

* design: 스켈레톤 뷰 지우고 로티 뷰 추가

* feat: 로티 로딩뷰로 수정

* style: 로그 삭제

* feat: 뷰 진행 플로우 변경

* refactor: 직접 만든 로직을 이미 존재하는 코틀린 api로 대체
  • Loading branch information
briandr97 authored Aug 12, 2023
1 parent ca29158 commit 736c11e
Show file tree
Hide file tree
Showing 11 changed files with 244 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.now.naaga.data.firebase.analytics.AnalyticsDelegate
import com.now.naaga.data.firebase.analytics.DefaultAnalyticsDelegate
import com.now.naaga.data.firebase.analytics.RESULT_RESULT_RETURN
import com.now.naaga.databinding.ActivityAdventureResultBinding
import com.now.naaga.presentation.beginadventure.BeginAdventureActivity

class AdventureResultActivity : AppCompatActivity(), AnalyticsDelegate by DefaultAnalyticsDelegate() {
private lateinit var binding: ActivityAdventureResultBinding
Expand Down Expand Up @@ -91,7 +90,6 @@ class AdventureResultActivity : AppCompatActivity(), AnalyticsDelegate by Defaul
private fun setClickListeners() {
binding.btnAdventureResultReturn.setOnClickListener {
logClickEvent(getViewEntryName(it), RESULT_RESULT_RETURN)
startActivity(BeginAdventureActivity.getIntent(this))
finish()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@ import android.content.pm.PackageManager
import android.location.LocationManager
import android.os.Bundle
import android.provider.Settings
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.now.domain.model.AdventureStatus
import com.now.naaga.R
import com.now.naaga.data.firebase.analytics.AnalyticsDelegate
import com.now.naaga.data.firebase.analytics.BEGIN_BEGIN_ADVENTURE
import com.now.naaga.data.firebase.analytics.BEGIN_GO_MYPAGE
import com.now.naaga.data.firebase.analytics.BEGIN_GO_RANK
import com.now.naaga.data.firebase.analytics.BEGIN_GO_UPLOAD
import com.now.naaga.data.firebase.analytics.DefaultAnalyticsDelegate
import com.now.naaga.data.throwable.DataThrowable
import com.now.naaga.databinding.ActivityBeginAdventureBinding
import com.now.naaga.presentation.beginadventure.LocationPermissionDialog.Companion.TAG_LOCATION_DIALOG
import com.now.naaga.presentation.mypage.MyPageActivity
Expand All @@ -25,6 +29,13 @@ import com.now.naaga.presentation.rank.RankActivity

class BeginAdventureActivity : AppCompatActivity(), AnalyticsDelegate by DefaultAnalyticsDelegate() {
private lateinit var binding: ActivityBeginAdventureBinding
private lateinit var viewModel: BeginAdventureViewModel

private val onAdventureActivityLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { _ ->
startLoading()
fetchInProgressAdventure()
}

private val locationPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestMultiplePermissions()) { permissions ->
Expand All @@ -49,9 +60,47 @@ class BeginAdventureActivity : AppCompatActivity(), AnalyticsDelegate by Default
binding = ActivityBeginAdventureBinding.inflate(layoutInflater)
setContentView(binding.root)

startLoading()
registerAnalytics(this.lifecycle)
initViewModel()
fetchInProgressAdventure()
requestLocationPermission()
setClickListeners()
subscribe()

binding.viewModel = viewModel
binding.lifecycleOwner = this
}

private fun initViewModel() {
viewModel = ViewModelProvider(this, BeginAdventureViewModel.Factory)[BeginAdventureViewModel::class.java]
}

private fun fetchInProgressAdventure() {
viewModel.fetchAdventure(AdventureStatus.IN_PROGRESS)
}

private fun subscribe() {
viewModel.loading.observe(this) { loading ->
setLoadingView(loading)
}
viewModel.error.observe(this) { error: DataThrowable ->
Toast.makeText(this, error.message, Toast.LENGTH_SHORT).show()
}
}

private fun setLoadingView(loading: Boolean) {
if (!loading) {
finishLoading()
}
}

private fun startLoading() {
binding.lottieBeginAdventureLoading.visibility = View.VISIBLE
}

private fun finishLoading() {
binding.lottieBeginAdventureLoading.visibility = View.GONE
}

private fun requestLocationPermission() {
Expand Down Expand Up @@ -99,9 +148,17 @@ class BeginAdventureActivity : AppCompatActivity(), AnalyticsDelegate by Default
startActivity(Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS))
Toast.makeText(this, GPS_TURN_ON_MESSAGE, Toast.LENGTH_SHORT).show()
} else {
val intent = OnAdventureActivity.getIntent(this)
startActivity(intent)
finish()
onAdventureActivityLauncher.launch(getIntentWithAdventureOrWithout())
}
}

private fun getIntentWithAdventureOrWithout(): Intent {
val existingAdventure = viewModel.adventure.value

return if (existingAdventure == null) {
OnAdventureActivity.getIntent(this)
} else {
OnAdventureActivity.getIntentWithAdventure(this, existingAdventure)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.now.naaga.presentation.beginadventure

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.now.domain.model.Adventure
import com.now.domain.model.AdventureStatus
import com.now.domain.repository.AdventureRepository
import com.now.naaga.data.repository.DefaultAdventureRepository
import com.now.naaga.data.throwable.DataThrowable

class BeginAdventureViewModel(private val adventureRepository: AdventureRepository) : ViewModel() {
private val _adventure = MutableLiveData<Adventure>()
val adventure: LiveData<Adventure> = _adventure

private val _error = MutableLiveData<DataThrowable>()
val error: LiveData<DataThrowable> = _error

private val _loading = MutableLiveData<Boolean>(false)
val loading: LiveData<Boolean> = _loading

fun fetchAdventure(adventureStatus: AdventureStatus) {
_loading.value = true
adventureRepository.fetchAdventureByStatus(adventureStatus) { result ->
_loading.value = false
result
.onSuccess {
_adventure.value = it.firstOrNull()
}
.onFailure {
_error.value = it as DataThrowable
}
}
}

companion object {
val Factory = BeginAdventureViewModelFactory(DefaultAdventureRepository())

class BeginAdventureViewModelFactory(
private val adventureRepository: AdventureRepository,
) : ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return BeginAdventureViewModel(adventureRepository) as T
}
}
}
}
12 changes: 12 additions & 0 deletions android/app/src/main/res/anim/anim_skeleton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<alpha
android:duration="500"
android:fromAlpha="0.7"
android:interpolator="@android:anim/accelerate_interpolator"
android:repeatCount="infinite"
android:repeatMode="reverse"
android:toAlpha="1.0" />

</set>
19 changes: 18 additions & 1 deletion android/app/src/main/res/layout/activity_begin_adventure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,28 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="viewModel"
type="com.now.naaga.presentation.beginadventure.BeginAdventureViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".presentation.beginadventure.BeginAdventureActivity">

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottie_beginAdventure_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_gray_opacity_medium"
app:lottie_rawRes="@raw/simple_loading"
app:lottie_loop="true"
app:lottie_autoPlay="true"
android:elevation="8dp" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_beginAdventure_begin"
style="@style/BeginActivity.Button"
Expand Down Expand Up @@ -38,7 +55,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_default_medium"
android:fontFamily="@font/pretendard_bold"
android:text="모험 시작"
android:text="@{viewModel.adventure == null ? @string/beginAdventure_do_adventure : @string/beginAdventure_continue_adventure}"
android:textColor="@color/white"
android:textSize="32sp"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/activity_on_adventure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:lottie_rawRes="@raw/animation_ll5gzgdu"
app:lottie_rawRes="@raw/walking_loading"
app:lottie_loop="true"
app:lottie_autoPlay="true" />

Expand Down
97 changes: 97 additions & 0 deletions android/app/src/main/res/layout/skeleton_begin_adventure.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?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="com.now.naaga.presentation.beginadventure.BeginAdventureViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/main_gray"
android:elevation="8dp"
tools:context=".presentation.beginadventure.BeginAdventureActivity">

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_beginAdventure_begin"
style="@style/BeginActivity.Button.Skeleton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="40dp"
android:layout_marginTop="100dp"
android:paddingVertical="32dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/iv_beginAdventure_logo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginHorizontal="40dp"
android:src="@drawable/ic_logo_white"
app:layout_constraintDimensionRatio="1:1.1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/tv_beginAdventure_begin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/space_default_medium"
android:fontFamily="@font/pretendard_bold"
android:text="@{viewModel.adventure == null ? @string/beginAdventure_do_adventure : @string/beginAdventure_continue_adventure}"
android:textColor="@color/white"
android:textSize="32sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_beginAdventure_logo" />

</androidx.constraintlayout.widget.ConstraintLayout>

<ImageButton
android:id="@+id/iv_beginAdventure_mypage"
style="@style/BeginActivity.Button.Skeleton"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_mypage"
app:layout_constraintBottom_toBottomOf="@+id/iv_beginAdventure_upload"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/iv_beginAdventure_upload"
app:layout_constraintTop_toTopOf="@+id/iv_beginAdventure_upload" />

<ImageButton
android:id="@+id/iv_beginAdventure_rank"
style="@style/BeginActivity.Button.Skeleton"
android:layout_width="80dp"
android:layout_height="80dp"
android:src="@drawable/ic_rank"
app:layout_constraintBottom_toBottomOf="@+id/iv_beginAdventure_upload"
app:layout_constraintEnd_toStartOf="@+id/iv_beginAdventure_upload"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_beginAdventure_upload" />

<ImageButton
android:id="@+id/iv_beginAdventure_upload"
style="@style/BeginActivity.Button.Skeleton"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginHorizontal="30dp"
android:layout_marginBottom="20dp"
android:src="@drawable/ic_upload"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/iv_beginAdventure_mypage"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/iv_beginAdventure_rank" />


</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
1 change: 1 addition & 0 deletions android/app/src/main/res/raw/simple_loading.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":"5.8.1","fr":30,"ip":0,"op":60,"w":300,"h":300,"nm":"loading_6","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 2","sr":1,"ks":{"o":{"a":0,"k":100,"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":60,"s":[360]}],"ix":10},"p":{"a":0,"k":[150.00000000000003,150.00000000000003,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[30.000000000000004,30.000000000000004,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[300,300],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.22745098039215686,0.6627450980392157,0.8627450980392157,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":50,"ix":5},"lc":2,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false},{"ty":"tm","s":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":10,"s":[0]},{"t":60,"s":[99]}],"ix":1},"e":{"a":1,"k":[{"i":{"x":[0.667],"y":[1]},"o":{"x":[0.333],"y":[0]},"t":0,"s":[1]},{"t":50,"s":[100]}],"ix":2},"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":0,"s":[0]},{"t":60,"s":[3]}],"ix":3},"m":1,"ix":2,"nm":"Trim Paths 1","mn":"ADBE Vector Filter - Trim","hd":false}],"ip":0,"op":300,"st":0,"bm":0},{"ddd":0,"ind":2,"ty":4,"nm":"Shape Layer 1","sr":1,"ks":{"o":{"a":0,"k":30,"ix":11},"r":{"a":0,"k":0,"ix":10},"p":{"a":0,"k":[150.00000000000003,150.00000000000003,0],"ix":2,"l":2},"a":{"a":0,"k":[0,0,0],"ix":1,"l":2},"s":{"a":0,"k":[30.000000000000004,30.000000000000004,100],"ix":6,"l":2}},"ao":0,"shapes":[{"ty":"gr","it":[{"d":1,"ty":"el","s":{"a":0,"k":[300,300],"ix":2},"p":{"a":0,"k":[0,0],"ix":3},"nm":"Ellipse Path 1","mn":"ADBE Vector Shape - Ellipse","hd":false},{"ty":"st","c":{"a":0,"k":[0.6666666666666666,0.8431372549019608,0.9215686274509803,1],"ix":3},"o":{"a":0,"k":100,"ix":4},"w":{"a":0,"k":50,"ix":5},"lc":1,"lj":1,"ml":4,"bm":0,"nm":"Stroke 1","mn":"ADBE Vector Graphic - Stroke","hd":false},{"ty":"tr","p":{"a":0,"k":[0,0],"ix":2},"a":{"a":0,"k":[0,0],"ix":1},"s":{"a":0,"k":[100,100],"ix":3},"r":{"a":0,"k":0,"ix":6},"o":{"a":0,"k":100,"ix":7},"sk":{"a":0,"k":0,"ix":4},"sa":{"a":0,"k":0,"ix":5},"nm":"Transform"}],"nm":"Ellipse 1","np":3,"cix":2,"bm":0,"ix":1,"mn":"ADBE Vector Group","hd":false}],"ip":0,"op":300,"st":0,"bm":0}],"markers":[]}
1 change: 1 addition & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string name="beginAdventure_approximate_access">대략적인 위치 권한만 허용되었습니다</string>
<string name="beginAdventure_denied_access">위치 권한 요청이 거절되었습니다</string>
<string name="beginAdventure_features_not_ready">아직 준비되지 않은 기능입니다.</string>
<string name="beginAdventure_do_adventure">모험 하기</string>
<string name="beginAdventure_continue_adventure">이어 하기</string>

<!-- LocationDialog-->
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<item name="android:backgroundTint">@color/main_purple</item>
<item name="android:elevation">6dp</item>
</style>

<style name="BeginActivity.Button.Skeleton">
<item name="android:background">@drawable/rect_white_radius_small</item>
<item name="android:backgroundTint">@color/light_gray</item>
<item name="android:elevation">6dp</item>
</style>
</resources>

0 comments on commit 736c11e

Please sign in to comment.