├── .gitignore
├── Example
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── tgio
│ │ └── parselivequery
│ │ └── example
│ │ ├── Application.java
│ │ └── MainActivity.java
│ └── res
│ ├── layout
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── LICENSE
├── README.md
├── Server
├── package.json
└── server.js
├── bintray.gradle
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── install.gradle
├── parse-livequery
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── tgio
│ │ └── parselivequery
│ │ ├── BaseQuery.java
│ │ ├── Constants.java
│ │ ├── Event.java
│ │ ├── LiveQueryClient.java
│ │ ├── LiveQueryEvent.java
│ │ ├── RxBus.java
│ │ ├── Subscription.java
│ │ └── interfaces
│ │ └── OnListener.java
│ └── res
│ └── values
│ └── strings.xml
├── script.sh
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | /script.sh
9 | /Server/logs
--------------------------------------------------------------------------------
/Example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | android {
3 | compileSdkVersion 25
4 | buildToolsVersion '25.0.2'
5 |
6 | defaultConfig {
7 | applicationId "tgio.parselivequery.example"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 |
21 | dependencies {
22 | compile project(':parse-livequery')
23 | compile 'com.android.support:appcompat-v7:25.1.0'
24 | compile 'com.parse:parse-android:1.13.1'
25 | // compile 'com.github.tgio:parse-livequery:1.0.3'
26 | }
27 |
--------------------------------------------------------------------------------
/Example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/pro/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/Example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Example/src/main/java/tgio/parselivequery/example/Application.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery.example;
2 |
3 | import com.parse.Parse;
4 |
5 | import tgio.parselivequery.LiveQueryClient;
6 |
7 | /**
8 | * Created by pro on 16-07-08.
9 | */
10 | public class Application extends android.app.Application {
11 | public static final String WS_URL = "ws://192.168.0.100:4040/";
12 | public static final String MY_APP_ID = "myAppId";
13 | public static String SERVER = "http://192.168.0.100:1337/parse/";
14 | public static String CLIENT_KEY = "2ead5328dda34e688816040a0e78948a";
15 |
16 | @Override
17 | public void onCreate() {
18 | super.onCreate();
19 | Parse.initialize(new Parse.Configuration.Builder(this)
20 | .applicationId(MY_APP_ID)
21 | .server(SERVER)
22 | .clientKey(CLIENT_KEY)
23 | .build()
24 | );
25 |
26 | LiveQueryClient.init(WS_URL, MY_APP_ID, true);
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/Example/src/main/java/tgio/parselivequery/example/MainActivity.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery.example;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.util.Log;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.TextView;
10 |
11 | import com.parse.ParseObject;
12 |
13 | import org.json.JSONObject;
14 |
15 | import tgio.parselivequery.LiveQueryClient;
16 | import tgio.parselivequery.BaseQuery;
17 | import tgio.parselivequery.LiveQueryEvent;
18 | import tgio.parselivequery.Subscription;
19 | import tgio.parselivequery.interfaces.OnListener;
20 |
21 | public class MainActivity extends AppCompatActivity {
22 |
23 | private TextView resultView;
24 | private Button mConnectButton;
25 | private Button mDisconnectButton;
26 | private Button mUnsubscribeButton;
27 | private Button mSendButton;
28 | private EditText mMessageEditText;
29 |
30 | @Override
31 | protected void onCreate(Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | setContentView(R.layout.activity_main);
34 |
35 | resultView = (TextView) findViewById(R.id.resultView);
36 | mUnsubscribeButton = (Button) findViewById(R.id.unsubscribe);
37 | mConnectButton = (Button) findViewById(R.id.connect);
38 | mDisconnectButton = (Button) findViewById(R.id.disconnect);
39 | mSendButton = (Button) findViewById(R.id.send);
40 | mMessageEditText = (EditText) findViewById(R.id.message);
41 |
42 | // Connection, when starts or by Connect Button
43 | //LiveQueryClient.connect();
44 |
45 | LiveQueryClient.on(LiveQueryEvent.CONNECTED, new OnListener() {
46 | @Override
47 | public void on(final JSONObject object) {
48 | // Subscribe to any event if you need as soon as connect to server
49 | runOnUiThread(new Runnable() {
50 | @Override
51 | public void run() {
52 | resultView.append(object.toString() + "\n");
53 | }
54 | });
55 |
56 | }
57 | });
58 |
59 | LiveQueryClient.on(LiveQueryEvent.SUBSCRIBED, new OnListener() {
60 | @Override
61 | public void on(final JSONObject object) {
62 | runOnUiThread(new Runnable() {
63 | @Override
64 | public void run() {
65 | resultView.append(object.toString() + "\n");
66 | }
67 | });
68 | }
69 | });
70 |
71 | // Subscription
72 | final Subscription subscription = new BaseQuery.Builder("Message")
73 | .where("body", "asd")
74 | .addField("body")
75 | .build()
76 | .subscribe();
77 |
78 | // Listen
79 | subscription.on(LiveQueryEvent.CREATE, new OnListener() {
80 | @Override
81 | public void on(final JSONObject object) {
82 | Log.e("CREATE", object.toString());
83 | runOnUiThread(new Runnable() {
84 | @Override
85 | public void run() {
86 | resultView.append(object.toString() + "\n");
87 | }
88 | });
89 | }
90 | });
91 |
92 | // Listen ALL events
93 | // subscription.on(LiveQueryEvent.ALL, new OnListener() {
94 | // @Override
95 | // public void on(final JSONObject object) {
96 | // runOnUiThread(new Runnable() {
97 | // @Override
98 | // public void run() {
99 | // resultView.append(object.toString() + "\n");
100 | // }
101 | // });
102 | // }
103 | // });
104 |
105 | // Unsubscribe
106 | mUnsubscribeButton.setOnClickListener(new View.OnClickListener() {
107 | @Override
108 | public void onClick(View v) {
109 | subscription.unsubscribe();
110 | }
111 | });
112 |
113 | // Connect
114 | mConnectButton.setOnClickListener(new View.OnClickListener() {
115 | @Override
116 | public void onClick(View v) {
117 | LiveQueryClient.connect();
118 | }
119 | });
120 |
121 | // Disconnect
122 | mDisconnectButton.setOnClickListener(new View.OnClickListener() {
123 | @Override
124 | public void onClick(View v) {
125 | LiveQueryClient.disconnect();
126 | }
127 | });
128 |
129 | // Send Message for testing, text must be "asd"
130 | mSendButton.setOnClickListener(new View.OnClickListener() {
131 | @Override
132 | public void onClick(View v) {
133 | String message = mMessageEditText.getText().toString().trim();
134 | mMessageEditText.setText("");
135 | if (message.length() > 0) {
136 | ParseObject po = new ParseObject("Message");
137 | po.put("body", message);
138 | po.saveInBackground();
139 | }
140 | }
141 | });
142 | }
143 | }
144 |
--------------------------------------------------------------------------------
/Example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
17 |
18 |
23 |
24 |
30 |
31 |
36 |
37 |
38 |
39 |
45 |
46 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
70 |
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/Example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/Example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/Example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/Example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/Example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | ParseLiveQuery
3 |
4 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Deprecated, please use https://github.com/parse-community/ParseLiveQuery-Android
2 |
3 | [](https://jitpack.io/#tgio/ParseLiveQuery/-SNAPSHOT)
4 | ## Parse LiveQuery Implementation for Android
5 | Simple ParseLiveQuery with subscribe, unsubscribe and listen events.
6 | Based on [ParseLiveQuery](https://github.com/TGIO/ParseLiveQuery)
7 |
8 | #### Import guide
9 |
10 | ```
11 | dependencies {
12 | compile 'com.github.tgio:parse-livequery:1.0.3'
13 | }
14 | ```
15 |
16 | #### Server-Setup
17 |
18 | 1. Make sure u have node and npm installed.
19 | 2. cd Server && npm install
20 | 3. node server.js
21 |
22 |
23 | #### Usage
24 |
25 |
26 | ```java
27 | //Do initialization, for example in App.java
28 | LiveQueryClient.init(WS_URL, MY_APP_ID, true);
29 |
30 | //Connect
31 | LiveQueryClient.connect();
32 |
33 | //Subscribe for parse object "Message" where "body" equals "asd" and include "body" field in response
34 |
35 | // Subscription
36 | final Subscription subscription = new BaseQuery.Builder("Message")
37 | .where("body", "asd")
38 | .addField("body")
39 | .build()
40 | .subscribe();
41 |
42 | // Listen
43 | subscription.on(LiveQueryEvent.CREATE, new OnListener() {
44 | @Override
45 | public void on(final JSONObject object) {
46 | Log.e("CREATED", object.toString());
47 | }
48 | });
49 |
50 | // Unsubscribe
51 | //subscription.unsubscribe();
52 |
53 | ```
54 |
55 | #### Contributors
56 | [Khirr] (https://github.com/khirr)
57 |
--------------------------------------------------------------------------------
/Server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "parse-server-example-for-android-livequery",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "server.js",
6 | "scripts": {
7 | "start": "node server.js"
8 | },
9 | "author": "",
10 | "license": "ISC",
11 | "dependencies": {
12 | "kerberos": "0.0.21",
13 | "mongodb-runner": "^3.3.2",
14 | "parse-dashboard": "^1.0.14",
15 | "parse-server": "^2.2.15"
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/Server/server.js:
--------------------------------------------------------------------------------
1 | var express = require('express');
2 | var ParseServer = require('parse-server').ParseServer;
3 | var ParseDashboard = require('parse-dashboard');
4 |
5 | var app = express();
6 |
7 | var api = new ParseServer({
8 | databaseURI: 'mongodb://localhost:27017/dev', // Connection string for your MongoDB database
9 | appId: 'myAppId',
10 | masterKey: 'myMasterKey', // Keep this key secret!
11 | fileKey: 'optionalFileKey',
12 | serverURL: 'http://192.168.0.31:1337/parse', // Don't forget to change to https if needed
13 | liveQuery: {
14 | classNames: ['Message']
15 | }
16 | });
17 |
18 | var dashboard = new ParseDashboard({
19 | "apps": [
20 | {
21 | "serverURL": "http://192.168.0.31:1337/parse",
22 | "appId": "myAppId",
23 | "masterKey": "myMasterKey",
24 | "appName": "MyApp",
25 | "clientKey": "2ead5328dda34e688816040a0e78948a"
26 | }
27 | ]
28 | });
29 |
30 | // Serve the Parse API on the /parse URL prefix
31 | app.use('/parse', api);
32 | app.use('/dashboard', dashboard);
33 |
34 | var httpServer = require('http').createServer(app);
35 | httpServer.listen(4040);
36 | var parseLiveQueryServer = ParseServer.createLiveQueryServer(httpServer);
37 |
38 | app.listen(1337, function() {
39 | console.log('parse-server-example running on port 1337.');
40 | });
41 |
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.jfrog.bintray'
2 |
3 | version = libraryVersion
4 |
5 | task sourcesJar(type: Jar) {
6 | classifier = 'sources'
7 | from file("src/main/java/")
8 | }
9 |
10 | task androidJar(type: Jar, dependsOn: ['assemble']) {
11 | group 'Build'
12 | description 'pack jnilibs'
13 | from zipTree('build/intermediates/bundles/release/classes.jar')
14 | from(file('src/main/jniLibs')) {
15 | into 'lib'
16 | }
17 | }
18 |
19 | task javadoc(type: Javadoc) {
20 | source = file("src/main/java/")
21 | classpath += project.files('/Users/pro/Library/Android/sdk/platforms/android-23/android.jar')
22 | }
23 |
24 | task javadocJar(type: Jar, dependsOn: javadoc) {
25 | classifier = 'javadoc'
26 | from javadoc.destinationDir
27 | }
28 |
29 | artifacts {
30 | archives javadocJar
31 | archives sourcesJar
32 | }
33 |
34 | // Bintray
35 | Properties properties = new Properties()
36 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
37 |
38 | bintray {
39 | user = properties.getProperty("bintray.user")
40 | key = properties.getProperty("bintray.apikey")
41 |
42 | configurations = ['archives']
43 | pkg {
44 | repo = bintrayRepo
45 | name = bintrayName
46 | desc = libraryDescription
47 | websiteUrl = siteUrl
48 | vcsUrl = gitUrl
49 | licenses = allLicenses
50 | publish = true
51 | publicDownloadNumbers = true
52 | version {
53 | desc = libraryDescription
54 | gpg {
55 | sign = true //Determines whether to GPG sign the files. The default is false
56 | passphrase = properties.getProperty("bintray.gpg.password")
57 | //Optional. The passphrase for GPG signing'
58 | }
59 | }
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.2.3'
10 | classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.7.1'
11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
12 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | jcenter()
19 | }
20 | }
21 |
22 | task clean(type: Delete) {
23 | delete rootProject.buildDir
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/TGIO/ParseLiveQuery/92ed9d0b1b7936bf714850044df2a2c564184aa3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/install.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.github.dcendents.android-maven'
2 |
3 | group = publishedGroupId // Maven Group ID for the artifact
4 |
5 | install {
6 | repositories.mavenInstaller {
7 | // This generates POM.xml with proper parameters
8 | pom {
9 | project {
10 | packaging 'aar'
11 | groupId publishedGroupId
12 | artifactId artifact
13 |
14 | // Add your description here
15 | name libraryName
16 | description libraryDescription
17 | url siteUrl
18 |
19 | // Set your license
20 | licenses {
21 | license {
22 | name licenseName
23 | url licenseUrl
24 | }
25 | }
26 | developers {
27 | developer {
28 | id developerId
29 | name developerName
30 | email developerEmail
31 | }
32 | }
33 | scm {
34 | connection gitUrl
35 | developerConnection gitUrl
36 | url siteUrl
37 | }
38 | }
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/parse-livequery/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/parse-livequery/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.kt3k.coveralls'
3 |
4 | def version = 4;
5 | ext {
6 | bintrayRepo = 'maven'
7 | bintrayName = 'parse-livequery'
8 |
9 | publishedGroupId = 'com.github.tgio'
10 | libraryName = 'Parse LiveQuery'
11 | artifact = 'parse-livequery'
12 |
13 | libraryDescription = "Very simple and modern implementation, it lacks tests and extra functionality at this moment but i'm working on it."
14 |
15 | siteUrl = 'https://github.com/TGIO/ParseLiveQuery'
16 | gitUrl = 'https://github.com/TGIO/ParseLiveQuery.git'
17 |
18 | libraryVersion = "1.0.".concat(version.toString())
19 |
20 | developerId = 'tgio'
21 | developerName = 'Giorgi Tabatadze'
22 | developerEmail = 'gio.caporegime@gmail.com'
23 |
24 | licenseName = 'The Apache Software License, Version 2.0'
25 | licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
26 | allLicenses = ["Apache-2.0"]
27 | }
28 |
29 | android {
30 | compileSdkVersion 25
31 | buildToolsVersion '25.0.2'
32 |
33 | defaultConfig {
34 | minSdkVersion 14
35 | targetSdkVersion 25
36 | versionCode = version
37 | versionName = libraryVersion
38 | }
39 | buildTypes {
40 | release {
41 | minifyEnabled false
42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
43 | }
44 | }
45 | }
46 |
47 | repositories {
48 | maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
49 | }
50 |
51 | dependencies {
52 | compile 'com.android.support:support-annotations:25.1.0'
53 |
54 | compile 'com.squareup.okhttp3:okhttp:3.5.0'
55 |
56 | compile 'io.reactivex:rxjava:1.2.5'
57 | compile 'io.reactivex:rxandroid:1.2.1'
58 |
59 | compile 'com.artemzin.rxjava:proguard-rules:1.1.6.0'
60 |
61 | testCompile 'org.robolectric:robolectric:3.0'
62 | testCompile 'org.skyscreamer:jsonassert:1.2.3'
63 | }
64 |
65 | //region Code Coverage
66 |
67 | apply plugin: 'jacoco'
68 |
69 | jacoco {
70 | toolVersion "0.7.1.201405082137"
71 | }
72 |
73 | task jacocoTestReport(type:JacocoReport, dependsOn: ["test", "testDebugUnitTest"]) {
74 | group = "Reporting"
75 | description = "Generate Jacoco coverage reports"
76 |
77 | classDirectories = fileTree(
78 | dir: "${buildDir}/intermediates/classes/debug",
79 | excludes: ['**/R.class',
80 | '**/R$*.class',
81 | '**/*$ViewInjector*.*',
82 | '**/BuildConfig.*',
83 | '**/Manifest*.*']
84 | )
85 |
86 | sourceDirectories = files("${buildDir.parent}/src/main/java")
87 | additionalSourceDirs = files([
88 | "${buildDir}/generated/source/buildConfig/debug",
89 | "${buildDir}/generated/source/r/debug"
90 | ])
91 | executionData = files("${buildDir}/jacoco/testDebugUnitTest.exec")
92 |
93 | reports {
94 | xml.enabled = false
95 | html.enabled = true
96 | }
97 | }
98 |
99 | //endregion
100 |
101 | //region Coveralls
102 |
103 | coveralls.jacocoReportPath = "${buildDir}/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"
104 |
105 | //endregion
106 |
107 | apply from: '../bintray.gradle';
108 | apply from: '../install.gradle';
109 |
--------------------------------------------------------------------------------
/parse-livequery/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/pro/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/BaseQuery.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | import android.support.annotation.StringDef;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONException;
7 | import org.json.JSONObject;
8 |
9 | import java.lang.annotation.Retention;
10 | import java.lang.annotation.RetentionPolicy;
11 | import java.util.ArrayList;
12 | import java.util.List;
13 |
14 | /**
15 | * Created by pro on 16-06-21.
16 | */
17 | public class BaseQuery {
18 | @Retention(RetentionPolicy.SOURCE)
19 | @StringDef({
20 | Constants.CONNECT,
21 | Constants.SUBSCRIBE,
22 | Constants.CREATE,
23 | Constants.ENTER,
24 | Constants.UPDATE,
25 | Constants.LEAVE,
26 | Constants.DELETE,
27 | Constants.UNSUBSCRIBE,
28 | Constants.ERROR
29 | })
30 |
31 | public @interface op {}
32 | public String className;
33 | public String whereKey;
34 | public String whereValue;
35 | public @op String op;
36 | public int requestId;
37 | public List fields = null;
38 | private String mSessionToken;
39 |
40 | @Override
41 | public String toString() {
42 | JSONObject jo = new JSONObject();
43 | JSONObject query = new JSONObject();
44 | JSONObject where = new JSONObject();
45 | try {
46 | jo.put(Constants.OP, op);
47 | jo.put(Constants.REQUEST_ID, requestId);
48 | if (mSessionToken != null) {
49 | jo.put(Constants.SESSION_TOKEN, mSessionToken);
50 | }
51 | query.put(Constants.CLASS_NAME, className);
52 | where.put(whereKey, whereValue);
53 | query.put(Constants.WHERE, where);
54 | if (fields != null) {
55 | JSONArray fieldsArray = new JSONArray();
56 | for (String field : fields) {
57 | fieldsArray.put(field);
58 | }
59 | query.put(Constants.FIELDS, fieldsArray);
60 | }
61 | jo.put(Constants.QUERY, query);
62 | } catch (JSONException e) {
63 | e.printStackTrace();
64 | }
65 | return jo.toString();
66 | }
67 |
68 | protected void setSessionToken(String sessionToken) {
69 | mSessionToken = sessionToken;
70 | }
71 |
72 | protected String unsubscribeQueryToString() {
73 | JSONObject jo = new JSONObject();
74 | try {
75 | jo.put(Constants.OP, Constants.UNSUBSCRIBE);
76 | jo.put(Constants.REQUEST_ID, requestId);
77 | } catch (JSONException e) {
78 | e.printStackTrace();
79 | }
80 | return jo.toString();
81 | }
82 |
83 | public Subscription subscribe() {
84 | Subscription subscription = new Subscription(this);
85 | subscription.subscribe();
86 | return subscription;
87 | }
88 |
89 | private BaseQuery(@op String op, int requestId, String className) {
90 | this.op = op;
91 | this.requestId = requestId;
92 | this.className = className;
93 | }
94 |
95 | public static class Builder {
96 | BaseQuery baseQuery;
97 |
98 |
99 | public Builder(String className) {
100 | this.baseQuery = new BaseQuery(Constants.SUBSCRIBE, LiveQueryClient.getNewRequestId(), className);
101 | this.baseQuery.setSessionToken(LiveQueryClient.getSessionToken());
102 | }
103 |
104 | public Builder addField(String field) {
105 | if(baseQuery.fields == null) {
106 | baseQuery.fields = new ArrayList<>();
107 | }
108 | baseQuery.fields.add(field);
109 | return this;
110 | }
111 |
112 | public Builder sessionToken(String sessionToken) {
113 | this.baseQuery.setSessionToken(sessionToken);
114 | return this;
115 | }
116 |
117 | public Builder where(String key, String value) {
118 | this.baseQuery.whereKey = key;
119 | this.baseQuery.whereValue = value;
120 | return this;
121 | }
122 |
123 | public BaseQuery build(){
124 | return baseQuery;
125 | }
126 | }
127 | }
128 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/Constants.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | /**
4 | * Created by pro on 16-06-21.
5 | */
6 | class Constants {
7 |
8 | protected static final String CONNECT = "connect";
9 | protected static final String SUBSCRIBE = "subscribe";
10 | protected static final String CREATE = "create";
11 | protected static final String ENTER = "enter";
12 | protected static final String UPDATE = "update";
13 | protected static final String LEAVE = "leave";
14 | protected static final String DELETE = "delete";
15 | protected static final String UNSUBSCRIBE = "unsubscribe";
16 | protected static final String ERROR = "error";
17 | protected static final String SESSION_TOKEN = "sessionToken";
18 |
19 | protected static final String OP = "op";
20 | protected static final String REQUEST_ID = "requestId";
21 | protected static final String CLASS_NAME = "className";
22 | protected static final String WHERE = "where";
23 | protected static final String FIELDS = "fields";
24 | protected static final String QUERY = "query";
25 |
26 | protected static final String CONNECTED = "connected";
27 | protected static final String SUBSCRIBED = "subscribed";
28 |
29 | protected static final String ALL = "all";
30 | }
31 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/Event.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | import tgio.parselivequery.interfaces.OnListener;
4 |
5 | public class Event {
6 |
7 | private OnListener mListener;
8 | private String mOp;
9 |
10 | public Event(String op, OnListener listener) {
11 | mOp = op;
12 | mListener = listener;
13 | }
14 |
15 | public OnListener getListener() {
16 | return mListener;
17 | }
18 |
19 | public String getOp() {
20 | return mOp;
21 | }
22 | }
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/LiveQueryClient.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | import android.util.Log;
4 |
5 | import org.json.JSONException;
6 | import org.json.JSONObject;
7 |
8 | import java.util.ArrayList;
9 | import java.util.concurrent.Executors;
10 | import java.util.concurrent.ScheduledExecutorService;
11 | import java.util.concurrent.TimeUnit;
12 |
13 | import okhttp3.OkHttpClient;
14 | import okhttp3.Request;
15 | import okhttp3.Response;
16 | import okhttp3.WebSocket;
17 | import okhttp3.WebSocketListener;
18 | import rx.functions.Action1;
19 | import tgio.parselivequery.interfaces.OnListener;
20 |
21 | public class LiveQueryClient {
22 | static final int INFINITE = 0;
23 |
24 | static final String CLASS_NAME = "LiveQueryClient";
25 |
26 | static String baseUrl;
27 | static String applicationId;
28 | static WebSocket webSocket;
29 | static boolean isOpened = false;
30 | static boolean isConnected = false;
31 | static int lastRequestID = -1;
32 |
33 | static boolean autoReConnect = false;
34 |
35 | public static LiveQueryClient instance;
36 | private ArrayList mEvents = new ArrayList<>();
37 |
38 | private static ArrayList mSubscriptions = new ArrayList<>();
39 |
40 | private static ScheduledExecutorService mScheduleTaskExecutor;
41 |
42 | private static String mSessionToken;
43 |
44 | LiveQueryClient (String _baseUrl, String _applicationId) {
45 | baseUrl = _baseUrl;
46 | applicationId = _applicationId;
47 | // Listen events
48 | listenEvents();
49 | }
50 |
51 | private void connectToServer() {
52 | OkHttpClient client = new OkHttpClient()
53 | .newBuilder()
54 | .readTimeout(INFINITE, TimeUnit.SECONDS)
55 | .build();
56 |
57 | Request request = new Request.Builder()
58 | .url(baseUrl)
59 | .build();
60 | client.newWebSocket(request, webSocketListener);
61 |
62 | // Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
63 | client.dispatcher().executorService().shutdown();
64 | }
65 |
66 | private static LiveQueryClient getInstance() {
67 | if (instance == null) {
68 | instance = new LiveQueryClient(baseUrl, applicationId);
69 | }
70 | return instance;
71 |
72 | }
73 |
74 | public static void init(String _baseUrl, String _applicationId) {
75 | baseUrl = _baseUrl;
76 | applicationId = _applicationId;
77 | getInstance();
78 | }
79 |
80 | public static void init(String _baseUrl, String _applicationId, boolean _autoReConnect) {
81 | baseUrl = _baseUrl;
82 | applicationId = _applicationId;
83 | autoReConnect = _autoReConnect;
84 | getInstance();
85 | }
86 |
87 | public static void init(String _baseUrl, String _applicationId, String _sessionToken, boolean _autoReConnect) {
88 | baseUrl = _baseUrl;
89 | applicationId = _applicationId;
90 | autoReConnect = _autoReConnect;
91 | mSessionToken = _sessionToken;
92 | getInstance();
93 | }
94 |
95 | public static void connect() {
96 | if (isConnected()) {
97 | Log.i(CLASS_NAME, CLASS_NAME + " is already connected");
98 | return;
99 | }
100 | getInstance().connectToServer();
101 | }
102 |
103 | public static void disconnect() {
104 | destroyConnection();
105 | getInstance().removeTryToReConnect();
106 | Log.i(CLASS_NAME, CLASS_NAME + " disconnected");
107 | }
108 |
109 | private static void destroyConnection() {
110 | try {
111 | if (webSocket != null) {
112 | webSocket.close(1000, "Connection closed");
113 | }
114 | webSocket = null;
115 | setIsConnected(false);
116 |
117 | } catch (Exception e) {
118 | e.printStackTrace();
119 | }
120 | }
121 |
122 | public static int getNewRequestId(){
123 | lastRequestID++;
124 | return lastRequestID;
125 | }
126 |
127 | private void connectInternal() {
128 | webSocket.send(getConnectMessage());
129 | }
130 |
131 | private static void validateConnection() {
132 | getInstance().connectInternal();
133 | }
134 |
135 | private void executeQueryInternal(String query) {
136 | if (webSocket != null) {
137 | webSocket.send(query);
138 | }
139 | }
140 |
141 | protected static void executeQuery(BaseQuery baseQuery) {
142 | getInstance().executeQueryInternal(baseQuery.toString());
143 | }
144 |
145 | protected static void executeQuery(String query) {
146 | getInstance().executeQueryInternal(query);
147 | }
148 |
149 | static String getConnectMessage() {
150 | return String.format("{ \"op\": \"%s\", \"applicationId\": \"%s\" }", "connect", applicationId);
151 | }
152 |
153 | public static synchronized boolean isConnected() {
154 | return isConnected;
155 | }
156 |
157 | private static synchronized void setIsConnected(boolean connected) {
158 | isConnected = connected;
159 | }
160 |
161 |
162 | WebSocketListener webSocketListener = new WebSocketListener() {
163 | @Override
164 | public void onOpen(WebSocket _webSocket, Response response) {
165 | isOpened = true;
166 | if (_webSocket != null) {
167 | webSocket = _webSocket;
168 | validateConnection();
169 | }
170 | }
171 | @Override
172 | public void onFailure(WebSocket webSocket, Throwable t, Response response) {
173 | t.printStackTrace();
174 | destroyConnection();
175 | tryToReConnect();
176 | }
177 | @Override
178 | public void onMessage(WebSocket webSocket, String text) {
179 | try {
180 | JSONObject jsonObject = new JSONObject(text);
181 | @BaseQuery.op String op = jsonObject.optString(Constants.OP);
182 | RxBus.broadCast(new LiveQueryEvent(op, jsonObject));
183 | // Create server subscriptions
184 | if (op.equals(LiveQueryEvent.CONNECTED)) {
185 | setIsConnected(true);
186 | registerExistingSubscriptions();
187 | }
188 | } catch (JSONException e) {
189 | e.printStackTrace();
190 | }
191 | }
192 | };
193 |
194 | // Connect && Disconnect events
195 | public static void on(String op, OnListener listener) {
196 | getInstance().mEvents.add(new Event(op, listener));
197 | }
198 |
199 | private void listenEvents() {
200 | RxBus.subscribe(new Action1() {
201 | @Override
202 | public void call(final LiveQueryEvent event) {
203 | for (Event ev : mEvents) {
204 | if (event.op.equals(ev.getOp())) {
205 | ev.getListener().on(event.object);
206 | }
207 | }
208 | }
209 | });
210 | }
211 |
212 | // Register subscriptions
213 | public static void registerSubscription(Subscription subscription) {
214 | mSubscriptions.add(subscription);
215 | if (isConnected()) {
216 | executeQuery(subscription.getQuery());
217 | }
218 | }
219 |
220 | // Remove subscription
221 | public static void removeSubscription(Subscription subscription) {
222 | mSubscriptions.remove(subscription);
223 | LiveQueryClient.executeQuery(subscription.getQuery().unsubscribeQueryToString());
224 | }
225 |
226 | // Register existing subscription after server connection
227 | private synchronized void registerExistingSubscriptions() {
228 | for (Subscription subscription : mSubscriptions) {
229 | executeQuery(subscription.getQuery());
230 | }
231 | }
232 |
233 | // Reconnection
234 | private synchronized void tryToReConnect() {
235 | if (!autoReConnect) return;
236 | mScheduleTaskExecutor = Executors.newSingleThreadScheduledExecutor();
237 | mScheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
238 | @Override
239 | public void run() {
240 | try {
241 | connectToServer();
242 | removeTryToReConnect();
243 | } catch (Exception e) {
244 | e.printStackTrace();
245 | }
246 | }
247 | }, 3, 3, TimeUnit.SECONDS);
248 | }
249 |
250 | private void removeTryToReConnect() {
251 | if (mScheduleTaskExecutor != null) {
252 | try {
253 | mScheduleTaskExecutor.shutdownNow();
254 | } catch (Exception e) {
255 | e.printStackTrace();
256 | }
257 | }
258 | }
259 |
260 | // Token
261 | protected static String getSessionToken() {
262 | return mSessionToken;
263 | }
264 |
265 | }
266 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/LiveQueryEvent.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | import org.json.JSONObject;
4 |
5 | public class LiveQueryEvent {
6 |
7 | public static final String CONNECTED = Constants.CONNECTED;
8 | public static final String SUBSCRIBED = Constants.SUBSCRIBED;
9 | public static final String CREATE = Constants.CREATE;
10 | public static final String ENTER = Constants.ENTER;
11 | public static final String UPDATE = Constants.UPDATE;
12 | public static final String LEAVE = Constants.LEAVE;
13 | public static final String DELETE = Constants.DELETE;
14 | public static final String ALL = Constants.ERROR;
15 |
16 | public @BaseQuery.op String op;
17 | public JSONObject object;
18 |
19 | public LiveQueryEvent(String op, JSONObject object) {
20 | this.op = op;
21 | this.object = object;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/parse-livequery/src/main/java/tgio/parselivequery/RxBus.java:
--------------------------------------------------------------------------------
1 | package tgio.parselivequery;
2 |
3 | import rx.*;
4 | import rx.functions.Action1;
5 | import rx.subjects.PublishSubject;
6 | import rx.subjects.SerializedSubject;
7 | import rx.subjects.Subject;
8 |
9 | // this is the middleman object
10 | public class RxBus {
11 | private static RxBus instance = null;
12 | private final Subject