diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..3733e0d --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 1.8 + + + + + + + + \ No newline at end of file diff --git a/.idea/artifacts/FirestoreKMP_js_0_0_1.xml b/.idea/artifacts/FirestoreKMP_js_0_0_1.xml new file mode 100644 index 0000000..c3c6dd0 --- /dev/null +++ b/.idea/artifacts/FirestoreKMP_js_0_0_1.xml @@ -0,0 +1,6 @@ + + + $PROJECT_DIR$/build/libs + + + \ No newline at end of file diff --git a/.idea/artifacts/FirestoreKMP_jvm_0_0_1.xml b/.idea/artifacts/FirestoreKMP_jvm_0_0_1.xml new file mode 100644 index 0000000..96ef94a --- /dev/null +++ b/.idea/artifacts/FirestoreKMP_jvm_0_0_1.xml @@ -0,0 +1,6 @@ + + + $PROJECT_DIR$/build/libs + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..a98c07f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 740b807..7831d91 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -6,13 +6,15 @@ - diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..0380d8d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 703e5d4..017d547 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,14 +1,8 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534f..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/README.md b/README.md index c4b77c5..35fca07 100644 --- a/README.md +++ b/README.md @@ -1 +1,36 @@ -# Mach 7 for Android +# Firestore SDK for Kotlin Multiplatform + +Library wrapping the Firestore SDK for Kotlin Multiplatform with clients for Android and iOS. Shared common code can +run methods that get delegated to the platform specific SDKs. + +This was originally for a client and now is being used as an example library for a talk on KMP libraries. We'll probably +archive this pretty soon because it'll be a lot of support. + +## Usage + +Use Koltin 1.3.50. + +Dependency config + +```groovy +sourceSets { + commonMain { + dependencies { + implementation 'co.touchlab:firestore:0.2.5' + } + } +} +``` + +You'll need to config both Android and iOS as you normally would for Firestore, but then you should be able to get the +Firestore instance like this. + +```kotlin +getFirebaseInstance() +``` + +Then you can do Firestore things. + +## Droidcon + +[See live example here](https://github.com/touchlab/DroidconKotlin/blob/master/sessionize/lib/src/commonMain/kotlin/co/touchlab/sessionize/SponsorModel.kt#L25) \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index bd79989..e24dda8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,17 +1,12 @@ apply plugin: 'com.android.application' - apply plugin: 'kotlin-android' - apply plugin: 'kotlin-android-extensions' -apply plugin: 'androidx.navigation.safeargs' - - android { compileSdkVersion 28 - buildToolsVersion "29.0.0" + buildToolsVersion "29.0.1" defaultConfig { - applicationId "co.touchlab.firebase.firestore.test" + applicationId "co.touchlab.firebase.firestore" minSdkVersion 21 targetSdkVersion 28 versionCode 1 @@ -41,18 +36,16 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.0.0' + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.0-RC" testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' - implementation "androidx.navigation:navigation-fragment-ktx:2.1.0-alpha06" - implementation "androidx.navigation:navigation-ui-ktx:2.1.0-alpha06" - implementation 'com.google.firebase:firebase-firestore:20.1.0' - implementation 'com.google.firebase:firebase-core:17.0.0' + implementation 'com.google.firebase:firebase-core:17.0.1' - implementation project(':firebase') + implementation project(':firestore') } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4c34a1a..51ad924 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,7 +9,6 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" - android:name=".MainApp" > diff --git a/app/src/main/java/co/touchlab/firebase/firestore/MainActivity.kt b/app/src/main/java/co/touchlab/firebase/firestore/MainActivity.kt new file mode 100644 index 0000000..305154f --- /dev/null +++ b/app/src/main/java/co/touchlab/firebase/firestore/MainActivity.kt @@ -0,0 +1,78 @@ +package co.touchlab.firebase.firestore + +import android.os.Bundle +import android.widget.ArrayAdapter +import android.widget.Button +import android.widget.ListView +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.FlowCollector + +class MainActivity : AppCompatActivity(), CoroutineScope by MainScope() { + + private val flow = getFirebaseInstance().collection("testdata") + .asFlow() + + @InternalCoroutinesApi + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + launch { + flow.collect(object : FlowCollector { + override suspend fun emit(value: QuerySnapshot) { + findViewById(R.id.games).adapter = + ArrayAdapter( + this@MainActivity, + android.R.layout.simple_list_item_1, + value.documents.map { it.data?.get("name") as String? } + .filterNotNull() + ) + + } + }) + } + + findViewById