diff --git a/.gitignore b/.gitignore index dbf3ff1..846a4d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,7 @@ -# Created by https://www.toptal.com/developers/gitignore/api/android,androidstudio,linux,macos,windows -# Edit at https://www.toptal.com/developers/gitignore?templates=android,androidstudio,linux,macos,windows +# Created by https://www.toptal.com/developers/gitignore/api/windows,macos,jetbrains+all,android +# Edit at https://www.toptal.com/developers/gitignore?templates=windows,macos,jetbrains+all,android ### Android ### -# Built application files -*.apk -*.aar -*.ap_ -*.aab - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ -# Uncomment the following line in case you need and you don't have the release build type files in your app -# release/ - # Gradle files .gradle/ build/ @@ -28,90 +9,126 @@ build/ # Local configuration file (sdk path, etc) local.properties -# Proguard folder generated by Eclipse -proguard/ - -# Log Files +# Log/OS Files *.log -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder +# Android Studio generated files and folders captures/ +.externalNativeBuild/ +.cxx/ +*.apk +output.json # IntelliJ *.iml -.idea/workspace.xml -.idea/tasks.xml -.idea/gradle.xml -.idea/assetWizardSettings.xml -.idea/dictionaries -.idea/libraries -# Android Studio 3 in .gitignore file. -.idea/caches -.idea/modules.xml -# Comment next line if keeping position of elements in Navigation Editor is relevant for you -.idea/navEditor.xml -.idea/codeStyles -.idea/runConfigurations.xml -.idea/jarRepositories.xml +.idea/ +misc.xml +deploymentTargetDropDown.xml +render.experimental.xml # Keystore files -# Uncomment the following lines if you do not want to check your keystore files in. -#*.jks -#*.keystore - -# External native build folder generated in Android Studio 2.2 and later -.externalNativeBuild -.cxx/ +*.jks +*.keystore # Google Services (e.g. APIs or Firebase) -# google-services.json - -# Freeline -freeline.py -freeline/ -freeline_project_description.json - -# fastlane -fastlane/report.xml -fastlane/Preview.html -fastlane/screenshots -fastlane/test_output -fastlane/readme.md - -# Version control -vcs.xml - -# lint -lint/intermediates/ -lint/generated/ -lint/outputs/ -lint/tmp/ -# lint/reports/ +google-services.json + +# Android Profiling +*.hprof ### Android Patch ### gen-external-apklibs -output.json # Replacement of .externalNativeBuild directories introduced # with Android Studio 3.5. -### Linux ### -*~ +### JetBrains+all ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ -# temporary files which can be created if a process still has a handle open of a deleted file -.fuse_hidden* +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties -# KDE directory preferences -.directory +# Editor-based Rest Client +.idea/httpRequests -# Linux trash folder which might appear on any partition or disk -.Trash-* +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser -# .nfs files are created when an open file is removed but is still being accessed -.nfs* +### JetBrains+all Patch ### +# Ignore everything but code style settings and run configurations +# that are supposed to be shared within teams. + +.idea/* + +!.idea/codeStyles +!.idea/runConfigurations ### macOS ### # General @@ -122,6 +139,7 @@ output.json # Icon must end with two \r Icon + # Thumbnails ._* @@ -141,6 +159,10 @@ Network Trash Folder Temporary Items .apdisk +### macOS Patch ### +# iCloud generated files +*.icloud + ### Windows ### # Windows thumbnail cache files Thumbs.db @@ -167,105 +189,4 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk -### AndroidStudio ### -# Covers files to be ignored for android development using Android Studio. - -# Built application files - -# Files for the ART/Dalvik VM - -# Java class files - -# Generated files - -# Gradle files -.gradle - -# Signing files -.signing/ - -# Local configuration file (sdk path, etc) - -# Proguard folder generated by Eclipse - -# Log Files - -# Android Studio -/*/build/ -/*/local.properties -/*/out -/*/*/build -/*/*/production -*.ipr -*.swp - -# Android Patch - -# External native build folder generated in Android Studio 2.2 and later - -# NDK -obj/ - -# IntelliJ IDEA -*.iws -/out/ - -# User-specific configurations -.idea/caches/ -.idea/libraries/ -.idea/shelf/ -.idea/.name -.idea/compiler.xml -.idea/copyright/profiles_settings.xml -.idea/encodings.xml -.idea/misc.xml -.idea/scopes/scope_settings.xml -.idea/vcs.xml -.idea/jsLibraryMappings.xml -.idea/datasources.xml -.idea/dataSources.ids -.idea/sqlDataSources.xml -.idea/dynamic.xml -.idea/uiDesigner.xml - -# OS-specific files -.DS_Store? - -# Legacy Eclipse project files -.classpath -.project -.cproject -.settings/ - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.war -*.ear - -# virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) -hs_err_pid* - -## Plugin-specific files: - -# mpeltonen/sbt-idea plugin -.idea_modules/ - -# JIRA plugin -atlassian-ide-plugin.xml - -# Mongo Explorer plugin -.idea/mongoSettings.xml - -# Crashlytics plugin (for Android Studio and IntelliJ) -com_crashlytics_export_strings.xml -crashlytics.properties -crashlytics-build.properties -fabric.properties - -### AndroidStudio Patch ### - -!/gradle/wrapper/gradle-wrapper.jar - -# End of https://www.toptal.com/developers/gitignore/api/android,androidstudio,linux,macos,windows +# End of https://www.toptal.com/developers/gitignore/api/windows,macos,jetbrains+all,android \ No newline at end of file diff --git a/build.gradle b/build.gradle index 16bca34..aebfc8b 100755 --- a/build.gradle +++ b/build.gradle @@ -1,19 +1,14 @@ -// Top-level build file where you can add configuration options common to all sub-projects/modules. - buildscript { - ext.kotlin_version = '1.6.10' + ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() maven { url "https://plugins.gradle.org/m2/" } } dependencies { - classpath 'com.android.tools.build:gradle:7.3.0-alpha05' + classpath 'com.android.tools.build:gradle:7.2.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0" - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index f3d88b1..249e583 100755 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..ae04661 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 2fe81a7..a69d9cb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015-2021 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -17,78 +17,113 @@ # ############################################################################## -## -## Gradle start up script for UN*X -## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## # Attempt to set APP_HOME + # Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null + +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +APP_BASE_NAME=${0##*/} # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum warn () { echo "$*" -} +} >&2 die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false nonstop=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables - JAVACMD="$JAVA_HOME/jre/sh/java" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -97,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - JAVACMD="java" + JAVACMD=java which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the @@ -105,79 +140,101 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. # For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) fi - i=`expr $i + 1` + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index 24467a1..53a6b23 100755 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,10 +25,13 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -51,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -61,38 +64,26 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/indefinitepagerindicator/build.gradle b/indefinitepagerindicator/build.gradle index 710e971..3e1e20c 100755 --- a/indefinitepagerindicator/build.gradle +++ b/indefinitepagerindicator/build.gradle @@ -5,14 +5,13 @@ apply plugin: "org.jlleitschuh.gradle.ktlint" group = 'com.ryanjeffreybrooks.IndefinitePagerIndicator' android { - compileSdkVersion 32 - buildToolsVersion '30.0.3' + + compileSdkVersion 33 + buildToolsVersion '33.0.0' defaultConfig { minSdkVersion 16 - targetSdkVersion 32 - versionCode 1 - versionName "1.0" + targetSdkVersion 33 } buildFeatures { @@ -30,11 +29,9 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - - implementation 'androidx.annotation:annotation:1.3.0' - implementation 'androidx.appcompat:appcompat:1.4.1' - implementation 'androidx.core:core-ktx:1.7.0' + implementation 'androidx.annotation:annotation:1.4.0' + implementation 'androidx.appcompat:appcompat:1.4.2' + implementation 'androidx.core:core-ktx:1.8.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' implementation 'androidx.viewpager:viewpager:1.0.0' implementation 'androidx.viewpager2:viewpager2:1.0.0' diff --git a/indefinitepagerindicator/src/main/java/com/rbrooks/indefinitepagerindicator/IndefinitePagerIndicator.kt b/indefinitepagerindicator/src/main/java/com/rbrooks/indefinitepagerindicator/IndefinitePagerIndicator.kt index 60df11a..0392c52 100755 --- a/indefinitepagerindicator/src/main/java/com/rbrooks/indefinitepagerindicator/IndefinitePagerIndicator.kt +++ b/indefinitepagerindicator/src/main/java/com/rbrooks/indefinitepagerindicator/IndefinitePagerIndicator.kt @@ -1,8 +1,10 @@ package com.rbrooks.indefinitepagerindicator +import android.annotation.TargetApi import android.content.Context import android.graphics.Canvas import android.graphics.Paint +import android.os.Build import android.util.AttributeSet import android.util.DisplayMetrics import android.view.View @@ -16,22 +18,26 @@ import androidx.viewpager.widget.ViewPager import androidx.viewpager2.widget.ViewPager2 import kotlin.math.abs -class IndefinitePagerIndicator @JvmOverloads constructor( - context: Context, - attrs: AttributeSet? = null, - defStyle: Int = 0 -) : View(context, attrs, defStyle), ViewPager.OnPageChangeListener { - // region Members +class IndefinitePagerIndicator : View, ViewPager.OnPageChangeListener { - private companion object { - private const val DEFAULT_DOT_COUNT = 5 - private const val DEFAULT_FADING_DOT_COUNT = 1 - private const val DEFAULT_DOT_RADIUS_DP = 4 - private const val DEFAULT_SELECTED_DOT_RADIUS_DP = 5.5f - private const val DEFAULT_DOT_SEPARATION_DISTANCE_DP = 10 + constructor(context: Context?) : super(context) + + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) { + init(attrs ?: return) + } + + constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { + init(attrs ?: return, defStyleAttr) } + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) { + init(attrs ?: return, defStyleAttr, defStyleRes) + } + + // region Members + private var recyclerView: RecyclerView? = null private var viewPager: ViewPager? = null private var viewPager2: ViewPager2? = null @@ -64,8 +70,10 @@ class IndefinitePagerIndicator @JvmOverloads constructor( context, R.color.default_selected_dot_color ) - private var selectedDotPaint: Paint - private var dotPaint: Paint + + private var selectedDotPaint: Paint? = null + + private var dotPaint: Paint? = null /** * The current pager position. Used to draw the selected dot if different size/color. @@ -87,50 +95,30 @@ class IndefinitePagerIndicator @JvmOverloads constructor( // region Constructor - init { - attrs?.let { - val typedArray = context.theme.obtainStyledAttributes( - attrs, - R.styleable.IndefinitePagerIndicator, - 0, - 0 - ) - dotCount = typedArray.getInteger( - R.styleable.IndefinitePagerIndicator_dotCount, - DEFAULT_DOT_COUNT - ) - fadingDotCount = typedArray.getInt( - R.styleable.IndefinitePagerIndicator_fadingDotCount, - DEFAULT_FADING_DOT_COUNT - ) - dotRadiusPx = typedArray.getDimensionPixelSize( - R.styleable.IndefinitePagerIndicator_dotRadius, - dotRadiusPx - ) - selectedDotRadiusPx = typedArray.getDimensionPixelSize( - R.styleable.IndefinitePagerIndicator_selectedDotRadius, - selectedDotRadiusPx - ) - dotColor = typedArray.getColor( - R.styleable.IndefinitePagerIndicator_dotColor, - dotColor - ) - selectedDotColor = typedArray.getColor( - R.styleable.IndefinitePagerIndicator_selectedDotColor, - selectedDotColor - ) - dotSeparationDistancePx = typedArray.getDimensionPixelSize( - R.styleable.IndefinitePagerIndicator_dotSeparation, - dotSeparationDistancePx - ) - supportRtl = typedArray.getBoolean( - R.styleable.IndefinitePagerIndicator_supportRTL, - false - ) - verticalSupport = typedArray.getBoolean( - R.styleable.IndefinitePagerIndicator_verticalSupport, - false - ) + private fun init(attrs: AttributeSet, defStyleAttr: Int = 0, defStyleRes: Int = 0) { + + val typedArray = context.theme.obtainStyledAttributes( + attrs, + R.styleable.IndefinitePagerIndicator, + defStyleAttr, + defStyleRes + ) + try { + with(typedArray) { + dotCount = getInteger(R.styleable.IndefinitePagerIndicator_dotCount, DEFAULT_DOT_COUNT) + fadingDotCount = getInt(R.styleable.IndefinitePagerIndicator_fadingDotCount, DEFAULT_FADING_DOT_COUNT) + dotRadiusPx = getDimensionPixelSize(R.styleable.IndefinitePagerIndicator_dotRadius, dotRadiusPx) + selectedDotRadiusPx = getDimensionPixelSize(R.styleable.IndefinitePagerIndicator_selectedDotRadius, selectedDotRadiusPx) + dotColor = getColor(R.styleable.IndefinitePagerIndicator_dotColor, dotColor) + selectedDotColor = getColor(R.styleable.IndefinitePagerIndicator_selectedDotColor, selectedDotColor) + dotSeparationDistancePx = getDimensionPixelSize(R.styleable.IndefinitePagerIndicator_dotSeparation, dotSeparationDistancePx) + supportRtl = getBoolean(R.styleable.IndefinitePagerIndicator_supportRTL, false) + verticalSupport = getBoolean(R.styleable.IndefinitePagerIndicator_verticalSupport, false) + } + } catch (e: Exception) { + e.printStackTrace() + } finally { + // don't forget to recycle typed attributes typedArray.recycle() } @@ -143,9 +131,10 @@ class IndefinitePagerIndicator @JvmOverloads constructor( ) } - // endregion - // region View +// endregion + +// region View override fun onDraw(canvas: Canvas) { super.onDraw(canvas) @@ -181,9 +170,9 @@ class IndefinitePagerIndicator @JvmOverloads constructor( } } - // endregion +// endregion - // region Public Api +// region Public Api fun attachToRecyclerView(recyclerView: RecyclerView?) { removeAllSources() @@ -215,7 +204,7 @@ class IndefinitePagerIndicator @JvmOverloads constructor( this.viewPager2?.registerOnPageChangeCallback(it) } - selectedItemPosition = this.viewPager2?.currentItem ?: 0 + selectedItemPosition = viewPager2.currentItem } fun setDotCount(count: Int) { @@ -228,24 +217,18 @@ class IndefinitePagerIndicator @JvmOverloads constructor( invalidate() } - fun setSelectedDotRadius(radius: Int) { - selectedDotRadiusPx = dpToPx( - dp = radius.toFloat() - ) + fun setSelectedDotRadius(radius: Float) { + selectedDotRadiusPx = dpToPx(dp = radius) invalidate() } - fun setDotRadius(radius: Int) { - dotRadiusPx = dpToPx( - dp = radius.toFloat() - ) + fun setDotRadius(radius: Float) { + dotRadiusPx = dpToPx(dp = radius) invalidate() } - fun setDotSeparationDistance(distance: Int) { - dotSeparationDistancePx = dpToPx( - dp = distance.toFloat() - ) + fun setDotSeparationDistance(distance: Float) { + dotSeparationDistancePx = dpToPx(dp = distance) invalidate() } @@ -261,19 +244,19 @@ class IndefinitePagerIndicator @JvmOverloads constructor( fun setDotColor(@ColorInt newDotColor: Int) { dotColor = newDotColor - dotPaint.color = dotColor + dotPaint?.color = dotColor invalidate() } fun setSelectedDotColor(@ColorInt newSelectedDotColor: Int) { selectedDotColor = newSelectedDotColor - selectedDotPaint.color = selectedDotColor + selectedDotPaint?.color = selectedDotColor invalidate() } - // endregion +// endregion - // region Private Api +// region Private Api private fun getDefaultPaintConfig( defaultStyle: Paint.Style = Paint.Style.FILL, @@ -300,7 +283,7 @@ class IndefinitePagerIndicator @JvmOverloads constructor( private fun getDotCoordinate(position: Int): Float = (position - intermediateSelectedItemPosition) * getDistanceBetweenTheCenterOfTwoDots() + - (getDistanceBetweenTheCenterOfTwoDots() * offsetPercent) + (getDistanceBetweenTheCenterOfTwoDots() * offsetPercent) /** * Get the y coordinate for a dot. @@ -337,7 +320,7 @@ class IndefinitePagerIndicator @JvmOverloads constructor( else -> { // Determine how close the dot is to the edge of the view for scaling the size of the dot val percentTowardsEdge = (coordinateAbs - largeDotThreshold) / - (getCalculatedWidth() / 2.01f - largeDotThreshold) + (getCalculatedWidth() / 2.01f - largeDotThreshold) interpolator.getInterpolation(1 - percentTowardsEdge) * dotRadiusPx } } @@ -351,8 +334,12 @@ class IndefinitePagerIndicator @JvmOverloads constructor( * All other dots will be the normal specified dot color. */ private fun getPaint(coordinate: Float): Paint = when { - abs(coordinate) < getDistanceBetweenTheCenterOfTwoDots() / 2 -> selectedDotPaint - else -> dotPaint + abs(coordinate) < getDistanceBetweenTheCenterOfTwoDots() / 2 -> selectedDotPaint ?: getDefaultPaintConfig( + defaultColor = selectedDotColor + ) + else -> dotPaint ?: getDefaultPaintConfig( + defaultColor = dotColor + ) } /** @@ -397,9 +384,9 @@ class IndefinitePagerIndicator @JvmOverloads constructor( private fun getRTLPosition(position: Int) = getItemCount() - position - 1 - // endregion +// endregion - // region Listeners +// region Listeners override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) { if (supportRtl && isRtl()) { @@ -482,7 +469,10 @@ class IndefinitePagerIndicator @JvmOverloads constructor( private fun getMostVisibleChild(): View? { var mostVisibleChild: View? = null var mostVisibleChildPercent = 0f - for (i in recyclerView?.layoutManager?.childCount!! - 1 downTo 0) { + + val childCount = recyclerView?.layoutManager?.childCount ?: return null + + for (i in childCount - 1 downTo 0) { val child = recyclerView?.layoutManager?.getChildAt(i) if (child != null) { val percentVisible = calculatePercentVisible( @@ -511,7 +501,9 @@ class IndefinitePagerIndicator @JvmOverloads constructor( } private fun setIntermediateSelectedItemPosition(mostVisibleChild: View) { - recyclerView?.findContainingViewHolder(mostVisibleChild)?.bindingAdapterPosition + recyclerView + ?.findContainingViewHolder(mostVisibleChild) + ?.bindingAdapterPosition ?.let { position -> intermediateSelectedItemPosition = if (isRtl() && !verticalSupport) { getRTLPosition( @@ -543,5 +535,13 @@ class IndefinitePagerIndicator @JvmOverloads constructor( } } - // endregion +// endregion + + private companion object { + private const val DEFAULT_DOT_COUNT = 5 + private const val DEFAULT_FADING_DOT_COUNT = 1 + private const val DEFAULT_DOT_RADIUS_DP = 4 + private const val DEFAULT_SELECTED_DOT_RADIUS_DP = 5.5f + private const val DEFAULT_DOT_SEPARATION_DISTANCE_DP = 10 + } } diff --git a/sample/build.gradle b/sample/build.gradle index fa34d16..2c91fa1 100755 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -2,13 +2,13 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { - compileSdkVersion 32 - buildToolsVersion '30.0.3' + compileSdkVersion 33 + buildToolsVersion '33.0.0' defaultConfig { applicationId "com.rbrooks.infinitepageindicator" minSdkVersion 16 - targetSdkVersion 32 + targetSdkVersion 33 versionCode 1 versionName "1.0" } @@ -24,7 +24,7 @@ android { } buildFeatures { - viewBinding = true + viewBinding true } compileOptions { @@ -38,14 +38,13 @@ android { } dependencies { - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" + + // Library dependency + implementation project(':indefinitepagerindicator') // Support libs - implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'androidx.appcompat:appcompat:1.4.2' implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.recyclerview:recyclerview:1.2.1' - implementation 'com.google.android.material:material:1.5.0' - - // Library dependency - implementation project(':indefinitepagerindicator') + implementation 'com.google.android.material:material:1.6.1' } diff --git a/sample/src/main/java/com/rbrooks/indefinitepagerindicatorsample/viewPagerSample/ViewPagerSampleFragment.kt b/sample/src/main/java/com/rbrooks/indefinitepagerindicatorsample/viewPagerSample/ViewPagerSampleFragment.kt index da0ec53..3b83608 100755 --- a/sample/src/main/java/com/rbrooks/indefinitepagerindicatorsample/viewPagerSample/ViewPagerSampleFragment.kt +++ b/sample/src/main/java/com/rbrooks/indefinitepagerindicatorsample/viewPagerSample/ViewPagerSampleFragment.kt @@ -67,9 +67,9 @@ class ViewPagerSampleFragment : Fragment(), OnPagerNumberChangeListener, View.On R.color.colorCrazyHappy ) ) - setDotSeparationDistance(distance = 50) - setDotRadius(radius = 10) - setSelectedDotRadius(radius = 15) + setDotSeparationDistance(distance = 50f) + setDotRadius(radius = 10f) + setSelectedDotRadius(radius = 15f) setFadingDotCount(2) }