├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── dependencies.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── preview ├── header.png └── preview.gif ├── ratebottomsheet-example ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── mikhaellopez │ │ └── ratebottomsheetsample │ │ └── MainActivity.kt │ └── res │ ├── drawable │ └── ic_launcher_foreground.xml │ ├── layout │ └── activity_main.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── ic_launcher_background.xml │ ├── strings.xml │ └── themes.xml ├── ratebottomsheet ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── mikhaellopez │ │ └── ratebottomsheet │ │ ├── ABaseRateBottomSheet.kt │ │ ├── AskRateBottomSheet.kt │ │ ├── PreferenceHelper.kt │ │ ├── RateBottomSheet.kt │ │ └── RateBottomSheetManager.kt │ └── res │ ├── drawable │ └── close.xml │ ├── layout │ └── rate_bottom_sheet_layout.xml │ └── values │ └── strings.xml └── settings.gradle /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: lopspower 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # GENERATED 2 | *build 3 | buildsystem 4 | .gradle 5 | .DS_Store 6 | 7 | # LOCAL 8 | local.properties 9 | 10 | # IDEA 11 | *.idea 12 | *.iml -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 LOPEZ MIKHAEL 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | sample 4 | 5 | RateBottomSheet 6 | ================= 7 | 8 | [![Platform](https://img.shields.io/badge/platform-android-green.svg)](http://developer.android.com/index.html) 9 | [![API](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=16) 10 | [![Twitter](https://img.shields.io/badge/Twitter-@LopezMikhael-blue.svg?style=flat)](http://twitter.com/lopezmikhael) 11 | 12 | This an Android library to help to promote your Android App by prompting users to **rate** your app in the Google Play Store with a material design friendly **BottomSheet**. 13 | 14 | 15 | Android app on Google Play 16 | 17 | 18 | USAGE 19 | ----- 20 | 21 | To used this usefull library you can grab it via Gradle: 22 | 23 | ```groovy 24 | implementation 'com.mikhaellopez:ratebottomsheet:1.1.0' 25 | ``` 26 | 27 | KOTLIN 28 | ----- 29 | 30 | ```kotlin 31 | RateBottomSheetManager(this) 32 | .setInstallDays(1) // 3 by default 33 | .setLaunchTimes(2) // 5 by default 34 | .setRemindInterval(1) // 2 by default 35 | .setShowAskBottomSheet(false) // True by default 36 | .setShowLaterButton(false) // True by default 37 | .setShowCloseButtonIcon(false) // True by default 38 | .monitor() 39 | 40 | // Show bottom sheet if meets conditions 41 | // With AppCompatActivity or Fragment 42 | RateBottomSheet.showRateBottomSheetIfMeetsConditions(this) 43 | ``` 44 | 45 | Override string xml resources on your application to change the texts in bottom sheet: 46 | 47 | ```xml 48 | 49 | Like this App? 50 | Do you like using this application? 51 | Yes I do 52 | Not really 53 | 54 | Rate this app 55 | Would you mind taking a moment to rate it? It won\'t take more than a minute. Thanks for your support! 56 | Rate it now 57 | Remind me later 58 | No, thanks 59 | 60 | ``` 61 | 62 | LISTENER 63 | ----- 64 | 65 | When calling `RateBottomSheet.showRateBottomSheetIfMeetsConditions(...)` you can choose to add another parameter of type `AskRateBottomSheet.ActionListener`; this allows you to implement 3 optional callbacks. 66 | Here is how: 67 | 68 | ```kotlin 69 | RateBottomSheet.showRateBottomSheetIfMeetsConditions( 70 | this, 71 | listener = object : AskRateBottomSheet.ActionListener { 72 | override fun onDislikeClickListener() { 73 | // Will be called when a click on the "I don't like" button is triggered 74 | } 75 | 76 | override fun onRateClickListener() { 77 | // Will be called when a click on the "Rate" button is triggered 78 | } 79 | 80 | /*override fun onNoClickListener() { 81 | // Will be called when a click on the "No thanks" button is triggered, 82 | // in this example is commented, 83 | // but each callback is optional and it's up to you whether to implement it or not! 84 | }*/ 85 | } 86 | ) 87 | ``` 88 | 89 | DEBUG 90 | ----- 91 | 92 | Enable `debugForceOpen` to show bottom sheet without conditions check like this: 93 | 94 | ```kotlin 95 | RateBottomSheetManager(this) 96 | .setDebugForceOpenEnable(true) // False by default 97 | 98 | // Don't forget to run showRate function 99 | RateBottomSheet.showRateBottomSheetIfMeetsConditions(this) 100 | ``` 101 | 102 | You can also enable logs with `debugLogEnable` properties: 103 | 104 | ```kotlin 105 | RateBottomSheetManager(this) 106 | .setDebugLogEnable(true) // False by default 107 | ``` 108 | 109 | Clear all current data from RateBottomSheet like this: 110 | 111 | ```kotlin 112 | RateBottomSheetManager(this) 113 | .clear() 114 | ``` 115 | 116 | JAVA 117 | ----- 118 | 119 | You can call `showRateBottomSheetIfMeetsConditions` func like this: 120 | 121 | ```java 122 | RateBottomSheet.Companion.showRateBottomSheetIfMeetsConditions(this); 123 | ``` 124 | 125 | And because this library it's write in Kotlin you need to add **kotlin-stdlib** dependency on your java project: 126 | 127 | ```groovy 128 | implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.3.71' 129 | ``` 130 | 131 | SUPPORT ❤️ 132 | ----- 133 | 134 | Find this library useful? Support it by joining [**stargazers**](https://github.com/lopspower/RateBottomSheet/stargazers) for this repository ⭐️ 135 |
136 | And [**follow me**](https://github.com/lopspower?tab=followers) for my next creations 👍 137 | 138 | LICENCE 139 | ----- 140 | 141 | RateBottomSheet by [Lopez Mikhael](http://mikhaellopez.com/) is licensed under a [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0). 142 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | apply from: 'dependencies.gradle' 3 | 4 | buildscript { 5 | ext.kotlin_version = '1.3.71' 6 | repositories { 7 | google() 8 | jcenter() 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.6.2' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | classpath "org.jetbrains.kotlin:kotlin-android-extensions:$kotlin_version" 14 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.1' 15 | classpath 'com.github.ben-manes:gradle-versions-plugin:0.25.0' 16 | } 17 | } 18 | 19 | task clean(type: Delete) { 20 | delete rootProject.buildDir 21 | } 22 | -------------------------------------------------------------------------------- /dependencies.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | google() 4 | jcenter() 5 | } 6 | } 7 | 8 | ext { 9 | // APP VERSION 10 | androidVersionCode = 5 11 | androidVersionName = '1.1.0' 12 | 13 | // ANDROID VERSION 14 | androidCompileSdkVersion = 29 15 | androidMinSdkVersion = 16 16 | androidTargetSdkVersion = 29 17 | 18 | // KOTLIN 19 | kotlinStdlib = "org.jetbrains.kotlin:kotlin-stdlib:${ext.kotlin_version}" 20 | 21 | // ANDROID LIB 22 | androidAppCompatXVersion = '1.1.0' 23 | androidXAppCompat = "androidx.appcompat:appcompat:$androidAppCompatXVersion" 24 | 25 | // MATERIAL DESIGN 26 | materialDesignGroupId = "com.google.android.material" 27 | materialDesignArtifactId = "material" 28 | materialDesignVersion = '1.1.0' 29 | materialDesign = "$materialDesignGroupId:$materialDesignArtifactId:$materialDesignVersion" 30 | 31 | // DEPENDENCY CHECK STRATEGY 32 | dependencyUpdatesStrategy = { 33 | componentSelection { rules -> 34 | rules.all { ComponentSelection selection -> 35 | boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm'].any { qualifier -> 36 | selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/ 37 | } 38 | if (rejected) { 39 | selection.reject('Release candidate') 40 | } 41 | } 42 | } 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # Gralde 4 | org.gradle.jvmargs=-Xmx3072m 5 | 6 | # Android 7 | # Accelerate clean builds with the build cache, speed :transformClassesWithDexForDebug 8 | android.enableBuildCache=true 9 | # When set to true, this flag indicates that you want to start using AndroidX from now on. 10 | # If the flag is absent, Android Studio behaves as if the flag were set to false. 11 | android.useAndroidX=true 12 | # When set to true, this flag indicates that you want to have tool support (from the Android Gradle 13 | # plugin) to automatically convert existing third-party libraries as if they were written for 14 | # AndroidX. If the flag is absent, Android Studio behaves as if the flag were set to false. 15 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 08 10:30:36 CEST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /preview/header.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/preview/header.png -------------------------------------------------------------------------------- /preview/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/preview/preview.gif -------------------------------------------------------------------------------- /ratebottomsheet-example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.github.ben-manes.versions' 5 | 6 | android { 7 | compileSdkVersion androidCompileSdkVersion 8 | defaultConfig { 9 | applicationId "com.mikhaellopez.ratebottomsheetsample" 10 | minSdkVersion androidMinSdkVersion 11 | targetSdkVersion androidTargetSdkVersion 12 | versionCode 1 13 | versionName "1.0" 14 | } 15 | compileOptions { 16 | sourceCompatibility JavaVersion.VERSION_1_8 17 | targetCompatibility JavaVersion.VERSION_1_8 18 | } 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt') 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | implementation project(':ratebottomsheet') 29 | //implementation "com.mikhaellopez:ratebottomsheet:$androidVersionName" 30 | 31 | // KOTLIN 32 | implementation kotlinStdlib 33 | // ANDROID 34 | implementation androidXAppCompat 35 | implementation materialDesign 36 | 37 | // DEPENDENCY CHECK STRATEGY 38 | dependencyUpdates.resolutionStrategy = dependencyUpdatesStrategy 39 | } -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/java/com/mikhaellopez/ratebottomsheetsample/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheetsample 2 | 3 | import android.os.Bundle 4 | import android.widget.Toast 5 | import androidx.appcompat.app.AppCompatActivity 6 | import com.mikhaellopez.ratebottomsheet.AskRateBottomSheet 7 | import com.mikhaellopez.ratebottomsheet.RateBottomSheet 8 | import com.mikhaellopez.ratebottomsheet.RateBottomSheetManager 9 | import kotlinx.android.synthetic.main.activity_main.* 10 | 11 | class MainActivity : AppCompatActivity() { 12 | 13 | override fun onCreate(savedInstanceState: Bundle?) { 14 | super.onCreate(savedInstanceState) 15 | setContentView(R.layout.activity_main) 16 | 17 | RateBottomSheetManager(this) 18 | .setInstallDays(1) // 3 by default 19 | .setLaunchTimes(2) // 5 by default 20 | .setRemindInterval(1) // 2 by default 21 | .setShowAskBottomSheet(true) // True by default 22 | .setShowLaterButton(true) // True by default 23 | .setShowCloseButtonIcon(true) // True by default 24 | .setDebugLogEnable(true) // False by default 25 | .monitor() 26 | 27 | // The listener is optional, as well as each single callback: 28 | // you can choose which one you want to override 29 | val actionListener = object : AskRateBottomSheet.ActionListener { 30 | override fun onDislikeClickListener() { 31 | Toast.makeText( 32 | this@MainActivity, 33 | "Oh... that's sad! :(", 34 | Toast.LENGTH_SHORT 35 | ).show() 36 | } 37 | 38 | override fun onRateClickListener() { 39 | Toast.makeText( 40 | this@MainActivity, 41 | "Great choice! ♡", 42 | Toast.LENGTH_SHORT 43 | ).show() 44 | } 45 | 46 | override fun onNoClickListener() { 47 | Toast.makeText( 48 | this@MainActivity, 49 | "Well... at least you like it, I'm ok with that", 50 | Toast.LENGTH_LONG 51 | ).show() 52 | } 53 | } 54 | 55 | // Show bottom sheet if meets conditions 56 | RateBottomSheet.showRateBottomSheetIfMeetsConditions(this) 57 | 58 | btnShowRate.setOnClickListener { 59 | RateBottomSheetManager(this) 60 | .setDebugForceOpenEnable(true) // False by default 61 | RateBottomSheet.showRateBottomSheetIfMeetsConditions( 62 | activity = this, 63 | listener = actionListener 64 | ) 65 | } 66 | } 67 | 68 | } -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 9 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 18 | 19 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lopspower/RateBottomSheet/cb37cf290676223413c741ed6b9145021b750653/ratebottomsheet-example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #424242 4 | #212121 5 | #2e7d32 6 | 7 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #4D4F57 4 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RateBottomSheet 3 | 4 | -------------------------------------------------------------------------------- /ratebottomsheet-example/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /ratebottomsheet/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | apply plugin: 'com.jfrog.bintray' 5 | apply plugin: 'maven-publish' 6 | apply plugin: 'com.github.ben-manes.versions' 7 | 8 | android { 9 | compileSdkVersion androidCompileSdkVersion 10 | defaultConfig { 11 | minSdkVersion androidMinSdkVersion 12 | targetSdkVersion androidTargetSdkVersion 13 | versionCode androidVersionCode 14 | versionName androidVersionName 15 | } 16 | compileOptions { 17 | sourceCompatibility JavaVersion.VERSION_1_8 18 | targetCompatibility JavaVersion.VERSION_1_8 19 | } 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | } 24 | } 25 | } 26 | 27 | dependencies { 28 | // KOTLIN 29 | implementation kotlinStdlib 30 | // ANDROID 31 | implementation materialDesign 32 | 33 | // DEPENDENCY CHECK STRATEGY 34 | dependencyUpdates.resolutionStrategy = dependencyUpdatesStrategy 35 | } 36 | 37 | //region Publish to jCenter 38 | def libGroupId = 'com.mikhaellopez' 39 | def libArtifactId = 'ratebottomsheet' 40 | def libVersion = androidVersionName 41 | def libDesc = '' 42 | def libLicenses = ['Apache-2.0'] 43 | def libSiteUrl = 'https://github.com/lopspower/RateBottomSheet' 44 | def libVCSUrl = 'https://github.com/lopspower/RateBottomSheet.git' 45 | 46 | // Generate Source Jar 47 | task sourceJar(type: Jar) { 48 | from android.sourceSets.main.java.srcDirs 49 | classifier "sources" 50 | } 51 | 52 | // Create the publication with the pom configuration 53 | publishing { 54 | publications { 55 | MyPublication(MavenPublication) { 56 | groupId libGroupId 57 | artifactId libArtifactId 58 | version libVersion 59 | 60 | pom.withXml { 61 | def dependenciesNode = asNode().appendNode('dependencies') 62 | // Add MaterialDesign 63 | def materialDesignDepNode = dependenciesNode.appendNode('dependency') 64 | materialDesignDepNode.appendNode('groupId', materialDesignGroupId) 65 | materialDesignDepNode.appendNode('artifactId', materialDesignArtifactId) 66 | materialDesignDepNode.appendNode('version', materialDesignVersion) 67 | } 68 | 69 | artifact(sourceJar) 70 | artifact("$buildDir/outputs/aar/$libArtifactId-release.aar") 71 | } 72 | } 73 | } 74 | 75 | // Bintray config 76 | Properties properties = new Properties() 77 | properties.load(project.rootProject.file('local.properties').newDataInputStream()) 78 | 79 | bintray { 80 | user = properties.getProperty("bintray.user") 81 | key = properties.getProperty("bintray.apikey") 82 | publications = ['MyPublication'] 83 | pkg { 84 | repo = "maven" 85 | name = "$libGroupId:$libArtifactId" 86 | desc = libDesc 87 | licenses = libLicenses 88 | websiteUrl = libSiteUrl 89 | vcsUrl = libVCSUrl 90 | version { 91 | name = libVersion 92 | vcsTag = libVersion 93 | released = new Date() 94 | } 95 | } 96 | } 97 | //endregion -------------------------------------------------------------------------------- /ratebottomsheet/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/ABaseRateBottomSheet.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheet 2 | 3 | import android.content.Context 4 | import android.content.res.ColorStateList 5 | import android.os.Build 6 | import android.os.Bundle 7 | import android.util.TypedValue 8 | import android.view.LayoutInflater 9 | import android.view.View 10 | import android.view.ViewGroup 11 | import com.google.android.material.bottomsheet.BottomSheetBehavior 12 | import com.google.android.material.bottomsheet.BottomSheetDialog 13 | import com.google.android.material.bottomsheet.BottomSheetDialogFragment 14 | import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* 15 | 16 | /** 17 | * Copyright (C) 2020 Mikhael LOPEZ 18 | * Licensed under the Apache License Version 2.0 19 | */ 20 | abstract class ABaseRateBottomSheet : BottomSheetDialogFragment() { 21 | 22 | override fun onCreateView( 23 | inflater: LayoutInflater, 24 | container: ViewGroup?, 25 | savedInstanceState: Bundle? 26 | ): View? { 27 | dialog?.setOnShowListener { dialog -> 28 | (dialog as? BottomSheetDialog)?.also { 29 | it.findViewById(com.google.android.material.R.id.design_bottom_sheet) 30 | ?.also { bottomSheetInternal -> 31 | BottomSheetBehavior.from(bottomSheetInternal).state = 32 | BottomSheetBehavior.STATE_EXPANDED 33 | } 34 | } 35 | } 36 | return inflater.inflate(R.layout.rate_bottom_sheet_layout, container, false) 37 | } 38 | 39 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 40 | super.onViewCreated(view, savedInstanceState) 41 | 42 | btnRateBottomSheetCancel.visibility = 43 | if (RateBottomSheetManager.showCloseButtonIcon) View.VISIBLE else View.GONE 44 | 45 | context?.also { 46 | btnRateBottomSheetOk.backgroundTintList = 47 | ColorStateList.valueOf(getThemeAccentColor(it)) 48 | } 49 | 50 | btnRateBottomSheetCancel.setOnClickListener { dismiss() } 51 | btnRateBottomSheetNo.setOnClickListener { defaultBtnNoClickAction(it) } 52 | btnRateBottomSheetLater.setOnClickListener { defaultBtnLaterClickAction(it) } 53 | } 54 | 55 | protected fun defaultBtnNoClickAction(view: View) { 56 | RateBottomSheetManager(view.context).disableAgreeShowDialog() 57 | dismiss() 58 | } 59 | 60 | private fun defaultBtnLaterClickAction(view: View) { 61 | RateBottomSheetManager(view.context).setRemindInterval() 62 | dismiss() 63 | } 64 | 65 | private fun getThemeAccentColor(context: Context): Int { 66 | val colorAttr = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 67 | android.R.attr.colorAccent 68 | } else { // Get colorAccent defined for AppCompat 69 | context.resources.getIdentifier("colorAccent", "attr", context.packageName) 70 | } 71 | val outValue = TypedValue() 72 | context.theme.resolveAttribute(colorAttr, outValue, true) 73 | return outValue.data 74 | } 75 | 76 | } -------------------------------------------------------------------------------- /ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/AskRateBottomSheet.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheet 2 | 3 | import android.os.Bundle 4 | import android.view.View 5 | import androidx.fragment.app.FragmentManager 6 | import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* 7 | 8 | /** 9 | * Copyright (C) 2020 Mikhael LOPEZ 10 | * Licensed under the Apache License Version 2.0 11 | */ 12 | class AskRateBottomSheet( 13 | private val listener: ActionListener? = null 14 | ) : ABaseRateBottomSheet() { 15 | 16 | /** 17 | * You can use this listener if you choose to setShowAskBottomSheet(true) 18 | * See .RateBottomSheet.ActionListener for more callbacks 19 | * 20 | * Each callback has an empty body, meaning that is optional 21 | */ 22 | interface ActionListener : RateBottomSheet.ActionListener { 23 | /** 24 | * Will be called when a click on the "I don't like" button is triggered 25 | */ 26 | fun onDislikeClickListener() {} 27 | } 28 | 29 | companion object { 30 | internal fun show(manager: FragmentManager, listener: ActionListener? = null) { 31 | AskRateBottomSheet(listener).show(manager, "askRateBottomSheet") 32 | } 33 | } 34 | 35 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 36 | super.onViewCreated(view, savedInstanceState) 37 | 38 | btnRateBottomSheetLater.visibility = View.GONE 39 | textRateBottomSheetTitle.text = getString(R.string.rate_popup_ask_title) 40 | textRateBottomSheetMessage.text = getString(R.string.rate_popup_ask_message) 41 | btnRateBottomSheetNo.text = getString(R.string.rate_popup_ask_no) 42 | btnRateBottomSheetOk.text = getString(R.string.rate_popup_ask_ok) 43 | 44 | btnRateBottomSheetOk.setOnClickListener { 45 | activity?.run { RateBottomSheet.show(supportFragmentManager, listener) } 46 | dismiss() 47 | } 48 | 49 | btnRateBottomSheetNo.setOnClickListener { 50 | defaultBtnNoClickAction(it) 51 | listener?.onDislikeClickListener() 52 | } 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/PreferenceHelper.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheet 2 | 3 | import android.content.Context 4 | import android.content.SharedPreferences 5 | import java.util.* 6 | 7 | /** 8 | * Copyright (C) 2020 Mikhael LOPEZ 9 | * Licensed under the Apache License Version 2.0 10 | */ 11 | class PreferenceHelper(context: Context) { 12 | 13 | companion object { 14 | private const val PREF_FILE_NAME = "rate_bottom_sheet_pref" 15 | private const val PREF_INSTALL_DAYS = "pref_rate_install_days" 16 | private const val PREF_CPT_LAUNCH_TIMES = "pref_rate_cpt_launch_times" 17 | private const val PREF_IS_AGREE_SHOW_BOTTOM_SHEET = "pref_rate_is_agree_show_bottom_sheet" 18 | private const val PREF_REMIND_INTERVAL = "pref_rate_remind_interval" 19 | } 20 | 21 | private val sharedPreferences = 22 | context.getSharedPreferences(PREF_FILE_NAME, Context.MODE_PRIVATE) 23 | 24 | internal fun getInstallDays(): Long = 25 | sharedPreferences.getLong(PREF_INSTALL_DAYS, 0) 26 | 27 | internal fun setInstallDays() { 28 | sharedPreferences.put(PREF_INSTALL_DAYS, Date().time) 29 | } 30 | 31 | internal fun getCptLaunchTimes(): Int = 32 | sharedPreferences.getInt(PREF_CPT_LAUNCH_TIMES, 0) 33 | 34 | internal fun setCptLaunchTimes() { 35 | sharedPreferences.getInt(PREF_CPT_LAUNCH_TIMES, 0).also { 36 | sharedPreferences.put(PREF_CPT_LAUNCH_TIMES, it + 1) 37 | } 38 | } 39 | 40 | internal fun isAgreeShowBottomSheet(): Boolean = 41 | sharedPreferences.getBoolean(PREF_IS_AGREE_SHOW_BOTTOM_SHEET, true) 42 | 43 | internal fun disableAgreeShowBottomSheet() { 44 | sharedPreferences.put(PREF_IS_AGREE_SHOW_BOTTOM_SHEET, false) 45 | } 46 | 47 | internal fun getRemindInterval(): Long = 48 | sharedPreferences.getLong(PREF_REMIND_INTERVAL, 0) 49 | 50 | internal fun setRemindInterval() { 51 | sharedPreferences.put(PREF_REMIND_INTERVAL, Date().time) 52 | } 53 | 54 | internal fun clear() { 55 | sharedPreferences.clear(PREF_INSTALL_DAYS) 56 | sharedPreferences.clear(PREF_CPT_LAUNCH_TIMES) 57 | sharedPreferences.clear(PREF_IS_AGREE_SHOW_BOTTOM_SHEET) 58 | sharedPreferences.clear(PREF_REMIND_INTERVAL) 59 | } 60 | 61 | //region Extensions 62 | private fun SharedPreferences.put(key: String, value: Boolean) { 63 | edit().putBoolean(key, value).apply() 64 | } 65 | 66 | private fun SharedPreferences.put(key: String, value: Int) { 67 | edit().putInt(key, value).apply() 68 | } 69 | 70 | private fun SharedPreferences.put(key: String, value: Long) { 71 | edit().putLong(key, value).apply() 72 | } 73 | 74 | private fun SharedPreferences.clear(key: String) { 75 | edit().remove(key).apply() 76 | } 77 | //endregion 78 | 79 | 80 | } 81 | -------------------------------------------------------------------------------- /ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheet.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheet 2 | 3 | import android.app.Activity 4 | import android.content.ActivityNotFoundException 5 | import android.content.Context 6 | import android.content.Intent 7 | import android.net.Uri 8 | import android.os.Bundle 9 | import android.view.View 10 | import androidx.appcompat.app.AppCompatActivity 11 | import androidx.fragment.app.Fragment 12 | import androidx.fragment.app.FragmentManager 13 | import kotlinx.android.synthetic.main.rate_bottom_sheet_layout.* 14 | 15 | /** 16 | * Copyright (C) 2020 Mikhael LOPEZ 17 | * Licensed under the Apache License Version 2.0 18 | */ 19 | class RateBottomSheet( 20 | private val listener: ActionListener? = null 21 | ) : ABaseRateBottomSheet() { 22 | 23 | /** 24 | * You can use this listener if you choose to setShowAskBottomSheet(false) 25 | * Otherwise, consider using .AskRateBottomSheet.ActionListener 26 | * 27 | * Each callback has an empty body, meaning that is optional 28 | */ 29 | interface ActionListener { 30 | /** 31 | * Will be called when a click on the "Rate" button is triggered 32 | */ 33 | fun onRateClickListener() {} 34 | 35 | /** 36 | * Will be called when a click on the "No thanks" button is triggered 37 | */ 38 | fun onNoClickListener() {} 39 | } 40 | 41 | companion object { 42 | internal fun show(manager: FragmentManager, listener: ActionListener? = null) { 43 | RateBottomSheet(listener).show(manager, "rateBottomSheet") 44 | } 45 | 46 | /** 47 | * Display rate bottom sheet if meets conditions. 48 | * 49 | * @param activity [AppCompatActivity] 50 | * @param listener [AskRateBottomSheet.ActionListener] 51 | */ 52 | fun showRateBottomSheetIfMeetsConditions( 53 | activity: AppCompatActivity, 54 | listener: AskRateBottomSheet.ActionListener? = null 55 | ) { 56 | showRateBottomSheetIfMeetsConditions( 57 | activity.applicationContext, 58 | activity.supportFragmentManager, 59 | listener 60 | ) 61 | } 62 | 63 | /** 64 | * Display rate bottom sheet if meets conditions. 65 | * 66 | * @param fragment [Fragment] 67 | * @param listener [AskRateBottomSheet.ActionListener] 68 | */ 69 | fun showRateBottomSheetIfMeetsConditions( 70 | fragment: Fragment, 71 | listener: AskRateBottomSheet.ActionListener? = null 72 | ) { 73 | (fragment.activity as? AppCompatActivity)?.also { 74 | showRateBottomSheetIfMeetsConditions( 75 | it.applicationContext, 76 | fragment.childFragmentManager, 77 | listener 78 | ) 79 | } 80 | } 81 | 82 | /** 83 | * Display rate bottom sheet if meets conditions. 84 | * 85 | * @param context [Context] 86 | * @param fragmentManager [FragmentManager] 87 | * @param listener [AskRateBottomSheet.ActionListener] 88 | */ 89 | fun showRateBottomSheetIfMeetsConditions( 90 | context: Context, 91 | fragmentManager: FragmentManager, 92 | listener: AskRateBottomSheet.ActionListener? = null 93 | ) { 94 | if (RateBottomSheetManager(context).shouldShowRateBottomSheet()) { 95 | if (RateBottomSheetManager.showAskBottomSheet) { 96 | AskRateBottomSheet.show(fragmentManager, listener) 97 | } else { 98 | show(fragmentManager) 99 | } 100 | } 101 | } 102 | } 103 | 104 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 105 | super.onViewCreated(view, savedInstanceState) 106 | 107 | btnRateBottomSheetLater.visibility = 108 | if (RateBottomSheetManager.showLaterButton) View.VISIBLE else View.GONE 109 | 110 | textRateBottomSheetTitle.text = getString(R.string.rate_popup_title) 111 | textRateBottomSheetMessage.text = getString(R.string.rate_popup_message) 112 | btnRateBottomSheetNo.text = getString(R.string.rate_popup_no) 113 | btnRateBottomSheetLater.text = getString(R.string.rate_popup_later) 114 | btnRateBottomSheetOk.text = getString(R.string.rate_popup_ok) 115 | 116 | btnRateBottomSheetOk.setOnClickListener { 117 | activity?.run { 118 | openStore(packageName) 119 | RateBottomSheetManager(it.context).disableAgreeShowDialog() 120 | } 121 | dismiss() 122 | listener?.onRateClickListener() 123 | } 124 | 125 | btnRateBottomSheetNo.setOnClickListener { 126 | defaultBtnNoClickAction(it) 127 | listener?.onNoClickListener() 128 | } 129 | } 130 | 131 | private fun Activity.openStore(appPackageName: String) { 132 | try { 133 | startActivity( 134 | Intent( 135 | Intent.ACTION_VIEW, 136 | Uri.parse("market://details?id=$appPackageName") 137 | ) 138 | ) 139 | } catch (_: ActivityNotFoundException) { 140 | startActivity( 141 | Intent( 142 | Intent.ACTION_VIEW, 143 | Uri.parse("https://play.google.com/store/apps/details?id=$appPackageName") 144 | ) 145 | ) 146 | } 147 | } 148 | 149 | } -------------------------------------------------------------------------------- /ratebottomsheet/src/main/java/com/mikhaellopez/ratebottomsheet/RateBottomSheetManager.kt: -------------------------------------------------------------------------------- 1 | package com.mikhaellopez.ratebottomsheet 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import java.util.* 6 | 7 | /** 8 | * Copyright (C) 2020 Mikhael LOPEZ 9 | * Licensed under the Apache License Version 2.0 10 | * Manage all properties for the conditions 11 | * to display the rate bottom sheet 12 | */ 13 | class RateBottomSheetManager(context: Context) { 14 | 15 | companion object { 16 | var installDays: Int = 3 17 | private set 18 | var launchTimes: Int = 5 19 | private set 20 | var remindInterval: Int = 2 21 | private set 22 | var showAskBottomSheet: Boolean = true 23 | private set 24 | var showLaterButton: Boolean = true 25 | private set 26 | var showCloseButtonIcon: Boolean = true 27 | private set 28 | var debugForceOpenEnable: Boolean = false 29 | private set 30 | var debugLogEnable: Boolean = false 31 | private set 32 | } 33 | 34 | private val preferenceHelper = PreferenceHelper(context) 35 | 36 | internal fun shouldShowRateBottomSheet(): Boolean { 37 | val isAgreeShowBottomSheet = preferenceHelper.isAgreeShowBottomSheet() 38 | val isOverInstallDays = preferenceHelper.getInstallDays().isOverDate(installDays) 39 | val isOverLaunchTimes = preferenceHelper.getCptLaunchTimes() >= launchTimes 40 | val isOverRemindInterval = preferenceHelper.getRemindInterval().isOverDate(remindInterval) 41 | 42 | if (debugLogEnable) { 43 | Log.d( 44 | "RateBottomSheetManager", 45 | " \nRateBottomSheet Conditions:\n" + 46 | "- isAgreeShowBottomSheet = $isAgreeShowBottomSheet\n" + 47 | "- isOverLaunchTimes = $isOverLaunchTimes : cptLaunchTimes = ${preferenceHelper.getCptLaunchTimes()}\n" + 48 | "- isOverInstallDays = $isOverInstallDays : " + 49 | "${preferenceHelper.getInstallDays().showOverCondition(installDays)})\n" + 50 | "- isOverRemindInterval = $isOverRemindInterval : " + 51 | preferenceHelper.getRemindInterval().showOverCondition(remindInterval) 52 | ) 53 | } 54 | 55 | return debugForceOpenEnable 56 | || (isAgreeShowBottomSheet && isOverLaunchTimes 57 | && isOverInstallDays && isOverRemindInterval) 58 | } 59 | 60 | internal fun setRemindInterval() { 61 | preferenceHelper.setRemindInterval() 62 | } 63 | 64 | internal fun disableAgreeShowDialog() { 65 | preferenceHelper.disableAgreeShowBottomSheet() 66 | } 67 | 68 | //region SET PUBLIC 69 | /** 70 | * Set nb days needed to show rate bottom sheet. 71 | * 3 days needed by default. 72 | * 73 | * @param installDays [Int] 74 | * @return [RateBottomSheetManager] 75 | */ 76 | fun setInstallDays(installDays: Int): RateBottomSheetManager = 77 | apply { RateBottomSheetManager.installDays = installDays } 78 | 79 | /** 80 | * Set nb launch needed to show rate bottom sheet. 81 | * 5 launch needed by default. 82 | * 83 | * @param launchTimes [Int] 84 | * @return [RateBottomSheetManager] 85 | */ 86 | fun setLaunchTimes(launchTimes: Int): RateBottomSheetManager = 87 | apply { RateBottomSheetManager.launchTimes = launchTimes } 88 | 89 | /** 90 | * Set nb days to recall rate bottom sheet. 91 | * 2 days by default. 92 | * 93 | * @param remindInterval [Int] 94 | * @return [RateBottomSheetManager] 95 | */ 96 | fun setRemindInterval(remindInterval: Int): RateBottomSheetManager = 97 | apply { RateBottomSheetManager.remindInterval = remindInterval } 98 | 99 | /** 100 | * Display the first bottom sheet to filter users who like the app. 101 | * true by default. 102 | * 103 | * @param showAskBottomSheet [Boolean] 104 | * @return [RateBottomSheetManager] 105 | */ 106 | fun setShowAskBottomSheet(showAskBottomSheet: Boolean): RateBottomSheetManager = 107 | apply { RateBottomSheetManager.showAskBottomSheet = showAskBottomSheet } 108 | 109 | /** 110 | * Display the later button. 111 | * true by default. 112 | * 113 | * @param showLaterButton [Boolean] 114 | * @return [RateBottomSheetManager] 115 | */ 116 | fun setShowLaterButton(showLaterButton: Boolean): RateBottomSheetManager = 117 | apply { RateBottomSheetManager.showLaterButton = showLaterButton } 118 | 119 | /** 120 | * Display the close icon button on bottom sheet. 121 | * true by default. 122 | * 123 | * @param showCloseButtonIcon [Boolean] 124 | * @return [RateBottomSheetManager] 125 | */ 126 | fun setShowCloseButtonIcon(showCloseButtonIcon: Boolean): RateBottomSheetManager = 127 | apply { RateBottomSheetManager.showCloseButtonIcon = showCloseButtonIcon } 128 | 129 | /** 130 | * Enable debug mode to ignore conditions to show the rate bottom sheet. 131 | * false by default. 132 | * 133 | * @param debugForceOpenEnable [Boolean] 134 | * @return [RateBottomSheetManager] 135 | */ 136 | fun setDebugForceOpenEnable(debugForceOpenEnable: Boolean): RateBottomSheetManager = 137 | apply { RateBottomSheetManager.debugForceOpenEnable = debugForceOpenEnable } 138 | 139 | /** 140 | * Display logs to debug the conditions. 141 | * false by default. 142 | * 143 | * @param debugLogEnable [Boolean] 144 | * @return [RateBottomSheetManager] 145 | */ 146 | fun setDebugLogEnable(debugLogEnable: Boolean): RateBottomSheetManager = 147 | apply { RateBottomSheetManager.debugLogEnable = debugLogEnable } 148 | 149 | /** 150 | * Clear all data conditions: 151 | * installDays, cptLaunchTimes, isAgreeShowBottomSheet, remindInterval. 152 | * 153 | * @return [RateBottomSheetManager] 154 | */ 155 | fun clear(): RateBottomSheetManager = 156 | apply { preferenceHelper.clear() } 157 | 158 | /** 159 | * Record actions of users for the display conditions. 160 | */ 161 | fun monitor() { 162 | if (preferenceHelper.getInstallDays() == 0L) { 163 | preferenceHelper.setInstallDays() 164 | } 165 | preferenceHelper.setCptLaunchTimes() 166 | } 167 | //endregion 168 | 169 | //region UTILS 170 | private fun Long.isOverDate(threshold: Int): Boolean = 171 | Date().time - this >= threshold * 24 * 60 * 60 * 1000 172 | 173 | private fun Long.showOverCondition(threshold: Int): String = 174 | "${(Date().time - this) / (60 * 60 * 24 * 1000)} >= $threshold " + 175 | "-> ${Date().time} (now) - $this (condition) = ${Date().time - this} " + 176 | ">= ${threshold * 24 * 60 * 60 * 1000} (config)" 177 | //endregion 178 | 179 | } -------------------------------------------------------------------------------- /ratebottomsheet/src/main/res/drawable/close.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | -------------------------------------------------------------------------------- /ratebottomsheet/src/main/res/layout/rate_bottom_sheet_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 13 | 14 | 23 | 24 | 33 | 34 | 42 | 43 | 53 | 54 | 59 | 60 | 70 | 71 | 75 | 76 | 86 | 87 | 91 | 92 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /ratebottomsheet/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Like this App? 4 | Do you like using this application? 5 | Yes I do 6 | Not really 7 | 8 | Rate this app 9 | Would you mind taking a moment to rate it? It won\'t take more than a minute. Thanks for your support! 10 | Rate it now 11 | Remind me later 12 | No, thanks 13 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':ratebottomsheet-example', ':ratebottomsheet' --------------------------------------------------------------------------------