Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantsaini1 authored Oct 14, 2022
0 parents commit 8a6a328
Show file tree
Hide file tree
Showing 22 changed files with 3,186 additions and 0 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: place your license here and we'll include it in the module distribution
496 changes: 496 additions & 0 deletions README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions android/Resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

Files in this directory are copied to the APK's `assets/Resources` when doing an app build.
This is the same directory a Titanium app's `Resources` files are copied to. The app's
`Resources` files take priority and will be copied over module `Resources` files having
the same name.
9 changes: 9 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repositories {
maven { url 'https://jitpack.io' }
}


dependencies {
implementation 'com.github.parse-community.Parse-SDK-Android:parse:2.0.3'
implementation 'com.github.parse-community:ParseLiveQuery-Android:1.2.2'
}
Binary file added android/dist/ti.parselivequery-android-1.1.0.zip
Binary file not shown.
6 changes: 6 additions & 0 deletions android/lib/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

You can place your `*.jar` and `*.aar` library dependencies in this directory.

Note that its best to reference dependencies in the module's "build.gradle" file
instead if you can. This avoids class name collision in case another module uses
the same library.
18 changes: 18 additions & 0 deletions android/manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 1.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86 x86_64
description: ti-parselivequery
author: Prashant Saini
license: Open Source
copyright: Copyright (c) 2022 by Prashant Saini

# these should not be edited
name: ti-parselivequery
moduleid: ti.parselivequery
guid: f542beda-b74a-4af5-9479-4b2191e471eb
platform: android
minsdk: 9.0.0.GA
27 changes: 27 additions & 0 deletions android/platform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

The `./build/android` directory is treated like a gradle project's `./src/main` directory.
These files will be bundled into the module's built AAR library and copied into the built app's APK.

Adding files to the below folder will add them to APK's root "assets" folder.
(Note that a Titanium app's files under the `Resources` directory are copied to the APK's `assets/Resources`.)

<project-dir>/build/android/assets

The below folders are an example on how to add resource files to the APK's "res" folder.

<project-dir>/build/android/res/drawable
<project-dir>/build/android/res/raw
<project-dir>/build/android/res/xml

Prebuilt C/C++ `*.so` libraries must go under the following folder to be bundled with the AAR and APK.

<project-dir>/build/android/jniLibs

Android AIDL code generation files go under the following folder. The build system will automatically
generate Java code for them when the app that is built.

<project-dir>/build/android/aidl

Android "RenderScript" files (aka: `*.rs` files) go under the below folder.

<project-dir>/build/android/rs
64 changes: 64 additions & 0 deletions android/src/ti/parselivequery/Constant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Created by Prashant Saini
*/

package ti.parselivequery;

public class Constant {
// events related to `ParseLiveQueryClient`
final static String EVENT_CLIENT_CONNECTED = "clientConnected";
final static String EVENT_CLIENT_DISCONNECTED = "clientDisconnected";
final static String EVENT_CLIENT_SOCKET_ERROR = "clientSocketError";
final static String EVENT_CLIENT_ERROR = "clientError";


// events related to `createQuery`
final static String EVENT_QUERY_ERROR = "error";
final static String EVENT_QUERY_SUBSCRIBE = "subscribe";
final static String EVENT_QUERY_UNSUBSCRIBE = "unsubscribe";
final static String EVENT_QUERY_EVENT = "event";


// properties related to module
final static String PROPERTY_APP_ID = "appId";
final static String PROPERTY_CLIENT_KEY = "clientKey";
final static String PROPERTY_SERVER = "server";
final static String PROPERTY_ENABLE_LOCAL_STORE = "enableLocalStore";
final static boolean PROPERTY_ENABLE_LOCAL_STORE_DEFAULT = false;

// properties related to all events
final static String PROPERTY_CLASS_VALUE = "value";
final static String PROPERTY_CLASS_MSG = "message";
final static String PROPERTY_ERROR_CODE = "code";


// properties related to `createQuery`
final static String PROPERTY_CLASS_NAME = "className";
final static String PROPERTY_SUCCESS = "success";
final static String PROPERTY_PARSE_OBJECT = "parseObject";
final static String PROPERTY_COUNT = "count";
final static String PROPERTY_PARSE_OBJECTS = "parseObjects";


// event properties related to `createQuery`
final static String PROPERTY_EVENT_TYPE = "parseEventType";

/* -------- v1.1.0 ---------- */
// properties related to `createParseFile`
final static String PROPERTY_FILE_NAME = "fileName";
final static String PROPERTY_FILE_DATA = "fileData"; // type TiBlob in Java, Ti.Blob in JS
final static String PROPERTY_FILE_PROGRESS = "fileProgress";


// properties related to `createParseGeoPoint`
final static String PROPERTY_LATITUDE = "latitude";
final static String PROPERTY_LONGITUDE = "longitude";


// properties related to `createParsePolygon`
final static String PROPERTY_PARSE_GEOPOINT_LIST = "parseGeoPointList";

// properties related to `createParseUser`
final static String PROPERTY_PARSE_USER = "parseUser";
final static String PROPERTY_PARSE_USERS = "parseUsers";
}
103 changes: 103 additions & 0 deletions android/src/ti/parselivequery/ParseClientProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* Created by Prashant Saini
*/

package ti.parselivequery;

import com.parse.livequery.LiveQueryException;
import com.parse.livequery.ParseLiveQueryClient;
import com.parse.livequery.ParseLiveQueryClientCallbacks;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.annotations.Kroll;

import static ti.parselivequery.Constant.EVENT_CLIENT_CONNECTED;
import static ti.parselivequery.Constant.EVENT_CLIENT_DISCONNECTED;
import static ti.parselivequery.Constant.EVENT_CLIENT_ERROR;
import static ti.parselivequery.Constant.EVENT_CLIENT_SOCKET_ERROR;
import static ti.parselivequery.Constant.PROPERTY_CLASS_VALUE;

@SuppressWarnings("unused")
@Kroll.proxy(creatableInModule = TiParselivequeryModule.class)
public class ParseClientProxy extends KrollProxy implements ParseLiveQueryClientCallbacks {
private boolean isConnected = false;
ParseLiveQueryClient parseLiveQueryClient;

public ParseClientProxy() {
parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient();
registerListener();
}

@Override
public void release() {
super.release();
destroyClient();
}

@Kroll.getProperty
public boolean getIsConnected() {
return isConnected;
}

@Kroll.method
public void registerListener() {
parseLiveQueryClient.registerListener(this);
}

@Kroll.method
public void unregisterListener() {
parseLiveQueryClient.unregisterListener(this);
}

@Kroll.method
public void reconnectClient() {
parseLiveQueryClient.reconnect();
}

@Kroll.method
public void reconnectClientIfNeeded() {
parseLiveQueryClient.connectIfNeeded();
}

@Kroll.method
public void disconnectClient() {
parseLiveQueryClient.disconnect();
}

@Kroll.method
public void destroyClient() {
disconnectClient();
unregisterListener();
parseLiveQueryClient = null;
}

private void fireClientEvent(String eventName, Object value) {
KrollDict result = new KrollDict();
result.put(PROPERTY_CLASS_VALUE, value);
fireEvent(eventName, result);
}

@Override
public void onLiveQueryClientConnected(ParseLiveQueryClient client) {
isConnected = true;
fireClientEvent(EVENT_CLIENT_CONNECTED, true);
}

@Override
public void onLiveQueryClientDisconnected(ParseLiveQueryClient client, boolean userInitiated) {
isConnected = false;
fireClientEvent(EVENT_CLIENT_DISCONNECTED, false);
}

@Override
public void onLiveQueryError(ParseLiveQueryClient client, LiveQueryException reason) {
fireClientEvent(EVENT_CLIENT_ERROR, reason.getLocalizedMessage());
}

@Override
public void onSocketError(ParseLiveQueryClient client, Throwable reason) {
isConnected = false;
fireClientEvent(EVENT_CLIENT_SOCKET_ERROR, reason.getLocalizedMessage());
}
}
52 changes: 52 additions & 0 deletions android/src/ti/parselivequery/ParseDataTypeConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Created by Prashant Saini
*/

package ti.parselivequery;

import org.appcelerator.titanium.util.TiConvert;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
* Created by Prashant Saini on 10/10/22.
*/
public class ParseDataTypeConverter {
static Object toParseDataTypeFrom(Object value) {
Object parseDataTypeValue = value;

if (value instanceof ParseObjectProxy) {
parseDataTypeValue = ((ParseObjectProxy) value).parseObject;
} else if (value instanceof ParseUserProxy) {
parseDataTypeValue = ((ParseUserProxy) value).getMyParseUser();
} else if (value instanceof ParseFileProxy) {
parseDataTypeValue = ((ParseFileProxy) value).getParseFile();
} else if (value instanceof ParseGeoPointProxy) {
parseDataTypeValue = ((ParseGeoPointProxy) value).getParseGeoPoint();
} else if (value instanceof ParsePolygonProxy) {
parseDataTypeValue = ((ParsePolygonProxy) value).getParsePolygon();
} else if (value instanceof HashMap) {
//noinspection unchecked
parseDataTypeValue = TiConvert.toJSON((HashMap) value);
} else if (value instanceof Object[]) {
parseDataTypeValue = TiConvert.toJSONArray((Object[]) value);
} else if (value == null) {
parseDataTypeValue = JSONObject.NULL;
}

return parseDataTypeValue;
}

static List<Object> toParseDataTypeFromArray(Object values) {
List<Object> list = new ArrayList<>();

for (Object nextObject : (Object[]) values) {
list.add( toParseDataTypeFrom(nextObject) );
}

return list;
}
}
Loading

0 comments on commit 8a6a328

Please sign in to comment.