diff --git a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskInfo.kt b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskInfo.kt new file mode 100644 index 0000000..fd916c4 --- /dev/null +++ b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskInfo.kt @@ -0,0 +1,9 @@ +package com.mikhaellopez.ratebottomsheet + +data class AskInfo( + val title: String? = null, + val message: String? = null, + val laterText: String? = null, + val cancelText: String? = null, + val okText: String? = null +) diff --git a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskRateBottomSheet.kt b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskRateBottomSheet.kt index e88ec01..dd0004f 100644 --- a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskRateBottomSheet.kt +++ b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskRateBottomSheet.kt @@ -10,7 +10,11 @@ import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* * Licensed under the Apache License Version 2.0 */ class AskRateBottomSheet( - private val listener: ActionListener? = null + private val listener: ActionListener? = null, + private val askInfo: AskInfo? = null, + private val rateInfo: RateInfo? = null, + private val customPackageId: String? = null, + private val customUrl: String? = null ) : ABaseRateBottomSheet() { /** @@ -27,8 +31,22 @@ class AskRateBottomSheet( } companion object { - internal fun show(manager: FragmentManager, listener: ActionListener? = null) { - AskRateBottomSheet(listener).show(manager, "askRateBottomSheet") + internal fun show( + manager: FragmentManager, + listener: ActionListener? = null, + askInfo: AskInfo? = null, + rateInfo: RateInfo? = null, + customPackageId: String? = null, + customUrl: String? = null + ) { + AskRateBottomSheet( + listener, + askInfo, + rateInfo, + customPackageId, + customUrl + ) + .show(manager, "askRateBottomSheet") } } @@ -36,13 +54,22 @@ class AskRateBottomSheet( super.onViewCreated(view, savedInstanceState) btnRateBottomSheetLater.visibility = View.GONE - textRateBottomSheetTitle.text = getString(R.string.rate_popup_ask_title) - textRateBottomSheetMessage.text = getString(R.string.rate_popup_ask_message) - btnRateBottomSheetNo.text = getString(R.string.rate_popup_ask_no) - btnRateBottomSheetOk.text = getString(R.string.rate_popup_ask_ok) + textRateBottomSheetTitle.text = askInfo?.title ?: getString(R.string.rate_popup_ask_title) + textRateBottomSheetMessage.text = askInfo?.message ?: getString(R.string.rate_popup_ask_message) + btnRateBottomSheetNo.text = askInfo?.cancelText ?: getString(R.string.rate_popup_ask_no) + btnRateBottomSheetOk.text = askInfo?.okText ?: getString(R.string.rate_popup_ask_ok) btnRateBottomSheetOk.setOnClickListener { - activity?.run { RateBottomSheet.show(supportFragmentManager, listener) } + activity?.run { + RateBottomSheet.show( + supportFragmentManager, + listener, + askInfo, + rateInfo, + customPackageId, + customUrl + ) + } dismiss() } diff --git a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheet.kt b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheet.kt index e6fdd86..a4fbcd9 100644 --- a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheet.kt +++ b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheet.kt @@ -8,7 +8,6 @@ import android.net.Uri import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity -import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* @@ -17,7 +16,11 @@ import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* * Licensed under the Apache License Version 2.0 */ class RateBottomSheet( - private val listener: ActionListener? = null + private val listener: ActionListener? = null, + private val askInfo: AskInfo? = null, + private val rateInfo: RateInfo? = null, + private val customUrl: String? = null, + private val customPackageId: String? = null ) : ABaseRateBottomSheet() { /** @@ -39,8 +42,18 @@ class RateBottomSheet( } companion object { - internal fun show(manager: FragmentManager, listener: ActionListener? = null) { - RateBottomSheet(listener).show(manager, "rateBottomSheet") + internal fun show( + manager: FragmentManager, + listener: ActionListener? = null, + askInfo: AskInfo? = null, + rateInfo: RateInfo? = null, + customPackageId: String? = null, + customUrl: String? = null + ) { + RateBottomSheet(listener, askInfo, rateInfo, customUrl, customPackageId).show( + manager, + "rateBottomSheet" + ) } /** @@ -51,34 +64,21 @@ class RateBottomSheet( */ fun showRateBottomSheetIfMeetsConditions( activity: AppCompatActivity, - listener: AskRateBottomSheet.ActionListener? = null + listener: AskRateBottomSheet.ActionListener? = null, + askInfo: AskInfo? = null, + rateInfo: RateInfo? = null, + customPackageId: String? = null, + customUrl: String? = null ) { showRateBottomSheetIfMeetsConditions( activity.applicationContext, activity.supportFragmentManager, - listener + listener, + askInfo, + rateInfo, customPackageId, customUrl ) } - /** - * Display rate bottom sheet if meets conditions. - * - * @param fragment [Fragment] - * @param listener [AskRateBottomSheet.ActionListener] - */ - fun showRateBottomSheetIfMeetsConditions( - fragment: Fragment, - listener: AskRateBottomSheet.ActionListener? = null - ) { - (fragment.activity as? AppCompatActivity)?.also { - showRateBottomSheetIfMeetsConditions( - it.applicationContext, - fragment.childFragmentManager, - listener - ) - } - } - /** * Display rate bottom sheet if meets conditions. * @@ -86,16 +86,33 @@ class RateBottomSheet( * @param fragmentManager [FragmentManager] * @param listener [AskRateBottomSheet.ActionListener] */ - fun showRateBottomSheetIfMeetsConditions( + private fun showRateBottomSheetIfMeetsConditions( context: Context, fragmentManager: FragmentManager, - listener: AskRateBottomSheet.ActionListener? = null + listener: AskRateBottomSheet.ActionListener? = null, + askInfo: AskInfo? = null, + rateInfo: RateInfo? = null, + customPackageId: String? = null, + customUrl: String? = null ) { if (RateBottomSheetManager(context).shouldShowRateBottomSheet()) { if (RateBottomSheetManager.showAskBottomSheet) { - AskRateBottomSheet.show(fragmentManager, listener) + AskRateBottomSheet.show( + fragmentManager, + listener, + askInfo, + rateInfo, + customPackageId, + customUrl + ) } else { - show(fragmentManager) + show( + fragmentManager, + askInfo = askInfo, + rateInfo = rateInfo, + customPackageId = customPackageId, + customUrl = customUrl + ) } } } @@ -107,15 +124,16 @@ class RateBottomSheet( btnRateBottomSheetLater.visibility = if (RateBottomSheetManager.showLaterButton) View.VISIBLE else View.GONE - textRateBottomSheetTitle.text = getString(R.string.rate_popup_title) - textRateBottomSheetMessage.text = getString(R.string.rate_popup_message) - btnRateBottomSheetNo.text = getString(R.string.rate_popup_no) - btnRateBottomSheetLater.text = getString(R.string.rate_popup_later) - btnRateBottomSheetOk.text = getString(R.string.rate_popup_ok) + setupViewsTexts() btnRateBottomSheetOk.setOnClickListener { activity?.run { - openStore(packageName) + val uri = when { + customPackageId != null -> customPackageId + customUrl != null -> customUrl + else -> packageName + } + openStore(uri) RateBottomSheetManager(it.context).disableAgreeShowDialog() } dismiss() @@ -128,6 +146,15 @@ class RateBottomSheet( } } + private fun setupViewsTexts() { + textRateBottomSheetTitle.text = rateInfo?.title ?: getString(R.string.rate_popup_title) + textRateBottomSheetMessage.text = + rateInfo?.message ?: getString(R.string.rate_popup_message) + btnRateBottomSheetNo.text = rateInfo?.cancelText ?: getString(R.string.rate_popup_no) + btnRateBottomSheetLater.text = rateInfo?.laterText ?: getString(R.string.rate_popup_later) + btnRateBottomSheetOk.text = rateInfo?.okText ?: getString(R.string.rate_popup_ok) + } + private fun Activity.openStore(appPackageName: String) { try { startActivity( diff --git a/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateInfo.kt b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateInfo.kt new file mode 100644 index 0000000..3ddf9fb --- /dev/null +++ b/ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateInfo.kt @@ -0,0 +1,9 @@ +package com.mikhaellopez.ratebottomsheet + +data class RateInfo( + val title: String? = null, + val message: String? = null, + val cancelText: String? = null, + val okText: String? = null, + val laterText: String? = null +)