├── .github └── workflows │ └── pull-request.yml ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── samplejava ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── chattutorial │ │ ├── ChannelActivity.java │ │ ├── ChannelActivity2.java │ │ ├── ChannelActivity3.java │ │ ├── ChannelActivity4.java │ │ ├── ImgurAttachmentFactory.java │ │ └── MainActivity.java │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── ic_launcher_background.xml │ └── imgur_logo.png │ ├── layout │ ├── activity_channel.xml │ ├── activity_channel_2.xml │ ├── activity_channel_3.xml │ ├── activity_channel_4.xml │ ├── activity_main.xml │ └── attachment_imgur.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── themes.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml ├── samplekotlin ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── example │ │ └── chattutorial │ │ ├── ChannelActivity.kt │ │ ├── ChannelActivity2.kt │ │ ├── ChannelActivity3.kt │ │ ├── ChannelActivity4.kt │ │ ├── ImgurAttachmentFactory.kt │ │ └── MainActivity.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── ic_launcher_background.xml │ └── imgur_logo.png │ ├── layout │ ├── activity_channel.xml │ ├── activity_channel_2.xml │ ├── activity_channel_3.xml │ ├── activity_channel_4.xml │ ├── activity_main.xml │ └── attachment_imgur.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values-night │ └── themes.xml │ └── values │ ├── colors.xml │ ├── strings.xml │ └── themes.xml └── settings.gradle.kts /.github/workflows/pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | test: 7 | name: Build app 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | 13 | - name: Set up JDK 17 14 | uses: actions/setup-java@v2 15 | with: 16 | distribution: adopt 17 | java-version: 17 18 | 19 | - name: Build app 20 | run: ./gradlew assembleDebug 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | buildSrc/build 3 | .gradle 4 | /local.properties 5 | /.idea/ 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | .cxx 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2020, Stream.io Inc 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Android Chat Tutorial Sample 2 | 3 | This repository allows you to check the result after completing each step described in the [Android Chat Tutorial](https://getstream.io/tutorials/android-chat/#kotlin). It contains samples written in both **Kotlin** (_samplekotlin_ module) and **Java** (_samplejava_ module). For more Android Chat examples, see the [Github repo for the SDK](https://github.com/GetStream/stream-chat-android) and the [UI Components sample app](https://github.com/GetStream/stream-chat-android/tree/main/stream-chat-android-ui-components-sample) in it. 4 | 5 | > Already all-in on Jetpack Compose? Check out the [tutorial repo of our Compose UI Components](https://github.com/GetStream/compose-chat-tutorial) instead. 6 | 7 | The project is pre-configured with a shared [Stream](https://getstream.io) account for testing purposes. You can learn more about Stream Chat [here](https://getstream.io/chat/), and then sign up for an account and obtain your own keys [here](https://getstream.io/chat/trial). 8 | 9 | ## Stream Chat, Video and Activity Feeds 10 | 11 | This project uses [Stream](https://getstream.io/)'s battle-tested chat infrastructure. Check out our: 12 | 13 | - ⭐ [Chat API](https://getstream.io/chat/) 14 | - 📱 [Video API](https://getstream.io/video/) 15 | - 🔔 [Activity Feeds](https://getstream.io/activity-feeds/) 16 | 17 | ## Quick start 18 | 19 | 1. Clone the repository 20 | 2. Open the project in Android Studio 21 | 3. Run the _samplekotlin_ or _samplejava_ configuration 22 | 4. Make sure to check the [Details](#details) section below for customizations 23 | 24 | ## Details 25 | 26 | The sample apps consist of two screens: 27 | 28 | * `MainActivity`: Shows the list of available channels. 29 | * `ChannelActivity`: Shows the selected channel view, which includes the header, message list, and message input view. 30 | 31 | Each module contains multiple `ChannelActivity` implementations, which correspond to the steps of the tutorial. You can easily swap them by changing the `setOnChannelClickListener` located in `MainActivity`: 32 | 33 | ```kotlin 34 | channelListView.setOnChannelClickListener { channel -> 35 | // open the channel activity 36 | startActivity(ChannelActivity.newIntent(this, channel)) 37 | } 38 | ``` 39 | 40 | Currently, you can choose from four different `ChannelActivity` implementations: 41 | 42 | * `ChannelActivity` - a basic _Message List_ implementation 43 | * `ChannelActivity2` - includes a new _MessageListView_ style and custom attachment type 44 | * `ChannelActivity4` - includes a custom _Typing Header_ component created with the [Low-Level Client](https://github.com/GetStream/stream-chat-android/tree/main/stream-chat-android-client) library 45 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | } 6 | dependencies { 7 | classpath "com.android.tools.build:gradle:8.8.2" 8 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21" 9 | } 10 | } 11 | 12 | task clean(type: Delete) { 13 | delete rootProject.buildDir 14 | } 15 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Jul 24 11:31:30 KST 2024 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /samplejava/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /samplejava/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | } 4 | 5 | android { 6 | compileSdk 35 7 | namespace "com.example.chattutorial" 8 | 9 | defaultConfig { 10 | applicationId "com.example.chattutorial" 11 | minSdk 21 12 | targetSdk 34 13 | versionCode 1 14 | versionName "1.0" 15 | 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | // Enable ViewBinding 27 | buildFeatures { 28 | viewBinding true 29 | } 30 | } 31 | 32 | dependencies { 33 | // Add new dependencies 34 | implementation "io.getstream:stream-chat-android-ui-components:6.12.1" 35 | implementation "io.getstream:stream-chat-android-offline:6.12.1" 36 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.7" 37 | implementation "com.google.android.material:material:1.12.0" 38 | implementation "androidx.activity:activity-ktx:1.10.1" 39 | implementation "io.coil-kt:coil:2.7.0" 40 | } 41 | -------------------------------------------------------------------------------- /samplejava/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /samplejava/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/ChannelActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import androidx.activity.OnBackPressedCallback; 8 | import androidx.annotation.Nullable; 9 | import androidx.appcompat.app.AppCompatActivity; 10 | import androidx.lifecycle.ViewModelProvider; 11 | 12 | import com.example.chattutorial.databinding.ActivityChannelBinding; 13 | 14 | import io.getstream.chat.android.models.Channel; 15 | import io.getstream.chat.android.models.Message; 16 | import io.getstream.chat.android.ui.common.state.messages.Edit; 17 | import io.getstream.chat.android.ui.common.state.messages.MessageMode; 18 | import io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView; 19 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel; 20 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModelBinding; 21 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel; 22 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModelBinding; 23 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel; 24 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelBinding; 25 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory; 26 | 27 | public class ChannelActivity extends AppCompatActivity { 28 | 29 | private final static String CID_KEY = "key:cid"; 30 | 31 | public static Intent newIntent(Context context, Channel channel) { 32 | final Intent intent = new Intent(context, ChannelActivity.class); 33 | intent.putExtra(CID_KEY, channel.getCid()); 34 | return intent; 35 | } 36 | 37 | @Override 38 | protected void onCreate(@Nullable Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | 41 | // Step 0 - inflate binding 42 | ActivityChannelBinding binding = ActivityChannelBinding.inflate(getLayoutInflater()); 43 | setContentView(binding.getRoot()); 44 | 45 | String cid = getIntent().getStringExtra(CID_KEY); 46 | if (cid == null) { 47 | throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity"); 48 | } 49 | 50 | // Step 1 - Create three separate ViewModels for the views so it's easy 51 | // to customize them individually 52 | ViewModelProvider.Factory factory = new MessageListViewModelFactory.Builder(this) 53 | .cid(cid) 54 | .build(); 55 | ViewModelProvider provider = new ViewModelProvider(this, factory); 56 | MessageListHeaderViewModel messageListHeaderViewModel = provider.get(MessageListHeaderViewModel.class); 57 | MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class); 58 | MessageComposerViewModel messageComposerViewModel = provider.get(MessageComposerViewModel.class); 59 | 60 | // TODO set custom Imgur attachment factory 61 | 62 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 63 | MessageListHeaderViewModelBinding.bind(messageListHeaderViewModel, binding.messageListHeaderView, this); 64 | MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this); 65 | MessageComposerViewModelBinding.bind(messageComposerViewModel, binding.messageComposerView, this); 66 | 67 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 68 | messageListViewModel.getMode().observe(this, mode -> { 69 | if (mode instanceof MessageMode.MessageThread) { 70 | Message parentMessage = ((MessageMode.MessageThread) mode).getParentMessage(); 71 | messageListHeaderViewModel.setActiveThread(parentMessage); 72 | messageComposerViewModel.setMessageMode(new MessageMode.MessageThread(parentMessage)); 73 | } else if (mode instanceof MessageMode.Normal) { 74 | messageListHeaderViewModel.resetThread(); 75 | messageComposerViewModel.leaveThread(); 76 | } 77 | }); 78 | 79 | // Step 4 - Let the message input know when we are editing a message 80 | binding.messageListView.setMessageEditHandler(message -> { 81 | messageComposerViewModel.performMessageAction(new Edit(message)); 82 | }); 83 | 84 | // Step 5 - Handle navigate up state 85 | messageListViewModel.getState().observe(this, state -> { 86 | if (state instanceof MessageListViewModel.State.NavigateUp) { 87 | finish(); 88 | } 89 | }); 90 | 91 | // Step 6 - Handle back button behaviour correctly when you're in a thread 92 | MessageListHeaderView.OnClickListener backHandler = () -> messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE); 93 | binding.messageListHeaderView.setBackButtonClickListener(backHandler); 94 | getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { 95 | @Override 96 | public void handleOnBackPressed() { 97 | backHandler.onClick(); 98 | } 99 | }); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/ChannelActivity2.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import androidx.activity.OnBackPressedCallback; 8 | import androidx.annotation.Nullable; 9 | import androidx.appcompat.app.AppCompatActivity; 10 | import androidx.lifecycle.ViewModelProvider; 11 | 12 | import com.example.chattutorial.databinding.ActivityChannel2Binding; 13 | 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | 17 | import io.getstream.chat.android.models.Channel; 18 | import io.getstream.chat.android.models.Message; 19 | import io.getstream.chat.android.ui.common.state.messages.Edit; 20 | import io.getstream.chat.android.ui.common.state.messages.MessageMode; 21 | import io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView; 22 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager; 23 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel; 24 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModelBinding; 25 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel; 26 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModelBinding; 27 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel; 28 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelBinding; 29 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory; 30 | 31 | public class ChannelActivity2 extends AppCompatActivity { 32 | 33 | private final static String CID_KEY = "key:cid"; 34 | 35 | public static Intent newIntent(Context context, Channel channel) { 36 | final Intent intent = new Intent(context, ChannelActivity.class); 37 | intent.putExtra(CID_KEY, channel.getCid()); 38 | return intent; 39 | } 40 | 41 | @Override 42 | protected void onCreate(@Nullable Bundle savedInstanceState) { 43 | super.onCreate(savedInstanceState); 44 | 45 | // Step 0 - inflate binding 46 | ActivityChannel2Binding binding = ActivityChannel2Binding.inflate(getLayoutInflater()); 47 | setContentView(binding.getRoot()); 48 | 49 | String cid = getIntent().getStringExtra(CID_KEY); 50 | if (cid == null) { 51 | throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity2"); 52 | } 53 | 54 | // Step 1 - Create three separate ViewModels for the views so it's easy 55 | // to customize them individually 56 | ViewModelProvider.Factory factory = new MessageListViewModelFactory.Builder(this) 57 | .cid(cid) 58 | .build(); 59 | ViewModelProvider provider = new ViewModelProvider(this, factory); 60 | MessageListHeaderViewModel messageListHeaderViewModel = provider.get(MessageListHeaderViewModel.class); 61 | MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class); 62 | MessageComposerViewModel messageComposerViewModel = provider.get(MessageComposerViewModel.class); 63 | 64 | // Set a view factory manager for Imgur attachments 65 | ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory(); 66 | 67 | List imgurAttachmentViewFactories = new ArrayList<>(); 68 | imgurAttachmentViewFactories.add(imgurAttachmentFactory); 69 | 70 | AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories); 71 | binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager); 72 | 73 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 74 | MessageListHeaderViewModelBinding.bind(messageListHeaderViewModel, binding.messageListHeaderView, this); 75 | MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this); 76 | MessageComposerViewModelBinding.bind(messageComposerViewModel, binding.messageComposerView, this); 77 | 78 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 79 | messageListViewModel.getMode().observe(this, mode -> { 80 | if (mode instanceof MessageMode.MessageThread) { 81 | Message parentMessage = ((MessageMode.MessageThread) mode).getParentMessage(); 82 | messageListHeaderViewModel.setActiveThread(parentMessage); 83 | messageComposerViewModel.setMessageMode(new MessageMode.MessageThread(parentMessage)); 84 | } else if (mode instanceof MessageMode.Normal) { 85 | messageListHeaderViewModel.resetThread(); 86 | messageComposerViewModel.leaveThread(); 87 | } 88 | }); 89 | 90 | // Step 4 - Let the message input know when we are editing a message 91 | binding.messageListView.setMessageEditHandler(message -> { 92 | messageComposerViewModel.performMessageAction(new Edit(message)); 93 | }); 94 | 95 | // Step 5 - Handle navigate up state 96 | messageListViewModel.getState().observe(this, state -> { 97 | if (state instanceof MessageListViewModel.State.NavigateUp) { 98 | finish(); 99 | } 100 | }); 101 | 102 | // Step 6 - Handle back button behaviour correctly when you're in a thread 103 | MessageListHeaderView.OnClickListener backHandler = () -> messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE); 104 | binding.messageListHeaderView.setBackButtonClickListener(backHandler); 105 | getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { 106 | @Override 107 | public void handleOnBackPressed() { 108 | backHandler.onClick(); 109 | } 110 | }); 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/ChannelActivity3.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | 7 | import androidx.activity.OnBackPressedCallback; 8 | import androidx.annotation.NonNull; 9 | import androidx.annotation.Nullable; 10 | import androidx.appcompat.app.AppCompatActivity; 11 | import androidx.lifecycle.LiveData; 12 | import androidx.lifecycle.Transformations; 13 | import androidx.lifecycle.ViewModelProvider; 14 | 15 | import com.example.chattutorial.databinding.ActivityChannel3Binding; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | import io.getstream.chat.android.client.ChatClient; 21 | import io.getstream.chat.android.client.channel.state.ChannelState; 22 | import io.getstream.chat.android.client.extensions.FlowExtensions; 23 | import io.getstream.chat.android.models.Channel; 24 | import io.getstream.chat.android.models.Message; 25 | import io.getstream.chat.android.models.TypingEvent; 26 | import io.getstream.chat.android.state.extensions.ChatClientExtensions; 27 | import io.getstream.chat.android.ui.common.state.messages.Edit; 28 | import io.getstream.chat.android.ui.common.state.messages.MessageMode; 29 | import io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView; 30 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager; 31 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel; 32 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModelBinding; 33 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel; 34 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModelBinding; 35 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel; 36 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelBinding; 37 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory; 38 | import kotlinx.coroutines.flow.Flow; 39 | 40 | public class ChannelActivity3 extends AppCompatActivity { 41 | 42 | private final static String CID_KEY = "key:cid"; 43 | 44 | public static Intent newIntent(Context context, Channel channel) { 45 | final Intent intent = new Intent(context, ChannelActivity.class); 46 | intent.putExtra(CID_KEY, channel.getCid()); 47 | return intent; 48 | } 49 | 50 | @Override 51 | protected void onCreate(@Nullable Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | 54 | // Step 0 - inflate binding 55 | ActivityChannel3Binding binding = ActivityChannel3Binding.inflate(getLayoutInflater()); 56 | setContentView(binding.getRoot()); 57 | 58 | String cid = getIntent().getStringExtra(CID_KEY); 59 | if (cid == null) { 60 | throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity3"); 61 | } 62 | 63 | // Step 1 - Create three separate ViewModels for the views so it's easy 64 | // to customize them individually 65 | ViewModelProvider.Factory factory = new MessageListViewModelFactory.Builder(this) 66 | .cid(cid) 67 | .build(); 68 | ViewModelProvider provider = new ViewModelProvider(this, factory); 69 | MessageListHeaderViewModel messageListHeaderViewModel = provider.get(MessageListHeaderViewModel.class); 70 | MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class); 71 | MessageComposerViewModel messageComposerViewModel = provider.get(MessageComposerViewModel.class); 72 | 73 | // Set a view factory manager for Imgur attachments 74 | ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory(); 75 | 76 | List imgurAttachmentViewFactories = new ArrayList(); 77 | imgurAttachmentViewFactories.add(imgurAttachmentFactory); 78 | 79 | AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories); 80 | binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager); 81 | 82 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 83 | MessageListHeaderViewModelBinding.bind(messageListHeaderViewModel, binding.messageListHeaderView, this); 84 | MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this); 85 | MessageComposerViewModelBinding.bind(messageComposerViewModel, binding.messageComposerView, this); 86 | 87 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 88 | messageListViewModel.getMode().observe(this, mode -> { 89 | if (mode instanceof MessageMode.MessageThread) { 90 | Message parentMessage = ((MessageMode.MessageThread) mode).getParentMessage(); 91 | messageListHeaderViewModel.setActiveThread(parentMessage); 92 | messageComposerViewModel.setMessageMode(new MessageMode.MessageThread(parentMessage)); 93 | } else if (mode instanceof MessageMode.Normal) { 94 | messageListHeaderViewModel.resetThread(); 95 | messageComposerViewModel.leaveThread(); 96 | } 97 | }); 98 | 99 | // Step 4 - Let the message input know when we are editing a message 100 | binding.messageListView.setMessageEditHandler(message -> { 101 | messageComposerViewModel.performMessageAction(new Edit(message)); 102 | }); 103 | 104 | // Step 5 - Handle navigate up state 105 | messageListViewModel.getState().observe(this, state -> { 106 | if (state instanceof MessageListViewModel.State.NavigateUp) { 107 | finish(); 108 | } 109 | }); 110 | 111 | // Step 6 - Handle back button behaviour correctly when you're in a thread 112 | MessageListHeaderView.OnClickListener backHandler = () -> messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE); 113 | binding.messageListHeaderView.setBackButtonClickListener(backHandler); 114 | getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { 115 | @Override 116 | public void handleOnBackPressed() { 117 | backHandler.onClick(); 118 | } 119 | }); 120 | 121 | // Custom typing info header bar 122 | String nobodyTyping = "nobody is typing"; 123 | binding.typingHeaderView.setText(nobodyTyping); 124 | 125 | // Observe typing events and update typing header depending on its state. 126 | Flow channelStateFlow = ChatClientExtensions.watchChannelAsState(ChatClient.instance(), cid, 30); 127 | LiveData typingEventLiveData = Transformations.switchMap( 128 | FlowExtensions.asLiveData(channelStateFlow), 129 | channelState -> FlowExtensions.asLiveData(channelState.getTyping()) 130 | ); 131 | 132 | typingEventLiveData.observe(this, typingEvent -> { 133 | String headerText; 134 | 135 | if (typingEvent.getUsers().size() != 0) { 136 | headerText = "typing: " + joinTypingUpdatesToUserNames(typingEvent); 137 | } else { 138 | headerText = nobodyTyping; 139 | } 140 | 141 | binding.typingHeaderView.setText(headerText); 142 | }); 143 | } 144 | 145 | // Helper method that transforms typing updates into a string 146 | // containing typing member's names 147 | @NonNull 148 | private String joinTypingUpdatesToUserNames(@NonNull TypingEvent typingEvent) { 149 | StringBuilder joinedString = new StringBuilder(); 150 | 151 | for (int i = 0; i < typingEvent.getUsers().size(); i++) { 152 | if (i < typingEvent.getUsers().size() - 1) { 153 | joinedString.append(typingEvent.getUsers().get(i).getName()).append(", "); 154 | } else { 155 | joinedString.append(typingEvent.getUsers().get(i).getName()); 156 | } 157 | } 158 | 159 | return joinedString.toString(); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/ChannelActivity4.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.text.TextUtils; 7 | import android.widget.TextView; 8 | 9 | import androidx.activity.OnBackPressedCallback; 10 | import androidx.annotation.Nullable; 11 | import androidx.appcompat.app.AppCompatActivity; 12 | import androidx.lifecycle.ViewModelProvider; 13 | 14 | import com.example.chattutorial.databinding.ActivityChannel4Binding; 15 | 16 | import java.util.ArrayList; 17 | import java.util.HashSet; 18 | import java.util.List; 19 | import java.util.Set; 20 | 21 | import io.getstream.chat.android.client.ChatClient; 22 | import io.getstream.chat.android.client.events.TypingStartEvent; 23 | import io.getstream.chat.android.client.events.TypingStopEvent; 24 | import io.getstream.chat.android.models.Channel; 25 | import io.getstream.chat.android.models.Message; 26 | import io.getstream.chat.android.models.User; 27 | import io.getstream.chat.android.ui.common.state.messages.Edit; 28 | import io.getstream.chat.android.ui.common.state.messages.MessageMode; 29 | import io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView; 30 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager; 31 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel; 32 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModelBinding; 33 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel; 34 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModelBinding; 35 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel; 36 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelBinding; 37 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory; 38 | 39 | public class ChannelActivity4 extends AppCompatActivity { 40 | 41 | private final static String CID_KEY = "key:cid"; 42 | 43 | public static Intent newIntent(Context context, Channel channel) { 44 | final Intent intent = new Intent(context, ChannelActivity4.class); 45 | intent.putExtra(CID_KEY, channel.getCid()); 46 | return intent; 47 | } 48 | 49 | @Override 50 | protected void onCreate(@Nullable Bundle savedInstanceState) { 51 | super.onCreate(savedInstanceState); 52 | 53 | // Step 0 - inflate binding 54 | ActivityChannel4Binding binding = ActivityChannel4Binding.inflate(getLayoutInflater()); 55 | setContentView(binding.getRoot()); 56 | 57 | String cid = getIntent().getStringExtra(CID_KEY); 58 | if (cid == null) { 59 | throw new IllegalStateException("Specifying a channel id is required when starting ChannelActivity4"); 60 | } 61 | 62 | // Step 1 - Create three separate ViewModels for the views so it's easy 63 | // to customize them individually 64 | ViewModelProvider.Factory factory = new MessageListViewModelFactory.Builder(this) 65 | .cid(cid) 66 | .build(); 67 | ViewModelProvider provider = new ViewModelProvider(this, factory); 68 | MessageListHeaderViewModel messageListHeaderViewModel = provider.get(MessageListHeaderViewModel.class); 69 | MessageListViewModel messageListViewModel = provider.get(MessageListViewModel.class); 70 | MessageComposerViewModel messageComposerViewModel = provider.get(MessageComposerViewModel.class); 71 | 72 | // Set a view factory manager for Imgur attachments 73 | ImgurAttachmentFactory imgurAttachmentFactory = new ImgurAttachmentFactory(); 74 | 75 | List imgurAttachmentViewFactories = new ArrayList<>(); 76 | imgurAttachmentViewFactories.add(imgurAttachmentFactory); 77 | 78 | AttachmentFactoryManager attachmentFactoryManager = new AttachmentFactoryManager(imgurAttachmentViewFactories); 79 | binding.messageListView.setAttachmentFactoryManager(attachmentFactoryManager); 80 | 81 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 82 | MessageListHeaderViewModelBinding.bind(messageListHeaderViewModel, binding.messageListHeaderView, this); 83 | MessageListViewModelBinding.bind(messageListViewModel, binding.messageListView, this); 84 | MessageComposerViewModelBinding.bind(messageComposerViewModel, binding.messageComposerView, this); 85 | 86 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 87 | messageListViewModel.getMode().observe(this, mode -> { 88 | if (mode instanceof MessageMode.MessageThread) { 89 | Message parentMessage = ((MessageMode.MessageThread) mode).getParentMessage(); 90 | messageListHeaderViewModel.setActiveThread(parentMessage); 91 | messageComposerViewModel.setMessageMode(new MessageMode.MessageThread(parentMessage)); 92 | } else if (mode instanceof MessageMode.Normal) { 93 | messageListHeaderViewModel.resetThread(); 94 | messageComposerViewModel.leaveThread(); 95 | } 96 | }); 97 | 98 | // Step 4 - Let the message input know when we are editing a message 99 | binding.messageListView.setMessageEditHandler(message -> { 100 | messageComposerViewModel.performMessageAction(new Edit(message)); 101 | }); 102 | 103 | // Step 5 - Handle navigate up state 104 | messageListViewModel.getState().observe(this, state -> { 105 | if (state instanceof MessageListViewModel.State.NavigateUp) { 106 | finish(); 107 | } 108 | }); 109 | 110 | // Step 6 - Handle back button behaviour correctly when you're in a thread 111 | MessageListHeaderView.OnClickListener backHandler = () -> messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed.INSTANCE); 112 | binding.messageListHeaderView.setBackButtonClickListener(backHandler); 113 | getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { 114 | @Override 115 | public void handleOnBackPressed() { 116 | backHandler.onClick(); 117 | } 118 | }); 119 | 120 | // Custom typing info header bar 121 | TextView typingHeaderView = findViewById(R.id.typingHeaderView); 122 | String nobodyTyping = "nobody is typing"; 123 | typingHeaderView.setText(nobodyTyping); 124 | 125 | // Observe raw events through the low-level client 126 | Set currentlyTyping = new HashSet<>(); 127 | ChatClient.instance() 128 | .channel(cid) 129 | .subscribeFor( 130 | this, 131 | new Class[]{TypingStartEvent.class, TypingStopEvent.class}, 132 | event -> { 133 | if (event instanceof TypingStartEvent) { 134 | User user = ((TypingStartEvent) event).getUser(); 135 | currentlyTyping.add(user.getName()); 136 | } else if (event instanceof TypingStopEvent) { 137 | User user = ((TypingStopEvent) event).getUser(); 138 | currentlyTyping.remove(user.getName()); 139 | } 140 | 141 | String typing = "nobody is typing"; 142 | if (!currentlyTyping.isEmpty()) { 143 | typing = "typing: " + TextUtils.join(", ", currentlyTyping); 144 | } 145 | 146 | typingHeaderView.setText(typing); 147 | } 148 | ); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/ImgurAttachmentFactory.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import android.view.LayoutInflater; 4 | import android.view.ViewGroup; 5 | 6 | import androidx.annotation.NonNull; 7 | import androidx.annotation.Nullable; 8 | 9 | import com.example.chattutorial.databinding.AttachmentImgurBinding; 10 | import com.google.android.material.shape.ShapeAppearanceModel; 11 | 12 | import org.jetbrains.annotations.NotNull; 13 | 14 | import coil.Coil; 15 | import coil.request.ImageRequest; 16 | import io.getstream.chat.android.models.Attachment; 17 | import io.getstream.chat.android.models.Message; 18 | import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListListeners; 19 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.BaseAttachmentFactory; 20 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.InnerAttachmentViewHolder; 21 | 22 | /** 23 | * A custom attachment factory to show an imgur logo if the attachment URL is an imgur image. 24 | **/ 25 | public class ImgurAttachmentFactory extends BaseAttachmentFactory { 26 | 27 | 28 | // Step 1 - Check whether the message contains an Imgur attachment 29 | @Override 30 | public boolean canHandle(@NonNull Message message) { 31 | return containsImgurAttachments(message) != null; 32 | } 33 | 34 | // Step 2 - Create the ViewHolder that will be used to display the Imgur logo 35 | // over Imgur attachments 36 | @NonNull 37 | @Override 38 | public InnerAttachmentViewHolder createViewHolder( 39 | @NonNull Message message, 40 | @Nullable MessageListListeners listeners, 41 | @NonNull ViewGroup parent 42 | ) { 43 | Attachment imgurAttachment = containsImgurAttachments(message); 44 | 45 | AttachmentImgurBinding attachmentImgurBinding = AttachmentImgurBinding.inflate(LayoutInflater.from(parent.getContext()), null, false); 46 | 47 | return new ImgurAttachmentViewHolder(attachmentImgurBinding, imgurAttachment); 48 | } 49 | 50 | private Attachment containsImgurAttachments(@NotNull Message message) { 51 | for (int i = 0; i < message.getAttachments().size(); i++) { 52 | String imageUrl = message.getAttachments().get(i).getImageUrl(); 53 | 54 | if (imageUrl != null && imageUrl.contains("imgur")) { 55 | return message.getAttachments().get(i); 56 | } 57 | } 58 | 59 | return null; 60 | } 61 | 62 | private static class ImgurAttachmentViewHolder extends InnerAttachmentViewHolder { 63 | 64 | public ImgurAttachmentViewHolder(AttachmentImgurBinding binding, 65 | @Nullable Attachment imgurAttachment) { 66 | super(binding.getRoot()); 67 | 68 | ShapeAppearanceModel shapeAppearanceModel = binding.ivMediaThumb.getShapeAppearanceModel() 69 | .toBuilder() 70 | .setAllCornerSizes(binding.ivMediaThumb.getResources().getDimension(io.getstream.chat.android.ui.R.dimen.stream_ui_selected_attachment_corner_radius)) 71 | .build(); 72 | 73 | binding.ivMediaThumb.setShapeAppearanceModel(shapeAppearanceModel); 74 | 75 | if (imgurAttachment != null) { 76 | ImageRequest imageRequest = new ImageRequest.Builder(binding.getRoot().getContext()) 77 | .data(imgurAttachment.getImageUrl()) 78 | .allowHardware(false) 79 | .crossfade(true) 80 | .placeholder(io.getstream.chat.android.ui.R.drawable.stream_ui_picture_placeholder) 81 | .target(binding.ivMediaThumb) 82 | .build(); 83 | Coil.imageLoader(binding.getRoot().getContext()).enqueue(imageRequest); 84 | } 85 | } 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /samplejava/src/main/java/com/example/chattutorial/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial; 2 | 3 | import static java.util.Collections.singletonList; 4 | 5 | import android.os.Bundle; 6 | 7 | import androidx.appcompat.app.AppCompatActivity; 8 | import androidx.lifecycle.ViewModelProvider; 9 | 10 | import com.example.chattutorial.databinding.ActivityMainBinding; 11 | 12 | import org.jetbrains.annotations.Nullable; 13 | 14 | import io.getstream.chat.android.client.ChatClient; 15 | import io.getstream.chat.android.client.logger.ChatLogLevel; 16 | import io.getstream.chat.android.models.FilterObject; 17 | import io.getstream.chat.android.models.Filters; 18 | import io.getstream.chat.android.models.User; 19 | import io.getstream.chat.android.offline.plugin.factory.StreamOfflinePluginFactory; 20 | import io.getstream.chat.android.state.plugin.config.StatePluginConfig; 21 | import io.getstream.chat.android.state.plugin.factory.StreamStatePluginFactory; 22 | import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModel; 23 | import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModelBinding; 24 | import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModelFactory; 25 | 26 | public final class MainActivity extends AppCompatActivity { 27 | 28 | protected void onCreate(@Nullable Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | 31 | // Step 0 - inflate binding 32 | ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater()); 33 | setContentView(binding.getRoot()); 34 | 35 | // Step 1 - Set up the OfflinePlugin for offline storage 36 | StreamOfflinePluginFactory streamOfflinePluginFactory = new StreamOfflinePluginFactory( 37 | getApplicationContext() 38 | ); 39 | StreamStatePluginFactory streamStatePluginFactory = new StreamStatePluginFactory( 40 | new StatePluginConfig(true, true), this 41 | ); 42 | 43 | // Step 2 - Set up the client for API calls with the plugin for offline storage 44 | ChatClient client = new ChatClient.Builder("uun7ywwamhs9", getApplicationContext()) 45 | .withPlugins(streamOfflinePluginFactory, streamStatePluginFactory) 46 | .logLevel(ChatLogLevel.ALL) // Set to NOTHING in prod 47 | .build(); 48 | 49 | // Step 3 - Authenticate and connect the user 50 | User user = new User.Builder() 51 | .withId("tutorial-droid") 52 | .withName("Tutorial Droid") 53 | .withImage("https://bit.ly/2TIt8NR") 54 | .build(); 55 | 56 | client.connectUser( 57 | user, 58 | "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidHV0b3JpYWwtZHJvaWQifQ.WwfBzU1GZr0brt_fXnqKdKhz3oj0rbDUm2DqJO_SS5U" 59 | ).enqueue(result -> { 60 | // Step 4 - Set the channel list filter and order 61 | // This can be read as requiring only channels whose "type" is "messaging" AND 62 | // whose "members" include our "user.id" 63 | FilterObject filter = Filters.and( 64 | Filters.eq("type", "messaging"), 65 | Filters.in("members", singletonList(user.getId())) 66 | ); 67 | 68 | ViewModelProvider.Factory factory = new ChannelListViewModelFactory.Builder() 69 | .filter(filter) 70 | .sort(ChannelListViewModel.DEFAULT_SORT) 71 | .build(); 72 | 73 | ChannelListViewModel channelsViewModel = 74 | new ViewModelProvider(this, factory).get(ChannelListViewModel.class); 75 | 76 | // Step 5 - Connect the ChannelListViewModel to the ChannelListView, loose 77 | // coupling makes it easy to customize 78 | ChannelListViewModelBinding.bind(channelsViewModel, binding.channelListView, this); 79 | binding.channelListView.setChannelItemClickListener( 80 | channel -> startActivity(ChannelActivity4.newIntent(this, channel)) 81 | ); 82 | }); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /samplejava/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /samplejava/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /samplejava/src/main/res/drawable/imgur_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/drawable/imgur_logo.png -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/activity_channel.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 23 | 24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/activity_channel_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 23 | 24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/activity_channel_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 24 | 25 | 33 | 34 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/activity_channel_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 24 | 25 | 33 | 34 | 41 | 42 | -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /samplejava/src/main/res/layout/attachment_imgur.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 20 | 21 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplejava/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplejava/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplejava/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /samplejava/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | 11 | -------------------------------------------------------------------------------- /samplejava/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Stream Chat Tutorial 3 | 4 | -------------------------------------------------------------------------------- /samplejava/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /samplekotlin/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /samplekotlin/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | } 5 | 6 | android { 7 | compileSdk 35 8 | namespace "com.example.chattutorial" 9 | 10 | defaultConfig { 11 | applicationId "com.example.chattutorial" 12 | minSdk 21 13 | targetSdk 34 14 | versionCode 1 15 | versionName "1.0" 16 | } 17 | 18 | // Enable ViewBinding 19 | buildFeatures { 20 | viewBinding true 21 | } 22 | 23 | compileOptions { 24 | sourceCompatibility = JavaVersion.VERSION_11 25 | targetCompatibility = JavaVersion.VERSION_11 26 | } 27 | 28 | kotlinOptions { 29 | jvmTarget = "11" 30 | } 31 | } 32 | 33 | dependencies { 34 | // Add new dependencies 35 | implementation "io.getstream:stream-chat-android-ui-components:6.12.1" 36 | implementation "io.getstream:stream-chat-android-offline:6.12.1" 37 | implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.8.7" 38 | implementation "com.google.android.material:material:1.12.0" 39 | implementation "androidx.activity:activity-ktx:1.10.1" 40 | implementation "io.coil-kt:coil:2.7.0" 41 | } 42 | -------------------------------------------------------------------------------- /samplekotlin/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /samplekotlin/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import androidx.activity.addCallback 7 | import androidx.activity.viewModels 8 | import androidx.appcompat.app.AppCompatActivity 9 | import com.example.chattutorial.databinding.ActivityChannelBinding 10 | import io.getstream.chat.android.models.Channel 11 | import io.getstream.chat.android.ui.common.state.messages.Edit 12 | import io.getstream.chat.android.ui.common.state.messages.MessageMode 13 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel 14 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel 15 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel 16 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory 17 | import io.getstream.chat.android.ui.viewmodel.messages.bindView 18 | 19 | class ChannelActivity : AppCompatActivity() { 20 | 21 | private lateinit var binding: ActivityChannelBinding 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | 26 | // Step 0 - inflate binding 27 | binding = ActivityChannelBinding.inflate(layoutInflater) 28 | setContentView(binding.root) 29 | 30 | val cid = checkNotNull(intent.getStringExtra(CID_KEY)) { 31 | "Specifying a channel id is required when starting ChannelActivity" 32 | } 33 | 34 | // Step 1 - Create three separate ViewModels for the views so it's easy 35 | // to customize them individually 36 | val factory = MessageListViewModelFactory(this, cid) 37 | val messageListHeaderViewModel: MessageListHeaderViewModel by viewModels { factory } 38 | val messageListViewModel: MessageListViewModel by viewModels { factory } 39 | val messageComposerViewModel: MessageComposerViewModel by viewModels { factory } 40 | 41 | // TODO set custom Imgur attachment factory 42 | 43 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 44 | messageListHeaderViewModel.bindView(binding.messageListHeaderView, this) 45 | messageListViewModel.bindView(binding.messageListView, this) 46 | messageComposerViewModel.bindView(binding.messageComposerView, this) 47 | 48 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 49 | messageListViewModel.mode.observe(this) { mode -> 50 | when (mode) { 51 | is MessageMode.MessageThread -> { 52 | messageListHeaderViewModel.setActiveThread(mode.parentMessage) 53 | messageComposerViewModel.setMessageMode(MessageMode.MessageThread(mode.parentMessage)) 54 | } 55 | 56 | is MessageMode.Normal -> { 57 | messageListHeaderViewModel.resetThread() 58 | messageComposerViewModel.leaveThread() 59 | } 60 | } 61 | } 62 | 63 | // Step 4 - Let the message input know when we are editing a message 64 | binding.messageListView.setMessageEditHandler { message -> 65 | messageComposerViewModel.performMessageAction(Edit(message)) 66 | } 67 | 68 | // Step 5 - Handle navigate up state 69 | messageListViewModel.state.observe(this) { state -> 70 | if (state is MessageListViewModel.State.NavigateUp) { 71 | finish() 72 | } 73 | } 74 | 75 | // Step 6 - Handle back button behaviour correctly when you're in a thread 76 | val backHandler = { 77 | messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed) 78 | } 79 | binding.messageListHeaderView.setBackButtonClickListener(backHandler) 80 | onBackPressedDispatcher.addCallback(this) { 81 | backHandler() 82 | } 83 | } 84 | 85 | companion object { 86 | private const val CID_KEY = "key:cid" 87 | 88 | fun newIntent(context: Context, channel: Channel): Intent = 89 | Intent(context, ChannelActivity::class.java).putExtra(CID_KEY, channel.cid) 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity2.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import androidx.activity.addCallback 7 | import androidx.activity.viewModels 8 | import androidx.appcompat.app.AppCompatActivity 9 | import com.example.chattutorial.databinding.ActivityChannel2Binding 10 | import io.getstream.chat.android.models.Channel 11 | import io.getstream.chat.android.ui.common.state.messages.Edit 12 | import io.getstream.chat.android.ui.common.state.messages.MessageMode 13 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager 14 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel 15 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel 16 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel 17 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory 18 | import io.getstream.chat.android.ui.viewmodel.messages.bindView 19 | 20 | class ChannelActivity2 : AppCompatActivity() { 21 | 22 | private lateinit var binding: ActivityChannel2Binding 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | 27 | // Step 0 - inflate binding 28 | binding = ActivityChannel2Binding.inflate(layoutInflater) 29 | setContentView(binding.root) 30 | 31 | val cid = checkNotNull(intent.getStringExtra(CID_KEY)) { 32 | "Specifying a channel id is required when starting ChannelActivity2" 33 | } 34 | 35 | // Step 1 - Create three separate ViewModels for the views so it's easy 36 | // to customize them individually 37 | val factory = MessageListViewModelFactory(this, cid) 38 | val messageListHeaderViewModel: MessageListHeaderViewModel by viewModels { factory } 39 | val messageListViewModel: MessageListViewModel by viewModels { factory } 40 | val messageComposerViewModel: MessageComposerViewModel by viewModels { factory } 41 | 42 | // Set a view factory manager for Imgur attachments 43 | val imgurAttachmentViewFactory = ImgurAttachmentFactory() 44 | val attachmentViewFactory = AttachmentFactoryManager(listOf(imgurAttachmentViewFactory)) 45 | binding.messageListView.setAttachmentFactoryManager(attachmentViewFactory) 46 | 47 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 48 | messageListHeaderViewModel.bindView(binding.messageListHeaderView, this) 49 | messageListViewModel.bindView(binding.messageListView, this) 50 | messageComposerViewModel.bindView(binding.messageComposerView, this) 51 | 52 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 53 | messageListViewModel.mode.observe(this) { mode -> 54 | when (mode) { 55 | is MessageMode.MessageThread -> { 56 | messageListHeaderViewModel.setActiveThread(mode.parentMessage) 57 | messageComposerViewModel.setMessageMode(MessageMode.MessageThread(mode.parentMessage)) 58 | } 59 | 60 | is MessageMode.Normal -> { 61 | messageListHeaderViewModel.resetThread() 62 | messageComposerViewModel.leaveThread() 63 | } 64 | } 65 | } 66 | 67 | // Step 4 - Let the message input know when we are editing a message 68 | binding.messageListView.setMessageEditHandler { message -> 69 | messageComposerViewModel.performMessageAction(Edit(message)) 70 | } 71 | 72 | // Step 5 - Handle navigate up state 73 | messageListViewModel.state.observe(this) { state -> 74 | if (state is MessageListViewModel.State.NavigateUp) { 75 | finish() 76 | } 77 | } 78 | 79 | // Step 6 - Handle back button behaviour correctly when you're in a thread 80 | val backHandler = { 81 | messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed) 82 | } 83 | binding.messageListHeaderView.setBackButtonClickListener(backHandler) 84 | onBackPressedDispatcher.addCallback(this) { 85 | backHandler() 86 | } 87 | } 88 | 89 | companion object { 90 | private const val CID_KEY = "key:cid" 91 | 92 | fun newIntent(context: Context, channel: Channel): Intent = 93 | Intent(context, ChannelActivity2::class.java).putExtra(CID_KEY, channel.cid) 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity3.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import androidx.activity.addCallback 7 | import androidx.activity.viewModels 8 | import androidx.appcompat.app.AppCompatActivity 9 | import androidx.lifecycle.Lifecycle 10 | import androidx.lifecycle.lifecycleScope 11 | import androidx.lifecycle.repeatOnLifecycle 12 | import com.example.chattutorial.databinding.ActivityChannel3Binding 13 | import io.getstream.chat.android.client.ChatClient 14 | import io.getstream.chat.android.models.Channel 15 | import io.getstream.chat.android.state.extensions.watchChannelAsState 16 | import io.getstream.chat.android.ui.common.state.messages.Edit 17 | import io.getstream.chat.android.ui.common.state.messages.MessageMode 18 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager 19 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel 20 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel 21 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel 22 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory 23 | import io.getstream.chat.android.ui.viewmodel.messages.bindView 24 | import kotlinx.coroutines.flow.filterNotNull 25 | import kotlinx.coroutines.flow.flatMapLatest 26 | import kotlinx.coroutines.launch 27 | 28 | class ChannelActivity3 : AppCompatActivity() { 29 | 30 | private lateinit var binding: ActivityChannel3Binding 31 | 32 | override fun onCreate(savedInstanceState: Bundle?) { 33 | super.onCreate(savedInstanceState) 34 | 35 | // Step 0 - inflate binding 36 | binding = ActivityChannel3Binding.inflate(layoutInflater) 37 | setContentView(binding.root) 38 | 39 | val cid = checkNotNull(intent.getStringExtra(CID_KEY)) { 40 | "Specifying a channel id is required when starting ChannelActivity3" 41 | } 42 | 43 | // Step 1 - Create three separate ViewModels for the views so it's easy 44 | // to customize them individually 45 | val factory = MessageListViewModelFactory(this, cid) 46 | val messageListHeaderViewModel: MessageListHeaderViewModel by viewModels { factory } 47 | val messageListViewModel: MessageListViewModel by viewModels { factory } 48 | val messageComposerViewModel: MessageComposerViewModel by viewModels { factory } 49 | 50 | // Set a view factory manager for Imgur attachments 51 | val imgurAttachmentViewFactory = ImgurAttachmentFactory() 52 | val attachmentViewFactory = AttachmentFactoryManager(listOf(imgurAttachmentViewFactory)) 53 | binding.messageListView.setAttachmentFactoryManager(attachmentViewFactory) 54 | 55 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 56 | messageListHeaderViewModel.bindView(binding.messageListHeaderView, this) 57 | messageListViewModel.bindView(binding.messageListView, this) 58 | messageComposerViewModel.bindView(binding.messageComposerView, this) 59 | 60 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 61 | messageListViewModel.mode.observe(this) { mode -> 62 | when (mode) { 63 | is MessageMode.MessageThread -> { 64 | messageListHeaderViewModel.setActiveThread(mode.parentMessage) 65 | messageComposerViewModel.setMessageMode(MessageMode.MessageThread(mode.parentMessage)) 66 | } 67 | 68 | is MessageMode.Normal -> { 69 | messageListHeaderViewModel.resetThread() 70 | messageComposerViewModel.leaveThread() 71 | } 72 | } 73 | } 74 | 75 | // Step 4 - Let the message input know when we are editing a message 76 | binding.messageListView.setMessageEditHandler { message -> 77 | messageComposerViewModel.performMessageAction(Edit(message)) 78 | } 79 | 80 | // Step 5 - Handle navigate up state 81 | messageListViewModel.state.observe(this) { state -> 82 | if (state is MessageListViewModel.State.NavigateUp) { 83 | finish() 84 | } 85 | } 86 | 87 | // Step 6 - Handle back button behaviour correctly when you're in a thread 88 | val backHandler = { 89 | messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed) 90 | } 91 | binding.messageListHeaderView.setBackButtonClickListener(backHandler) 92 | onBackPressedDispatcher.addCallback(this) { 93 | backHandler() 94 | } 95 | 96 | // Custom typing info header bar 97 | val nobodyTyping = "nobody is typing" 98 | binding.typingHeaderView.text = nobodyTyping 99 | 100 | // Observe typing events and update typing header depending on its state. 101 | 102 | lifecycleScope.launch { 103 | repeatOnLifecycle(Lifecycle.State.STARTED) { 104 | ChatClient.instance().watchChannelAsState(cid, 30) 105 | .filterNotNull() 106 | .flatMapLatest { it.typing } 107 | .collect { 108 | binding.typingHeaderView.text = when { 109 | it.users.isNotEmpty() -> it.users.joinToString(prefix = "typing: ") { user -> user.name } 110 | else -> nobodyTyping 111 | } 112 | } 113 | } 114 | } 115 | } 116 | 117 | companion object { 118 | private const val CID_KEY = "key:cid" 119 | 120 | fun newIntent(context: Context, channel: Channel): Intent = 121 | Intent(context, ChannelActivity3::class.java).putExtra(CID_KEY, channel.cid) 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/ChannelActivity4.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.content.Context 4 | import android.content.Intent 5 | import android.os.Bundle 6 | import androidx.activity.addCallback 7 | import androidx.activity.viewModels 8 | import androidx.appcompat.app.AppCompatActivity 9 | import com.example.chattutorial.databinding.ActivityChannel4Binding 10 | import io.getstream.chat.android.client.ChatClient 11 | import io.getstream.chat.android.client.channel.subscribeFor 12 | import io.getstream.chat.android.client.events.TypingStartEvent 13 | import io.getstream.chat.android.client.events.TypingStopEvent 14 | import io.getstream.chat.android.models.Channel 15 | import io.getstream.chat.android.ui.common.state.messages.Edit 16 | import io.getstream.chat.android.ui.common.state.messages.MessageMode 17 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactoryManager 18 | import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel 19 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel 20 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel 21 | import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory 22 | import io.getstream.chat.android.ui.viewmodel.messages.bindView 23 | 24 | class ChannelActivity4 : AppCompatActivity() { 25 | 26 | private lateinit var binding: ActivityChannel4Binding 27 | 28 | override fun onCreate(savedInstanceState: Bundle?) { 29 | super.onCreate(savedInstanceState) 30 | 31 | // Step 0 - inflate binding 32 | binding = ActivityChannel4Binding.inflate(layoutInflater) 33 | setContentView(binding.root) 34 | 35 | val cid = checkNotNull(intent.getStringExtra(CID_KEY)) { 36 | "Specifying a channel id is required when starting ChannelActivity4" 37 | } 38 | 39 | // Step 1 - Create three separate ViewModels for the views so it's easy 40 | // to customize them individually 41 | val factory = MessageListViewModelFactory(this, cid) 42 | val messageListHeaderViewModel: MessageListHeaderViewModel by viewModels { factory } 43 | val messageListViewModel: MessageListViewModel by viewModels { factory } 44 | val messageComposerViewModel: MessageComposerViewModel by viewModels { factory } 45 | 46 | // Set a view factory manager for Imgur attachments 47 | val imgurAttachmentViewFactory = ImgurAttachmentFactory() 48 | val attachmentViewFactory = AttachmentFactoryManager(listOf(imgurAttachmentViewFactory)) 49 | binding.messageListView.setAttachmentFactoryManager(attachmentViewFactory) 50 | 51 | // Step 2 - Bind the view and ViewModels, they are loosely coupled so it's easy to customize 52 | messageListHeaderViewModel.bindView(binding.messageListHeaderView, this) 53 | messageListViewModel.bindView(binding.messageListView, this) 54 | messageComposerViewModel.bindView(binding.messageComposerView, this) 55 | 56 | // Step 3 - Let both MessageListHeaderView and MessageComposerView know when we open a thread 57 | messageListViewModel.mode.observe(this) { mode -> 58 | when (mode) { 59 | is MessageMode.MessageThread -> { 60 | messageListHeaderViewModel.setActiveThread(mode.parentMessage) 61 | messageComposerViewModel.setMessageMode(MessageMode.MessageThread(mode.parentMessage)) 62 | } 63 | 64 | is MessageMode.Normal -> { 65 | messageListHeaderViewModel.resetThread() 66 | messageComposerViewModel.leaveThread() 67 | } 68 | } 69 | } 70 | 71 | // Step 4 - Let the message input know when we are editing a message 72 | binding.messageListView.setMessageEditHandler { message -> 73 | messageComposerViewModel.performMessageAction(Edit(message)) 74 | } 75 | 76 | // Step 5 - Handle navigate up state 77 | messageListViewModel.state.observe(this) { state -> 78 | if (state is MessageListViewModel.State.NavigateUp) { 79 | finish() 80 | } 81 | } 82 | 83 | // Step 6 - Handle back button behaviour correctly when you're in a thread 84 | val backHandler = { 85 | messageListViewModel.onEvent(MessageListViewModel.Event.BackButtonPressed) 86 | } 87 | binding.messageListHeaderView.setBackButtonClickListener(backHandler) 88 | onBackPressedDispatcher.addCallback(this) { 89 | backHandler() 90 | } 91 | 92 | // Custom typing info header bar 93 | val nobodyTyping = "nobody is typing" 94 | binding.typingHeaderView.text = nobodyTyping 95 | 96 | val currentlyTyping = mutableSetOf() 97 | 98 | // Observe typing events and update typing header depending on its state. 99 | ChatClient 100 | .instance() 101 | .channel(cid) 102 | .subscribeFor( 103 | this, TypingStartEvent::class, TypingStopEvent::class 104 | ) { event -> 105 | when (event) { 106 | is TypingStartEvent -> currentlyTyping.add(event.user.name) 107 | is TypingStopEvent -> currentlyTyping.remove(event.user.name) 108 | else -> {} 109 | } 110 | 111 | binding.typingHeaderView.text = when { 112 | currentlyTyping.isNotEmpty() -> currentlyTyping.joinToString(prefix = "typing: ") 113 | else -> nobodyTyping 114 | } 115 | } 116 | } 117 | 118 | companion object { 119 | private const val CID_KEY = "key:cid" 120 | 121 | fun newIntent(context: Context, channel: Channel): Intent = 122 | Intent(context, ChannelActivity4::class.java).putExtra(CID_KEY, channel.cid) 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/ImgurAttachmentFactory.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import coil.load 6 | import com.example.chattutorial.databinding.AttachmentImgurBinding 7 | import io.getstream.chat.android.models.Attachment 8 | import io.getstream.chat.android.models.Message 9 | import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListListeners 10 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.AttachmentFactory 11 | import io.getstream.chat.android.ui.feature.messages.list.adapter.viewholder.attachment.InnerAttachmentViewHolder 12 | 13 | /** A custom attachment factory to show an imgur logo if the attachment URL is an imgur image. */ 14 | class ImgurAttachmentFactory : AttachmentFactory { 15 | 16 | // Step 1 - Check whether the message contains an Imgur attachment 17 | override fun canHandle(message: Message): Boolean { 18 | val imgurAttachment = message.attachments.firstOrNull { it.isImgurAttachment() } 19 | return imgurAttachment != null 20 | } 21 | 22 | // Step 2 - Create the ViewHolder that will be used to display the Imgur logo 23 | // over Imgur attachments 24 | override fun createViewHolder( 25 | message: Message, 26 | listeners: MessageListListeners?, 27 | parent: ViewGroup 28 | ): InnerAttachmentViewHolder { 29 | val imgurAttachment = message.attachments.first { it.isImgurAttachment() } 30 | val binding = AttachmentImgurBinding 31 | .inflate(LayoutInflater.from(parent.context), null, false) 32 | return ImgurAttachmentViewHolder( 33 | imgurAttachment = imgurAttachment, 34 | binding = binding 35 | ) 36 | } 37 | 38 | private fun Attachment.isImgurAttachment(): Boolean = imageUrl?.contains("imgur") == true 39 | 40 | private class ImgurAttachmentViewHolder( 41 | binding: AttachmentImgurBinding, 42 | imgurAttachment: Attachment 43 | ) : 44 | InnerAttachmentViewHolder(binding.root) { 45 | 46 | init { 47 | binding.ivMediaThumb.apply { 48 | shapeAppearanceModel = shapeAppearanceModel 49 | .toBuilder() 50 | .setAllCornerSizes(resources.getDimension(io.getstream.chat.android.ui.R.dimen.stream_ui_selected_attachment_corner_radius)) 51 | .build() 52 | load(imgurAttachment.imageUrl) { 53 | allowHardware(false) 54 | crossfade(true) 55 | placeholder(io.getstream.chat.android.ui.R.drawable.stream_ui_picture_placeholder) 56 | } 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /samplekotlin/src/main/java/com/example/chattutorial/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.example.chattutorial 2 | 3 | import android.os.Bundle 4 | import android.widget.Toast 5 | import androidx.activity.viewModels 6 | import androidx.appcompat.app.AppCompatActivity 7 | import com.example.chattutorial.databinding.ActivityMainBinding 8 | import io.getstream.chat.android.client.ChatClient 9 | import io.getstream.chat.android.client.logger.ChatLogLevel 10 | import io.getstream.chat.android.models.Filters 11 | import io.getstream.chat.android.models.User 12 | import io.getstream.chat.android.offline.plugin.factory.StreamOfflinePluginFactory 13 | import io.getstream.chat.android.state.plugin.config.StatePluginConfig 14 | import io.getstream.chat.android.state.plugin.factory.StreamStatePluginFactory 15 | import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModel 16 | import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModelFactory 17 | import io.getstream.chat.android.ui.viewmodel.channels.bindView 18 | 19 | class MainActivity : AppCompatActivity() { 20 | 21 | private lateinit var binding: ActivityMainBinding 22 | 23 | override fun onCreate(savedInstanceState: Bundle?) { 24 | super.onCreate(savedInstanceState) 25 | 26 | // Step 0 - inflate binding 27 | binding = ActivityMainBinding.inflate(layoutInflater) 28 | setContentView(binding.root) 29 | 30 | // Step 1 - Set up the OfflinePlugin for offline storage 31 | val offlinePluginFactory = StreamOfflinePluginFactory(appContext = this) 32 | val statePluginFactory = StreamStatePluginFactory( 33 | config = StatePluginConfig( 34 | backgroundSyncEnabled = true, 35 | userPresence = true, 36 | ), 37 | appContext = this, 38 | ) 39 | 40 | // Step 2 - Set up the client for API calls with the plugin for offline storage 41 | val client = ChatClient.Builder("uun7ywwamhs9", applicationContext) 42 | .withPlugins(offlinePluginFactory, statePluginFactory) 43 | .logLevel(ChatLogLevel.ALL) // Set to NOTHING in prod 44 | .build() 45 | 46 | // Step 3 - Authenticate and connect the user 47 | val user = User( 48 | id = "tutorial-droid", 49 | name = "Tutorial Droid", 50 | image = "https://bit.ly/2TIt8NR" 51 | ) 52 | client.connectUser( 53 | user = user, 54 | token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidHV0b3JpYWwtZHJvaWQifQ.WwfBzU1GZr0brt_fXnqKdKhz3oj0rbDUm2DqJO_SS5U" 55 | ).enqueue { 56 | if (it.isSuccess) { 57 | // Step 4 - Set the channel list filter and order 58 | // This can be read as requiring only channels whose "type" is "messaging" AND 59 | // whose "members" include our "user.id" 60 | val filter = Filters.and( 61 | Filters.eq("type", "messaging"), 62 | Filters.`in`("members", listOf(user.id)) 63 | ) 64 | val viewModelFactory = 65 | ChannelListViewModelFactory(filter, ChannelListViewModel.DEFAULT_SORT) 66 | val viewModel: ChannelListViewModel by viewModels { viewModelFactory } 67 | 68 | // Step 5 - Connect the ChannelListViewModel to the ChannelListView, loose 69 | // coupling makes it easy to customize 70 | viewModel.bindView(binding.channelListView, this) 71 | binding.channelListView.setChannelItemClickListener { channel -> 72 | startActivity(ChannelActivity4.newIntent(this, channel)) 73 | } 74 | } else { 75 | Toast.makeText(this, "something went wrong!", Toast.LENGTH_SHORT).show() 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | 31 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/drawable/imgur_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/drawable/imgur_logo.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/activity_channel.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 23 | 24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/activity_channel_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 23 | 24 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/activity_channel_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 25 | 26 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/activity_channel_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 14 | 15 | 25 | 26 | 34 | 35 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/layout/attachment_imgur.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 20 | 21 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GetStream/android-chat-tutorial/6effe19383e15ee88c40a23320cea01377ea011c/samplekotlin/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /samplekotlin/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | 11 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Stream Chat Tutorial 3 | 4 | -------------------------------------------------------------------------------- /samplekotlin/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | google() 4 | mavenCentral() 5 | gradlePluginPortal() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | 16 | rootProject.name = "android-chat-tutorial" 17 | include(":samplejava") 18 | include(":samplekotlin") 19 | --------------------------------------------------------------------------------