From 4bd29b2e308f53dbcd3e2d81c7d16f5bbb79649f Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 11 Jun 2021 17:35:08 +0530 Subject: [PATCH] feat: support for jvm --- README.md | 4 +- example-java/.gitignore | 1 + example-java/build.gradle | 40 +++++ example-java/src/main/AndroidManifest.xml | 21 +++ .../appwrite/example_java/MainActivity.java | 60 +++++++ .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 ++++ .../src/main/res/layout/activity_main.xml | 18 ++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 + example-java/src/main/res/values/colors.xml | 10 ++ example-java/src/main/res/values/strings.xml | 3 + example-java/src/main/res/values/themes.xml | 16 ++ library/build.gradle | 8 +- library/src/main/java/io/appwrite/Client.kt | 6 +- .../main/java/io/appwrite/KeepAliveService.kt | 2 +- .../io/appwrite/views/CallbackActivity.kt | 2 +- settings.gradle | 1 + 18 files changed, 391 insertions(+), 11 deletions(-) create mode 100644 example-java/.gitignore create mode 100644 example-java/build.gradle create mode 100644 example-java/src/main/AndroidManifest.xml create mode 100644 example-java/src/main/java/io/appwrite/example_java/MainActivity.java create mode 100644 example-java/src/main/res/drawable/ic_launcher_background.xml create mode 100644 example-java/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 example-java/src/main/res/layout/activity_main.xml create mode 100644 example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 example-java/src/main/res/values/colors.xml create mode 100644 example-java/src/main/res/values/strings.xml create mode 100644 example-java/src/main/res/values/themes.xml diff --git a/README.md b/README.md index de93f8d..87260ad 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ From the options, choose to add a new **Android** platform and add your app cred Add your app name and package name. Your package name is generally the applicationId in your app-level `build.gradle` file. By registering a new platform, you are allowing your app to communicate with the Appwrite API. -### Registering Activities +### Registering additional activities In order to capture the Appwrite OAuth callback url, the following activity needs to be added to your [AndroidManifest.xml](https://github.com/appwrite/playground-for-android/blob/master/app/src/main/AndroidManifest.xml). Be sure to replace the **[PROJECT_ID]** string with your actual Appwrite project ID. You can find your Appwrite project ID in your project settings screen in the console. ```xml @@ -154,4 +154,4 @@ This library is auto-generated by Appwrite custom [SDK Generator](https://github ## License -Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. \ No newline at end of file diff --git a/example-java/.gitignore b/example-java/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/example-java/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/example-java/build.gradle b/example-java/build.gradle new file mode 100644 index 0000000..fb49677 --- /dev/null +++ b/example-java/build.gradle @@ -0,0 +1,40 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.3" + + defaultConfig { + applicationId "io.appwrite.example_java" + minSdkVersion 23 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +dependencies { + + implementation project(path: ':library') + implementation 'androidx.appcompat:appcompat:1.3.0' + implementation 'com.google.android.material:material:1.3.0' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' + testImplementation 'junit:junit:4.+' + androidTestImplementation 'androidx.test.ext:junit:1.1.2' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' +} \ No newline at end of file diff --git a/example-java/src/main/AndroidManifest.xml b/example-java/src/main/AndroidManifest.xml new file mode 100644 index 0000000..1fd3789 --- /dev/null +++ b/example-java/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/example-java/src/main/java/io/appwrite/example_java/MainActivity.java b/example-java/src/main/java/io/appwrite/example_java/MainActivity.java new file mode 100644 index 0000000..5b0d09b --- /dev/null +++ b/example-java/src/main/java/io/appwrite/example_java/MainActivity.java @@ -0,0 +1,60 @@ +package io.appwrite.example_java; + +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; +import io.appwrite.Client; +import io.appwrite.exceptions.AppwriteException; +import io.appwrite.services.Account; +import kotlin.Result; +import kotlin.coroutines.Continuation; +import kotlin.coroutines.CoroutineContext; +import kotlin.coroutines.EmptyCoroutineContext; +import okhttp3.Response; + +public class MainActivity extends AppCompatActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + Client client = new Client(getApplicationContext()) + .setEndpoint("https://demo.appwrite.io/v1") + .setProject("6070749e6acd4"); + + Account account = new Account(client); + + try { + account.createSession("test7@test.com","password", new Continuation() { + @NotNull + @Override + public CoroutineContext getContext() { + return EmptyCoroutineContext.INSTANCE; + } + + @Override + public void resumeWith(@NotNull Object o) { + String json = ""; + try { + if (o instanceof Result.Failure) { + Result.Failure failure = (Result.Failure) o; + throw failure.exception; + } else { + Response response = (Response) o; + json = response.body().string(); + json = new JSONObject(json).toString(8); + Log.d("RESPONSE", json); + } + } catch (Throwable th) { + Log.e("ERROR", th.toString()); + } + } + }); + } catch (AppwriteException e) { + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/example-java/src/main/res/drawable/ic_launcher_background.xml b/example-java/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/example-java/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/example-java/src/main/res/drawable/ic_launcher_foreground.xml b/example-java/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/example-java/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/example-java/src/main/res/layout/activity_main.xml b/example-java/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..4fc2444 --- /dev/null +++ b/example-java/src/main/res/layout/activity_main.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/example-java/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/example-java/src/main/res/values/colors.xml b/example-java/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/example-java/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/example-java/src/main/res/values/strings.xml b/example-java/src/main/res/values/strings.xml new file mode 100644 index 0000000..71e50b3 --- /dev/null +++ b/example-java/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Example Java + \ No newline at end of file diff --git a/example-java/src/main/res/values/themes.xml b/example-java/src/main/res/values/themes.xml new file mode 100644 index 0000000..dde245d --- /dev/null +++ b/example-java/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 49928b6..308fdc3 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -9,15 +9,15 @@ ext { PUBLISH_GROUP_ID = 'io.appwrite' PUBLISH_ARTIFACT_ID = 'sdk-for-android' PUBLISH_VERSION = '0.0.0-SNAPSHOT' - POM_URL = '' + POM_URL = 'https://github.com/appwrite/sdk-for-android' POM_SCM_URL = 'https://github.com/appwrite/sdk-for-android' POM_ISSUE_URL = 'https://github.com/appwrite/sdk-for-android/issues' POM_DESCRIPTION = 'Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Android SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)' POM_LICENSE_URL = 'https://opensource.org/licenses/GPL-3.0' POM_LICENSE_NAME = "GPL-3.0" - POM_DEVELOPER_ID = '' - POM_DEVELOPER_NAME = 'appwrite' - POM_DEVELOPER_EMAIL = '' + POM_DEVELOPER_ID = 'appwrite' + POM_DEVELOPER_NAME = 'Appwrite Team' + POM_DEVELOPER_EMAIL = 'team@appwrite.io' GITHUB_SCM_CONNECTION = 'scm:git:git://github.com/appwrite/sdk-for-android.git' } diff --git a/library/src/main/java/io/appwrite/Client.kt b/library/src/main/java/io/appwrite/Client.kt index 64065ba..cfec9af 100644 --- a/library/src/main/java/io/appwrite/Client.kt +++ b/library/src/main/java/io/appwrite/Client.kt @@ -35,7 +35,7 @@ import kotlin.coroutines.CoroutineContext import kotlin.coroutines.resume import kotlin.coroutines.resumeWithException -class Client( +class Client @JvmOverloads constructor( context: Context, var endPoint: String = "https://appwrite.io/v1", private var selfSigned: Boolean = false @@ -57,7 +57,7 @@ class Client( SharedPrefsCookiePersistor(context) ) - val appVersion by lazy { + private val appVersion by lazy { try { val pInfo = context.packageManager.getPackageInfo(context.packageName, 0) return@lazy pInfo.versionName @@ -148,7 +148,7 @@ class Client( return this } - fun addHeader(key: String, value: String): Client { + private fun addHeader(key: String, value: String): Client { headers[key] = value return this } diff --git a/library/src/main/java/io/appwrite/KeepAliveService.kt b/library/src/main/java/io/appwrite/KeepAliveService.kt index a4c68ea..fb46f7a 100644 --- a/library/src/main/java/io/appwrite/KeepAliveService.kt +++ b/library/src/main/java/io/appwrite/KeepAliveService.kt @@ -5,7 +5,7 @@ import android.content.Intent import android.os.Binder import android.os.IBinder -class KeepAliveService: Service() { +internal class KeepAliveService: Service() { companion object { val binder = Binder() } diff --git a/library/src/main/java/io/appwrite/views/CallbackActivity.kt b/library/src/main/java/io/appwrite/views/CallbackActivity.kt index 49baf68..0867849 100644 --- a/library/src/main/java/io/appwrite/views/CallbackActivity.kt +++ b/library/src/main/java/io/appwrite/views/CallbackActivity.kt @@ -12,7 +12,7 @@ class CallbackActivity: Activity() { val scheme = url?.scheme if (scheme != null) { // Found a scheme, try to callback to web auth component. - // Will only suceed if the scheme matches one launched by this sdk. + // Will only succeed if the scheme matches one launched by this sdk. WebAuthComponent.onCallback(scheme, url) } finish() diff --git a/settings.gradle b/settings.gradle index c9196b3..73c359b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,4 @@ rootProject.name = "Appwrite Android SDK" include ':example' include ':library' +include ':example-java' \ No newline at end of file