Skip to content

Commit

Permalink
Add a Sync demo sample base on 0.8.2 (#16)
Browse files Browse the repository at this point in the history
* initial sync demo sample
  • Loading branch information
nhachicha committed Jan 26, 2022
1 parent 22f2199 commit a669425
Show file tree
Hide file tree
Showing 82 changed files with 3,875 additions and 0 deletions.
54 changes: 54 additions & 0 deletions MultiplatformDemoWithSync/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
*.iml
.gradle
/local.properties
.idea
.DS_Store
/build
*/build
/captures
.externalNativeBuild
.cxx
local.properties
### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a large number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGNORE THE LOCK FILE
Pods/

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Gcc Patch
/*.gcno

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
**/xcshareddata/WorkspaceSettings.xcsettings

44 changes: 44 additions & 0 deletions MultiplatformDemoWithSync/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## Kotlin Multiplatform Sync demo App using a shared business logic:

The demo demonstrates [Sync](https://www.mongodb.com/realm/mobile/sync) capability between an Android, iOS, macOS and JVM (currently Mac & Linux).

<img src="./Screenshots/kotlin-sync-demo.gif" width="800">

# Steps to build:

## 1 - Create a Realm Sync App on MongoDB Atlas

- Follow the tutorial at https://docs.mongodb.com/realm/tutorial/realm-app/#a.-create-an-atlas-account or watch the screencast https://www.youtube.com/watch?v=lqo0Yf7lnyg

- Replace the App identifier and the created user/password in [shared/src/commonMain/kotlin/io/realm/kotlin/demo/util/Constants.kt](./shared/src/commonMain/kotlin/io/realm/kotlin/demo/util/Constants.kt)

## 2 - Build and run for Android

```
./gradlew :androidApp:installDebug
```

## 3 - Build and run for iOS

```
./gradlew shared:podInstall
cd iosApp
pod install
open iosApp.xcworkspace
```

## 4 - Build and run for macOS

```
./gradlew shared:podInstall
cd macosApp
pod install
open macosApp.xcworkspace
```

## 5 - Build and run for JVM

```
./gradlew :jvmApp:run
```

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 50 additions & 0 deletions MultiplatformDemoWithSync/androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
plugins {
id("com.android.application")
kotlin("android")
}

val compose_version = "1.2.0-alpha01"

dependencies {
implementation(project(":shared"))

implementation("androidx.compose.compiler:compiler:$compose_version")
implementation("androidx.compose.material:material:$compose_version")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2-native-mt") {
version {
strictly("1.5.2-native-mt")
}
}
implementation("androidx.compose.ui:ui:$compose_version")
implementation("androidx.compose.ui:ui-tooling:$compose_version")
implementation("androidx.activity:activity-compose:1.4.0-beta01")
}

android {
compileSdk = 31
defaultConfig {
applicationId = "io.realm.kotlin.demo"
minSdk = 21
targetSdk = 31
versionCode = 1
versionName = "1.0"
}
buildTypes {
getByName("release") {
isMinifyEnabled = false
}
}

// Required by Compose
kotlinOptions {
jvmTarget = "11"
}

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = compose_version
}
}
20 changes: 20 additions & 0 deletions MultiplatformDemoWithSync/androidApp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.realm.kotlin.demo">

<application
android:allowBackup="false"
android:supportsRtl="true"
android:label="Realm Kotlin Demo">

<!-- android:theme="@style/AppTheme">-->
<activity
android:name=".ui.counter.CounterActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.realm.kotlin.demo.theme

import androidx.compose.material.darkColors
import androidx.compose.ui.graphics.Color

val Purple200 = Color(0xFFBB86FC)
val Purple500 = Color(0xFF6200EE)
val Purple700 = Color(0xFF3700B3)
val Teal200 = Color(0xFF03DAC5)

val Green500 = Color(0xFF1EB980)
val DarkBlue900 = Color(0xFF26282F)

// Rally is always dark themed.
val ColorPalette = darkColors(
primary = Green500,
surface = DarkBlue900,
onSurface = Color.White,
background = DarkBlue900,
onBackground = Color.White
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.realm.kotlin.demo.theme

import androidx.compose.ui.graphics.Color

object RealmColor {
// Grays
val Charcoal = Color(0xFF1C233F)
val Elephant = Color(0xFF9A9BA5)
val ElephantHalf = Color(0xFFb1b3bf)
val Dov = Color(0xFFEBEBF2)

// Orb colors
val Ultramarine = Color(0xFF39477F)
val Indigo = Color(0xFF59569E)
val GrapeJelly = Color(0xFF9A59A5)
val Mulberry = Color(0xFFD34CA3)
val Flamingo = Color(0xFFF25192)
val SexySalmon = Color(0xFFF77C88)
val Peach = Color(0xFFFC9F95)
val Melon = Color(0xFFFCC397)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.realm.kotlin.demo.theme

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.ui.unit.dp

val Shapes = Shapes(
small = RoundedCornerShape(4.dp),
medium = RoundedCornerShape(4.dp),
large = RoundedCornerShape(0.dp)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.realm.kotlin.demo.theme

import androidx.compose.ui.unit.dp

val rowSize = 60.dp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2021 Realm Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.realm.kotlin.demo.theme

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material.MaterialTheme
import androidx.compose.material.darkColors
import androidx.compose.material.lightColors
import androidx.compose.runtime.Composable

private val DarkColorPalette = darkColors(
primary = Purple200,
primaryVariant = Purple700,
secondary = Teal200
)

private val LightColorPalette = lightColors(
primary = Purple500,
primaryVariant = Purple700,
secondary = Teal200
)

@Composable
fun MyApplicationTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
content: @Composable() () -> Unit
) {
val colors = if (darkTheme) {
DarkColorPalette
} else {
LightColorPalette
}

MaterialTheme(
colors = colors,
typography = Typography,
shapes = Shapes,
content = content
)
}

@Composable
fun RallyTheme(content: @Composable () -> Unit) {
MaterialTheme(colors = ColorPalette, typography = Typography, content = content)
}

0 comments on commit a669425

Please sign in to comment.