Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

/**
Expand All @@ -27,22 +31,45 @@ 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")
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
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()
}

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

Expand All @@ -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() {

/**
Expand All @@ -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"
)
}

/**
Expand All @@ -51,51 +64,55 @@ 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.
*
* @param context [Context]
* @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
)
}
}
}
Expand All @@ -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()
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)