SuddenH4X / awesome-app-rating

An Android library providing a dialog, which asks the user to rate the app or give feedback. You can also use the library to show the Google in-app review easily under certain conditions.
Apache License 2.0
231 stars 40 forks source link

setCustomCondition() and setCustomConditionToShowAgain() is not working #49

Closed RobinChien closed 3 years ago

RobinChien commented 3 years ago

Hi, I have tried setCustomCondition() and setCustomConditionToShowAgain(), but none of them worked.

Here is my testing code:

...

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        AppRating.Builder(this)
                        .setCustomCondition {
                            true
                        }
                        .setCustomConditionToShowAgain {
                            true
                        }
                        .showIfMeetsConditions()
}

...

And in the Logcat can see the Custom condition result is true but the next log shows the Conditions not met

2021-04-20 15:28:10.285 1348-1348/net.hikingbook.hikingbook D/awesome_app_rating: Custom condition set. This condition will be removed next time you call the Builder constructor.
2021-04-20 15:28:10.285 1348-1348/net.hikingbook.hikingbook D/awesome_app_rating: Custom condition to show again set. This condition willbe removed next time you call the Builder constructor.
2021-04-20 15:28:10.285 1348-1348/net.hikingbook.hikingbook D/awesome_app_rating: App launch will be counted: countAppLaunch is true.
2021-04-20 15:28:10.292 1348-1348/net.hikingbook.hikingbook V/awesome_app_rating: Increased launch times by 1. It's now 7.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook I/awesome_app_rating: Checking conditions.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook V/awesome_app_rating: Is dialog agreed: false.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook V/awesome_app_rating: Do not show again: false.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook D/awesome_app_rating: Show later button has already been clicked.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook V/awesome_app_rating: Days between later button click and now: 0.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook I/awesome_app_rating: Custom condition to show again found. Condition result is: true.
2021-04-20 15:28:10.293 1348-1348/net.hikingbook.hikingbook I/awesome_app_rating: Don't show rating dialog: Conditions not met.

And in-depth study shouldShowDialog() of ConditionsChecker object. The result of checkCustomCondition() is true, but I didn't set the days, so the minimumDays check in return is false. So the dialog will not display.

ConditionsChecker.kt

    fun shouldShowDialog(context: Context, dialogOptions: DialogOptions): Boolean {

        ...

        if (!checkCustomCondition(dialogOptions)) return false

        RatingLogger.verbose("Days between first app start and now: $daysBetween.")
        RatingLogger.debug("Show later button hasn't been clicked until now.")
        return (!isDialogAgreed &&
            !isDoNotShowAgain &&
            daysBetween >= PreferenceUtil.getMinimumDays(context) &&
            (PreferenceUtil.getLaunchTimes(context) >= PreferenceUtil.getMinimumLaunchTimes(context)))
    }
SuddenH4X commented 3 years ago

Hi @RobinChien,

sorry for the delayed answer. The methods setCustomCondition() and setCustomConditionToShowAgain() are used for additional conditions. Therefore the days and the launch times will be counted anyway. If you want to use only the custom conditions you have to set the other checks to 0:

.setMinimumLaunchTimes(0)
.setMinimumDays(0)
.setMinimumLaunchTimesToShowAgain(0)
.setMinimumDaysToShowAgain(0)