Skip to content

Commit a5b4531

Browse files
committed
Merge branch 'busec0/maui-mac-catalyst' into busec0/maui-windows
2 parents 5807bcf + b4376b5 commit a5b4531

File tree

208 files changed

+45031
-40970
lines changed

Some content is hidden

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

208 files changed

+45031
-40970
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* @getditto/sdk-engineers
88

99
# SDK-specific owners
10-
/android-cpp/ @kristopherjohnson @danielhenrymantilla
10+
/android-cpp/ @kristopherjohnson @teodorciuraru
1111
/android-java/ @phatblat @anyercastillo
1212
/android-kotlin/ @phatblat @anyercastillo
13-
/cpp-tui/ @kristopherjohnson @danielhenrymantilla
13+
/cpp-tui/ @kristopherjohnson @teodorciuraru
1414
/dotnet-maui/ @busec0 @phatblat
1515
/dotnet-tui/ @busec0 @phatblat
1616
/flutter_quickstart/ @cameron1024 @teodorciuraru
1717
/javascript-tui/ @konstantinbe @pvditto @teodorciuraru
1818
/javascript-web/ @konstantinbe @pvditto @teodorciuraru
1919
/react-native/ @teodorciuraru @kristopherjohnson
20-
/rust-tui/ @kristopherjohnson @danielhenrymantilla
20+
/rust-tui/ @kristopherjohnson @cameron1024
2121
/swift/ @phatblat @konstantinbe

.github/workflows/pr-checks.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,41 @@ jobs:
5353

5454
- name: Build
5555
run: "(cd rust-tui; cargo build)"
56+
57+
js-web:
58+
name: javascript-web lint
59+
runs-on: ubuntu-24.04
60+
steps:
61+
- uses: actions/checkout@v4
62+
63+
- name: Install Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: "20"
67+
68+
- name: Install Dependencies
69+
working-directory: javascript-web
70+
run: npm ci
71+
72+
- name: Run linter
73+
working-directory: javascript-web
74+
run: npm run lint
75+
76+
js-node:
77+
name: javascript-tui lint
78+
runs-on: ubuntu-24.04
79+
steps:
80+
- uses: actions/checkout@v4
81+
82+
- name: Install Node.js
83+
uses: actions/setup-node@v4
84+
with:
85+
node-version: "20"
86+
87+
- name: Install Dependencies
88+
working-directory: javascript-tui
89+
run: npm ci
90+
91+
- name: Run linter and tests
92+
working-directory: javascript-tui
93+
run: npm run test

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ xcuserdata
3333
bazel-*
3434
build-cmake
3535
node_modules/
36-
.dart_tool/
36+
.dart_tool/

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This repo contains apps that demonstrate how to use the Ditto SDK for supported
44
programming languages and platforms.
55

6-
See Ditto's [Quickstarts](https://docs.ditto.live/sdk/latest/quickstarts)
6+
See Ditto's [Quickstarts](https://docs.ditto.live/sdk/latest/quickstarts/quickstarts-landing)
77
documentation for more information.
88

99
For support, please contact Ditto Support (<[email protected]>).
@@ -37,9 +37,11 @@ build and run them.
3737
- [Android Kotlin](android-kotlin/README.md)
3838
- [Android Java](android-java/README.md)
3939
- [Android C++](android-cpp/README.md)
40+
- [Java Server](java-spring/README.md)
4041
- [C++ TUI](cpp-tui/README.md)
4142
- [C# .NET MAUI](dotnet-maui/README.md)
4243
- [C# .NET TUI](dotnet-tui/README.md)
44+
- [C# .NET Win Forms](dotnet-winforms/README.md)
4345
- [Flutter](flutter_quickstart/README.md)
4446
- [Javascript TUI](javascript-tui/README.md)
4547
- [Javascript Web](javascript-web/README.md)

android-java/README.md

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,67 @@
11
# Ditto Android Java Quickstart App 🚀
22

3-
## Dependencies
3+
## Prerequisites
44

5-
- A modern JDK installation
6-
- Android Studio
5+
After you have completed the [common prerequisites] you will need the following:
76

8-
## Getting Started
7+
- [Android Studio](https://developer.android.com/studio) Ladybug or newer
98

10-
To get started, you'll first need to create an app in the [Ditto Portal] with the
11-
"Online Playground" authentication type. You'll need to find your AppId, Online Playground Token, Auth URL, and Websocket URL (at the top of the page) in order to use this quickstart.
9+
## Permissions (already configured)
1210

13-
In `app/src/main/java/com/example/dittotasks/MainActivity.java`, find the following variables:
11+
- <https://docs.ditto.live/sdk/latest/install-guides/java/android#configuring-permissions>
1412

15-
```java
16-
private String DITTO_APP_ID = "";
17-
private String DITTO_PLAYGROUND_TOKEN = "";
18-
private String DITTO_AUTH_URL = "";
19-
private String DITTO_WEBSOCKET_URL = "";
13+
## Documentation
14+
15+
- [Install Guide](https://docs.ditto.live/sdk/latest/install-guides/java/android)
16+
- [API Reference](https://software.ditto.live/android/Ditto/4.8.2/api-reference/)
17+
- [SDK Release Notes](https://docs.ditto.live/sdk/latest/release-notes/java)
18+
19+
[common prerequisites]: https://github.com/getditto/quickstart#common-prerequisites
20+
21+
## Building and Running the Android Application
22+
23+
Assuming you have Android Studio and other prerequisites installed, you can
24+
build and run the app by following these steps:
25+
26+
1. Create an application at <https://portal.ditto.live/>. Make note of the app ID and online playground token.
27+
2. Copy the `.env.sample` file at the top level of the `quickstart` repo to `.env` and add your App ID, Online Playground Token, Auth URL, and Websocket URL.
28+
3. Launch Android Studio and open the `quickstart/android-java` directory.
29+
4. In Android Studio, select a connected Android device, or create and launch an Android emulator and select it as the destination, then choose the **Run > Run 'app'** menu item.
30+
31+
The app will build and run on the selected device or emulator. You can add,
32+
edit, and delete tasks in the app.
33+
34+
If you run the app on additional devices or emulators, the data will be synced
35+
between them.
36+
37+
Compatible with Android Automotive OS (AAOS)
38+
39+
## A Guided Tour of the Android App Source Code
40+
41+
The Android app is a simple to-do list app that demonstrates how to use the
42+
Ditto Android SDK to sync data with other devices.
43+
It is implemented using Java and
44+
[Jetpack Compose](https://developer.android.com/compose), which is a modern
45+
toolkit for building native Android UI.
46+
47+
It is assumed that the reader is familiar with Android development and with
48+
Compose, but needs some guidance on how to use Ditto. The following is a
49+
summary of the key parts of integration with Ditto.
50+
51+
### Adding the Ditto SDK
52+
53+
In `app/build.gradle.kts`, you will see this line that causes Android Studio
54+
to download the Ditto SDK from Maven Central and add it to the project:
55+
56+
```kotlin
57+
implementation(libs.ditto)
58+
```
59+
60+
This line in `gradle/libs.versions.toml` specifies which version of the Ditto
61+
SDK to use:
62+
63+
```kotlin
64+
ditto = "4.10.0"
2065
```
2166

22-
Paste your own AppID, Playground Token, Auth URL, and Websocket URL into these variables, then click the Run button in Android Studio to launch the app in an emulator.
67+
To use a newer version of the SDK, change the version number on this line.

android-java/app/build.gradle.kts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,72 @@
1+
import com.android.build.api.variant.BuildConfigField
2+
import java.io.FileInputStream
3+
import java.io.FileNotFoundException
4+
import java.util.Properties
5+
16
plugins {
27
alias(libs.plugins.android.application)
38
alias(libs.plugins.kotlin.android)
49
alias(libs.plugins.kotlin.compose)
510
}
611

12+
fun loadEnvProperties(): Properties {
13+
val envFile = rootProject.file("../.env")
14+
val properties = Properties()
15+
if (envFile.exists()) {
16+
FileInputStream(envFile).use { properties.load(it) }
17+
} else {
18+
throw FileNotFoundException(".env file not found at: ${envFile.path}")
19+
}
20+
return properties
21+
}
22+
23+
// Define BuildConfig.DITTO_APP_ID, BuildConfig.DITTO_PLAYGROUND_TOKEN,
24+
// BuildConfig.DITTO_CUSTOM_AUTH_URL, BuildConfig.DITTO_WEBSOCKET_URL
25+
// based on values in the .env file
26+
//
27+
// More information can be found here:
28+
// https://docs.ditto.live/sdk/latest/install-guides/java/android#integrating-and-initializing
29+
androidComponents {
30+
onVariants {
31+
val prop = loadEnvProperties()
32+
it.buildConfigFields.put(
33+
"DITTO_APP_ID",
34+
BuildConfigField(
35+
"String",
36+
"${prop["DITTO_APP_ID"]}",
37+
"Ditto application ID"
38+
)
39+
)
40+
it.buildConfigFields.put(
41+
"DITTO_PLAYGROUND_TOKEN",
42+
BuildConfigField(
43+
"String",
44+
"${prop["DITTO_PLAYGROUND_TOKEN"]}",
45+
"Ditto online playground authentication token"
46+
)
47+
)
48+
49+
it.buildConfigFields.put(
50+
"DITTO_AUTH_URL",
51+
BuildConfigField(
52+
"String",
53+
"${prop["DITTO_AUTH_URL"]}",
54+
"Ditto Auth URL"
55+
)
56+
)
57+
58+
it.buildConfigFields.put(
59+
"DITTO_WEBSOCKET_URL",
60+
BuildConfigField(
61+
"String",
62+
"${prop["DITTO_WEBSOCKET_URL"]}",
63+
"Ditto Websocket URL"
64+
)
65+
)
66+
}
67+
}
68+
69+
770
android {
871
namespace = "com.example.dittotasks"
972
compileSdk = 34
@@ -35,6 +98,7 @@ android {
3598
jvmTarget = "11"
3699
}
37100
buildFeatures {
101+
buildConfig = true
38102
compose = true
39103
}
40104
// This ensures Ditto can produce meaningful stack traces

android-java/app/src/main/java/com/example/dittotasks/MainActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ public class MainActivity extends ComponentActivity {
4141
DittoSyncSubscription taskSubscription;
4242
DittoStoreObserver taskObserver;
4343

44-
private String DITTO_APP_ID = "<put your Ditto Portal App ID here>";
45-
private String DITTO_PLAYGROUND_TOKEN = "<put your Ditto Portal Playground Token here>";
46-
private String DITTO_AUTH_URL = "<put your Ditto Portal Auth URL here>";
47-
private String DITTO_WEBSOCKET_URL = "<put your Ditto Portal WebSocket URL here>";
44+
private String DITTO_APP_ID = BuildConfig.DITTO_APP_ID;
45+
private String DITTO_PLAYGROUND_TOKEN = BuildConfig.DITTO_PLAYGROUND_TOKEN;
46+
private String DITTO_AUTH_URL = BuildConfig.DITTO_AUTH_URL;
47+
private String DITTO_WEBSOCKET_URL = BuildConfig.DITTO_WEBSOCKET_URL;
4848

4949
// This is required to be set to false to use the correct URLs
5050
private Boolean DITTO_ENABLE_CLOUD_SYNC = false;

android-java/gradle/libs.versions.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[versions]
2+
ditto = "4.10.0"
23
agp = "8.7.3"
34
constraintlayout = "2.2.0"
4-
ditto = "4.10.0"
55
kotlin = "2.0.0"
66
coreKtx = "1.10.1"
77
junit = "4.13.2"
@@ -39,4 +39,3 @@ recyclerview-v7 = { module = "com.android.support:recyclerview-v7", version.ref
3939
android-application = { id = "com.android.application", version.ref = "agp" }
4040
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
4141
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
42-

android-kotlin/QuickStartTasks/app/src/main/java/live/ditto/quickstart/tasks/TasksApplication.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TasksApplication : Application() {
6262
transportConfig.enableAllPeerToPeer()
6363
ditto.transportConfig = transportConfig
6464

65-
// disable sync with v3 peers, required for syncing with the Ditto Cloud (Big Peer)
65+
// disable sync with v3 peers, required for DQL
6666
ditto.disableSyncWithV3()
6767
}
6868
}

android-kotlin/QuickStartTasks/app/src/main/java/live/ditto/quickstart/tasks/data/Task.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package live.ditto.quickstart.tasks.data
22

33
import android.util.Log
4+
import org.json.JSONException
45
import org.json.JSONObject
56
import java.util.UUID
67

@@ -22,7 +23,7 @@ data class Task(
2223
done = json["done"] as Boolean,
2324
deleted = json["deleted"] as Boolean
2425
)
25-
} catch (e: Exception) {
26+
} catch (e: JSONException) {
2627
Log.e(TAG, "Unable to convert JSON to Task", e)
2728
Task(title = "", done = false, deleted = false)
2829
}

android-kotlin/QuickStartTasks/app/src/main/java/live/ditto/quickstart/tasks/edit/EditScreenViewModel.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.lifecycle.MutableLiveData
55
import androidx.lifecycle.ViewModel
66
import androidx.lifecycle.viewModelScope
77
import kotlinx.coroutines.launch
8+
import live.ditto.DittoError
89
import live.ditto.quickstart.tasks.DittoHandler.Companion.ditto
910
import live.ditto.quickstart.tasks.data.Task
1011

@@ -35,7 +36,7 @@ class EditScreenViewModel : ViewModel() {
3536
_id = task._id
3637
title.postValue(task.title)
3738
done.postValue(task.done)
38-
} catch (e: Exception) {
39+
} catch (e: DittoError) {
3940
Log.e(TAG, "Unable to setup view task data", e)
4041
}
4142
}
@@ -78,7 +79,7 @@ class EditScreenViewModel : ViewModel() {
7879
)
7980
}
8081
}
81-
} catch (e: Exception) {
82+
} catch (e: DittoError) {
8283
Log.e(TAG, "Unable to save task", e)
8384
}
8485
}
@@ -95,7 +96,7 @@ class EditScreenViewModel : ViewModel() {
9596
mapOf("id" to id)
9697
)
9798
}
98-
} catch (e: Exception) {
99+
} catch (e: DittoError) {
99100
Log.e(TAG, "Unable to set deleted=true", e)
100101
}
101102
}

android-kotlin/QuickStartTasks/app/src/main/java/live/ditto/quickstart/tasks/list/TasksListScreenViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TasksListScreenViewModel : ViewModel() {
5252
// https://docs.ditto.live/sdk/latest/sync/start-and-stop-sync
5353
ditto.startSync()
5454

55-
// register subscription
55+
// Register a subscription, which determines what data syncs to this peer
5656
// https://docs.ditto.live/sdk/latest/sync/syncing-data#creating-subscriptions
5757
syncSubscription = ditto.sync.registerSubscription(QUERY)
5858
} catch (e: DittoError) {
@@ -74,7 +74,7 @@ class TasksListScreenViewModel : ViewModel() {
7474
viewModelScope.launch {
7575
populateTasksCollection()
7676

77-
// register observer for live query
77+
// Register observer, which runs against the local database on this peer
7878
// https://docs.ditto.live/sdk/latest/crud/observing-data-changes#setting-up-store-observers
7979
ditto.store.registerObserver(QUERY) { result ->
8080
val list = result.items.map { item -> Task.fromJson(item.jsonString()) }
@@ -112,7 +112,7 @@ class TasksListScreenViewModel : ViewModel() {
112112
)
113113
)
114114
)
115-
} catch (e: Exception) {
115+
} catch (e: DittoError) {
116116
Log.e(TAG, "Unable to insert initial document", e)
117117
}
118118
}
@@ -138,7 +138,7 @@ class TasksListScreenViewModel : ViewModel() {
138138
"_id" to taskId
139139
)
140140
)
141-
} catch (e: Exception) {
141+
} catch (e: DittoError) {
142142
Log.e(TAG, "Unable to toggle done state", e)
143143
}
144144
}
@@ -153,7 +153,7 @@ class TasksListScreenViewModel : ViewModel() {
153153
"UPDATE tasks SET deleted = true WHERE _id = :id",
154154
mapOf("id" to taskId)
155155
)
156-
} catch (e: Exception) {
156+
} catch (e: DittoError) {
157157
Log.e(TAG, "Unable to set deleted=true", e)
158158
}
159159
}

dotnet-maui/DittoMauiTasksApp/DittoMauiTasksApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</ItemGroup>
3939
<ItemGroup>
4040
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="9.0.1" />
41-
<PackageReference Include="Ditto" Version="4.11.0-maccatalyst.2" />
41+
<PackageReference Include="Ditto" Version="4.11.0-preview.2" />
4242
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.0" />
4343
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
4444
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />

0 commit comments

Comments
 (0)