diff --git a/README.md b/README.md index 27206c8..e337f38 100644 --- a/README.md +++ b/README.md @@ -66,47 +66,48 @@ showcaseManager.show(context) // or showcaseManager.show(context, REQUEST_CODE_S ### Builder Configuration -| Usage | Description | Optional | Default Value | StyleRes | -|:--------------------------------------------------------|:---------------------------------------------------------------------------------|:---------|:----------------------------|:---------| -| `builder.focus(View)` | view to be focused on | no | null | no | -| `builder.focus(Array)` | view array to be focused on | no | null | no | -| `builder.resId(Int)` | Showcase.Theme style | yes | null | yes | -| `builder.titleText(String)` | text to be showed on top of the tooltip | yes | "" | no | -| `builder.descriptionText(String)` | description text will be displayed on tooltip | yes | "" | no | -| `builder.titleTextColor(Int)` | titleText's color | yes | Color.BLACK | yes | -| `builder.descriptionTextColor(Int)` | descriptionText's color | yes | Color.BLACK | yes | -| `builder.titleTextSize(Int)` | titleText's text size in SP | yes | 18 SP | no | -| `builder.descriptionTextSize(Int)` | descriptionText's text size in SP | yes | 14 SP | no | -| `builder.titleTextFontFamily(String)` | titleText's fontFamily | yes | sans-serif | yes | -| `builder.descriptionTextFontFamily(String)` | descriptionText's fontFamily | yes | sans-serif | yes | -| `builder.titleTextStyle(Int)` | titleText's textStyle | yes | Typeface.NORMAL | yes | -| `builder.descriptionTextStyle(Int)` | descriptionText's textStyle | yes | Typeface.NORMAL | yes | -| `builder.backgroundColor(Int)` | background color of tooltip | yes | Color.WHITE | yes | -| `builder.closeButtonColor(Int)` | closeButton's color | yes | Color.BLACK | yes | -| `builder.showCloseButton(Boolean)` | show close button on tooltip | yes | true | yes | -| `builder.arrowResource(Int)` | custom icon resource for the arrow rotates 180° if the arrow position is bottom | yes | ic_arrow_up | no | -| `builder.arrowPosition(ArrowPosition)` | arrow can be placed under or over the tooltip | yes | ArrowPosition.AUTO | no | -| `builder.arrowPercentage(Int)` | arrow position percentage can be decided | yes | null | no | -| `builder.highlightType(HighlightType)` | view can be highlighted with a circle shape or rectangle | yes | HighlightType.RECTANGLE | no | -| `builder.cancelListener(CancelListener)` | will be called after user quit from tooltip | yes | null | no | -| `builder.windowBackgroundColor(Int)` | background of the window's color can be decided | yes | Color.BLACK | yes | -| `builder.windowBackgroundTint(Int)` | alpha value of window's background color | yes | 204 | no | -| `builder.titleTextSize(Int)` | titleText's text size in SP | yes | 18 | no | -| `builder.cancellableFromOutsideTouch(Boolean)` | outside touch from tooltip will act as close click | yes | false | yes | -| `builder.showcaseViewClickable(Boolean)` | makes the showcase view clickable or not | yes | false | yes | -| `builder.isDebugMode(Boolean)` | tooltip won't be presented | yes | false | no | -| `builder.attachOnParentLifecycle(Boolean)` | observe parent lifecycle and dismiss showcase | yes | false | no | -| `builder.textPosition(TextPosition)` | text can be positioning center, end and start | yes | TextPosition.START | no | -| `builder.imageUrl(String)` | show image on tooltip | yes | null | no | -| `builder.customContent(Int)` | show given layout | yes | null | no | -| `builder.statusBarVisible(Boolean)` | statusBar visibility of window | yes | true | no | -| `builder.toolTipVisible(Boolean)` | tooltip visibility | yes | true | no | -| `builder.highlightRadius(Float, Float, Float, Float)` | tooltip visibility | yes | 0f, 0f, 0f, 0f | no | -| `builder.setSlidableContentList(List)` | show slidable content | yes | null | no | -| `builder.showDurationMillis(Long)` | duration of the tooltip visibility | yes | 2000L | no | -| `builder.showcaseViewVisibleIndefinitely(Boolean)` | controls tooltip visibility condition | yes | true | no | -| `builder.build()` | will return ShowcaseManager instance | no | | | -| `showcaseManager.show(Context)` | show the tooltip with set attributes on | no | | | +| Usage | Description | Optional | Default Value | StyleRes | +|:--------------------------------------------------------|:--------------------------------------------------------------------------------|:---------|:----------------------------|:---------| +| `builder.focus(View)` | view to be focused on | no | null | no | +| `builder.focus(Array)` | view array to be focused on | no | null | no | +| `builder.resId(Int)` | Showcase.Theme style | yes | null | yes | +| `builder.titleText(String)` | text to be showed on top of the tooltip | yes | "" | no | +| `builder.descriptionText(String)` | description text will be displayed on tooltip | yes | "" | no | +| `builder.titleTextColor(Int)` | titleText's color | yes | Color.BLACK | yes | +| `builder.descriptionTextColor(Int)` | descriptionText's color | yes | Color.BLACK | yes | +| `builder.titleTextSize(Int)` | titleText's text size in SP | yes | 18 SP | no | +| `builder.descriptionTextSize(Int)` | descriptionText's text size in SP | yes | 14 SP | no | +| `builder.titleTextFontFamily(String)` | titleText's fontFamily | yes | sans-serif | yes | +| `builder.descriptionTextFontFamily(String)` | descriptionText's fontFamily | yes | sans-serif | yes | +| `builder.titleTextStyle(Int)` | titleText's textStyle | yes | Typeface.NORMAL | yes | +| `builder.descriptionTextStyle(Int)` | descriptionText's textStyle | yes | Typeface.NORMAL | yes | +| `builder.backgroundColor(Int)` | background color of tooltip | yes | Color.WHITE | yes | +| `builder.closeButtonColor(Int)` | closeButton's color | yes | Color.BLACK | yes | +| `builder.showCloseButton(Boolean)` | show close button on tooltip | yes | true | yes | +| `builder.setArrowVisibility(Boolean)` | controls whether arrow icon should be shown or not | yes | true | no | +| `builder.arrowResource(Int)` | custom icon resource for the arrow rotates 180° if the arrow position is bottom | yes | ic_arrow_up | no | +| `builder.arrowPosition(ArrowPosition)` | arrow can be placed under or over the tooltip | yes | ArrowPosition.AUTO | no | +| `builder.arrowPercentage(Int)` | arrow position percentage can be decided | yes | null | no | +| `builder.highlightType(HighlightType)` | view can be highlighted with a circle shape or rectangle | yes | HighlightType.RECTANGLE | no | +| `builder.cancelListener(CancelListener)` | will be called after user quit from tooltip | yes | null | no | +| `builder.windowBackgroundColor(Int)` | background of the window's color can be decided | yes | Color.BLACK | yes | +| `builder.windowBackgroundTint(Int)` | alpha value of window's background color | yes | 204 | no | +| `builder.titleTextSize(Int)` | titleText's text size in SP | yes | 18 | no | +| `builder.cancellableFromOutsideTouch(Boolean)` | outside touch from tooltip will act as close click | yes | false | yes | +| `builder.showcaseViewClickable(Boolean)` | makes the showcase view clickable or not | yes | false | yes | +| `builder.isDebugMode(Boolean)` | tooltip won't be presented | yes | false | no | +| `builder.attachOnParentLifecycle(Boolean)` | observe parent lifecycle and dismiss showcase | yes | false | no | +| `builder.textPosition(TextPosition)` | text can be positioning center, end and start | yes | TextPosition.START | no | +| `builder.imageUrl(String)` | show image on tooltip | yes | null | no | +| `builder.customContent(Int)` | show given layout | yes | null | no | +| `builder.statusBarVisible(Boolean)` | statusBar visibility of window | yes | true | no | +| `builder.toolTipVisible(Boolean)` | tooltip visibility | yes | true | no | +| `builder.highlightRadius(Float, Float, Float, Float)` | tooltip visibility | yes | 0f, 0f, 0f, 0f | no | +| `builder.setSlidableContentList(List)` | show slidable content | yes | null | no | +| `builder.showDurationMillis(Long)` | duration of the tooltip visibility | yes | 2000L | no | +| `builder.showcaseViewVisibleIndefinitely(Boolean)` | controls tooltip visibility condition | yes | true | no | +| `builder.build()` | will return ShowcaseManager instance | no | | | +| `showcaseManager.show(Context)` | show the tooltip with set attributes on | no | | | ### Action Result diff --git a/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseManager.kt b/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseManager.kt index 0b089fb..f016757 100644 --- a/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseManager.kt +++ b/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseManager.kt @@ -117,6 +117,7 @@ class ShowcaseManager private constructor( private var titleText: String = Constants.DEFAULT_TEXT private var descriptionText: CharSequence = Constants.DEFAULT_TEXT private var isShowcaseViewVisibleIndefinitely: Boolean = Constants.DEFAULT_SHOW_FOREVER + private var isArrowVisible: Boolean = Constants.DEFAULT_ARROW_VISIBILITY private var showDuration: Long = Constants.DEFAULT_SHOW_DURATION @ColorInt private var titleTextColor: Int = Constants.DEFAULT_TEXT_COLOR @@ -192,6 +193,13 @@ class ShowcaseManager private constructor( fun showcaseViewVisibleIndefinitely(isVisibleIndefinitely: Boolean) = apply { isShowcaseViewVisibleIndefinitely = isVisibleIndefinitely } + /** + * Controls whether arrow icon should be shown or not. By default it is true. + * + * @param isVisible assigns boolean value to isArrowVisible. + */ + fun setArrowVisibility(isVisible: Boolean) = apply { isArrowVisible = isVisible } + /** * Assign duration value to showDuration. By default it is 2000L. * To see the effect, set [showcaseViewVisibleIndefinitely] to false. @@ -382,7 +390,8 @@ class ShowcaseManager private constructor( radiusBottomStart = radiusBottomStart, isToolTipVisible = isToolTipVisible, showDuration = showDuration, - isShowcaseViewVisibleIndefinitely = isShowcaseViewVisibleIndefinitely + isShowcaseViewVisibleIndefinitely = isShowcaseViewVisibleIndefinitely, + isArrowVisible = isArrowVisible, ) return ShowcaseManager(showcaseModel = showcaseModel, resId = resId) diff --git a/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseModel.kt b/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseModel.kt index 1fa28e0..7cbf01e 100644 --- a/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseModel.kt +++ b/library/src/main/java/com/trendyol/showcase/showcase/ShowcaseModel.kt @@ -51,6 +51,7 @@ data class ShowcaseModel( val isToolTipVisible: Boolean, val showDuration: Long, val isShowcaseViewVisibleIndefinitely: Boolean, + val isArrowVisible: Boolean, ) : Parcelable { fun horizontalCenter() = rectF.left + ((rectF.right - rectF.left) / 2) diff --git a/library/src/main/java/com/trendyol/showcase/ui/tooltip/TooltipViewState.kt b/library/src/main/java/com/trendyol/showcase/ui/tooltip/TooltipViewState.kt index 18c123c..4a4cc1e 100644 --- a/library/src/main/java/com/trendyol/showcase/ui/tooltip/TooltipViewState.kt +++ b/library/src/main/java/com/trendyol/showcase/ui/tooltip/TooltipViewState.kt @@ -53,9 +53,29 @@ internal data class TooltipViewState( fun getArrowResource() = if (showcaseModel.arrowResource == Constants.DEFAULT_ARROW_RESOURCE) R.drawable.ic_showcase_arrow_up else showcaseModel.arrowResource - fun getTopArrowVisibility() = if (arrowPosition == AbsoluteArrowPosition.UP) View.VISIBLE else View.GONE + fun getTopArrowVisibility(): Int { + if (showcaseModel.isArrowVisible.not()) { + return View.GONE + } + + return if (arrowPosition == AbsoluteArrowPosition.UP) { + View.VISIBLE + } else { + View.GONE + } + } - fun getBottomArrowVisibility() = if (arrowPosition == AbsoluteArrowPosition.DOWN) View.VISIBLE else View.GONE + fun getBottomArrowVisibility(): Int { + if (showcaseModel.isArrowVisible.not()) { + return View.GONE + } + + return if (arrowPosition == AbsoluteArrowPosition.DOWN) { + View.VISIBLE + } else { + View.GONE + } + } fun getCloseButtonColor() = showcaseModel.closeButtonColor diff --git a/library/src/main/java/com/trendyol/showcase/util/Constants.kt b/library/src/main/java/com/trendyol/showcase/util/Constants.kt index 2a9a998..e970603 100644 --- a/library/src/main/java/com/trendyol/showcase/util/Constants.kt +++ b/library/src/main/java/com/trendyol/showcase/util/Constants.kt @@ -23,6 +23,7 @@ object Constants { const val DEFAULT_TEXT = "" const val DEFAULT_SHOW_DURATION = 2000L const val DEFAULT_SHOW_FOREVER = true + const val DEFAULT_ARROW_VISIBILITY = true const val DEFAULT_ARROW_RESOURCE = -1 val DEFAULT_ARROW_POSITION = ArrowPosition.AUTO val DEFAULT_HIGHLIGHT_TYPE = HighlightType.RECTANGLE diff --git a/library/src/main/res/layout/layout_tooltip.xml b/library/src/main/res/layout/layout_tooltip.xml index 85c0463..eb4568f 100644 --- a/library/src/main/res/layout/layout_tooltip.xml +++ b/library/src/main/res/layout/layout_tooltip.xml @@ -132,5 +132,6 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/layoutContents" - tools:srcCompat="@drawable/ic_showcase_arrow_down" /> + tools:srcCompat="@drawable/ic_showcase_arrow_up" + tools:visibility="visible" /> diff --git a/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateFactory.kt b/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateFactory.kt index 623c353..a645a7c 100644 --- a/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateFactory.kt +++ b/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateFactory.kt @@ -27,7 +27,8 @@ internal object TooltipViewStateFactory { imageUrl: String = "", customContent: Int? = null, isStatusBarVisible: Boolean = false, - arrowMargin: Int = 0 + arrowMargin: Int = 0, + isArrowVisible: Boolean = true ): TooltipViewState { val showcaseModel = ShowcaseModel( rectF = RectF(), @@ -67,7 +68,8 @@ internal object TooltipViewStateFactory { descriptionTextStyle = Typeface.NORMAL, titleTextFontFamily = "sans-serif", showDuration = 2000L, - isShowcaseViewVisibleIndefinitely = true + isShowcaseViewVisibleIndefinitely = true, + isArrowVisible = isArrowVisible ) return provideTooltipViewState(showcaseModel, absoluteArrowPosition, arrowMargin) } diff --git a/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateTest.kt b/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateTest.kt index 4ad282d..2479c2a 100644 --- a/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateTest.kt +++ b/library/src/test/java/com/trendyol/showcase/ui/tooltip/TooltipViewStateTest.kt @@ -190,6 +190,34 @@ class TooltipViewStateTest { actualResult `should be` expectedResult } + @Test + fun `Given isArrowVisible false, When getTopArrowVisibility called, Then it should return GONE`() { + // Given + val isArrowVisible = false + val expectedResult = View.GONE + val tooltipViewState = TooltipViewStateFactory.provideTooltipViewState(isArrowVisible = isArrowVisible) + + // When + val actualResult = tooltipViewState.getTopArrowVisibility() + + // Then + actualResult `should be` expectedResult + } + + @Test + fun `Given isArrowVisible false, When getBottomArrowVisibility called, Then it should return GONE`() { + // Given + val isArrowVisible = false + val expectedResult = View.GONE + val tooltipViewState = TooltipViewStateFactory.provideTooltipViewState(isArrowVisible = isArrowVisible) + + // When + val actualResult = tooltipViewState.getBottomArrowVisibility() + + // Then + actualResult `should be` expectedResult + } + @Test fun `when showCloseButton is true then getCloseButtonVisibility() returns VISIBLE`() { //when @@ -237,4 +265,4 @@ class TooltipViewStateTest { actualResult `should be` expectedResult } -} \ No newline at end of file +}