From 2428527389c772f6ad3ba39e8aefa4cd71d5cc7a Mon Sep 17 00:00:00 2001 From: Ali Haider Date: Wed, 14 Sep 2022 16:48:44 +0500 Subject: [PATCH] Add New feature to change text of Next Button --- .../com/mohsin/onboardingbubbles/BubbleMessageView.kt | 10 ++++++++++ .../com/mohsin/onboardingbubbles/BubbleShowCase.kt | 2 ++ .../mohsin/onboardingbubbles/BubbleShowCaseBuilder.kt | 10 ++++++++++ .../java/com/mohsin/onboardingbubbles/MainActivity.kt | 1 + 4 files changed, 23 insertions(+) diff --git a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleMessageView.kt b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleMessageView.kt index 6db0fb7..5397897 100644 --- a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleMessageView.kt +++ b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleMessageView.kt @@ -118,6 +118,10 @@ class BubbleMessageView : ConstraintLayout { if (builder.mShowNextButton) { nextButton?.visibility = View.VISIBLE } + + if (builder.mNextButtonText != null) { + nextButton?.text = builder.mNextButtonText + } } private fun setBubbleListener(builder: Builder) { @@ -288,6 +292,7 @@ class BubbleMessageView : ConstraintLayout { var mArrowPosition = ArrayList() var mListener: OnBubbleMessageViewListener? = null var mShowNextButton: Boolean = false + var mNextButtonText: String? = null fun from(context: Context): Builder { mContext = WeakReference(context) @@ -355,6 +360,11 @@ class BubbleMessageView : ConstraintLayout { return this } + fun setNextButtonText(text: String?): Builder { + mNextButtonText = text + return this + } + fun listener(listener: OnBubbleMessageViewListener?): Builder { mListener = listener return this diff --git a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCase.kt b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCase.kt index 3828ecc..e09ecea 100644 --- a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCase.kt +++ b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCase.kt @@ -59,6 +59,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder) { private val mSubtitleTextSize: Int? = builder.mSubtitleTextSize private val mShowOnce: String? = builder.mShowOnce private val mShowNextButton: Boolean = builder.mShowNextButton + private val mNextButtonText: String? = builder.mNextButtonText private val mDisableTargetClick: Boolean = builder.mDisableTargetClick private val mDisableCloseAction: Boolean = builder.mDisableCloseAction private val mHighlightMode: HighlightMode? = builder.mHighlightMode @@ -195,6 +196,7 @@ class BubbleShowCase(builder: BubbleShowCaseBuilder) { .subtitle(mSubtitle) .image(mImage) .showNextButton(mShowNextButton) + .setNextButtonText(mNextButtonText) .closeActionImage(mCloseAction) .disableCloseAction(mDisableCloseAction) .listener(object : OnBubbleMessageViewListener { diff --git a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCaseBuilder.kt b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCaseBuilder.kt index 6064a23..a241efa 100644 --- a/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCaseBuilder.kt +++ b/OnBoardingBubbles/src/main/java/com/mohsin/onboardingbubbles/BubbleShowCaseBuilder.kt @@ -33,6 +33,7 @@ class BubbleShowCaseBuilder(activity: Activity) { internal var mBubbleShowCaseListener: BubbleShowCaseListener? = null internal var mSequenceShowCaseListener: SequenceShowCaseListener? = null internal var mShowNextButton: Boolean = false + internal var mNextButtonText: String? = null private var onGlobalLayoutListenerTargetView: ViewTreeObserver.OnGlobalLayoutListener? = null @@ -224,6 +225,15 @@ class BubbleShowCaseBuilder(activity: Activity) { return this } + /** + * Set a text of Next Button + * Default value -> Next + */ + fun setNextButtonText(text: String): BubbleShowCaseBuilder { + mNextButtonText = text + return this + } + /** * Add a BubbleShowCaseListener in order to listen the user actions: * - onTargetClick -> It is triggered when the user clicks on the target view diff --git a/app/src/main/java/com/mohsin/onboardingbubbles/MainActivity.kt b/app/src/main/java/com/mohsin/onboardingbubbles/MainActivity.kt index 829bb99..43865db 100644 --- a/app/src/main/java/com/mohsin/onboardingbubbles/MainActivity.kt +++ b/app/src/main/java/com/mohsin/onboardingbubbles/MainActivity.kt @@ -58,6 +58,7 @@ class MainActivity : AppCompatActivity() { .descriptionTextSize(16) .closeActionImage(null) .showNextButton(true) + .setNextButtonText("Finish") .targetView(binding.buttonTextSizeShowCase) }