Skip to content

Commit b21d763

Browse files
Initial core impl (#1)
2 parents 0f23a03 + 6983ad5 commit b21d763

File tree

153 files changed

+16703
-207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

153 files changed

+16703
-207
lines changed

.gitignore

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
# Gradle files
2-
.gradle/
3-
build/
4-
5-
# Local configuration file (sdk path, etc)
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
615
local.properties
716

817
# Log/OS Files
@@ -17,7 +26,6 @@ captures/
1726
output-metadata.json
1827

1928
# IntelliJ
20-
*.iml
2129
.idea/
2230
misc.xml
2331
deploymentTargetDropDown.xml

LICENSE

Lines changed: 219 additions & 201 deletions
Large diffs are not rendered by default.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.kotlin.compose)
5+
}
6+
7+
android {
8+
namespace = "io.getstream.android.core"
9+
compileSdk = 36
10+
11+
defaultConfig {
12+
applicationId = "io.getstream.android.core.sample"
13+
minSdk = 21
14+
targetSdk = 36
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = false
24+
proguardFiles(
25+
getDefaultProguardFile("proguard-android-optimize.txt"),
26+
"proguard-rules.pro"
27+
)
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_11
32+
targetCompatibility = JavaVersion.VERSION_11
33+
}
34+
kotlinOptions {
35+
jvmTarget = "11"
36+
}
37+
buildFeatures {
38+
compose = true
39+
}
40+
}
41+
42+
dependencies {
43+
44+
implementation(project(":stream-android-core"))
45+
46+
implementation(libs.androidx.core.ktx)
47+
implementation(libs.androidx.appcompat)
48+
implementation(libs.material)
49+
implementation(libs.androidx.lifecycle.runtime.ktx)
50+
implementation(libs.androidx.activity.compose)
51+
implementation(platform(libs.androidx.compose.bom))
52+
implementation(libs.androidx.ui)
53+
implementation(libs.androidx.ui.graphics)
54+
implementation(libs.androidx.ui.tooling.preview)
55+
implementation(libs.androidx.material3)
56+
testImplementation(libs.junit)
57+
androidTestImplementation(libs.androidx.junit)
58+
androidTestImplementation(libs.androidx.espresso.core)
59+
androidTestImplementation(platform(libs.androidx.compose.bom))
60+
androidTestImplementation(libs.androidx.ui.test.junit4)
61+
debugImplementation(libs.androidx.ui.tooling)
62+
debugImplementation(libs.androidx.ui.test.manifest)
63+
}

app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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

app/src/main/AndroidManifest.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.Streamandroidcore">
14+
<activity
15+
android:name=".sample.SampleActivity"
16+
android:exported="true"
17+
android:label="@string/title_activity_sample"
18+
android:theme="@style/Theme.Streamandroidcore">
19+
<intent-filter>
20+
<action android:name="android.intent.action.MAIN" />
21+
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
27+
</manifest>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-android-base/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.getstream.android.core.sample
17+
18+
import android.os.Build
19+
import android.os.Bundle
20+
import android.util.Log
21+
import androidx.activity.ComponentActivity
22+
import androidx.activity.compose.setContent
23+
import androidx.activity.enableEdgeToEdge
24+
import androidx.compose.foundation.layout.Column
25+
import androidx.compose.foundation.layout.fillMaxSize
26+
import androidx.compose.foundation.layout.padding
27+
import androidx.compose.material3.Scaffold
28+
import androidx.compose.material3.Text
29+
import androidx.compose.runtime.Composable
30+
import androidx.compose.ui.Modifier
31+
import androidx.compose.ui.tooling.preview.Preview
32+
import androidx.lifecycle.Lifecycle
33+
import androidx.lifecycle.compose.collectAsStateWithLifecycle
34+
import androidx.lifecycle.lifecycleScope
35+
import androidx.lifecycle.repeatOnLifecycle
36+
import io.getstream.android.core.api.StreamClient
37+
import io.getstream.android.core.api.authentication.StreamTokenProvider
38+
import io.getstream.android.core.api.model.value.StreamApiKey
39+
import io.getstream.android.core.api.model.value.StreamHttpClientInfoHeader
40+
import io.getstream.android.core.api.model.value.StreamToken
41+
import io.getstream.android.core.api.model.value.StreamUserId
42+
import io.getstream.android.core.api.model.value.StreamWsUrl
43+
import io.getstream.android.core.sample.client.createStreamClient
44+
import io.getstream.android.core.sample.ui.theme.StreamandroidcoreTheme
45+
import kotlinx.coroutines.launch
46+
import kotlinx.coroutines.runBlocking
47+
48+
class SampleActivity : ComponentActivity() {
49+
50+
val userId = StreamUserId.fromString("petar")
51+
val streamClient =
52+
createStreamClient(
53+
scope = lifecycleScope,
54+
apiKey = StreamApiKey.fromString("pd67s34fzpgw"),
55+
userId = userId,
56+
wsUrl =
57+
StreamWsUrl.fromString(
58+
"wss://chat-edge-frankfurt-ce1.stream-io-api.com/api/v2/connect"
59+
),
60+
clientInfoHeader =
61+
StreamHttpClientInfoHeader.create(
62+
product = "android-core",
63+
productVersion = "1.0.0",
64+
os = "Android",
65+
apiLevel = Build.VERSION.SDK_INT,
66+
deviceModel = "Pixel 7 Pro",
67+
app = "Stream Android Core Sample",
68+
appVersion = "1.0.0",
69+
),
70+
tokenProvider =
71+
object : StreamTokenProvider {
72+
override suspend fun loadToken(userId: StreamUserId): StreamToken {
73+
return StreamToken.fromString(
74+
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoicGV0YXIifQ.mZFi4iSblaIoyo9JDdcxIkGkwI-tuApeSBawxpz42rs"
75+
)
76+
}
77+
},
78+
)
79+
80+
override fun onCreate(savedInstanceState: Bundle?) {
81+
super.onCreate(savedInstanceState)
82+
lifecycleScope.launch {
83+
repeatOnLifecycle(Lifecycle.State.RESUMED) { streamClient.connect() }
84+
}
85+
enableEdgeToEdge()
86+
setContent {
87+
StreamandroidcoreTheme {
88+
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
89+
Column {
90+
Greeting(name = "Android", modifier = Modifier.padding(innerPadding))
91+
ClientInfo(streamClient = streamClient)
92+
}
93+
}
94+
}
95+
}
96+
}
97+
98+
override fun onPause() {
99+
runBlocking { streamClient.disconnect() }
100+
super.onPause()
101+
}
102+
}
103+
104+
@Composable
105+
fun Greeting(name: String, modifier: Modifier = Modifier) {
106+
Text(text = "Hello $name!", modifier = modifier)
107+
}
108+
109+
@Preview(showBackground = true)
110+
@Composable
111+
fun GreetingPreview() {
112+
StreamandroidcoreTheme { Greeting("Android") }
113+
}
114+
115+
@Composable
116+
fun ClientInfo(streamClient: StreamClient) {
117+
val state = streamClient.connectionState.collectAsStateWithLifecycle()
118+
Log.d("SampleActivity", "Client state: ${state.value}")
119+
Text(text = "Client state: ${state.value}")
120+
}

0 commit comments

Comments
 (0)