Skip to content

Commit

Permalink
Merge pull request #46 from SuddenH4X/release/2.3.0
Browse files Browse the repository at this point in the history
Release/2.3.0
  • Loading branch information
SuddenH4X authored Feb 13, 2021
2 parents 7d41a44 + 50ce547 commit e7d34db
Show file tree
Hide file tree
Showing 17 changed files with 362 additions and 86 deletions.
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ The library supports API level 14 and higher. You can simply include it in your
```groovy
dependencies {
...
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.2.1'
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.3.0'
}
```

Expand Down Expand Up @@ -75,7 +75,9 @@ If you have adjusted the dialog to suit your preferences, you have multiple poss
ratingBuilder.showIfMeetsConditions()
```

But you can also just create the dialog to show it later
This method also returns a boolean to indicate whether the dialog shows up or not. So you can prevent showing other dialogs at the same time as the rating dialog.

If you want you can also just create the dialog to show it later

```kotlin
ratingBuilder.create()
Expand All @@ -99,7 +101,7 @@ If you want to use the in-app review from Google instead of the library dialog,
.useGoogleInAppReview()
```

You should also add a `completeListener` which gets called if the in-app review flow has been completed. The boolean indicates if the flow started correctly, but not if the in-app review was displayed to the user.
You can also add a `completeListener` which gets called if the in-app review flow has been completed. The boolean indicates if the flow was started correctly, but not if the in-app review was displayed to the user.

```kotlin
.setGoogleInAppReviewCompleteListener(googleInAppReviewCompleteListener: (Boolean) -> Unit)
Expand Down Expand Up @@ -184,6 +186,12 @@ The following settings will only take effect if the library dialog is used (and
.setIconDrawable(iconDrawable: Drawable?) // default is null which means app icon
```

- Change the theme of the dialog

```kotlin
.setCustomTheme(customTheme: Int)
```

- Change the rate later button text

```kotlin
Expand Down Expand Up @@ -362,12 +370,18 @@ These settings will only apply if custom feedback is enabled:
.setRatingThreshold(ratingThreshold: RatingThreshold) // default is RatingThreshold.THREE
```

- Choose if the dialogs should be cancelable (by clicking outside or using the back button)
- Choose if the dialogs should be cancelable (by clicking outside or using the back button). This case is treated the same as a click on the `later` button.

```kotlin
.setCancelable(cancelable: Boolean) // default is false
```

- Add a cancel listener to the dialog

```kotlin
.setDialogCancelListener(dialogCancelListener: () -> Unit)
```

- Disable all library logs

```kotlin
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.10'
ext.kotlin_version = '1.4.30'
repositories {
google()
jcenter()
Expand Down
10 changes: 3 additions & 7 deletions exampleapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ android {
defaultConfig {
applicationId "com.suddenh4x.ratingdialog.exampleapp"
minSdkVersion 14
targetSdkVersion 30
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -27,12 +28,7 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation project(':library')

testImplementation 'junit:junit:4.13'

androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.MutableLiveData
import com.suddenh4x.ratingdialog.AppRating
import com.suddenh4x.ratingdialog.buttons.CustomFeedbackButtonClickListener
import com.suddenh4x.ratingdialog.preferences.MailSettings
import com.suddenh4x.ratingdialog.preferences.RatingThreshold

Expand All @@ -19,7 +18,11 @@ class MainActivity : AppCompatActivity() {
AppRating.reset(this)

toastLiveData.observe(this) { toastString ->
Toast.makeText(this, toastString, Toast.LENGTH_LONG).show()
if (toastString.isNotBlank()) {
Toast.makeText(this, toastString, Toast.LENGTH_LONG).show()
// This is a workaround so that the toast isn't shown again on orientation change
toastLiveData.postValue("")
}
}
}

Expand Down Expand Up @@ -70,11 +73,9 @@ class MainActivity : AppCompatActivity() {
AppRating.Builder(this)
.setDebug(true)
.setUseCustomFeedback(true)
.setCustomFeedbackButtonClickListener(object : CustomFeedbackButtonClickListener {
override fun onClick(userFeedbackText: String) {
toastLiveData.postValue("Feedback: $userFeedbackText")
}
})
.setCustomFeedbackButtonClickListener { userFeedbackText ->
toastLiveData.postValue("Feedback: $userFeedbackText")
}
.showIfMeetsConditions()
}

Expand Down Expand Up @@ -134,6 +135,21 @@ class MainActivity : AppCompatActivity() {
.showIfMeetsConditions()
}

fun onCancelableButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
AppRating.Builder(this)
.setDebug(true)
.setCancelable(true)
.setDialogCancelListener { toastLiveData.postValue("Dialog was canceled.") }
.showIfMeetsConditions()
}

fun onCustomThemeButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
AppRating.Builder(this)
.setDebug(true)
.setCustomTheme(R.style.AppTheme_CustomAlertDialog)
.showIfMeetsConditions()
}

companion object {
// The livedata is used so that no context is given into the click listeners. (NotSerializableException)
private val toastLiveData: MutableLiveData<String> = MutableLiveData()
Expand Down
29 changes: 27 additions & 2 deletions exampleapp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,33 @@
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_big"
android:onClick="onCustomTextsButtonClicked"
android:text="@string/button_example_custom_texts" />

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

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onCancelableButtonClicked"
android:text="@string/button_example_cancelable" />

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

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_big"
android:onClick="onCustomThemeButtonClicked"
android:text="@string/button_example_custom_theme" />

</LinearLayout>
</ScrollView>
</ScrollView>
5 changes: 5 additions & 0 deletions exampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<string name="text_example_custom_texts">In this example the default texts has been replaced with dummy texts. Debug
is enabled.</string>
<string name="button_example_custom_texts">Custom texts</string>
<string name="text_example_cancelable">In this example the dialog is cancelable. A dialogCancelListener was set to show a toast. Debug
is enabled.</string>
<string name="button_example_cancelable">Cancelable</string>
<string name="text_example_custom_theme">In this example the dialog is used with a custom theme. Debug is enabled.</string>
<string name="button_example_custom_theme">Custom theme</string>

<!-- Custom Button Texts -->
<string name="button_rate_now">Foo</string>
Expand Down
12 changes: 12 additions & 0 deletions exampleapp/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.CustomAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<!-- Customize your theme here. -->
<item name="colorPrimary">#FFC107</item>
<item name="buttonBarPositiveButtonStyle">@style/CustomPositiveButtonStyle</item>
</style>

<style name="CustomPositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:textColor">#F00</item>
<item name="backgroundTint">#00F</item>
</style>


<style name="ExampleText" parent="TextAppearance.AppCompat">
<item name="android:textSize">14sp</item>
<item name="android:gravity">center_horizontal</item>
Expand Down
18 changes: 10 additions & 8 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ apply plugin: 'kotlin-android-extensions'
apply plugin: "de.mannodermaus.android-junit5"
apply plugin: 'com.novoda.bintray-release'

def version = "2.2.1"
def version = "2.3.0"

android {
compileSdkVersion 30
defaultConfig {
minSdkVersion 14
targetSdkVersion 30
versionCode 3
versionName "$version"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -31,19 +32,20 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.annotation:annotation:1.1.0'

// needed for in-app review
implementation 'com.google.android.play:core:1.8.2'
implementation 'com.google.android.play:core:1.9.1'
implementation 'com.google.android.play:core-ktx:1.8.1'

testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.0"
testImplementation "io.mockk:mockk:1.9.3"
testImplementation("org.assertj:assertj-core:3.13.0")
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0")
testImplementation "io.mockk:mockk:1.10.5"
testImplementation("org.assertj:assertj-core:3.18.1")
}

publish {
Expand Down
12 changes: 11 additions & 1 deletion library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
<manifest package="com.suddenh4x.ratingdialog"/>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.suddenh4x.ratingdialog">

<queries>
<!-- Sending Emails -->
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
</manifest>
22 changes: 19 additions & 3 deletions library/src/main/java/com/suddenh4x/ratingdialog/AppRating.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ object AppRating {
RatingLogger.debug("Use custom icon drawable.")
}

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

fun setRateLaterButtonTextId(@StringRes rateLaterButtonTextId: Int) = apply {
dialogOptions.rateLaterButton.textId = rateLaterButtonTextId
}
Expand Down Expand Up @@ -205,6 +210,10 @@ object AppRating {
RatingLogger.debug("Set cancelable to $cancelable.")
}

fun setDialogCancelListener(dialogCancelListener: () -> Unit) = apply {
dialogOptions.dialogCancelListener = dialogCancelListener
}

fun setMinimumLaunchTimes(launchTimes: Int) = apply {
PreferenceUtil.setMinimumLaunchTimes(activity, launchTimes)
}
Expand Down Expand Up @@ -301,19 +310,26 @@ object AppRating {
}
}

fun showIfMeetsConditions() {
fun showIfMeetsConditions(): Boolean {
if (activity.supportFragmentManager.findFragmentByTag(TAG) != null) {
RatingLogger.info("Stop checking conditions, rating dialog is currently visible.")
return false
}

if (dialogOptions.countAppLaunch) {
RatingLogger.debug("App launch will be counted: countAppLaunch is true.")
PreferenceUtil.increaseLaunchTimes(activity)
} else {
RatingLogger.info("App launch not counted this time: countAppLaunch has been set to false.")
}

if (isDebug || ConditionsChecker.shouldShowDialog(activity, dialogOptions)) {
return if (isDebug || ConditionsChecker.shouldShowDialog(activity, dialogOptions)) {
RatingLogger.info("Show rating dialog now: Conditions met.")
showNow()
true
} else {
RatingLogger.info("Don't show rating dialog: Conditions not met.")
false
}
}

Expand All @@ -338,7 +354,7 @@ object AppRating {
}

companion object {
private val TAG = AppRating::class.java.simpleName
private const val TAG = "AwesomeAppRatingDialog"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal object DialogManager {
dialogOptions: DialogOptions
): AlertDialog {
RatingLogger.debug("Creating rating overview dialog.")
val builder = getDialogBuilder(activity)
val builder = getDialogBuilder(activity, dialogOptions.customTheme)

val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val ratingOverviewDialogView = inflater.inflate(R.layout.dialog_rating_overview, null)
Expand Down Expand Up @@ -125,7 +125,7 @@ internal object DialogManager {
dialogOptions: DialogOptions
): AlertDialog {
RatingLogger.debug("Creating store rating dialog.")
val builder = getDialogBuilder(context)
val builder = getDialogBuilder(context, dialogOptions.customTheme)

val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val ratingStoreDialogView = inflater.inflate(R.layout.dialog_rating_store, null)
Expand Down Expand Up @@ -162,7 +162,7 @@ internal object DialogManager {
dialogOptions: DialogOptions
): AlertDialog {
RatingLogger.debug("Creating mail feedback dialog.")
val builder = getDialogBuilder(context)
val builder = getDialogBuilder(context, dialogOptions.customTheme)

builder.apply {
setTitle(dialogOptions.feedbackTitleTextId)
Expand Down Expand Up @@ -202,7 +202,7 @@ internal object DialogManager {
dialogOptions: DialogOptions
): AlertDialog {
RatingLogger.debug("Creating custom feedback dialog.")
val builder = getDialogBuilder(context)
val builder = getDialogBuilder(context, dialogOptions.customTheme)

val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val ratingCustomFeedbackDialogView =
Expand Down Expand Up @@ -325,12 +325,12 @@ internal object DialogManager {
}
}

private fun getDialogBuilder(context: Context): AlertDialog.Builder {
private fun getDialogBuilder(context: Context, theme: Int): AlertDialog.Builder {
return try {
MaterialAlertDialogBuilder(context)
MaterialAlertDialogBuilder(context, theme)
} catch (ex: IllegalArgumentException) {
RatingLogger.debug("This app doesn't use a MaterialComponents theme. Using normal AlertDialog instead.")
AlertDialog.Builder(context)
AlertDialog.Builder(context, theme)
}
}
}
Loading

0 comments on commit e7d34db

Please sign in to comment.