Skip to content

Commit 3107a01

Browse files
authored
Refactor to Kotlin and other minor improvements (#52)
1 parent 2a4eabc commit 3107a01

32 files changed

+887
-860
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
# Changelog
22

3+
## Version 2.0.0
4+
5+
- Refactor to Kotlin
6+
- Option to handle session increments manually by setting `incrementSessionsAutomatically(false)` in Builder and using `incrementSessionCount()` helper function
7+
- Add click listeners for positive button and negative button
8+
- Option to reset count using `resetCount()`
9+
- Dark theme support
10+
311
## Version 1.1.2
12+
413
- Migrate library from JCenter to Maven Central
514
- Update targetSdkVersion to 29
615
- Fix warnings
716

817
## Version 1.1.1
18+
919
- Update dependencies to AndroidX
1020
- Dark mode support

README.md

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Smart App Rate
22

3-
Smart app rate dialog for Android which takes user rating into consideration. If the user rates the app below the defined threshold rating, the dialog will change into a feedback form. Otherwise, It will take the user to the
4-
Google PlayStore.
3+
Smart app rate dialog for Android which takes user rating into consideration. If the user rates the app below the defined threshold rating, the dialog will change into a feedback form. Otherwise, It
4+
will take the user to the Google PlayStore.
55

66
![](preview/preview.png)
77

88
## Features
9+
910
- Auto fetches the app icon to appear on top of the dialog
1011
- Make the dialog appear on a defined app session
1112
- Opens Feedback form if the user rates below the minimum threshold
@@ -14,79 +15,53 @@ Google PlayStore.
1415
- Customizable button colors and backgrounds
1516
- Override dialog redirection to Google Play or Feedback form according to your needs
1617

17-
If you want the dialog to appear on the Nth session of the app, just add the `session(N)` to the dialog builder method
18-
and move the code to the `onCreate()` method of your Activity class. The dialog will appear when the app is opened for the Nth time.
18+
If you want the dialog to appear on the Nth session of the app, just add the `session(N)` to the dialog builder method and move the code to the `onCreate()` method of your Activity class. The dialog
19+
will appear when the app is opened for the Nth time.
1920

2021
## How to use
2122

2223
Use the dialog as it is
2324

24-
```java
25-
26-
final RatingDialog ratingDialog = new RatingDialog.Builder(this)
27-
.threshold(3)
28-
.session(7)
29-
.onRatingBarFormSumbit(new RatingDialog.Builder.RatingDialogFormListener() {
30-
@Override
31-
public void onFormSubmitted(String feedback) {
25+
```kotlin
3226

33-
}
34-
}).build();
27+
val ratingDialog: RatingDialog = RatingDialog.Builder(this)
28+
.threshold(3)
29+
.session(1)
30+
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
31+
.build()
3532

36-
ratingDialog.show();
33+
ratingDialog.show()
3734

3835
```
3936

4037
or use the dialog builder class to customize the rating dialog to match your app's UI.
4138

42-
```java
43-
final RatingDialog ratingDialog = new RatingDialog.Builder(this)
44-
.icon(drawable)
45-
.session(7)
46-
.threshold(3)
47-
.title("How was your experience with us?")
48-
.titleTextColor(R.color.black)
49-
.positiveButtonText("Not Now")
50-
.negativeButtonText("Never")
51-
.positiveButtonTextColor(R.color.white)
52-
.negativeButtonTextColor(R.color.grey_500)
53-
.formTitle("Submit Feedback")
54-
.formHint("Tell us where we can improve")
55-
.formSubmitText("Submit")
56-
.formCancelText("Cancel")
57-
.ratingBarColor(R.color.yellow)
58-
.playstoreUrl("YOUR_URL")
59-
.onThresholdCleared(new RatingDialog.Builder.RatingThresholdClearedListener() {
60-
@Override
61-
public void onThresholdCleared(RatingDialog ratingDialog, float rating, boolean thresholdCleared) {
62-
//do something
63-
ratingDialog.dismiss();
64-
}
65-
})
66-
.onThresholdFailed(new RatingDialog.Builder.RatingThresholdFailedListener() {
67-
@Override
68-
public void onThresholdFailed(RatingDialog ratingDialog, float rating, boolean thresholdCleared) {
69-
//do something
70-
ratingDialog.dismiss();
71-
}
72-
})
73-
.onRatingChanged(new RatingDialog.Builder.RatingDialogListener() {
74-
@Override
75-
public void onRatingSelected(float rating, boolean thresholdCleared) {
76-
77-
}
78-
})
79-
.onRatingBarFormSumbit(new RatingDialog.Builder.RatingDialogFormListener() {
80-
@Override
81-
public void onFormSubmitted(String feedback) {
82-
83-
}
84-
}).build();
85-
86-
ratingDialog.show();
39+
```kotlin
40+
val ratingDialog = RatingDialog.Builder(this)
41+
.icon(R.mipmap.ic_launcher)
42+
.session(session)
43+
.threshold(3)
44+
.title(text = R.string.rating_dialog_experience, textColor = R.color.primaryTextColor)
45+
.positiveButton(text = R.string.rating_dialog_maybe_later, textColor = R.color.colorPrimary, background = R.drawable.button_selector_positive)
46+
.negativeButton(text = R.string.rating_dialog_never, textColor = R.color.secondaryTextColor)
47+
.formTitle(R.string.submit_feedback)
48+
.formHint(R.string.rating_dialog_suggestions)
49+
.feedbackTextColor(R.color.feedbackTextColor)
50+
.formSubmitText(R.string.rating_dialog_submit)
51+
.formCancelText(R.string.rating_dialog_cancel)
52+
.ratingBarColor(R.color.ratingBarColor)
53+
.playstoreUrl("YOUR_URL")
54+
.onThresholdCleared { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdCleared: $rating $thresholdCleared") }
55+
.onThresholdFailed { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdFailed: $rating $thresholdCleared") }
56+
.onRatingChanged { rating, thresholdCleared -> Log.i(TAG, "onRatingChanged: $rating $thresholdCleared") }
57+
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
58+
.build()
59+
60+
ratingDialog.show()
8761
```
8862

8963
### Note
64+
9065
* Don't use `session()` if you want to show the dialog on a click event.
9166
* Remove the `threshold()` from the builder if you don't want to show the feedback form to the user.
9267
* Use `onThresholdCleared()` to override the default redirection to Google Play.
@@ -95,11 +70,12 @@ final RatingDialog ratingDialog = new RatingDialog.Builder(this)
9570
## Installation
9671

9772
### Gradle
73+
9874
Add it as a dependency in your app's build.gradle file
9975

10076
```groovy
10177
dependencies {
102-
implementation 'com.codemybrainsout.rating:ratingdialog:1.1.0'
78+
implementation 'com.codemybrainsout.rating:ratingdialog:2.0.0'
10379
}
10480
```
10581

@@ -116,6 +92,7 @@ Follow us on:
11692
Author: [Rahul Juneja](https://github.com/ahulr)
11793

11894
# License
95+
11996
```
12097
Copyright (C) 2016 Code My Brains Out
12198

app/build.gradle

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
apply plugin: 'com.android.application'
2+
apply plugin: 'kotlin-android'
23

34
android {
4-
compileSdkVersion 30
5+
compileSdkVersion 31
56
buildToolsVersion "30.0.3"
67

78
defaultConfig {
89
applicationId "com.codemybrainsout.rating"
910
minSdkVersion 15
10-
targetSdkVersion 30
11+
targetSdkVersion 31
1112
versionCode 1
1213
versionName "1.0"
1314
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
@@ -26,8 +27,13 @@ dependencies {
2627
exclude group: 'com.android.support', module: 'support-annotations'
2728
})
2829

29-
implementation 'com.google.android.material:material:1.3.0'
30-
implementation "androidx.appcompat:appcompat:1.2.0"
31-
testImplementation 'junit:junit:4.13.2'
30+
implementation 'com.google.android.material:material:1.5.0'
31+
implementation "androidx.appcompat:appcompat:1.4.1"
3232
implementation project(':ratingdialog')
33+
implementation "androidx.core:core-ktx:1.7.0"
34+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
35+
testImplementation 'junit:junit:4.13.2'
36+
}
37+
repositories {
38+
mavenCentral()
3339
}

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
android:label="@string/app_name"
99
android:supportsRtl="true"
1010
android:theme="@style/AppTheme">
11-
<activity android:name=".MainActivity">
11+
12+
<activity
13+
android:name=".MainActivity"
14+
android:exported="true">
1215
<intent-filter>
1316
<action android:name="android.intent.action.MAIN" />
1417

1518
<category android:name="android.intent.category.LAUNCHER" />
1619
</intent-filter>
1720
</activity>
21+
1822
</application>
1923

2024
</manifest>

app/src/main/java/com/codemybrainsout/rating/MainActivity.java

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.codemybrainsout.rating
2+
3+
import android.os.Bundle
4+
import android.util.Log
5+
import android.widget.RelativeLayout
6+
import androidx.appcompat.app.AppCompatActivity
7+
import com.codemybrainsout.ratingdialog.RatingDialog
8+
9+
class MainActivity : AppCompatActivity() {
10+
11+
override fun onCreate(savedInstanceState: Bundle?) {
12+
super.onCreate(savedInstanceState)
13+
setContentView(R.layout.activity_main)
14+
val rlRate = findViewById<RelativeLayout>(R.id.rlRate)
15+
rlRate.setOnClickListener { showDialog() }
16+
}
17+
18+
private fun showCustomDialogOnSession(session: Int = 3) {
19+
val ratingDialog = RatingDialog.Builder(this)
20+
.icon(R.mipmap.ic_launcher)
21+
.session(session)
22+
.threshold(3)
23+
.title(text = R.string.rating_dialog_experience, textColor = R.color.primaryTextColor)
24+
.positiveButton(text = R.string.rating_dialog_maybe_later, textColor = R.color.colorPrimary, background = R.drawable.button_selector_positive)
25+
.negativeButton(text = R.string.rating_dialog_never, textColor = R.color.secondaryTextColor)
26+
.formTitle(R.string.submit_feedback)
27+
.formHint(R.string.rating_dialog_suggestions)
28+
.feedbackTextColor(R.color.feedbackTextColor)
29+
.formSubmitText(R.string.rating_dialog_submit)
30+
.formCancelText(R.string.rating_dialog_cancel)
31+
.ratingBarColor(R.color.ratingBarColor)
32+
.playstoreUrl("YOUR_URL")
33+
.onThresholdCleared { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdCleared: $rating $thresholdCleared") }
34+
.onThresholdFailed { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdFailed: $rating $thresholdCleared") }
35+
.onRatingChanged { rating, thresholdCleared -> Log.i(TAG, "onRatingChanged: $rating $thresholdCleared") }
36+
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
37+
.build()
38+
39+
ratingDialog.show()
40+
}
41+
42+
private fun showDialog() {
43+
val ratingDialog: RatingDialog = RatingDialog.Builder(this)
44+
.threshold(3)
45+
.session(1)
46+
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
47+
.build()
48+
49+
ratingDialog.show()
50+
}
51+
52+
companion object {
53+
private val TAG = MainActivity::class.java.simpleName
54+
}
55+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android"
33
android:shape="rectangle">
4-
<solid android:color="@color/grey_200" />
4+
<solid android:color="@color/secondaryTextColor" />
55
<corners android:bottomLeftRadius="5dp" />
66
</shape>
77

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<shape xmlns:android="http://schemas.android.com/apk/res/android"
33
android:shape="rectangle">
4-
<solid android:color="@color/accent" />
4+
<solid android:color="@color/colorAccent" />
55
<corners android:bottomRightRadius="5dp" />
66
</shape>
77

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="rectangle">
4+
<solid android:color="@color/colorAccent" />
5+
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" />
6+
</shape>
7+

0 commit comments

Comments
 (0)