diff --git a/.DS_Store b/.DS_Store index bacc6d5..f1e8353 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/.idea/login-kit-sample.iml b/.idea/login-kit-sample.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/login-kit-sample.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 2d51ff2..fa271f2 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ - [Sample iOS App](ios) - [Sample Android App](android) +- [Sample Android Jetpack Compose](androidcompose) - [Sample React Native](react-native) diff --git a/android/app/src/main/res/layout/activity_main.xml b/android/app/src/main/res/layout/activity_main.xml index afa6b25..c144e1a 100644 --- a/android/app/src/main/res/layout/activity_main.xml +++ b/android/app/src/main/res/layout/activity_main.xml @@ -29,7 +29,7 @@ android:fontFamily="@font/avenirnextgeo_regular" android:text="@string/user_display_name" android:textColor="@color/colorPrimaryDark" - android:visibility="invisible" + android:visibility="visible" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> @@ -43,7 +43,7 @@ android:contentDescription="@string/logout_button" android:fontFamily="@font/avenirnextgeo_regular" android:text="@string/logout_button" - android:visibility="invisible" + android:visibility="visible" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.497" @@ -60,7 +60,7 @@ android:fontFamily="@font/avenirnextgeo_regular" android:text="@string/user_external_id" android:textColor="@color/colorPrimaryDark" - android:visibility="invisible" + android:visibility="visible" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/labelDisplayNameView" /> @@ -70,6 +70,7 @@ android:layout_height="wrap_content" android:layout_marginStart="20dp" android:layout_marginTop="116dp" + android:text="@string/user_display_name" android:fontFamily="@font/avenirnextgeo_regular" app:layout_constraintStart_toEndOf="@+id/labelDisplayNameView" app:layout_constraintTop_toTopOf="parent" /> @@ -81,6 +82,7 @@ android:layout_marginStart="20dp" android:layout_marginTop="16dp" android:fontFamily="@font/avenirnextgeo_regular" + android:text="@string/user_external_id" app:layout_constraintStart_toEndOf="@+id/labelExternalIdView" app:layout_constraintTop_toBottomOf="@+id/displayNameView" /> @@ -91,7 +93,7 @@ android:layout_marginStart="32dp" android:layout_marginTop="64dp" android:contentDescription="@string/user_avatar_holding_text" - android:visibility="invisible" + android:visibility="visible" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/labelExternalIdView" app:srcCompat="@drawable/bitmoji450x450" /> diff --git a/android/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar index f6b961f..7454180 100644 Binary files a/android/gradle/wrapper/gradle-wrapper.jar and b/android/gradle/wrapper/gradle-wrapper.jar differ diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index ca40d74..ffed3a2 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 07 12:45:10 BST 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/android/gradlew b/android/gradlew index cccdd3d..1b6c787 100755 --- a/android/gradlew +++ b/android/gradlew @@ -1,78 +1,129 @@ -#!/usr/bin/env sh +#!/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. +# ############################################################################## -## -## 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="" +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 @@ -81,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 @@ -89,84 +140,95 @@ 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" || "$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 -# 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, 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" - -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi +# 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 \ + "$@" + +# 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/android/gradlew.bat b/android/gradlew.bat index f955316..ac1b06f 100644 --- a/android/gradlew.bat +++ b/android/gradlew.bat @@ -1,84 +1,89 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@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= - -@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 - -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. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -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. - -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% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="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 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@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 + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +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" + +@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 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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +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. + +goto fail + +: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 %* + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="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 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/androidcompose/.gitignore b/androidcompose/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/androidcompose/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/androidcompose/.idea/.gitignore b/androidcompose/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/androidcompose/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/androidcompose/.idea/.name b/androidcompose/.idea/.name new file mode 100644 index 0000000..7004bde --- /dev/null +++ b/androidcompose/.idea/.name @@ -0,0 +1 @@ +Snap Login Kit \ No newline at end of file diff --git a/androidcompose/.idea/codeStyles/Project.xml b/androidcompose/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..8a8ace6 --- /dev/null +++ b/androidcompose/.idea/codeStyles/Project.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/codeStyles/codeStyleConfig.xml b/androidcompose/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/androidcompose/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/androidcompose/.idea/compiler.xml b/androidcompose/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/androidcompose/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/deploymentTargetDropDown.xml b/androidcompose/.idea/deploymentTargetDropDown.xml new file mode 100644 index 0000000..0c0c338 --- /dev/null +++ b/androidcompose/.idea/deploymentTargetDropDown.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/gradle.xml b/androidcompose/.idea/gradle.xml new file mode 100644 index 0000000..0897082 --- /dev/null +++ b/androidcompose/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/inspectionProfiles/Project_Default.xml b/androidcompose/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..44ca2d9 --- /dev/null +++ b/androidcompose/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,41 @@ + + + + \ No newline at end of file diff --git a/androidcompose/.idea/kotlinc.xml b/androidcompose/.idea/kotlinc.xml new file mode 100644 index 0000000..fdf8d99 --- /dev/null +++ b/androidcompose/.idea/kotlinc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/migrations.xml b/androidcompose/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/androidcompose/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/misc.xml b/androidcompose/.idea/misc.xml new file mode 100644 index 0000000..9f71c83 --- /dev/null +++ b/androidcompose/.idea/misc.xml @@ -0,0 +1,10 @@ + + + + + + + + + \ No newline at end of file diff --git a/androidcompose/.idea/vcs.xml b/androidcompose/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/androidcompose/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/androidcompose/README.md b/androidcompose/README.md new file mode 100644 index 0000000..6c3d25b --- /dev/null +++ b/androidcompose/README.md @@ -0,0 +1,51 @@ +# Login Kit Jetpack Compose + +Login Kit sample code for Android. + +## App Registration + +You need to register your app at the [Snap Kit developer portal](https://kit.snapchat.com). + +After registering your app you will receive two OAuth clientIDs, you will receive a *Production* `clientID` and a *Development* `clientID`. + +You can use the *Development* `clientID` anytime even before an app is reviewed and approved. But when using the *Development* `clientID` only accounts listed under the *Demo Users* in the app registration/profile page on [Snap Kit developer portal]([https://kit.snapchat.com/portal](https://kit.snapchat.com/portal)) will be able to use your application. + +With the *Production* `clientID`, your app can post the content from any Snapchat account. But your app must be approved for the *Production* `clientID` to work. + +You also need to define a `redirectUrl` for your app, this is used within the AndroidManifest.xml + +## Setup +Steps 1 and 2 are already complete in this demo app and are just here for your understanding, step 3 needs to be carried out before you can run the application. + +1. You need to import the Login Kit . + +2. Open up your [App level build.gradle](`/androidcompose/app/build.gradle`) and add. + +```kotlin +android { + defaultConfig { + // other configrations + gradleLocalProperties(rootDir).also { + manifestPlaceholders.putAll(arrayOf( + "SNAP_CLIENT_ID" to it.getProperty("com.snap.kit.clientId"), + "SNAP_REDIRECT_URL" to it.getProperty("com.snap.kit.redirectUrl"), + "REDIRECT_URL_HOST" to it.getProperty("com.snap.kit.host"), + "REDIRECT_URL_PATH" to it.getProperty("com.snap.kit.path"), + "REDIRECT_URL_SCHEME" to it.getProperty("com.snap.kit.scheme"), + )) + } + } +} +dependencies { + implementation("com.snap.loginkit:loginkit:3.0.0") +} +``` + +1. Add the following in your `local.properties`. +```properties +com.snap.kit.clientId=YOUR_CLIENT_ID +com.snap.kit.redirectUrl=YOUR_REDIRECT_URL +com.snap.kit.host=YOUR_REDIRECT_URL_HOST +com.snap.kit.path=/YOUR_REDIRECT_URL_PATH +com.snap.kit.scheme=YOUR_REDIRECT_URL_SCHEME +``` \ No newline at end of file diff --git a/androidcompose/app/.gitignore b/androidcompose/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/androidcompose/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/androidcompose/app/build.gradle.kts b/androidcompose/app/build.gradle.kts new file mode 100644 index 0000000..e3420fc --- /dev/null +++ b/androidcompose/app/build.gradle.kts @@ -0,0 +1,91 @@ +import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties + +plugins { + id("com.android.application") + id("org.jetbrains.kotlin.android") + id("kotlin-kapt") + id("dagger.hilt.android.plugin") +} + +android { + namespace = "com.waseem.snaploginkit" + compileSdk = 34 + + defaultConfig { + applicationId = "com.waseem.snaploginkit" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + gradleLocalProperties(rootDir).also { + manifestPlaceholders.putAll(arrayOf( + "SNAP_CLIENT_ID" to it.getProperty("com.snap.kit.clientId"), + "SNAP_REDIRECT_URL" to it.getProperty("com.snap.kit.redirectUrl"), + "REDIRECT_URL_HOST" to it.getProperty("com.snap.kit.host"), + "REDIRECT_URL_PATH" to it.getProperty("com.snap.kit.path"), + "REDIRECT_URL_SCHEME" to it.getProperty("com.snap.kit.scheme"), + )) + } + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = "1.8" + } + buildFeatures { + compose = true + } + composeOptions { + kotlinCompilerExtensionVersion = "1.5.1" + } + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +dependencies { + + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") + implementation("androidx.activity:activity-compose:1.8.2") + implementation(platform("androidx.compose:compose-bom:2024.02.01")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-graphics") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3") + + //hilt + implementation("com.google.dagger:hilt-android:2.51") + kapt("com.google.dagger:hilt-compiler:2.51") + implementation("androidx.hilt:hilt-navigation-compose:1.2.0") + + //snapchat login kit + implementation("com.snap.loginkit:loginkit:3.0.0") + + //Coil + implementation("io.coil-kt:coil-compose:2.6.0") + + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.1.5") + androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") + androidTestImplementation(platform("androidx.compose:compose-bom:2024.02.01")) + androidTestImplementation("androidx.compose.ui:ui-test-junit4") + debugImplementation("androidx.compose.ui:ui-tooling") + debugImplementation("androidx.compose.ui:ui-test-manifest") +} \ No newline at end of file diff --git a/androidcompose/app/proguard-rules.pro b/androidcompose/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/androidcompose/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/androidcompose/app/src/androidTest/java/com/waseem/snaploginkit/ExampleInstrumentedTest.kt b/androidcompose/app/src/androidTest/java/com/waseem/snaploginkit/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..fa30cc9 --- /dev/null +++ b/androidcompose/app/src/androidTest/java/com/waseem/snaploginkit/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.waseem.snaploginkit + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.waseem.snaploginkit", appContext.packageName) + } +} \ No newline at end of file diff --git a/androidcompose/app/src/main/AndroidManifest.xml b/androidcompose/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..160e34d --- /dev/null +++ b/androidcompose/app/src/main/AndroidManifest.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/HomeScreen.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/HomeScreen.kt new file mode 100644 index 0000000..d783311 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/HomeScreen.kt @@ -0,0 +1,129 @@ +package com.waseem.snaploginkit + +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.ExitToApp +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Divider +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import coil.compose.AsyncImage +import com.waseem.snaploginkit.ui.theme.SnapLoginKitTheme + +@Composable +fun HomeScreen( + snapUser: SnapUser?, + onLogout: () -> Unit +) { + Scaffold { + Column( + modifier = Modifier + .fillMaxSize() + .padding(it) + .padding(horizontal = 16.dp), + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(400.dp) + .background(color = Color(0xFFF8F8F3)) //0xFFF8F8F3 + .padding(bottom = 30.dp), + contentAlignment = Alignment.BottomCenter + ) { + AsyncImage( + model = snapUser?.avatarUrl, + contentDescription = null, + modifier = Modifier + .size(200.dp) + .clip(shape = CircleShape) + .border(width = 3.dp, color = MaterialTheme.colorScheme.secondary, shape = CircleShape) + ) + } + + Text( + text = "Hello ${snapUser?.displayName},", + modifier = Modifier.padding(top = 20.dp), + style = MaterialTheme.typography.titleLarge.copy( + color = MaterialTheme.colorScheme.secondary.copy(alpha = 0.7f), + fontWeight = FontWeight.Bold + ) + ) + + Text( + text = stringResource(R.string.home_description), + modifier = Modifier.padding(vertical = 20.dp), + ) + + Box(modifier = Modifier.height(20.dp)) + + Divider() + + TextButton( + colors = ButtonDefaults.textButtonColors( + contentColor = Color.Red + ), + contentPadding = PaddingValues(horizontal = 0.dp), + onClick = onLogout + ) { + Icon(Icons.Rounded.ExitToApp, contentDescription = null) + Text( + modifier = Modifier.padding(start = 10.dp), + text = stringResource(R.string.logout) + ) + } + + } + } +} + +@Composable +private fun SnapchatLoginButton(onLogin: () -> Unit) { + Button( + colors = ButtonDefaults.buttonColors( // Customize button colors if needed + containerColor = Color(0xFFFFFC03), + contentColor = Color.Black + ), + onClick = onLogin, + ) { + Icon( + painter = painterResource(id = R.drawable.ic_snapchat), + contentDescription = null, + modifier = Modifier.padding(end = 10.dp) + ) + Text(text = "Login with Snapchat") + } +} + +@Preview(showBackground = true) +@Composable +private fun LoginScreenPreview() { + SnapLoginKitTheme { + HomeScreen( + snapUser = SnapUser(displayName = "Waseem Abbas", avatarUrl = "https://i.pravatar.cc/300") + ) {} + } +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/LoginScreen.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/LoginScreen.kt new file mode 100644 index 0000000..91ddf9b --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/LoginScreen.kt @@ -0,0 +1,128 @@ +package com.waseem.snaploginkit + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Divider +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import com.waseem.snaploginkit.ui.theme.SnapLoginKitTheme + +@Composable +fun LoginScreen(onLogin: () -> Unit) { + Scaffold { + Column( + modifier = Modifier + .fillMaxSize() + .padding(it) + .padding(horizontal = 16.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Box( + modifier = Modifier + .fillMaxWidth() + .height(400.dp) + .background(color = Color(0xFFF8F8F3)) //0xFFF8F8F3 + .padding(bottom = 20.dp) + ) { + Text( + text = "Scl.", + modifier = Modifier.align(Alignment.BottomCenter), + style = TextStyle( + fontSize = 96.sp, + fontWeight = FontWeight.Bold, + fontFamily = FontFamily.Cursive, + color = MaterialTheme.colorScheme.primary, + ) + ) + } + + Text( + text = stringResource(R.string.slogan), + modifier = Modifier.padding(vertical = 20.dp), + style = MaterialTheme.typography.titleMedium.copy( + color = MaterialTheme.colorScheme.secondary + ) + ) + + Text( + text = stringResource(R.string.login_description), + modifier = Modifier.padding(vertical = 20.dp), + textAlign = TextAlign.Center + ) + + Box(modifier = Modifier.height(20.dp)) + + SnapchatLoginButton(onLogin = onLogin) + + Row( + modifier = Modifier.padding(vertical = 20.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + Divider( + modifier = Modifier + .weight(1f) + .padding(horizontal = 10.dp) + ) + TextButton(onClick = { /*TODO*/ }) { + Text(text = "Read snapkit docs") + } + Divider( + modifier = Modifier + .weight(1f) + .padding(horizontal = 10.dp) + ) + } + + } + } +} + +@Composable +private fun SnapchatLoginButton(onLogin: () -> Unit) { + Button( + colors = ButtonDefaults.buttonColors( // Customize button colors if needed + containerColor = Color(0xFFFFFC03), + contentColor = Color.Black + ), + onClick = onLogin, + ) { + Icon( + painter = painterResource(id = R.drawable.ic_snapchat), + contentDescription = null, + modifier = Modifier.padding(end = 10.dp) + ) + Text(text = "Login with Snapchat") + } +} + +@Preview(showBackground = true) +@Composable +private fun LoginScreenPreview() { + SnapLoginKitTheme { + LoginScreen {} + } +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainActivity.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainActivity.kt new file mode 100644 index 0000000..2816982 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainActivity.kt @@ -0,0 +1,81 @@ +package com.waseem.snaploginkit + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.viewModels +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import com.waseem.snaploginkit.ui.theme.SnapLoginKitTheme +import dagger.hilt.android.AndroidEntryPoint + +@AndroidEntryPoint +class MainActivity : ComponentActivity() { + + private val viewModel: MainViewModel by viewModels() + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + + setContent { + SnapLoginKitTheme { + // A surface container using the 'background' color from the theme + + MainScreenContent( + state = viewModel.uiState.value, + onLogout = { viewModel.onLogout() }, + onLogin = { viewModel.onLogin() }, + onLoadUserInfo = { viewModel.getUserInfo() } + ) + } + } + } +} + +@Composable +private fun MainScreenContent( + state: MainUiState, + onLogin: () -> Unit, + onLogout: () -> Unit, + onLoadUserInfo: () -> Unit, +) { + when (state.authState) { + AuthState.LOGGED_IN -> { + if (state.snapUser == null) { + onLoadUserInfo() + } + HomeScreen( + onLogout = onLogout, + snapUser = state.snapUser + ) + } + + AuthState.LOGGED_OUT -> { + LoginScreen(onLogin = onLogin) + } + } +} + +@Preview(showBackground = true) +@Composable +private fun MainScreenPreview( + @PreviewParameter(MainScreenUiStatePreviewParameterProvider::class) state: MainUiState +) { + SnapLoginKitTheme { + MainScreenContent( + state = state, + onLogin = { }, + onLogout = {}, + onLoadUserInfo = {} + ) + } +} + +class MainScreenUiStatePreviewParameterProvider : PreviewParameterProvider { + override val values = sequenceOf( + MainUiState(AuthState.LOGGED_OUT), + MainUiState(AuthState.LOGGED_IN, snapUser = SnapUser("Waseem", "https://i.pravatar.cc/300")) + ) +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainUiState.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainUiState.kt new file mode 100644 index 0000000..0adc4a2 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainUiState.kt @@ -0,0 +1,16 @@ +package com.waseem.snaploginkit + +enum class AuthState { + LOGGED_IN, + LOGGED_OUT +} + +data class SnapUser( + val displayName: String, + val avatarUrl: String?, +) + +data class MainUiState ( + val authState: AuthState, + val snapUser: SnapUser? = null, +) \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainViewModel.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainViewModel.kt new file mode 100644 index 0000000..1dc83ea --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/MainViewModel.kt @@ -0,0 +1,91 @@ +package com.waseem.snaploginkit + +import android.util.Log +import androidx.compose.runtime.State +import androidx.compose.runtime.mutableStateOf +import androidx.lifecycle.ViewModel +import com.snap.loginkit.BitmojiQuery +import com.snap.loginkit.LoginResultCallback +import com.snap.loginkit.SnapLogin +import com.snap.loginkit.UserDataQuery +import com.snap.loginkit.UserDataResultCallback +import com.snap.loginkit.exceptions.LoginException +import com.snap.loginkit.exceptions.UserDataException +import com.snap.loginkit.models.UserDataResult +import dagger.hilt.android.lifecycle.HiltViewModel +import javax.inject.Inject + +@HiltViewModel +class MainViewModel @Inject constructor( + private val snapLogin: SnapLogin +) : ViewModel() { + + private val _uiState = snapLogin.isUserLoggedIn.let { + if (it) { + mutableStateOf(MainUiState(AuthState.LOGGED_IN)) + } else { + mutableStateOf(MainUiState(AuthState.LOGGED_OUT)) + } + } + val uiState: State = _uiState + + fun onLogin() { + snapLogin.startTokenGrant( + object : LoginResultCallback { + override fun onStart() { + Log.d("SnapLoginKit", "onStart") + } + + override fun onSuccess(p0: String) { + _uiState.value = _uiState.value.copy( + authState = AuthState.LOGGED_IN + ) + } + + override fun onFailure(p0: LoginException) { + Log.d("SnapLoginKit", "onFailure") + } + + } + ) + } + + fun getUserInfo() { + val bitmojiQuery = BitmojiQuery.newBuilder().withAvatarId().withTwoDAvatarUrl().build() + val userDetailQuery = UserDataQuery.newBuilder() + .withDisplayName() + .withBitmoji(bitmojiQuery) + .build() + snapLogin.fetchUserData(userDetailQuery, object : UserDataResultCallback { + override fun onSuccess(userDetailResult: UserDataResult) { + userDetailResult.data?.meData?.let { + val displayName = it.displayName ?: "No name" + val avatarUrl = it.bitmojiData?.twoDAvatarUrl + + _uiState.value = _uiState.value.copy( + snapUser = SnapUser( + displayName = displayName, + avatarUrl = avatarUrl + ) + ) + + Log.d("SnapLoginKit", "displayName: $displayName") + Log.d("SnapLoginKit", "avatarUrl: $avatarUrl") + } + TODO("Not yet implemented") + } + + override fun onFailure(p0: UserDataException) { + TODO("Not yet implemented") + } + + }) + } + + fun onLogout() { + snapLogin.clearToken() + _uiState.value = _uiState.value.copy( + authState = AuthState.LOGGED_OUT + ) + } +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/SnapKitAp.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/SnapKitAp.kt new file mode 100644 index 0000000..65bef30 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/SnapKitAp.kt @@ -0,0 +1,7 @@ +package com.waseem.snaploginkit + +import android.app.Application +import dagger.hilt.android.HiltAndroidApp + +@HiltAndroidApp +class SnapKitAp : Application() \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/di/AuthModule.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/di/AuthModule.kt new file mode 100644 index 0000000..f63b5d3 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/di/AuthModule.kt @@ -0,0 +1,22 @@ +package com.waseem.snaploginkit.di + +import android.content.Context +import com.snap.loginkit.SnapLogin +import com.snap.loginkit.SnapLoginProvider +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.android.qualifiers.ApplicationContext +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton + +@InstallIn(SingletonComponent::class) +@Module +object AuthModule { + + @Singleton + @Provides + fun provideSnapLogin( + @ApplicationContext context: Context + ): SnapLogin = SnapLoginProvider.get(context) +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Color.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Color.kt new file mode 100644 index 0000000..6ba4ffe --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.waseem.snaploginkit.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Theme.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Theme.kt new file mode 100644 index 0000000..1ddb1db --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Theme.kt @@ -0,0 +1,70 @@ +package com.waseem.snaploginkit.ui.theme + +import android.app.Activity +import android.os.Build +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.darkColorScheme +import androidx.compose.material3.dynamicDarkColorScheme +import androidx.compose.material3.dynamicLightColorScheme +import androidx.compose.material3.lightColorScheme +import androidx.compose.runtime.Composable +import androidx.compose.runtime.SideEffect +import androidx.compose.ui.graphics.toArgb +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.platform.LocalView +import androidx.core.view.WindowCompat + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun SnapLoginKitTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + val view = LocalView.current + if (!view.isInEditMode) { + SideEffect { + val window = (view.context as Activity).window + window.statusBarColor = colorScheme.primary.toArgb() + WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = darkTheme + } + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Type.kt b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Type.kt new file mode 100644 index 0000000..7e320f2 --- /dev/null +++ b/androidcompose/app/src/main/java/com/waseem/snaploginkit/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.waseem.snaploginkit.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/androidcompose/app/src/main/res/drawable/ic_launcher_background.xml b/androidcompose/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/androidcompose/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/androidcompose/app/src/main/res/drawable/ic_launcher_foreground.xml b/androidcompose/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/androidcompose/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/drawable/ic_snapchat.xml b/androidcompose/app/src/main/res/drawable/ic_snapchat.xml new file mode 100644 index 0000000..f4186f0 --- /dev/null +++ b/androidcompose/app/src/main/res/drawable/ic_snapchat.xml @@ -0,0 +1,9 @@ + + + diff --git a/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/androidcompose/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/androidcompose/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/androidcompose/app/src/main/res/values/arrays.xml b/androidcompose/app/src/main/res/values/arrays.xml new file mode 100644 index 0000000..eea2c47 --- /dev/null +++ b/androidcompose/app/src/main/res/values/arrays.xml @@ -0,0 +1,6 @@ + + + + https://auth.snapchat.com/oauth2/api/user.display_name + + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/values/colors.xml b/androidcompose/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/androidcompose/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/values/strings.xml b/androidcompose/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..6e7c103 --- /dev/null +++ b/androidcompose/app/src/main/res/values/strings.xml @@ -0,0 +1,7 @@ + + Snap Login Kit + It\'s easier to login now! + This is a sample project to show you how to use snapchat login kit in Android with Jetpack Compose. + Using snapchat login kit SDK, you can get the username and avatar of the snap user. + Logout + \ No newline at end of file diff --git a/androidcompose/app/src/main/res/values/themes.xml b/androidcompose/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..34afa25 --- /dev/null +++ b/androidcompose/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +