Skip to content

Commit 0a2495f

Browse files
Maijenburg, GoopherMaijenburg, Goopher
authored andcommitted
Added in app review system
1 parent ef4fc8a commit 0a2495f

File tree

5 files changed

+48
-6
lines changed

5 files changed

+48
-6
lines changed

library/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ android {
77
minSdkVersion 14
88
targetSdkVersion 30
99
}
10+
11+
compileOptions {
12+
sourceCompatibility JavaVersion.VERSION_1_8
13+
targetCompatibility JavaVersion.VERSION_1_8
14+
}
1015
}
1116

1217
dependencies {

library/src/main/java/hotchemi/android/rate/AppRate.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,11 @@ public AppRate setView(View view) {
108108
return this;
109109
}
110110

111+
public AppRate useInAppReviewSystem(boolean useInAppReviewSystem) {
112+
options.setUseInAppReview(useInAppReviewSystem);
113+
return this;
114+
}
115+
111116
public AppRate setOnClickButtonListener(OnClickButtonListener listener) {
112117
options.setListener(listener);
113118
return this;

library/src/main/java/hotchemi/android/rate/DialogManager.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package hotchemi.android.rate;
22

3+
import android.app.Activity;
34
import android.app.AlertDialog;
45
import android.app.Dialog;
56
import android.content.Context;
67
import android.content.DialogInterface;
78
import android.content.Intent;
89
import android.view.View;
910

11+
import com.google.android.play.core.review.ReviewInfo;
1012
import com.google.android.play.core.review.ReviewManager;
1113
import com.google.android.play.core.review.ReviewManagerFactory;
14+
import com.google.android.play.core.tasks.Task;
1215

1316
import static hotchemi.android.rate.IntentHelper.createIntentForAmazonAppstore;
1417
import static hotchemi.android.rate.IntentHelper.createIntentForGooglePlay;
@@ -37,12 +40,26 @@ static Dialog create(final Context context, final DialogOptions options) {
3740
builder.setPositiveButton(options.getPositiveText(context), new DialogInterface.OnClickListener() {
3841
@Override
3942
public void onClick(DialogInterface dialog, int which) {
40-
// ReviewManager rm = ReviewManagerFactory.create(context);
41-
final Intent intentToAppstore = options.getStoreType() == StoreType.GOOGLEPLAY ?
42-
createIntentForGooglePlay(context) : createIntentForAmazonAppstore(context);
43-
context.startActivity(intentToAppstore);
44-
setAgreeShowDialog(context, false);
45-
if (listener != null) listener.onClickButton(which);
43+
if (options.isUseInAppReview()) {
44+
ReviewManager rm = ReviewManagerFactory.create(context);
45+
Task<ReviewInfo> request = rm.requestReviewFlow();
46+
request.addOnCompleteListener(task -> {
47+
if (task.isSuccessful()) {
48+
ReviewInfo reviewInfo = task.getResult();
49+
Task<Void> flow = rm.launchReviewFlow((Activity) context, reviewInfo);
50+
flow.addOnCompleteListener(result -> {
51+
52+
});
53+
}
54+
});
55+
56+
} else {
57+
final Intent intentToAppstore = options.getStoreType() == StoreType.GOOGLEPLAY ?
58+
createIntentForGooglePlay(context) : createIntentForAmazonAppstore(context);
59+
context.startActivity(intentToAppstore);
60+
setAgreeShowDialog(context, false);
61+
if (listener != null) listener.onClickButton(which);
62+
}
4663
}
4764
});
4865

library/src/main/java/hotchemi/android/rate/DialogOptions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ final class DialogOptions {
1616

1717
private boolean cancelable = false;
1818

19+
private boolean useInAppReview = false;
20+
1921
private StoreType storeType = StoreType.GOOGLEPLAY;
2022

2123
private int titleResId = R.string.rate_dialog_title;
@@ -192,4 +194,12 @@ public String getNegativeText(Context context) {
192194
public void setNegativeText(String negativeText) {
193195
this.negativeText = negativeText;
194196
}
197+
198+
public boolean isUseInAppReview() {
199+
return useInAppReview;
200+
}
201+
202+
public void setUseInAppReview(boolean useInAppReview) {
203+
this.useInAppReview = useInAppReview;
204+
}
195205
}

sample/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ android {
1515
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
1616
}
1717
}
18+
19+
compileOptions {
20+
sourceCompatibility JavaVersion.VERSION_1_8
21+
targetCompatibility JavaVersion.VERSION_1_8
22+
}
1823
}
1924

2025
repositories {

0 commit comments

Comments
 (0)