Skip to content

Commit e7d34db

Browse files
authored
Merge pull request #46 from SuddenH4X/release/2.3.0
Release/2.3.0
2 parents 7d41a44 + 50ce547 commit e7d34db

17 files changed

Lines changed: 362 additions & 86 deletions

File tree

README.md

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ The library supports API level 14 and higher. You can simply include it in your
4040
```groovy
4141
dependencies {
4242
...
43-
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.2.1'
43+
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.3.0'
4444
}
4545
```
4646

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

78-
But you can also just create the dialog to show it later
78+
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.
79+
80+
If you want you can also just create the dialog to show it later
7981

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

102-
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.
104+
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.
103105

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

189+
- Change the theme of the dialog
190+
191+
```kotlin
192+
.setCustomTheme(customTheme: Int)
193+
```
194+
187195
- Change the rate later button text
188196

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

365-
- Choose if the dialogs should be cancelable (by clicking outside or using the back button)
373+
- 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.
366374

367375
```kotlin
368376
.setCancelable(cancelable: Boolean) // default is false
369377
```
370378

379+
- Add a cancel listener to the dialog
380+
381+
```kotlin
382+
.setDialogCancelListener(dialogCancelListener: () -> Unit)
383+
```
384+
371385
- Disable all library logs
372386

373387
```kotlin

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.4.10'
4+
ext.kotlin_version = '1.4.30'
55
repositories {
66
google()
77
jcenter()

exampleapp/build.gradle

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ android {
66
defaultConfig {
77
applicationId "com.suddenh4x.ratingdialog.exampleapp"
88
minSdkVersion 14
9+
targetSdkVersion 30
910
versionCode 1
1011
versionName "1.0.0"
1112
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -27,12 +28,7 @@ dependencies {
2728
implementation fileTree(dir: 'libs', include: ['*.jar'])
2829
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
2930
implementation 'androidx.appcompat:appcompat:1.2.0'
30-
implementation 'com.google.android.material:material:1.2.1'
31-
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
31+
implementation 'com.google.android.material:material:1.3.0'
32+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
3233
implementation project(':library')
33-
34-
testImplementation 'junit:junit:4.13'
35-
36-
androidTestImplementation 'androidx.test:runner:1.3.0'
37-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
3834
}

exampleapp/src/main/java/com/suddenh4x/ratingdialog/exampleapp/MainActivity.kt

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity
77
import androidx.core.content.res.ResourcesCompat
88
import androidx.lifecycle.MutableLiveData
99
import com.suddenh4x.ratingdialog.AppRating
10-
import com.suddenh4x.ratingdialog.buttons.CustomFeedbackButtonClickListener
1110
import com.suddenh4x.ratingdialog.preferences.MailSettings
1211
import com.suddenh4x.ratingdialog.preferences.RatingThreshold
1312

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

2120
toastLiveData.observe(this) { toastString ->
22-
Toast.makeText(this, toastString, Toast.LENGTH_LONG).show()
21+
if (toastString.isNotBlank()) {
22+
Toast.makeText(this, toastString, Toast.LENGTH_LONG).show()
23+
// This is a workaround so that the toast isn't shown again on orientation change
24+
toastLiveData.postValue("")
25+
}
2326
}
2427
}
2528

@@ -70,11 +73,9 @@ class MainActivity : AppCompatActivity() {
7073
AppRating.Builder(this)
7174
.setDebug(true)
7275
.setUseCustomFeedback(true)
73-
.setCustomFeedbackButtonClickListener(object : CustomFeedbackButtonClickListener {
74-
override fun onClick(userFeedbackText: String) {
75-
toastLiveData.postValue("Feedback: $userFeedbackText")
76-
}
77-
})
76+
.setCustomFeedbackButtonClickListener { userFeedbackText ->
77+
toastLiveData.postValue("Feedback: $userFeedbackText")
78+
}
7879
.showIfMeetsConditions()
7980
}
8081

@@ -134,6 +135,21 @@ class MainActivity : AppCompatActivity() {
134135
.showIfMeetsConditions()
135136
}
136137

138+
fun onCancelableButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
139+
AppRating.Builder(this)
140+
.setDebug(true)
141+
.setCancelable(true)
142+
.setDialogCancelListener { toastLiveData.postValue("Dialog was canceled.") }
143+
.showIfMeetsConditions()
144+
}
145+
146+
fun onCustomThemeButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
147+
AppRating.Builder(this)
148+
.setDebug(true)
149+
.setCustomTheme(R.style.AppTheme_CustomAlertDialog)
150+
.showIfMeetsConditions()
151+
}
152+
137153
companion object {
138154
// The livedata is used so that no context is given into the click listeners. (NotSerializableException)
139155
private val toastLiveData: MutableLiveData<String> = MutableLiveData()

exampleapp/src/main/res/layout/activity_main.xml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,33 @@
152152
<Button
153153
android:layout_width="match_parent"
154154
android:layout_height="wrap_content"
155-
android:layout_marginBottom="@dimen/margin_big"
156155
android:onClick="onCustomTextsButtonClicked"
157156
android:text="@string/button_example_custom_texts" />
157+
158+
<TextView
159+
style="@style/ExampleText"
160+
android:layout_width="match_parent"
161+
android:layout_height="wrap_content"
162+
android:text="@string/text_example_cancelable" />
163+
164+
<Button
165+
android:layout_width="match_parent"
166+
android:layout_height="wrap_content"
167+
android:onClick="onCancelableButtonClicked"
168+
android:text="@string/button_example_cancelable" />
169+
170+
<TextView
171+
style="@style/ExampleText"
172+
android:layout_width="match_parent"
173+
android:layout_height="wrap_content"
174+
android:text="@string/text_example_custom_theme" />
175+
176+
<Button
177+
android:layout_width="match_parent"
178+
android:layout_height="wrap_content"
179+
android:layout_marginBottom="@dimen/margin_big"
180+
android:onClick="onCustomThemeButtonClicked"
181+
android:text="@string/button_example_custom_theme" />
182+
158183
</LinearLayout>
159-
</ScrollView>
184+
</ScrollView>

exampleapp/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
<string name="text_example_custom_texts">In this example the default texts has been replaced with dummy texts. Debug
4141
is enabled.</string>
4242
<string name="button_example_custom_texts">Custom texts</string>
43+
<string name="text_example_cancelable">In this example the dialog is cancelable. A dialogCancelListener was set to show a toast. Debug
44+
is enabled.</string>
45+
<string name="button_example_cancelable">Cancelable</string>
46+
<string name="text_example_custom_theme">In this example the dialog is used with a custom theme. Debug is enabled.</string>
47+
<string name="button_example_custom_theme">Custom theme</string>
4348

4449
<!-- Custom Button Texts -->
4550
<string name="button_rate_now">Foo</string>

exampleapp/src/main/res/values/styles.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
<item name="colorAccent">@color/colorAccent</item>
99
</style>
1010

11+
<style name="AppTheme.CustomAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
12+
<!-- Customize your theme here. -->
13+
<item name="colorPrimary">#FFC107</item>
14+
<item name="buttonBarPositiveButtonStyle">@style/CustomPositiveButtonStyle</item>
15+
</style>
16+
17+
<style name="CustomPositiveButtonStyle" parent="Widget.MaterialComponents.Button.TextButton">
18+
<item name="android:textColor">#F00</item>
19+
<item name="backgroundTint">#00F</item>
20+
</style>
21+
22+
1123
<style name="ExampleText" parent="TextAppearance.AppCompat">
1224
<item name="android:textSize">14sp</item>
1325
<item name="android:gravity">center_horizontal</item>

library/build.gradle

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ apply plugin: 'kotlin-android-extensions'
44
apply plugin: "de.mannodermaus.android-junit5"
55
apply plugin: 'com.novoda.bintray-release'
66

7-
def version = "2.2.1"
7+
def version = "2.3.0"
88

99
android {
1010
compileSdkVersion 30
1111
defaultConfig {
1212
minSdkVersion 14
13+
targetSdkVersion 30
1314
versionCode 3
1415
versionName "$version"
1516
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -31,19 +32,20 @@ dependencies {
3132
implementation fileTree(dir: 'libs', include: ['*.jar'])
3233
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
3334
implementation 'androidx.appcompat:appcompat:1.2.0'
34-
implementation 'com.google.android.material:material:1.2.1'
35-
implementation 'androidx.constraintlayout:constraintlayout:2.0.2'
35+
implementation 'com.google.android.material:material:1.3.0'
36+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
3637
implementation 'androidx.core:core-ktx:1.3.2'
3738
implementation 'androidx.annotation:annotation:1.1.0'
3839

3940
// needed for in-app review
40-
implementation 'com.google.android.play:core:1.8.2'
41+
implementation 'com.google.android.play:core:1.9.1'
4142
implementation 'com.google.android.play:core-ktx:1.8.1'
4243

43-
testImplementation "org.junit.jupiter:junit-jupiter-api:5.5.0"
44-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.5.0"
45-
testImplementation "io.mockk:mockk:1.9.3"
46-
testImplementation("org.assertj:assertj-core:3.13.0")
44+
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.0"
45+
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.0"
46+
testImplementation("org.junit.jupiter:junit-jupiter-params:5.7.0")
47+
testImplementation "io.mockk:mockk:1.10.5"
48+
testImplementation("org.assertj:assertj-core:3.18.1")
4749
}
4850

4951
publish {
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
<manifest package="com.suddenh4x.ratingdialog"/>
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.suddenh4x.ratingdialog">
3+
4+
<queries>
5+
<!-- Sending Emails -->
6+
<intent>
7+
<action android:name="android.intent.action.SENDTO" />
8+
<data android:scheme="mailto" />
9+
</intent>
10+
</queries>
11+
</manifest>

library/src/main/java/com/suddenh4x/ratingdialog/AppRating.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ object AppRating {
5656
RatingLogger.debug("Use custom icon drawable.")
5757
}
5858

59+
fun setCustomTheme(customTheme: Int) = apply {
60+
dialogOptions.customTheme = customTheme
61+
RatingLogger.debug("Use custom theme.")
62+
}
63+
5964
fun setRateLaterButtonTextId(@StringRes rateLaterButtonTextId: Int) = apply {
6065
dialogOptions.rateLaterButton.textId = rateLaterButtonTextId
6166
}
@@ -205,6 +210,10 @@ object AppRating {
205210
RatingLogger.debug("Set cancelable to $cancelable.")
206211
}
207212

213+
fun setDialogCancelListener(dialogCancelListener: () -> Unit) = apply {
214+
dialogOptions.dialogCancelListener = dialogCancelListener
215+
}
216+
208217
fun setMinimumLaunchTimes(launchTimes: Int) = apply {
209218
PreferenceUtil.setMinimumLaunchTimes(activity, launchTimes)
210219
}
@@ -301,19 +310,26 @@ object AppRating {
301310
}
302311
}
303312

304-
fun showIfMeetsConditions() {
313+
fun showIfMeetsConditions(): Boolean {
314+
if (activity.supportFragmentManager.findFragmentByTag(TAG) != null) {
315+
RatingLogger.info("Stop checking conditions, rating dialog is currently visible.")
316+
return false
317+
}
318+
305319
if (dialogOptions.countAppLaunch) {
306320
RatingLogger.debug("App launch will be counted: countAppLaunch is true.")
307321
PreferenceUtil.increaseLaunchTimes(activity)
308322
} else {
309323
RatingLogger.info("App launch not counted this time: countAppLaunch has been set to false.")
310324
}
311325

312-
if (isDebug || ConditionsChecker.shouldShowDialog(activity, dialogOptions)) {
326+
return if (isDebug || ConditionsChecker.shouldShowDialog(activity, dialogOptions)) {
313327
RatingLogger.info("Show rating dialog now: Conditions met.")
314328
showNow()
329+
true
315330
} else {
316331
RatingLogger.info("Don't show rating dialog: Conditions not met.")
332+
false
317333
}
318334
}
319335

@@ -338,7 +354,7 @@ object AppRating {
338354
}
339355

340356
companion object {
341-
private val TAG = AppRating::class.java.simpleName
357+
private const val TAG = "AwesomeAppRatingDialog"
342358
}
343359
}
344360
}

0 commit comments

Comments
 (0)