Skip to content

Commit

Permalink
Merge pull request #79 from SuddenH4X/release/2.5.0
Browse files Browse the repository at this point in the history
Release/2.5.0
  • Loading branch information
SuddenH4X authored Sep 25, 2022
2 parents ead7040 + 94ded6a commit 4b0bbad
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 136 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,22 @@ This library:
- is completely written in Kotlin
- is Unit tested
- is optimized for MaterialComponent themes
- supports Jetpack Compose
- uses AndroidX
- uses no third party dependencies
- is easy debuggable
- is Android 11 (API 30) ready
- is Android 13 (API 33) ready
- is easy to use

## How to use
### Gradle

The library supports API level 14 and higher. You can simply include it in your app via Gradle:

```groovy
dependencies {
...
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.4.0'
implementation 'com.suddenh4x.ratingdialog:awesome-app-rating:2.5.0'
}
```

Expand Down Expand Up @@ -149,8 +151,6 @@ Follow these tips on stackoverflow to maximize your chance of testing it success
Source: https://stackoverflow.com/a/63950373
```

You should consider to wait with implementing it and use the normal rating dialog instead until Google has fixed the issue(s).

#### When to show up

- Change the number of days the app has to be installed
Expand Down Expand Up @@ -491,6 +491,12 @@ AppRating.Builder(this)

If you want to show the dialog on app start, but with your custom conditions, you can of course just call the Builder in your `onCreate()` method of your main Activity class. If so, don't forget to remove the `dontCountThisAsAppLaunch()` method from the example above.

### Jetpack Compose

The libraries dialog is implemented as a `DialogFragment` and thus needs a `FragmentActivity` to get displayed. If you use Jetpack Compose your activity maybe extends from `ComponentActivity` and because this class isn't a subtype of `FragmentActivity` the dialog won't show up. You'll only see an error message in LogCat.

To get it working you just have to change your activity to extend from `AppCompatActivity` instead (or `FragmentActivity`). Or you just use the official Google in-app review which doesn't depend on fragments.

## Note

* If the in-app review from Google will be used: After the first in-app review flow was completed successfully the `toShowAgain` conditions will be used. For example `.setMinimumLaunchTimesToShowAgain(launchTimesToShowAgain: Int)` instead of `.setMinimumLaunchTimes(launchTimes: Int)`
Expand All @@ -505,6 +511,7 @@ If you want to show the dialog on app start, but with your custom conditions, yo
* Look at the example app to get first impressions

## Recommendations

The following things are highly recommended to not annoy the user, which in turn could lead to negative reviews:

- Don't show the dialog immediately after install
Expand All @@ -516,7 +523,7 @@ The following things are highly recommended to not annoy the user, which in turn
## License

```
Copyright (C) 2020 SuddenH4X
Copyright (C) 2022 SuddenH4X
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
buildscript {
ext.kotlin_version = '1.5.21'
ext.kotlin_version = '1.7.10'
repositories {
google()
maven { url 'https://plugins.gradle.org/m2/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'de.mannodermaus.gradle.plugins:android-junit5:1.7.1.1'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:10.1.0'
classpath 'de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1'
classpath 'org.jlleitschuh.gradle:ktlint-gradle:11.0.0'
classpath 'io.github.gradle-nexus:publish-plugin:1.1.0'
}
}
Expand Down
29 changes: 21 additions & 8 deletions exampleapp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 30
namespace 'com.suddenh4x.ratingdialog.exampleapp'
compileSdkVersion 33
defaultConfig {
applicationId "com.suddenh4x.ratingdialog.exampleapp"
minSdkVersion 14
targetSdkVersion 30
minSdkVersion 21
targetSdkVersion 33
versionCode 1
versionName "1.0.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -20,6 +19,12 @@ android {
}
}

buildFeatures {
viewBinding = true
compose = true
}


kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
Expand All @@ -28,13 +33,21 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

composeOptions {
kotlinCompilerExtensionVersion '1.3.0'
}
}

dependencies {
implementation project(':library')
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.activity:activity-compose:1.6.0'
implementation 'androidx.compose.material:material:1.2.1'
implementation 'androidx.compose.ui:ui-tooling:1.2.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation "com.google.android.material:compose-theme-adapter:1.1.19"
implementation 'com.google.android.material:material:1.6.1'
}

afterEvaluate {
Expand Down

This file was deleted.

14 changes: 9 additions & 5 deletions exampleapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.suddenh4x.ratingdialog.exampleapp">
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
Expand All @@ -11,12 +10,17 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
<activity android:name="com.suddenh4x.ratingdialog.exampleapp.MainActivity">
<activity
android:name="com.suddenh4x.ratingdialog.exampleapp.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.suddenh4x.ratingdialog.exampleapp.JetpackComposeActivity"
android:exported="false" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package com.suddenh4x.ratingdialog.exampleapp

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.material.Scaffold
import androidx.compose.material.SnackbarHost
import androidx.compose.material.SnackbarHostState
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.google.android.material.composethemeadapter.MdcTheme
import com.suddenh4x.ratingdialog.AppRating
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch

class JetpackComposeActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_jetpack_compose)
AppRating.reset(this)

val composeView = findViewById<ComposeView>(R.id.ComposeView)
composeView.setContent {
val snackbarHostState = remember { SnackbarHostState() }

MdcTheme {
Scaffold(
snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = { JetpackComposeExampleTopAppBar() },
) { paddingValues ->
JetpackComposeExample(paddingValues, snackbarHostState)
}
}
}
}

@Composable
private fun JetpackComposeExampleTopAppBar() {
TopAppBar(
title = { Text("Jetpack Compose Example") },
)
}

@Composable
fun JetpackComposeExample(paddingValues: PaddingValues, snackbarHostState: SnackbarHostState) {
val coroutineScope = rememberCoroutineScope()

Column(
modifier = Modifier
.padding(paddingValues)
.padding(16.dp)
.fillMaxSize(),
) {
Text(
text = "This is a Jetpack Compose example with a ComponentActivity. So the button below only " +
"starts the Google in-app review. If you want to use the libraries dialog with Jetpack Compose " +
"your activity has to extend from FragmentActivity (e.g. ComponentActivity).",
)
Button(
modifier = Modifier
.fillMaxWidth()
.padding(top = 20.dp),
onClick = { openGoogleInAppReview(coroutineScope, snackbarHostState) },
) {
Text(text = "Jetpack Compose Example")
}
}
}

private fun openGoogleInAppReview(
coroutineScope: CoroutineScope,
snackbarHostState: SnackbarHostState
) {
AppRating.Builder(this@JetpackComposeActivity)
.useGoogleInAppReview()
.setGoogleInAppReviewCompleteListener { successful ->
showSnackbar(coroutineScope, snackbarHostState, successful)
}
.setDebug(true)
.showIfMeetsConditions()
}

private fun showSnackbar(
coroutineScope: CoroutineScope,
snackbarHostState: SnackbarHostState,
successful: Boolean
) {
coroutineScope.launch {
snackbarHostState.showSnackbar(
"Google in-app review completed " +
"(successful: $successful)",
)
}
}

@Preview
@Composable
fun JetpackComposeExamplePreview() {
val snackbarHostState = remember { SnackbarHostState() }
JetpackComposeExample(PaddingValues(), snackbarHostState)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.suddenh4x.ratingdialog.exampleapp

import android.content.Intent
import android.os.Bundle
import android.view.View
import android.widget.Toast
Expand Down Expand Up @@ -150,6 +151,11 @@ class MainActivity : AppCompatActivity() {
.showIfMeetsConditions()
}

fun onJetpackComposeButtonClicked(@Suppress("UNUSED_PARAMETER") view: View) {
val jetpackComposeIntent = Intent(this, JetpackComposeActivity::class.java)
startActivity(jetpackComposeIntent)
}

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
14 changes: 14 additions & 0 deletions exampleapp/src/main/res/layout/activity_jetpack_compose.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".JetpackComposeActivity">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/ComposeView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
13 changes: 12 additions & 1 deletion exampleapp/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,20 @@
<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" />

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

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/margin_big"
android:onClick="onJetpackComposeButtonClicked"
android:text="@string/button_example_jetpack_compose" />
</LinearLayout>
</ScrollView>
2 changes: 2 additions & 0 deletions exampleapp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@
<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>
<string name="text_example_jetpack_compose">This button opens a new activity (ComponentActivity) to showcase the Jetpack Compose support.</string>
<string name="button_example_jetpack_compose">Jetpack Compose Example</string>

<!-- Custom Button Texts -->
<string name="button_rate_now">Foo</string>
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip
Loading

0 comments on commit 4b0bbad

Please sign in to comment.