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

[Feature] 온보딩 모듈 추가 #438

Merged
merged 30 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
0bac2b8
del: 좋아요 기능 삭제
ThirFir Oct 16, 2024
bfa6f6e
fix: 키워드 알림 상태 버그
ThirFir Oct 21, 2024
0e5ec8e
del: onResume override
ThirFir Oct 22, 2024
26e7a33
fix: 식단 카드 간격 조정
ThirFir Oct 22, 2024
a372212
fix: 식단 카드 Radius
ThirFir Oct 22, 2024
7279ad8
fix: 식단 상세 정보 ui
ThirFir Oct 22, 2024
03c0c19
fix: 식단 공유 버튼 ui
ThirFir Oct 22, 2024
107a6dd
add: onboarding 모듈
ThirFir Oct 22, 2024
d1ae376
refactor: OnboardingManager 추가, MainActivity 식단 툴팁 변경
ThirFir Oct 22, 2024
26deffb
add: 화살표 위치 매개변수
ThirFir Oct 22, 2024
49d14dc
refactor: 공지 키워드 툴팁 코드 리팩토링
ThirFir Oct 22, 2024
1647ad9
del: Koin 모듈에서 balloon lib 의존성 제거
ThirFir Oct 22, 2024
39e520c
fix: tooltip initialize 여부 조건 추가
ThirFir Oct 22, 2024
c038ed3
del: Unused onboarding codes
ThirFir Oct 22, 2024
d0b8ece
refactor: Onboarding Hilt Component: Singleton -> ActivityComponent
ThirFir Oct 22, 2024
535d4c6
refactor: 온보딩 바텀시트 액션 모듈화 이용
ThirFir Oct 22, 2024
d9d15a4
refactor: DataStore DI 로직 변경
ThirFir Oct 22, 2024
d864ea5
fix: 함수명 포괄적으로 변경
ThirFir Oct 22, 2024
85f533d
add: 툴팁 닫기 API
ThirFir Oct 23, 2024
b3511fb
add: 식단 공유 툴팁
ThirFir Oct 23, 2024
64b5bf7
add: 이벤트 로깅
ThirFir Oct 23, 2024
dded9d7
add: 알림 액티비티에 공지 키워드 진입점 추가
ThirFir Oct 23, 2024
2792822
refactor: enum 위치 이동
ThirFir Oct 24, 2024
37f9ad5
add: 원본 공지 진입버튼
ThirFir Oct 24, 2024
7304ca3
feat: 식단 공유 툴팁 gif로 변경
ThirFir Oct 27, 2024
9f2792a
fix: 빌드 에러
ThirFir Oct 28, 2024
1fb52b3
fix: as -> as?, Dispatchers
ThirFir Oct 29, 2024
9065122
fix: Dispatchers Switching 제거
ThirFir Oct 30, 2024
8211f45
Merge branch 'feature/onboarding' into feature/dining-abtest
ThirFir Oct 30, 2024
f621430
Merge remote-tracking branch 'origin/develop' into feature/onboarding
ThirFir Oct 30, 2024
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
1 change: 1 addition & 0 deletions core/onboarding/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
19 changes: 19 additions & 0 deletions core/onboarding/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
plugins {
alias(libs.plugins.koin.library)
alias(libs.plugins.koin.hilt)
}

android {
namespace = "in.koreatech.koin.core.onboarding"
}
kapt {
correctErrorTypes = true
}
dependencies {
implementation(project(":domain"))

implementation(libs.core.ktx)
implementation(libs.appcompat)
implementation(libs.timber)
implementation(libs.balloon)
}
Empty file.
21 changes: 21 additions & 0 deletions core/onboarding/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package `in`.koreatech.koin.core.onboarding

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("in.koreatech.koin.core.onboarding.test", appContext.packageName)
}
}
4 changes: 4 additions & 0 deletions core/onboarding/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package `in`.koreatech.koin.core.onboarding

import com.skydoves.balloon.ArrowOrientation

enum class ArrowDirection {
BOTTOM, TOP, LEFT, RIGHT;

fun toArrowOrientation(): ArrowOrientation {
return when (this) {
BOTTOM -> ArrowOrientation.BOTTOM
TOP -> ArrowOrientation.TOP
LEFT -> ArrowOrientation.START
RIGHT -> ArrowOrientation.END
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package `in`.koreatech.koin.core.onboarding

import android.content.Context
import android.view.View
import androidx.annotation.FloatRange
import androidx.appcompat.content.res.AppCompatResources
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.skydoves.balloon.ArrowOrientation
import com.skydoves.balloon.ArrowOrientationRules
import com.skydoves.balloon.ArrowPositionRules
import com.skydoves.balloon.Balloon
import com.skydoves.balloon.BalloonAnimation
import com.skydoves.balloon.BalloonSizeSpec
import com.skydoves.balloon.IconForm
import com.skydoves.balloon.IconGravity
import `in`.koreatech.koin.domain.repository.OnboardingRepository
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

class OnboardingManager @Inject internal constructor(
private val onboardingRepository: OnboardingRepository,
private val context: Context,
private val mainDispatcher: CoroutineDispatcher
) {

private lateinit var tooltip: Balloon
private val tooltipDismissObserver = object : DefaultLifecycleObserver {
override fun onPause(owner: LifecycleOwner) {
if (::tooltip.isInitialized)
tooltip.dismiss()
super.onPause(owner)
}
}

/**
* 앱 실행 최초 1회에만 툴팁 표시
* @param type 툴팁 타입
* @param view 툴팁을 위치시킬 뷰
* @param arrowPosition 화살표 위치 (0.0 ~ 1.0)
* @param arrowDirection 툴팁 화살표 방향 (ex. ArrowDirection.LEFT -> 화살표는 왼쪽방향, 툴팁은 오른쪽에 위치)
* ```
* // In Activity
* @Inject
* lateinit var onboardingManager: OnboardingManager
* ...
*
* with(onboardingManager) {
* showOnboardingTooltipIfNeeded(
* type = OnboardingType.DINING_IMAGE,
* view = binding.textViewDiningTitle,
* arrowDirection = ArrowDirection.LEFT
* )
* }
* ```
*
* binding.textViewDiningTitle 오른쪽에 툴팁 표시됨.
*
* Fragment에서 사용할 때는 viewLifecycleOwner를 사용해야 함 !
*/
fun LifecycleOwner.showOnboardingTooltipIfNeeded(
type: OnboardingType,
view: View,
@FloatRange(from = 0.0, to = 1.0) arrowPosition: Float = 0.5f,
arrowDirection: ArrowDirection,
) {
lifecycle.addObserver(tooltipDismissObserver)
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
val shouldShow = onboardingRepository.getShouldOnboarding(type.name)
delay(500)
withContext(mainDispatcher) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이미 lifecycleScope 와 repeatOnLifecycle를 사용하는데, Main 디스패처를 주입해서 사용한 이유가 있나요?

Copy link
Contributor Author

@ThirFir ThirFir Oct 29, 2024

Choose a reason for hiding this comment

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

launch에 IO Dispatcher를 지정하려 했는데 안했네요 ㅎ.. 🤐

if (shouldShow) {
tooltip = createTooltip(type, arrowDirection, arrowPosition)
tooltip.showAlign(view, arrowDirection)
onboardingRepository.updateShouldOnboarding(type.name, false)
}
}
}
}
}

/**
* 앱 최초 실행 시에 실행시키고 싶은 액션이 있는 경우 사용
* @param action 실행시킬 액션. ex) BottomSheetDialogFragment.show()
*/
fun LifecycleOwner.showOnboardingIfNeeded(
type: OnboardingType,
action: () -> Unit
) {
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
val shouldShow = onboardingRepository.getShouldOnboarding(type.name)
withContext(mainDispatcher) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

이것도 마찬가지로 위와 같은 질문!

if (shouldShow) {
action()
onboardingRepository.updateShouldOnboarding(type.name, false)
}
}
}
}
}

fun dismissTooltip() {
if (::tooltip.isInitialized)
tooltip.dismiss()
}

private fun createTooltip(
type: OnboardingType,
arrowDirection: ArrowDirection,
arrowPosition: Float
): Balloon {
val iconForm = IconForm.Builder(context)
.setDrawable(AppCompatResources.getDrawable(context, R.drawable.round_close_24))
.setIconSize(32)
.setDrawableGravity(IconGravity.END)
.build()

return Balloon.Builder(context)
.setHeight(BalloonSizeSpec.WRAP)
.setWidth(BalloonSizeSpec.WRAP)
.setTextColorResource(R.color.white)
.setBackgroundColorResource(R.color.neutral_600)
.setTextSize(12f)
.setArrowOrientationRules(ArrowOrientationRules.ALIGN_FIXED)
.setArrowOrientation(arrowDirection.toArrowOrientation())
.setArrowPositionRules(ArrowPositionRules.ALIGN_BALLOON)
.setArrowSize(10)
.setArrowPosition(arrowPosition)
.setPaddingVertical(8)
.setPaddingHorizontal(10)
.setIconForm(iconForm)
.setMargin(10)
.setDismissWhenTouchOutside(false)
.setDismissWhenClicked(true)
.setCornerRadius(8f)
.setBalloonAnimation(BalloonAnimation.FADE)
.apply {
if (type.descriptionResId != 0)
setText(context.getString(type.descriptionResId))
}
.build()
}

private fun Balloon.showAlign(view: View, arrowDirection: ArrowDirection) {
when (arrowDirection) {
ArrowDirection.BOTTOM -> showAlignTop(view)
ArrowDirection.TOP -> showAlignBottom(view)
ArrowDirection.LEFT -> showAlignRight(view)
ArrowDirection.RIGHT -> showAlignLeft(view)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package `in`.koreatech.koin.core.onboarding

import android.content.Context
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ActivityComponent
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.android.scopes.ActivityScoped
import `in`.koreatech.koin.domain.repository.OnboardingRepository
import kotlinx.coroutines.Dispatchers

@Module
@InstallIn(ActivityComponent::class)
object OnboardingModule {

@Provides
@ActivityScoped
fun provideOnboardingManager(
onboardingRepository: OnboardingRepository,
@ApplicationContext context: Context
): OnboardingManager {
return OnboardingManager(onboardingRepository, context, Dispatchers.Main)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dispatchers.Main 이렇게 주입해서 사용할거면 클래스 생성자 dafult 파라미터는 어떠신가요~?
추가적으로 immediate를 사용하지 않고 그냥 Main 디스패처를 사용한 이유가 있나요?

Copy link
Contributor Author

@ThirFir ThirFir Oct 29, 2024

Choose a reason for hiding this comment

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

말씀대로 생성자로 옮겨도 될 거 같네요. 반영하겠습니다~
그리고 위 답(launch에 IO Dispatcher) 에 이어서 부모 코루틴이 IO Dispatcher CoroutineContext를 가지기 때문에, 어차피 Context Switching이 일어나야 하므로 Main 디스패처로 두었고, Main.Immediate는 구현하면서 고려는 하지 않았었습니다.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package `in`.koreatech.koin.core.onboarding

import androidx.annotation.StringRes

/**
* OnboardingType
* @property descriptionResId 툴팁 내용 리소스 아이디. 툴팁이 아닐 경우 0 할당
*/
enum class OnboardingType(
@StringRes val descriptionResId: Int,
) {
DINING_IMAGE(R.string.dining_image_tooltip),
DINING_NOTIFICATION(0),
DINING_SHARE(0),
ARTICLE_KEYWORD(R.string.article_keyword_tooltip)
}
5 changes: 5 additions & 0 deletions core/onboarding/src/main/res/drawable/round_close_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M18.3,5.71c-0.39,-0.39 -1.02,-0.39 -1.41,0L12,10.59 7.11,5.7c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41L10.59,12 5.7,16.89c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0L12,13.41l4.89,4.89c0.39,0.39 1.02,0.39 1.41,0 0.39,-0.39 0.39,-1.02 0,-1.41L13.41,12l4.89,-4.89c0.38,-0.38 0.38,-1.02 0,-1.4z"/>

</vector>
5 changes: 5 additions & 0 deletions core/onboarding/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#ffffff</color>
<color name="neutral_600">#4B4B4B</color>
</resources>
6 changes: 6 additions & 0 deletions core/onboarding/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="dining_image_tooltip">식단 사진을 확인해보세요!</string>
<string name="dining_share_tooltip">식단이 마음에 들었다면 공유하기!</string>
<string name="article_keyword_tooltip">키워드를 추가하고 맞춤 알림을 받아보세요!</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package `in`.koreatech.koin.core.onboarding

import org.junit.Test

import org.junit.Assert.*

/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}
Loading