diff --git a/build.gradle b/build.gradle index 6038229b..7a5a7fa7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,19 @@ buildscript { - ext.kotlin_version = '1.7.20' - ext.core_ktx_version = '1.9.0' repositories { google() mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' - classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.android.tools.build:gradle:8.11.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22" } } ext { sdk = [ - compileSdk: 33, + compileSdk: 36, targetSdk : 33, - minSdk : 21 + minSdk : 29 ] } @@ -29,4 +27,4 @@ allprojects { tasks.register("clean", Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index e77c8538..70594b51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,7 @@ # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.nonFinalResIds=false +android.nonTransitiveRClass=false android.useAndroidX=true -org.gradle.jvmargs=-XX:MaxMetaspaceSize=1g -org.gradle.jvmargs=-Xmx2g +org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=1g diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 13372aef..2c352119 100644 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 14e92a46..d4081da4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Sun Feb 14 17:02:05 WIB 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip diff --git a/gradlew b/gradlew index 9d82f789..f5feea6d 100755 --- a/gradlew +++ b/gradlew @@ -1,74 +1,130 @@ -#!/usr/bin/env bash +#!/bin/sh + +# +# 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. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## 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/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +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 -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +MAX_FD=maximum -warn ( ) { +warn () { echo "$*" -} +} >&2 -die ( ) { +die () { echo echo "$*" echo exit 1 -} +} >&2 # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false -case "`uname`" in - CYGWIN* ) - cygwin=true - ;; - Darwin* ) - darwin=true - ;; - MINGW* ) - msys=true - ;; +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; esac -# 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 -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - 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 @@ -77,84 +133,120 @@ Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else - 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. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + 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 location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "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*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + 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" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; 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 # 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=$((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 -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") -} -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +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. +# + +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 8a0b282a..9d21a218 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,4 +1,22 @@ -@if "%DEBUG%" == "" @echo off +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -8,26 +26,30 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@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= - set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused 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" + @rem Find java.exe 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. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -35,54 +57,36 @@ 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% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail -:init -@rem Get command-line arguments, handling Windowz variants - -if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_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=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -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/imagepicker/build.gradle b/imagepicker/build.gradle index 1921b3c9..568ec736 100644 --- a/imagepicker/build.gradle +++ b/imagepicker/build.gradle @@ -2,6 +2,7 @@ plugins { id "com.android.library" id "kotlin-android" id "kotlin-parcelize" + id "maven-publish" } android { @@ -15,6 +16,7 @@ android { } buildFeatures { + buildConfig true viewBinding true } @@ -40,28 +42,29 @@ android { } } + kotlinOptions { + jvmTarget = JavaVersion.VERSION_1_8.toString() + } + resourcePrefix "ef_" namespace 'com.esafirm.imagepicker' } -tasks.register("sourcesJar", Jar) { - from android.sourceSets.main.java.srcDirs - archiveClassifier.set('sources') -} - -artifacts { - archives sourcesJar +afterEvaluate { + publishing { + publications { + maven(MavenPublication) { + from components.release + } + } + } } dependencies { - implementation "com.github.bumptech.glide:glide:4.14.2" - implementation 'androidx.recyclerview:recyclerview:1.2.1' - - implementation 'androidx.appcompat:appcompat:1.5.1' + implementation "com.github.bumptech.glide:glide:4.16.0" + implementation 'androidx.recyclerview:recyclerview:1.4.0' - implementation "androidx.core:core-ktx:$core_ktx_version" + implementation 'androidx.appcompat:appcompat:1.7.1' - testImplementation platform("org.junit:junit-bom:5.9.1") - testImplementation "org.junit.jupiter:junit-jupiter" - testImplementation 'com.natpryce:hamkrest:1.8.0.1' + implementation "androidx.core:core-ktx:1.16.0" } diff --git a/imagepicker/jitpack.yml b/imagepicker/jitpack.yml new file mode 100644 index 00000000..1e41e00b --- /dev/null +++ b/imagepicker/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 \ No newline at end of file diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/adapter/ImagePickerAdapter.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/adapter/ImagePickerAdapter.kt index 60585429..dfc606f5 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/adapter/ImagePickerAdapter.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/adapter/ImagePickerAdapter.kt @@ -20,6 +20,7 @@ import com.esafirm.imagepicker.helper.diff.SimpleDiffUtilCallBack import com.esafirm.imagepicker.listeners.OnImageClickListener import com.esafirm.imagepicker.listeners.OnImageSelectedListener import com.esafirm.imagepicker.model.Image +import kotlin.math.min class ImagePickerAdapter( context: Context, @@ -130,6 +131,20 @@ class ImagePickerAdapter( } } + fun selectAll(limit: Int) { + mutateSelection { + selectedImages.clear() + val itemCount = min(limit, this.itemCount) + for (i in 0 until itemCount) { + val image = this.getItem(i) + if (image != null) { + selectedImages.add(image) + } + } + notifyDataSetChanged() + } + } + private fun mutateSelection(runnable: Runnable) { runnable.run() imageSelectedListener?.invoke(selectedImages) @@ -147,4 +162,4 @@ class ImagePickerAdapter( val fileTypeIndicator = binding.efItemFileTypeIndicator val container = binding.root as FrameLayout } -} \ No newline at end of file +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerActivity.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerActivity.kt index 8ece339f..672fc26d 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerActivity.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerActivity.kt @@ -4,9 +4,12 @@ import android.app.Activity import android.content.Context import android.content.Intent import android.graphics.PorterDuff +import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem +import android.view.WindowInsets +import androidx.activity.addCallback import androidx.activity.result.ActivityResult import androidx.activity.result.contract.ActivityResultContracts import androidx.appcompat.app.ActionBar @@ -19,6 +22,8 @@ import com.esafirm.imagepicker.helper.ImagePickerUtils import com.esafirm.imagepicker.helper.IpCrasher import com.esafirm.imagepicker.helper.LocaleManager import com.esafirm.imagepicker.helper.ViewUtils +import com.esafirm.imagepicker.helper.getColorPrimary +import com.esafirm.imagepicker.helper.isActionBarEnabled import com.esafirm.imagepicker.model.Image class ImagePickerActivity : AppCompatActivity(), ImagePickerInteractionListener { @@ -91,6 +96,28 @@ class ImagePickerActivity : AppCompatActivity(), ImagePickerInteractionListener ft.replace(R.id.ef_imagepicker_fragment_placeholder, imagePickerFragment) ft.commit() } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) { // Android 15+ + window.decorView.setOnApplyWindowInsetsListener { view, insets -> + view.setBackgroundColor(this.getColorPrimary()) + // Adjust padding to avoid overlap + if (!isActionBarEnabled()) { + val systemBarsInsets = insets.getInsets(WindowInsets.Type.systemBars()) + view.setPadding(0, systemBarsInsets.top, 0, systemBarsInsets.bottom) + } + insets + } + } + + onBackPressedDispatcher.addCallback(this) { + if (this@ImagePickerActivity::imagePickerFragment.isInitialized) { + if (!imagePickerFragment.handleBack()) { + finish() + } + } else { + finish() + } + } } /** @@ -108,6 +135,10 @@ class ImagePickerActivity : AppCompatActivity(), ImagePickerInteractionListener title = ConfigUtils.getDoneButtonText(this@ImagePickerActivity, config!!) isVisible = imagePickerFragment.isShowDoneButton } + menu.findItem(R.id.menu_select_all).apply { + title = ConfigUtils.getAllButtonText(this@ImagePickerActivity, config!!) + isVisible = imagePickerFragment.isShowAllButton + } } return super.onPrepareOptionsMenu(menu) } @@ -118,13 +149,17 @@ class ImagePickerActivity : AppCompatActivity(), ImagePickerInteractionListener override fun onOptionsItemSelected(item: MenuItem): Boolean { val id = item.itemId if (id == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } if (id == R.id.menu_done) { imagePickerFragment.onDone() return true } + if (id == R.id.menu_select_all) { + imagePickerFragment.onSelectAll() + return true + } if (id == R.id.menu_camera) { imagePickerFragment.captureImage() return true @@ -132,16 +167,6 @@ class ImagePickerActivity : AppCompatActivity(), ImagePickerInteractionListener return super.onOptionsItemSelected(item) } - override fun onBackPressed() { - if (this::imagePickerFragment.isInitialized) { - if (!imagePickerFragment.handleBack()) { - super.onBackPressed() - } - } else { - super.onBackPressed() - } - } - private fun setupView(config: ImagePickerConfig) { val toolbar = findViewById(R.id.toolbar) setSupportActionBar(toolbar) diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.kt index 2e266a41..01c55270 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerConfig.kt @@ -15,6 +15,7 @@ class ImagePickerConfig( var folderTitle: String? = null, var imageTitle: String? = null, var doneButtonText: String? = null, + var allButtonText: String? = null, var arrowColor: Int = NO_COLOR, var limit: Int = IpCons.MAX_LIMIT, @StyleRes var theme: Int = 0, @@ -28,7 +29,8 @@ class ImagePickerConfig( override var savePath: ImagePickerSavePath = ImagePickerSavePath.DEFAULT, override var returnMode: ReturnMode = ReturnMode.NONE, override var isSaveImage: Boolean = true, - var showDoneButtonAlways: Boolean = false + var showDoneButtonAlways: Boolean = false, + var showAllButton: Boolean = false, ) : BaseConfig(), Parcelable { @IgnoredOnParcel @@ -52,4 +54,4 @@ fun ImagePickerConfig.enableLog(isEnable: Boolean) { IpLogger.setEnable(isEnable) } -fun List.toFiles() = this.map { File(it.path) } \ No newline at end of file +fun List.toFiles() = this.map { File(it.path) } diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerFragment.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerFragment.kt index b6eda312..2cf435f0 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerFragment.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/ImagePickerFragment.kt @@ -49,8 +49,12 @@ class ImagePickerFragment : Fragment() { private val permissions: Array by lazy { when { - Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> - arrayOf(Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO) + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> { + if (config.isIncludeVideo) + arrayOf(Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO) + else + arrayOf(Manifest.permission.READ_MEDIA_IMAGES) + } Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || Environment.isExternalStorageLegacy() -> arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE) @@ -247,6 +251,14 @@ class ImagePickerFragment : Fragment() { presenter.onDoneSelectImages(recyclerViewManager.selectedImages, config) } + /** + * On select all images clicked + * Select all images in the current folder + */ + fun onSelectAll() { + recyclerViewManager.selectAllImages() + } + /** * Config recyclerView when configuration changed */ @@ -355,6 +367,9 @@ class ImagePickerFragment : Fragment() { val isShowDoneButton: Boolean get() = recyclerViewManager.isShowDoneButton + val isShowAllButton: Boolean + get() = recyclerViewManager.isShowAllButton + override fun onAttach(context: Context) { super.onAttach(context) if (context is ImagePickerInteractionListener) { diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/fileloader/DefaultImageFileLoader.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/features/fileloader/DefaultImageFileLoader.kt index bd5ea4d0..89b8c207 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/fileloader/DefaultImageFileLoader.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/fileloader/DefaultImageFileLoader.kt @@ -79,13 +79,14 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader { MediaStore.Images.Media._ID, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATA, - MediaStore.Images.Media.BUCKET_DISPLAY_NAME + MediaStore.Images.Media.BUCKET_DISPLAY_NAME, + MediaStore.Images.Media.MIME_TYPE, ) @SuppressLint("InlinedApi") private fun queryData(limit: Int? = null): Cursor? { val useNewApi = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q - val sourceUri = if (limit != null && useNewApi) { + val sourceUri = if (limit != null && !useNewApi) { getSourceUri().buildUpon() .appendQueryParameter(QUERY_LIMIT, limit.toString()) .build() @@ -127,9 +128,7 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader { return context.contentResolver.query(sourceUri, projection, args, null) } - val sortOrder = "${MediaStore.Images.Media.DATE_MODIFIED} DESC".let { - if (limit != null) "$it LIMIT $limit" else it - } + val sortOrder = "${MediaStore.Images.Media.DATE_MODIFIED} DESC" return context.contentResolver.query( sourceUri, projection, @@ -155,9 +154,10 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader { val id = cursor.getLong(cursor.getColumnIndex(projection[0])) val name = cursor.getString(cursor.getColumnIndex(projection[1])) + val mimeType = cursor.getString(cursor.getColumnIndex(projection[4])) if (name != null) { - return Image(id, name, path) + return Image(id, name, path, mimeType) } return null } @@ -201,7 +201,7 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader { cursor.close() val folders = folderMap.values.toList() - listener.onImageLoaded(result, folders) + listener.onImageLoaded(result, folders.sortedBy { it.folderName }) } override fun run() { @@ -227,4 +227,4 @@ class DefaultImageFileLoader(private val context: Context) : ImageFileLoader { } } } -} \ No newline at end of file +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/features/recyclers/RecyclerViewManager.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/features/recyclers/RecyclerViewManager.kt index 94122a74..bdc28611 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/features/recyclers/RecyclerViewManager.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/features/recyclers/RecyclerViewManager.kt @@ -21,6 +21,7 @@ import com.esafirm.imagepicker.listeners.OnImageSelectedListener import com.esafirm.imagepicker.model.Folder import com.esafirm.imagepicker.model.Image import com.esafirm.imagepicker.view.GridSpacingItemDecoration +import java.lang.Integer.min class RecyclerViewManager( private val recyclerView: RecyclerView, @@ -196,9 +197,19 @@ class RecyclerViewManager( return true } + fun selectAllImages() { + if (imageAdapter.selectedImages.size == min(config.limit, imageAdapter.itemCount)) { + imageAdapter.removeAllSelectedSingleClick() + } else { + imageAdapter.selectAll(config.limit) + } + } + val isShowDoneButton: Boolean get() = (!isDisplayingFolderView && (imageAdapter.selectedImages.isNotEmpty() || config.showDoneButtonAlways) && config.returnMode !== ReturnMode.ALL && config.returnMode !== ReturnMode.GALLERY_ONLY) -} \ No newline at end of file + val isShowAllButton: Boolean + get() = (!isDisplayingFolderView && config.showAllButton && config.mode == ImagePickerMode.MULTIPLE) +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ConfigUtils.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ConfigUtils.kt index fb9c21be..6ac68d56 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ConfigUtils.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ConfigUtils.kt @@ -40,4 +40,9 @@ object ConfigUtils { val doneButtonText = config.doneButtonText return if (doneButtonText.isNullOrBlank()) context.getString(R.string.ef_done) else doneButtonText } -} \ No newline at end of file + + fun getAllButtonText(context: Context, config: ImagePickerConfig): String { + val allButtonText = config.allButtonText + return if (allButtonText.isNullOrBlank()) context.getString(R.string.ef_all) else allButtonText + } +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ImagePickerUtils.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ImagePickerUtils.kt index 807585a2..c12da78b 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ImagePickerUtils.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ImagePickerUtils.kt @@ -97,13 +97,16 @@ object ImagePickerUtils { } fun isVideoFormat(image: Image): Boolean { - val extension = getExtension(image.path) - val mimeType = - if (TextUtils.isEmpty(extension)) URLConnection.guessContentTypeFromName(image.path) else MimeTypeMap.getSingleton() - .getMimeTypeFromExtension(extension) + val mimeType = getMimeType(image.path) return mimeType != null && mimeType.startsWith("video") } + fun getMimeType(path: String): String? { + val extension = getExtension(path) + return if (TextUtils.isEmpty(extension)) URLConnection.guessContentTypeFromName(path) else MimeTypeMap.getSingleton() + .getMimeTypeFromExtension(extension) + } + fun getVideoDurationLabel(context: Context?, uri: Uri): String { try { val retriever = MediaMetadataRetriever() @@ -145,4 +148,4 @@ object ImagePickerUtils { data.putParcelableArrayListExtra(IpCons.EXTRA_SELECTED_IMAGES, imageArrayList) return data } -} \ No newline at end of file +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ViewUtils.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ViewUtils.kt index fde43e33..cb528031 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ViewUtils.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/helper/ViewUtils.kt @@ -2,20 +2,44 @@ package com.esafirm.imagepicker.helper import android.content.Context import android.graphics.drawable.Drawable -import android.os.Build +import android.util.TypedValue import android.view.View import androidx.core.content.ContextCompat import com.esafirm.imagepicker.R object ViewUtils { fun getArrowIcon(context: Context): Drawable? { - val backResourceId: Int = if (context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) { - // For right-to-left layouts, pick the drawable that points to the right (forward). - R.drawable.ef_ic_arrow_forward + val backResourceId: Int = + if (context.resources.configuration.layoutDirection == View.LAYOUT_DIRECTION_RTL) { + // For right-to-left layouts, pick the drawable that points to the right (forward). + R.drawable.ef_ic_arrow_forward + } else { + // For left-to-right layouts, pick the drawable that points to the left (back). + R.drawable.ef_ic_arrow_back + } + return ContextCompat.getDrawable(context.applicationContext, backResourceId) + } +} + + +fun Context.getColorPrimary(): Int { + val typedValue = TypedValue() + val theme = this.theme + val resolved = theme.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, typedValue, true) + return if (resolved) { + if (typedValue.resourceId != 0) { + ContextCompat.getColor(this, typedValue.resourceId) } else { - // For left-to-right layouts, pick the drawable that points to the left (back). - R.drawable.ef_ic_arrow_back + typedValue.data } - return ContextCompat.getDrawable(context.applicationContext, backResourceId) + } else { + return 0 } } + +fun Context.isActionBarEnabled(): Boolean { + val typedValue = TypedValue() + val hasAttribute = + theme.resolveAttribute(androidx.appcompat.R.attr.windowActionBar, typedValue, true) + return hasAttribute && typedValue.data != 0 +} \ No newline at end of file diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/model/Image.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/model/Image.kt index 44631615..b2d36b01 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/model/Image.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/model/Image.kt @@ -13,6 +13,7 @@ class Image( val id: Long, val name: String, val path: String, + val mimeType: String?, ) : Parcelable { @IgnoredOnParcel @@ -49,6 +50,7 @@ class Image( result = 31 * result + name.hashCode() result = 31 * result + path.hashCode() result = 31 * result + (uriHolder?.hashCode() ?: 0) + result = 31 * result + (mimeType?.hashCode() ?: 0) return result } -} \ No newline at end of file +} diff --git a/imagepicker/src/main/java/com/esafirm/imagepicker/model/ImageFactory.kt b/imagepicker/src/main/java/com/esafirm/imagepicker/model/ImageFactory.kt index dbdff603..2d896408 100644 --- a/imagepicker/src/main/java/com/esafirm/imagepicker/model/ImageFactory.kt +++ b/imagepicker/src/main/java/com/esafirm/imagepicker/model/ImageFactory.kt @@ -10,7 +10,8 @@ object ImageFactory { return listOf(Image( id = ContentUris.parseId(uri), name = ImagePickerUtils.getNameFromFilePath(path), - path = path + path = path, + mimeType = ImagePickerUtils.getMimeType(path), )) } -} \ No newline at end of file +} diff --git a/imagepicker/src/main/res/menu/ef_image_picker_menu_main.xml b/imagepicker/src/main/res/menu/ef_image_picker_menu_main.xml index a0535829..5d54e70c 100644 --- a/imagepicker/src/main/res/menu/ef_image_picker_menu_main.xml +++ b/imagepicker/src/main/res/menu/ef_image_picker_menu_main.xml @@ -9,6 +9,10 @@ app:showAsAction="always" tools:ignore="AlwaysShowAction" /> + عليك إعطاء التطبيق الصلاحية لاستخدام الصور عليك إعطاء التطبيق الصلاحية لاستخدام الكاميرا لتتمكن من التصوير تحديد إختيار الصور + الجميع diff --git a/imagepicker/src/main/res/values-ca/strings.xml b/imagepicker/src/main/res/values-ca/strings.xml index 5dbc994f..d9aa8dd5 100644 --- a/imagepicker/src/main/res/values-ca/strings.xml +++ b/imagepicker/src/main/res/values-ca/strings.xml @@ -25,5 +25,6 @@ GIF Folder Image + Tot diff --git a/imagepicker/src/main/res/values-da/strings.xml b/imagepicker/src/main/res/values-da/strings.xml index 1955e0fd..b8b6d203 100644 --- a/imagepicker/src/main/res/values-da/strings.xml +++ b/imagepicker/src/main/res/values-da/strings.xml @@ -26,5 +26,6 @@ GIF Folder Image + Alle - \ No newline at end of file + diff --git a/imagepicker/src/main/res/values-de/strings.xml b/imagepicker/src/main/res/values-de/strings.xml index f3d51ffc..944a3cb1 100644 --- a/imagepicker/src/main/res/values-de/strings.xml +++ b/imagepicker/src/main/res/values-de/strings.xml @@ -26,5 +26,6 @@ GIF Folder Image + Alle diff --git a/imagepicker/src/main/res/values-es-rES/strings.xml b/imagepicker/src/main/res/values-es-rES/strings.xml index 81f33617..de468779 100644 --- a/imagepicker/src/main/res/values-es-rES/strings.xml +++ b/imagepicker/src/main/res/values-es-rES/strings.xml @@ -25,5 +25,6 @@ GIF Folder Image + Todas diff --git a/imagepicker/src/main/res/values-fr/strings.xml b/imagepicker/src/main/res/values-fr/strings.xml index 90a7407a..61818ffb 100644 --- a/imagepicker/src/main/res/values-fr/strings.xml +++ b/imagepicker/src/main/res/values-fr/strings.xml @@ -24,5 +24,6 @@ GIF + Tout diff --git a/imagepicker/src/main/res/values-in/strings.xml b/imagepicker/src/main/res/values-in/strings.xml index 5a4806fe..1bcb298e 100644 --- a/imagepicker/src/main/res/values-in/strings.xml +++ b/imagepicker/src/main/res/values-in/strings.xml @@ -21,4 +21,5 @@ Mohon berikan izin terhadap penyimpanan untuk memilih gambar Mohon berikan izin terhadap kamera untuk mengambil gambar Gambar yang terpilih sudah mencapai batas maksimal + Semua diff --git a/imagepicker/src/main/res/values-it/strings.xml b/imagepicker/src/main/res/values-it/strings.xml index 6db39f2a..ae46f361 100644 --- a/imagepicker/src/main/res/values-it/strings.xml +++ b/imagepicker/src/main/res/values-it/strings.xml @@ -21,5 +21,6 @@ Dai il permesso per poter scattare una foto Hai raggiunto il limite massimo di selezione Permesso negato + Tutto diff --git a/imagepicker/src/main/res/values-ja/strings.xml b/imagepicker/src/main/res/values-ja/strings.xml index c4a31679..e0a1d525 100644 --- a/imagepicker/src/main/res/values-ja/strings.xml +++ b/imagepicker/src/main/res/values-ja/strings.xml @@ -20,5 +20,6 @@ 端末のカメラへのアクセスを許可してください 選択できる画像の上限です 権限がありません + 全て diff --git a/imagepicker/src/main/res/values-ko/strings.xml b/imagepicker/src/main/res/values-ko/strings.xml index db37f48b..594d3c69 100644 --- a/imagepicker/src/main/res/values-ko/strings.xml +++ b/imagepicker/src/main/res/values-ko/strings.xml @@ -21,5 +21,6 @@ 이미지를 불러오기 위해 저장공간 권한을 허용해주세요 사진을 찍기위해 카메라 권한을 허용해주세요 이미지 선택 제한 초과 + 모두 diff --git a/imagepicker/src/main/res/values-nl/strings.xml b/imagepicker/src/main/res/values-nl/strings.xml new file mode 100644 index 00000000..57e8125d --- /dev/null +++ b/imagepicker/src/main/res/values-nl/strings.xml @@ -0,0 +1,33 @@ + + + Geef toegang tot externe opslag om afbeeldingen te + selecteren + + + OK + KLAAR + CAMERA + + Album + Tik om afbeeldingen te selecteren + Geen toestemming + + %d geselecteerd + %1$d/%2$d geselecteerd + + Kan afbeeldingsbestand niet maken + Geen camera gevonden + Oeps! Er is iets misgegaan! + + Geen afbeeldingen gevonden + Geef toestemming voor opslag om afbeeldingen te selecteren + Bitte erlaube Zugriff auf die Kamera um Bilder aufzunehmen + Limiet afbeeldingsselectie + + + GIF + Folder + Image + Alle + + diff --git a/imagepicker/src/main/res/values-pl/strings.xml b/imagepicker/src/main/res/values-pl/strings.xml new file mode 100644 index 00000000..61bdd614 --- /dev/null +++ b/imagepicker/src/main/res/values-pl/strings.xml @@ -0,0 +1,22 @@ + + + Zezwól na dostęp do pamięci wybranych obrazów + ОК + OK + APARAT + Album + Dotknij, aby wybrać obrazy + Nie ma dostępu + %d wybrane + %1$d/%2$d wybrane + Nie udało się utworzyć plik + Aparat nie jest dostępny + Coś nie działa! + Brak zdjęć + Zezwól na przechowywanie wybranych obrazów + Aby móc robić zdjęcia, musisz zezwolić aplikacji na korzystanie z + aparatu + + Limit wyboru obrazu + Wszystkie + diff --git a/imagepicker/src/main/res/values-pt-rBR/strings.xml b/imagepicker/src/main/res/values-pt-rBR/strings.xml index 02860b5c..79c04fa1 100644 --- a/imagepicker/src/main/res/values-pt-rBR/strings.xml +++ b/imagepicker/src/main/res/values-pt-rBR/strings.xml @@ -21,5 +21,6 @@ Por favor dê permissão ao armazenamento para selecionar as imagens Por favor dê permissão à câmera para tirar fotos Limite de imagens atingido + Tudo diff --git a/imagepicker/src/main/res/values-ro/strings.xml b/imagepicker/src/main/res/values-ro/strings.xml index 65a4e439..7bf3f09c 100644 --- a/imagepicker/src/main/res/values-ro/strings.xml +++ b/imagepicker/src/main/res/values-ro/strings.xml @@ -21,5 +21,6 @@ Vă rugăm să acordați permisiunea fotocamerei pentru a captura imagini Limita de selecție a imaginii depăşită Acces refuzat + Tot diff --git a/imagepicker/src/main/res/values-ru/strings.xml b/imagepicker/src/main/res/values-ru/strings.xml index c8039f46..d5224e8b 100644 --- a/imagepicker/src/main/res/values-ru/strings.xml +++ b/imagepicker/src/main/res/values-ru/strings.xml @@ -16,4 +16,5 @@ Пожалуйста, разрешите доступ к хранилищу, чтобы выбрать изображения Пожалуйста, разрешите доступ к камере, чтобы сделать снимок Лимит выбора изображений + Все diff --git a/imagepicker/src/main/res/values-sv-rSE/strings.xml b/imagepicker/src/main/res/values-sv-rSE/strings.xml index 3ff8482b..7be551fe 100644 --- a/imagepicker/src/main/res/values-sv-rSE/strings.xml +++ b/imagepicker/src/main/res/values-sv-rSE/strings.xml @@ -20,4 +20,5 @@ Inga bilder hittades Vänligen bevilja lagringsbehörighet för att välja bilder Bildvalsgräns - \ No newline at end of file + Allt + diff --git a/imagepicker/src/main/res/values-tr/strings.xml b/imagepicker/src/main/res/values-tr/strings.xml index ae9aa89c..09453c58 100644 --- a/imagepicker/src/main/res/values-tr/strings.xml +++ b/imagepicker/src/main/res/values-tr/strings.xml @@ -20,4 +20,5 @@ Lütfen resim seçmek için depolama iznini verin Resim çekmek için lütfen kamera iznini verin Resim seçimi sınırı + Tüm diff --git a/imagepicker/src/main/res/values-uk/strings.xml b/imagepicker/src/main/res/values-uk/strings.xml index a2a84e6c..91133822 100644 --- a/imagepicker/src/main/res/values-uk/strings.xml +++ b/imagepicker/src/main/res/values-uk/strings.xml @@ -16,4 +16,5 @@ Будь ласка, дозвольте доступ до сховища, щоб обрати зображення Будь ласка, дозвольте доступ до камери, щоб зробити знімок Ліміт вибору зображень + Все diff --git a/imagepicker/src/main/res/values-vi/strings.xml b/imagepicker/src/main/res/values-vi/strings.xml index acdad396..1e242f8e 100644 --- a/imagepicker/src/main/res/values-vi/strings.xml +++ b/imagepicker/src/main/res/values-vi/strings.xml @@ -22,4 +22,5 @@ Giới hạn chọn hình ảnh Vui lòng cấp quyền cho máy ảnh để chụp ảnh + Tất cả diff --git a/imagepicker/src/main/res/values-zh-rCN/strings.xml b/imagepicker/src/main/res/values-zh-rCN/strings.xml index 950a7999..4d2481bf 100644 --- a/imagepicker/src/main/res/values-zh-rCN/strings.xml +++ b/imagepicker/src/main/res/values-zh-rCN/strings.xml @@ -20,5 +20,6 @@ 请给予获取相机权限以拍摄照片 已达到最多选择照片数量 没有权限 + 全选 diff --git a/imagepicker/src/main/res/values-zh-rTW/strings.xml b/imagepicker/src/main/res/values-zh-rTW/strings.xml index 2392a5ef..ca89d6f9 100644 --- a/imagepicker/src/main/res/values-zh-rTW/strings.xml +++ b/imagepicker/src/main/res/values-zh-rTW/strings.xml @@ -20,5 +20,6 @@ 請允許存取相機以拍攝相片 已達到最多選擇相片數量 沒有權限 + 全選 diff --git a/imagepicker/src/main/res/values/strings.xml b/imagepicker/src/main/res/values/strings.xml index 4f33fbad..97aac74c 100644 --- a/imagepicker/src/main/res/values/strings.xml +++ b/imagepicker/src/main/res/values/strings.xml @@ -26,5 +26,6 @@ GIF Folder Image + All diff --git a/imagepicker/src/test/java/com/esafirm/imagepicker/Should.kt b/imagepicker/src/test/java/com/esafirm/imagepicker/Should.kt deleted file mode 100644 index 87ccecd9..00000000 --- a/imagepicker/src/test/java/com/esafirm/imagepicker/Should.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.esafirm.imagepicker - -import com.natpryce.hamkrest.Matcher -import com.natpryce.hamkrest.assertion.assertThat -import com.natpryce.hamkrest.equalTo - -infix fun T.shouldBe(value: Any?) = should(equalTo(value)) -infix fun T.shouldNot(value: Any?) = should(equalTo(value).not()) -infix fun T.shouldBe(matcher: Matcher) = should(matcher) -infix fun T.shouldNot(matcher: Matcher) = should(matcher.not()) - -private infix fun T.should(matcher: Matcher) = assertThat(this, matcher) \ No newline at end of file diff --git a/imagepicker/src/test/java/com/esafirm/imagepicker/helper/ConfigUtilsTest.kt b/imagepicker/src/test/java/com/esafirm/imagepicker/helper/ConfigUtilsTest.kt deleted file mode 100644 index 7f2e4143..00000000 --- a/imagepicker/src/test/java/com/esafirm/imagepicker/helper/ConfigUtilsTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.esafirm.imagepicker.helper - -import com.esafirm.imagepicker.features.ImagePickerConfig -import com.esafirm.imagepicker.features.ReturnMode -import com.esafirm.imagepicker.features.cameraonly.CameraOnlyConfig -import com.esafirm.imagepicker.shouldBe -import org.junit.jupiter.api.Test - -class ConfigUtilsTest { - - @Test - fun `camera action return mode should be valid`() { - val cameraConfig = CameraOnlyConfig() - ConfigUtils.shouldReturn(cameraConfig, true) shouldBe true - - val config = ImagePickerConfig( - returnMode = ReturnMode.CAMERA_ONLY - ) - ConfigUtils.shouldReturn(config, true) shouldBe true - ConfigUtils.shouldReturn(config, false) shouldBe false - } -} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index c281a616..8e8637d7 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -42,25 +42,23 @@ android { } dependencies { - implementation "com.github.bumptech.glide:glide:4.14.2" - implementation "androidx.appcompat:appcompat:1.5.1" + implementation "com.github.bumptech.glide:glide:4.16.0" + implementation "androidx.appcompat:appcompat:1.7.1" /* Development */ implementation project(':imagepicker') - debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1' - implementation "androidx.core:core-ktx:$core_ktx_version" + debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.14' + implementation "androidx.core:core-ktx:1.16.0" /* UI Test */ - final espressoVersion = '3.5.0' - final runnerVersion = '1.5.1' - androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion" - androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion" - androidTestImplementation "androidx.test:runner:$runnerVersion" - androidTestImplementation "androidx.test:rules:1.5.0" - androidTestImplementation 'androidx.test.ext:junit-ktx:1.1.4' - androidTestImplementation "androidx.test:core:1.5.0" - androidTestImplementation('com.adevinta.android:barista:4.2.0') { + androidTestImplementation "androidx.test.espresso:espresso-core:3.6.1" + androidTestImplementation "androidx.test.espresso:espresso-contrib:3.6.1" + androidTestImplementation "androidx.test:runner:1.6.2" + androidTestImplementation "androidx.test:rules:1.6.1" + androidTestImplementation 'androidx.test.ext:junit-ktx:1.2.1' + androidTestImplementation "androidx.test:core:1.6.1" + androidTestImplementation('com.adevinta.android:barista:4.3.0') { exclude group: 'org.jetbrains.kotlin' exclude group: 'org.hamcrest' } diff --git a/sample/src/androidTest/java/com/esafirm/sample/PickImageFolderMode.kt b/sample/src/androidTest/java/com/esafirm/sample/PickImageFolderMode.kt index 1018a561..a325a089 100644 --- a/sample/src/androidTest/java/com/esafirm/sample/PickImageFolderMode.kt +++ b/sample/src/androidTest/java/com/esafirm/sample/PickImageFolderMode.kt @@ -1,16 +1,25 @@ package com.esafirm.sample +import android.view.View +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView.ViewHolder +import androidx.test.espresso.Espresso import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.contrib.RecyclerViewActions.actionOnItemAtPosition +import androidx.test.espresso.matcher.ViewMatchers import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.LargeTest import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn +import com.adevinta.android.barista.internal.util.resourceMatcher import com.esafirm.sample.utils.Rules import com.esafirm.sample.utils.ViewAsserts import com.esafirm.sample.utils.Views +import com.esafirm.sample.utils.withViewCount +import org.hamcrest.Description +import org.hamcrest.TypeSafeMatcher import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -52,4 +61,33 @@ class PickImageFolderMode { ViewAsserts.imagePicked(imageView) } + @Test + fun selectAll() { + // Activate switch + clickOn(R.id.switch_select_all) + + Views.pickImageButton().perform(click()) + + val recyclerView = Views.recyclersView() + // Click folder + recyclerView.perform(actionOnItemAtPosition(0, click())) + + // Click all button + clickOn(R.id.menu_select_all) + clickOn(R.id.menu_done) + + // Check image is picked + Views.waitFor(1_000) + Espresso.onView(R.id.text_view.resourceMatcher()) + .check(matches(object : TypeSafeMatcher() { + override fun matchesSafely(item: View?): Boolean { + if (item !is TextView) return false + return item.text.toString().count { it == '\n' } == 9 + } + + override fun describeTo(description: Description) { + description.appendText("10 selected images expected") + } + })) + } } diff --git a/sample/src/androidTest/java/com/esafirm/sample/utils/Views.kt b/sample/src/androidTest/java/com/esafirm/sample/utils/Views.kt index 7709ad57..e06b3e10 100644 --- a/sample/src/androidTest/java/com/esafirm/sample/utils/Views.kt +++ b/sample/src/androidTest/java/com/esafirm/sample/utils/Views.kt @@ -4,13 +4,12 @@ import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.ScrollView +import android.widget.TextView import androidx.test.espresso.Espresso.onView import androidx.test.espresso.ViewInteraction import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom -import androidx.test.espresso.matcher.ViewMatchers.isDisplayed -import androidx.test.espresso.matcher.ViewMatchers.withId -import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.espresso.matcher.ViewMatchers.* +import androidx.test.espresso.util.TreeIterables import com.esafirm.sample.R import org.hamcrest.Description import org.hamcrest.Matcher @@ -19,6 +18,7 @@ import org.hamcrest.Matchers.allOf import org.hamcrest.TypeSafeMatcher import org.hamcrest.core.IsInstanceOf + object Views { fun waitFor(timeInMs: Long) { Thread.sleep(timeInMs) @@ -30,45 +30,59 @@ object Views { fun pickImageButton(): ViewInteraction { return onView( - allOf(withId(R.id.button_pick_image), withText("PICK IMAGE"), + allOf( + withId(R.id.button_pick_image), withText("PICK IMAGE"), childAtPosition( childAtPosition( withId(R.id.bottom_container), - 0), - 0), - isDisplayed())) + 0 + ), + 0 + ), + isDisplayed() + ) + ) } fun recyclersView(): ViewInteraction { return onView( - allOf(withId(R.id.recyclerView), + allOf( + withId(R.id.recyclerView), childAtPosition( ViewMatchers.withClassName(Matchers.`is`("android.widget.RelativeLayout")), - 2))) + 2 + ) + ) + ) } fun pickerDoneButton(): ViewInteraction { return onView( - allOf(withId(R.id.menu_done), withText("DONE"), - childAtPosition( - childAtPosition( - withId(R.id.toolbar), - 2), - 1), - isDisplayed())) + allOf( + withId(R.id.menu_done), + isDisplayed() + ) + ) } fun imageDetail(): ViewInteraction { return onView( - allOf(ViewMatchers.withParent(allOf(withId(R.id.container), - ViewMatchers.withParent(IsInstanceOf.instanceOf(ScrollView::class.java)))), + allOf( + ViewMatchers.withParent( + allOf( + withId(R.id.container), + ViewMatchers.withParent(IsInstanceOf.instanceOf(ScrollView::class.java)) + ) + ), isDisplayed(), isAssignableFrom(ImageView::class.java) - )) + ) + ) } private fun childAtPosition( - parentMatcher: Matcher, position: Int): Matcher { + parentMatcher: Matcher, position: Int + ): Matcher { return object : TypeSafeMatcher() { override fun describeTo(description: Description) { @@ -79,8 +93,28 @@ object Views { public override fun matchesSafely(view: View): Boolean { val parent = view.parent return parent is ViewGroup && parentMatcher.matches(parent) - && view == parent.getChildAt(position) + && view == parent.getChildAt(position) + } + } + } +} + +fun withViewCount(viewMatcher: Matcher, expectedCount: Int): Matcher { + return object : TypeSafeMatcher() { + private var actualCount = -1 + override fun describeTo(description: Description) { + when { + actualCount >= 0 -> description.also { + it.appendText("Expected items count: $expectedCount, but got: $actualCount") + } + } + } + + override fun matchesSafely(root: View?): Boolean { + actualCount = TreeIterables.breadthFirstViewTraversal(root).count { + viewMatcher.matches(it) } + return expectedCount == actualCount } } -} \ No newline at end of file +} diff --git a/sample/src/main/java/com/esafirm/sample/CustomUIActivity.kt b/sample/src/main/java/com/esafirm/sample/CustomUIActivity.kt index 3440e9bd..d2169585 100644 --- a/sample/src/main/java/com/esafirm/sample/CustomUIActivity.kt +++ b/sample/src/main/java/com/esafirm/sample/CustomUIActivity.kt @@ -107,7 +107,7 @@ class CustomUIActivity : AppCompatActivity() { override fun onOptionsItemSelected(item: MenuItem): Boolean { val id = item.itemId if (id == android.R.id.home) { - onBackPressed() + onBackPressedDispatcher.onBackPressed() return true } if (id == com.esafirm.imagepicker.R.id.menu_done) { @@ -121,18 +121,6 @@ class CustomUIActivity : AppCompatActivity() { return super.onOptionsItemSelected(item) } - /** - * If you're content for the back button to take you back, without consulting the state of the - * fragment, you don't need to override this. On the other hand, the ImagePickerFragment might - * want to handle the back button. For example, if it's in folder mode and a folder has been - * selected, the fragment will go back to the folder list if you call its handleBack(). - */ - override fun onBackPressed() { - if (!imagePickerFragment.handleBack()) { - super.onBackPressed() - } - } - private fun setupView() { setSupportActionBar(binding.toolbar.root as Toolbar) checkNotNull(supportActionBar) diff --git a/sample/src/main/java/com/esafirm/sample/MainActivity.kt b/sample/src/main/java/com/esafirm/sample/MainActivity.kt index 300f04fe..75a80d9d 100644 --- a/sample/src/main/java/com/esafirm/sample/MainActivity.kt +++ b/sample/src/main/java/com/esafirm/sample/MainActivity.kt @@ -56,6 +56,7 @@ class MainActivity : AppCompatActivity() { val includeVideo = binding.switchIncludeVideo.isChecked val onlyVideo = binding.switchOnlyVideo.isChecked val isExclude = binding.switchIncludeExclude.isChecked + val allButtonVisible = binding.switchSelectAll.isChecked ImagePickerComponentsHolder.setInternalComponent( CustomImagePickerComponents(this, useCustomImageLoader) @@ -69,7 +70,7 @@ class MainActivity : AppCompatActivity() { ImagePickerMode.MULTIPLE // multi mode (default mode) } - language = "in" // Set image picker language +// language = "in" // Set image picker language theme = R.style.ImagePickerTheme // set whether pick action or camera action should return immediate result or not. Only works in single mode for image picker @@ -93,6 +94,8 @@ class MainActivity : AppCompatActivity() { } else { selectedImages = images // original selected images, used in multi mode } + + showAllButton = allButtonVisible } } @@ -128,4 +131,4 @@ class MainActivity : AppCompatActivity() { ImageViewerActivity.start(this@MainActivity, images) } } -} \ No newline at end of file +} diff --git a/sample/src/main/res/layout/activity_main.xml b/sample/src/main/res/layout/activity_main.xml index 68c828b7..855bb530 100644 --- a/sample/src/main/res/layout/activity_main.xml +++ b/sample/src/main/res/layout/activity_main.xml @@ -54,6 +54,11 @@ style="@style/SampleSwitch" android:text="Exclude" /> + +