Skip to content

Commit 62c4c84

Browse files
committed
feat[live-objects]: add example module showcasing LiveObjects features
Added an Android Compose-based example application demonstrating Ably Live Objects integration. Includes tasks management and color voting screens.
1 parent 2c36548 commit 62c4c84

22 files changed

Lines changed: 1181 additions & 1 deletion

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ plugins {
88
alias(libs.plugins.maven.publish) apply false
99
alias(libs.plugins.lombok) apply false
1010
alias(libs.plugins.test.retry) apply false
11+
alias(libs.plugins.android.application) apply false
12+
alias(libs.plugins.kotlin.android) apply false
13+
alias(libs.plugins.kotlin.compose) apply false
1114
}
1215

1316
subprojects {

example/.gitignore

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

example/build.gradle.kts

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import java.io.FileInputStream
2+
import java.io.InputStreamReader
3+
import java.util.Properties
4+
5+
plugins {
6+
alias(libs.plugins.android.application)
7+
alias(libs.plugins.kotlin.android)
8+
alias(libs.plugins.kotlin.compose)
9+
}
10+
11+
android {
12+
namespace = "com.ably.example"
13+
compileSdk = 35
14+
15+
defaultConfig {
16+
applicationId = "com.ably.example"
17+
minSdk = 30
18+
targetSdk = 35
19+
versionCode = 1
20+
versionName = "1.0"
21+
22+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
23+
24+
buildConfigField("String", "ABLY_KEY", "\"${getLocalProperty("ABLY_KEY") ?: ""}\"")
25+
}
26+
27+
buildTypes {
28+
release {
29+
isMinifyEnabled = false
30+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
31+
}
32+
}
33+
compileOptions {
34+
sourceCompatibility = JavaVersion.VERSION_11
35+
targetCompatibility = JavaVersion.VERSION_11
36+
}
37+
kotlinOptions {
38+
jvmTarget = "11"
39+
}
40+
buildFeatures {
41+
compose = true
42+
buildConfig = true
43+
}
44+
}
45+
46+
dependencies {
47+
implementation(libs.core.ktx)
48+
implementation(libs.lifecycle.runtime.ktx)
49+
implementation(libs.activity.compose)
50+
implementation(platform(libs.compose.bom))
51+
implementation(libs.ui)
52+
implementation(libs.ui.graphics)
53+
implementation(libs.ui.tooling.preview)
54+
implementation(libs.material3)
55+
56+
implementation(project(":live-objects"))
57+
implementation(project(":android"))
58+
59+
implementation(libs.navigation.compose)
60+
61+
testImplementation(libs.junit)
62+
androidTestImplementation(libs.ext.junit)
63+
androidTestImplementation(libs.espresso.core)
64+
androidTestImplementation(platform(libs.compose.bom))
65+
androidTestImplementation(libs.ui.test.junit4)
66+
debugImplementation(libs.ui.tooling)
67+
debugImplementation(libs.ui.test.manifest)
68+
}
69+
70+
fun getLocalProperty(key: String, file: String = "local.properties"): String? {
71+
val properties = Properties()
72+
val localProperties = File(file)
73+
if (!localProperties.isFile) return null
74+
InputStreamReader(FileInputStream(localProperties), Charsets.UTF_8).use { reader ->
75+
properties.load(reader)
76+
}
77+
return properties.getProperty(key)
78+
}

example/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
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@style/Theme.Ably">
11+
<activity
12+
android:name=".MainActivity"
13+
android:exported="true"
14+
android:label="@string/app_name"
15+
android:theme="@style/Theme.Ably">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN"/>
18+
19+
<category android:name="android.intent.category.LAUNCHER"/>
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.ably.example
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.activity.enableEdgeToEdge
7+
import com.ably.example.screen.MainScreen
8+
import com.ably.example.ui.theme.AblyTheme
9+
import io.ably.lib.realtime.AblyRealtime
10+
import io.ably.lib.types.ClientOptions
11+
import io.ably.lib.util.Log
12+
13+
class MainActivity : ComponentActivity() {
14+
private val realtimeClient: AblyRealtime by lazy {
15+
AblyRealtime(
16+
ClientOptions().apply {
17+
key = BuildConfig.ABLY_KEY
18+
logLevel = Log.VERBOSE
19+
autoConnect = false
20+
}
21+
)
22+
}
23+
24+
override fun onCreate(savedInstanceState: Bundle?) {
25+
super.onCreate(savedInstanceState)
26+
enableEdgeToEdge()
27+
setContent {
28+
AblyTheme {
29+
MainScreen(realtimeClient)
30+
}
31+
}
32+
}
33+
34+
override fun onStart() {
35+
super.onStart()
36+
realtimeClient.connect()
37+
}
38+
39+
override fun onStop() {
40+
super.onStop()
41+
realtimeClient.close()
42+
}
43+
44+
override fun onResume() {
45+
super.onResume()
46+
realtimeClient.connect()
47+
}
48+
49+
override fun onPause() {
50+
super.onPause()
51+
realtimeClient.close()
52+
}
53+
}

0 commit comments

Comments
 (0)