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
Expand Up @@ -42,6 +42,14 @@ class MainActivity : AppCompatActivity() {
.showIfMeetsConditions()
}

fun onBottomSheetExampleButtonClicked(@Suppress("UNUSED_PARAMETER") view: View?) {
AppRating.Builder(this)
.setDebug(true)
.setBottomSheet(true)
.setCancelable(true)
.showIfMeetsConditions()
}

fun onDefaultExampleButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
AppRating.Builder(this)
.setDebug(true)
Expand Down Expand Up @@ -147,7 +155,7 @@ class MainActivity : AppCompatActivity() {
fun onCustomThemeButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
AppRating.Builder(this)
.setDebug(true)
.setCustomTheme(R.style.AppTheme_CustomAlertDialog)
.setCustomDialogTheme(R.style.AppTheme_CustomAlertDialog)
.showIfMeetsConditions()
}

Expand Down
14 changes: 13 additions & 1 deletion exampleapp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,20 @@
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_big"
android:onClick="onJetpackComposeButtonClicked"
android:text="@string/button_example_jetpack_compose" />

<TextView
style="@style/ExampleText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/text_example_bottom_sheet" />

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_big"
android:onClick="onBottomSheetExampleButtonClicked"
android:text="@string/button_example_bottom_sheet" />
</LinearLayout>
</ScrollView>
2 changes: 2 additions & 0 deletions exampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
<string name="button_example_custom_theme">Custom theme</string>
<string name="text_example_jetpack_compose">This button opens a new activity (ComponentActivity) to showcase the Jetpack Compose support.</string>
<string name="button_example_jetpack_compose">Jetpack Compose Example</string>
<string name="text_example_bottom_sheet">In this example the initial dialog is displayed as a bottom sheet instead of a full blown dialog</string>
<string name="button_example_bottom_sheet">Bottom Sheet Example</string>

<!-- Custom Button Texts -->
<string name="button_rate_now">Foo</string>
Expand Down
31 changes: 21 additions & 10 deletions library/src/main/java/com/suddenh4x/ratingdialog/AppRating.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,14 @@ object AppRating {
RatingLogger.debug("Use custom icon drawable.")
}

fun setCustomTheme(customTheme: Int) = apply {
dialogOptions.customTheme = customTheme
RatingLogger.debug("Use custom theme.")
fun setCustomDialogTheme(customTheme: Int) = apply {
dialogOptions.customDialogTheme = customTheme
RatingLogger.debug("Use custom dialog theme.")
}

fun setCustomBottomSheetTheme(customTheme: Int) = apply {
dialogOptions.customBottomSheetTheme = customTheme
RatingLogger.debug("Use custom bottom sheet theme.")
}

fun setRateLaterButtonTextId(@StringRes rateLaterButtonTextId: Int) = apply {
Expand Down Expand Up @@ -191,6 +196,7 @@ object AppRating {
dialogOptions.customFeedbackMessageTextId = feedbackCustomMessageTextId
}


fun setCustomFeedbackButtonTextId(@StringRes customFeedbackButtonTextId: Int) = apply {
dialogOptions.customFeedbackButton.textId = customFeedbackButtonTextId
}
Expand Down Expand Up @@ -239,26 +245,31 @@ object AppRating {
dialogOptions.customCondition = customCondition
RatingLogger.debug(
"Custom condition set. This condition will be removed next" +
" time you call the Builder constructor.",
" time you call the Builder constructor.",
)
}

fun setCustomConditionToShowAgain(customConditionToShowAgain: () -> Boolean) = apply {
dialogOptions.customConditionToShowAgain = customConditionToShowAgain
RatingLogger.debug(
"Custom condition to show again set. This condition will" +
"be removed next time you call the Builder constructor.",
"be removed next time you call the Builder constructor.",
)
}

fun dontCountThisAsAppLaunch() = apply {
dialogOptions.countAppLaunch = false
RatingLogger.debug(
"countAppLaunch is now set to false. This setting will be " +
"reset next time you call the Builder constructor.",
"reset next time you call the Builder constructor.",
)
}

fun setBottomSheet(bottomSheet: Boolean) = apply {
dialogOptions.bottomSheet = bottomSheet
RatingLogger.debug("Use bottom sheet instead of dialog: $bottomSheet.")
}

fun setLoggingEnabled(isLoggingEnabled: Boolean) = apply {
RatingLogger.isLoggingEnabled = isLoggingEnabled
}
Expand Down Expand Up @@ -309,12 +320,12 @@ object AppRating {
RatingLogger.debug("In-app review from Google hasn't been activated. Showing library dialog now.")
val fragmentActivity = componentActivity as? FragmentActivity
fragmentActivity?.let {
RateDialogFragment.newInstance(dialogOptions)
.show(fragmentActivity.supportFragmentManager, TAG)
val dialogFragment = RateDialogFragment.newInstance(dialogOptions)
dialogFragment.show(fragmentActivity.supportFragmentManager, TAG)
}
?: RatingLogger.error(
"To use the libraries dialog your activity has to extend from " +
"FragmentActivity (e.g. AppCompatActvity).",
"FragmentActivity (e.g. AppCompatActvity).",
)
}
}
Expand Down Expand Up @@ -359,7 +370,7 @@ object AppRating {
val flow = reviewManager?.launchReviewFlow(componentActivity, reviewInfo) ?: run {
onGoogleInAppReviewFailure(
"reviewManager is null. Did you call " +
"useGoogleInAppReview()?",
"useGoogleInAppReview()?",
)
return@addOnCompleteListener
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.suddenh4x.ratingdialog.dialog

import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.FrameLayout
import androidx.appcompat.app.AlertDialog
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.button.MaterialButton
import com.suddenh4x.ratingdialog.R

class BottomSheetAlertDialog : BottomSheetDialog {
constructor(context: Context) : super(context)
constructor(context: Context, theme: Int) : super(context, theme)
constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener?) : super(
context,
cancelable,
cancelListener
)

override fun setContentView(view: View) {
super.setContentView(wrapInAlert(view))
}

private fun wrapInAlert(view: View): View {
val alert = LayoutInflater.from(context).inflate(R.layout.sheet_alert_dialog, null)
alert.findViewById<FrameLayout>(R.id.content).addView(
view,
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)
)
return alert
}

internal fun getButton(whichButton: Int): Button? {
when (whichButton) {
AlertDialog.BUTTON_POSITIVE -> return findViewById<MaterialButton>(R.id.positive)
AlertDialog.BUTTON_NEGATIVE -> return findViewById<MaterialButton>(R.id.negative)
AlertDialog.BUTTON_NEUTRAL -> return findViewById<MaterialButton>(R.id.neutral)
}
throw IllegalArgumentException("Button must be one of BUTTON_POSITIVE, BUTTON_NEGATIVE, BUTTON_NEUTRAL")
}


internal fun setButton(whichButton: Int, text: CharSequence?, listener: DialogInterface.OnClickListener?) {
getButton(whichButton)?.let {
it.text = text
it.visibility = View.VISIBLE
it.setOnClickListener { listener?.onClick(this@BottomSheetAlertDialog, whichButton) }
}
}
}
Loading