-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Feature] 온보딩 모듈 추가 #438
Changes from 26 commits
0bac2b8
bfa6f6e
0e5ec8e
26e7a33
a372212
7279ad8
03c0c19
107a6dd
d1ae376
26deffb
49d14dc
1647ad9
39e520c
c038ed3
d0b8ece
535d4c6
d9d15a4
d864ea5
85f533d
b3511fb
64b5bf7
dded9d7
2792822
37f9ad5
7304ca3
9f2792a
1fb52b3
9065122
8211f45
f621430
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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) | ||
} |
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) | ||
} | ||
} |
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) { | ||
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) { | ||
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. 이것도 마찬가지로 위와 같은 질문! |
||
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) | ||
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. Dispatchers.Main 이렇게 주입해서 사용할거면 클래스 생성자 dafult 파라미터는 어떠신가요~? 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. 말씀대로 생성자로 옮겨도 될 거 같네요. 반영하겠습니다~ |
||
} | ||
} |
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) | ||
} |
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> |
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> |
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) | ||
} | ||
} |
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.
이미 lifecycleScope 와 repeatOnLifecycle를 사용하는데, Main 디스패처를 주입해서 사용한 이유가 있나요?
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.
launch에 IO Dispatcher를 지정하려 했는데 안했네요 ㅎ.. 🤐