Skip to content

Commit

Permalink
Merge pull request #34 from Trendyol/set-arrow-visibility
Browse files Browse the repository at this point in the history
Set arrow visibility
  • Loading branch information
ertugrulkaragoz authored Sep 20, 2023
2 parents 2ed40b3 + 9b52c81 commit 66a4cf8
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 48 deletions.
83 changes: 42 additions & 41 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/res/layout/layout_tooltip.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
</merge>
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -237,4 +265,4 @@ class TooltipViewStateTest {

actualResult `should be` expectedResult
}
}
}

0 comments on commit 66a4cf8

Please sign in to comment.