Skip to content

Commit

Permalink
Refactor to Kotlin and other minor improvements (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahulr authored Feb 13, 2022
1 parent 2a4eabc commit 3107a01
Show file tree
Hide file tree
Showing 32 changed files with 887 additions and 860 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
# Changelog

## Version 2.0.0

- Refactor to Kotlin
- Option to handle session increments manually by setting `incrementSessionsAutomatically(false)` in Builder and using `incrementSessionCount()` helper function
- Add click listeners for positive button and negative button
- Option to reset count using `resetCount()`
- Dark theme support

## Version 1.1.2

- Migrate library from JCenter to Maven Central
- Update targetSdkVersion to 29
- Fix warnings

## Version 1.1.1

- Update dependencies to AndroidX
- Dark mode support
99 changes: 38 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# Smart App Rate

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
Google PlayStore.
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 Google PlayStore.

![](preview/preview.png)

## Features

- Auto fetches the app icon to appear on top of the dialog
- Make the dialog appear on a defined app session
- Opens Feedback form if the user rates below the minimum threshold
Expand All @@ -14,79 +15,53 @@ Google PlayStore.
- Customizable button colors and backgrounds
- Override dialog redirection to Google Play or Feedback form according to your needs

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 will appear when the app is opened for the Nth time.
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
will appear when the app is opened for the Nth time.

## How to use

Use the dialog as it is

```java

final RatingDialog ratingDialog = new RatingDialog.Builder(this)
.threshold(3)
.session(7)
.onRatingBarFormSumbit(new RatingDialog.Builder.RatingDialogFormListener() {
@Override
public void onFormSubmitted(String feedback) {
```kotlin

}
}).build();
val ratingDialog: RatingDialog = RatingDialog.Builder(this)
.threshold(3)
.session(1)
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
.build()

ratingDialog.show();
ratingDialog.show()

```

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

```java
final RatingDialog ratingDialog = new RatingDialog.Builder(this)
.icon(drawable)
.session(7)
.threshold(3)
.title("How was your experience with us?")
.titleTextColor(R.color.black)
.positiveButtonText("Not Now")
.negativeButtonText("Never")
.positiveButtonTextColor(R.color.white)
.negativeButtonTextColor(R.color.grey_500)
.formTitle("Submit Feedback")
.formHint("Tell us where we can improve")
.formSubmitText("Submit")
.formCancelText("Cancel")
.ratingBarColor(R.color.yellow)
.playstoreUrl("YOUR_URL")
.onThresholdCleared(new RatingDialog.Builder.RatingThresholdClearedListener() {
@Override
public void onThresholdCleared(RatingDialog ratingDialog, float rating, boolean thresholdCleared) {
//do something
ratingDialog.dismiss();
}
})
.onThresholdFailed(new RatingDialog.Builder.RatingThresholdFailedListener() {
@Override
public void onThresholdFailed(RatingDialog ratingDialog, float rating, boolean thresholdCleared) {
//do something
ratingDialog.dismiss();
}
})
.onRatingChanged(new RatingDialog.Builder.RatingDialogListener() {
@Override
public void onRatingSelected(float rating, boolean thresholdCleared) {

}
})
.onRatingBarFormSumbit(new RatingDialog.Builder.RatingDialogFormListener() {
@Override
public void onFormSubmitted(String feedback) {

}
}).build();

ratingDialog.show();
```kotlin
val ratingDialog = RatingDialog.Builder(this)
.icon(R.mipmap.ic_launcher)
.session(session)
.threshold(3)
.title(text = R.string.rating_dialog_experience, textColor = R.color.primaryTextColor)
.positiveButton(text = R.string.rating_dialog_maybe_later, textColor = R.color.colorPrimary, background = R.drawable.button_selector_positive)
.negativeButton(text = R.string.rating_dialog_never, textColor = R.color.secondaryTextColor)
.formTitle(R.string.submit_feedback)
.formHint(R.string.rating_dialog_suggestions)
.feedbackTextColor(R.color.feedbackTextColor)
.formSubmitText(R.string.rating_dialog_submit)
.formCancelText(R.string.rating_dialog_cancel)
.ratingBarColor(R.color.ratingBarColor)
.playstoreUrl("YOUR_URL")
.onThresholdCleared { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdCleared: $rating $thresholdCleared") }
.onThresholdFailed { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdFailed: $rating $thresholdCleared") }
.onRatingChanged { rating, thresholdCleared -> Log.i(TAG, "onRatingChanged: $rating $thresholdCleared") }
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
.build()

ratingDialog.show()
```

### Note

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

### Gradle

Add it as a dependency in your app's build.gradle file

```groovy
dependencies {
implementation 'com.codemybrainsout.rating:ratingdialog:1.1.0'
implementation 'com.codemybrainsout.rating:ratingdialog:2.0.0'
}
```

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

# License

```
Copyright (C) 2016 Code My Brains Out
Expand Down
16 changes: 11 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {
compileSdkVersion 30
compileSdkVersion 31
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.codemybrainsout.rating"
minSdkVersion 15
targetSdkVersion 30
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
Expand All @@ -26,8 +27,13 @@ dependencies {
exclude group: 'com.android.support', module: 'support-annotations'
})

implementation 'com.google.android.material:material:1.3.0'
implementation "androidx.appcompat:appcompat:1.2.0"
testImplementation 'junit:junit:4.13.2'
implementation 'com.google.android.material:material:1.5.0'
implementation "androidx.appcompat:appcompat:1.4.1"
implementation project(':ratingdialog')
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
}
repositories {
mavenCentral()
}
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>

</manifest>
50 changes: 0 additions & 50 deletions app/src/main/java/com/codemybrainsout/rating/MainActivity.java

This file was deleted.

55 changes: 55 additions & 0 deletions app/src/main/java/com/codemybrainsout/rating/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.codemybrainsout.rating

import android.os.Bundle
import android.util.Log
import android.widget.RelativeLayout
import androidx.appcompat.app.AppCompatActivity
import com.codemybrainsout.ratingdialog.RatingDialog

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rlRate = findViewById<RelativeLayout>(R.id.rlRate)
rlRate.setOnClickListener { showDialog() }
}

private fun showCustomDialogOnSession(session: Int = 3) {
val ratingDialog = RatingDialog.Builder(this)
.icon(R.mipmap.ic_launcher)
.session(session)
.threshold(3)
.title(text = R.string.rating_dialog_experience, textColor = R.color.primaryTextColor)
.positiveButton(text = R.string.rating_dialog_maybe_later, textColor = R.color.colorPrimary, background = R.drawable.button_selector_positive)
.negativeButton(text = R.string.rating_dialog_never, textColor = R.color.secondaryTextColor)
.formTitle(R.string.submit_feedback)
.formHint(R.string.rating_dialog_suggestions)
.feedbackTextColor(R.color.feedbackTextColor)
.formSubmitText(R.string.rating_dialog_submit)
.formCancelText(R.string.rating_dialog_cancel)
.ratingBarColor(R.color.ratingBarColor)
.playstoreUrl("YOUR_URL")
.onThresholdCleared { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdCleared: $rating $thresholdCleared") }
.onThresholdFailed { dialog, rating, thresholdCleared -> Log.i(TAG, "onThresholdFailed: $rating $thresholdCleared") }
.onRatingChanged { rating, thresholdCleared -> Log.i(TAG, "onRatingChanged: $rating $thresholdCleared") }
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
.build()

ratingDialog.show()
}

private fun showDialog() {
val ratingDialog: RatingDialog = RatingDialog.Builder(this)
.threshold(3)
.session(1)
.onRatingBarFormSubmit { feedback -> Log.i(TAG, "onRatingBarFormSubmit: $feedback") }
.build()

ratingDialog.show()
}

companion object {
private val TAG = MainActivity::class.java.simpleName
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/button_selector_negative.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/grey_200" />
<solid android:color="@color/secondaryTextColor" />
<corners android:bottomLeftRadius="5dp" />
</shape>

2 changes: 1 addition & 1 deletion app/src/main/res/drawable/button_selector_positive.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/accent" />
<solid android:color="@color/colorAccent" />
<corners android:bottomRightRadius="5dp" />
</shape>

7 changes: 7 additions & 0 deletions app/src/main/res/drawable/button_selector_rounded.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/colorAccent" />
<corners android:bottomRightRadius="5dp" android:bottomLeftRadius="5dp" />
</shape>

Loading

0 comments on commit 3107a01

Please sign in to comment.