Giter Site home page Giter Site logo

tgio / parselivequery Goto Github PK

View Code? Open in Web Editor NEW
48.0 48.0 12.0 123 KB

Very simple and modern implementation, it lacks tests and extra functionality at this moment but i'm working on it.

License: Apache License 2.0

Java 93.66% JavaScript 5.13% Shell 1.21%

parselivequery's People

Contributors

khirr avatar tgio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

parselivequery's Issues

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

This library produces next error when added to gradle:

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

Android Studio 3.0
this is my gradle file:

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
compile "org.jetbrains.anko:anko:$anko_version"
implementation 'com.parse:parse-android:1.16.3'
implementation 'com.github.tgio:parse-livequery:1.0.3'
}

Relational queries and where clause

Thank you so much TGIO for your work on this much needed code.
I am having trouble trying to build a query with a where clause to retrieve an object with a pointer to another object. The key should be the objectId of the "pointed" object.
According to documentation:

The query.where field is mandatory. It represents the condition of the ParseQuery the client subscribes to. The format of the where field is the same with ParseQuery's REST API format.

So the resulting REST API construct should be:

curl -X GET \
  -H "X-Parse-Application-Id: ${APPLICATION_ID}" \
  -H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
  -G \
  --data-urlencode 'where={"post":{"__type":"Pointer","className":"Post","objectId":"8TOXdXf3tz"}}'

But I can't seem to be able to do something like this as the value of the key is a String and not a JSON. My closest attempt was:
{"op":"subscribe","requestId":0,"query":{"className":"Comment","where":{"post":"{"__type":"Pointer","className":"Post","objectId":"8TOXdXf3tz"}"}}}
which is not working. Note the String after the "post": which should be a JSON. I am obviously doing something wrong here.

Any help is appreciated and please apologize my English.
Thank you!

Program type already present: okhttp3.internal.ws.WebSocketReader$FrameCallback

i get an error while building application.

"Program type already present: okhttp3.internal.ws.WebSocketReader$FrameCallback
Message{kind=ERROR, text=Program type already present: okhttp3.internal.ws.WebSocketReader$FrameCallback, sources=[Unknown source file], tool name=Optional.of(D8)}"

my app just empty. i see this error that i add to gradle " implementation ('com.github.tgio:parse-livequery:1.0.3' "

how can i fix this ?

Calling Subscription more than one time

Works fine

When I subscribe first time its work fine

Not working

when i move back from current screen after unsubscribing and come back to same screen it invoking more than one time

  isSubscribed = false;
   if(!isSubscribed) {
                isSubscribed = true;
                sub = new BaseQuery.Builder("Message")
                        .addField("message")
                        .addField(MSG_RECEIVER_USER_ID)
                        .addField(MSG_SENDER_USER_ID)
                        .build()
                        .subscribe();

                sub.on(LiveQueryEvent.CREATE, new OnListener() {
                    @Override
                    public void on(JSONObject object) {
                        Log.e(TAG, "on: " + object);
                           
                        // Action to be executed here when an object that matches
                        // The filter you set up
                    }
                });
            }else{
                if(sub != null){
                    if(sub.isSubscribed()){
                        sub.unsubscribe();
                        isSubscribed = false;
                    }
                }
            }
     }


output (invoking more than one times)

on: {"op":"create","clientId":22,"requestId":2,"object":{"className":"Message",
"objectId":"MoItqxnFGC","updatedAt":"2017-02-27T10:37:08.679Z","createdAt":"2017-02-27T10:37:08.679Z","message":"dhjjf",
"receiver_user_id":"Rb4bg9Nv5z","sender_user_id":"ewaCQ6Y2I4"}}


on: {"op":"create","clientId":22,"requestId":2,"object":{"className":"Message",
"objectId":"MoItqxnFGC","updatedAt":"2017-02-27T10:37:08.679Z","createdAt":"2017-02-27T10:37:08.679Z","message":"dhjjf",
"receiver_user_id":"Rb4bg9Nv5z","sender_user_id":"ewaCQ6Y2I4"}}

Unsubscribe and Other Query options

Hello, TGIO!

First of all, thank you for your amazing work with LiveQuery!! :)

I'd like to ask you a few things.

  1. I'd like to know if I have a unsubscribe option. In case of negative, do you know how a unsubscribed query would affect the server?
  2. In my project I have to use other queries parts different then whereEqual. How can I use things like whereKeyExists("attrs"), for example?

Thank you TGIO! :)

Problem compiling okhttp library

Hello,
Thanks for this powerful and beautiful library.

I've found a error when compile using your library, the error says:
Could not find com.squareup.okhttp3:okhttp-ws:3.4.0-SNAPSHOT

I've downloaded your library and change for:
compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'

And now it works.

Subscription cant be cancel --crashes app

Hi, really love your library ,but am currently facing an issue with the subscription connect and disconnect ,as per your example you disconnect using a button click which is located in the same block the subscription initialisation ,

However in my use case i need to unsubscribe on the OnStop lifecycle , but it seem to now work as expected , on exit and enter of activity calling the subscription call , get this error

Caused by : java.lang.IllegalStateException: closed when i called subscribe();

Subscription sub = new BaseQuery.Builder("Message")
                .where("toid",toObject.getObjectId() )
                .addField("fromName")
                .addField("message")
                .build()
                .subscribe();

looking throught the source code , it seem the livequeryClient destory isnt called and cause the closed error , am currently not very good with websocket , i would really appreciate any help at all . thank you

 private void executeQueryInternal(String query) {
        if (webSocket != null) {
            try {
                webSocket.sendMessage(RequestBody.create(WebSocket.TEXT, query));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


AND HERE 

 protected static void executeQuery(BaseQuery baseQuery) {
        getInstance().executeQueryInternal(baseQuery.toString());
    }

AND HERE

 public static void registerSubscription(Subscription subscription) {
        mSubscriptions.add(subscription);
        if (isConnected()) {
            executeQuery(subscription.getQuery());
        }
    }


NoSuchMethodError: No virtual method setCallWebSocket

Hi,
When I try to run the app, in logcat given this err:

java.lang.NoSuchMethodError: No virtual method setCallWebSocket(Lokhttp3/Call;)V in class Lokhttp3/internal/Internal; or its super classes (declaration of 'okhttp3.internal.Internal' appears in /data/app/com.test-2/base.apk:classes3.dex)
at okhttp3.ws.WebSocketCall.enqueue

in my application :

public class MainApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Parse.initialize(....);
        LiveQueryClient.init(WS_URL, MY_APP_ID, true);
        LiveQueryClient.connect();
    }
}

Logic?

Hi .this is great.but i like to know what u are using here.becaz if u are using timer it will increase the api hit count.

Socket onError: Expected HTTP 101 response but was '502 Bad Gateway'

ParseLiveQueryClient parseLiveQueryClient = null;
        try {
            parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI("wss://APP-NAME.back4app.io"));
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("Orders");
        SubscriptionHandling<ParseObject> subscriptionHandling = parseLiveQueryClient.subscribe(parseQuery);

        subscriptionHandling.handleEvents(new SubscriptionHandling.HandleEventsCallback<ParseObject>() {
            @Override
            public void onEvents(ParseQuery<ParseObject> query, SubscriptionHandling.Event event, ParseObject object) {
                Toast.makeText(HomeScreen.this, "Subscribed!", Toast.LENGTH_SHORT).show();
            }
        });

Everytime i try to connect i get Socket OnError:

ParseLiveQueryClient: Socket onError
java.net.ProtocolException: Expected HTTP 101 response but was '401 Unauthorized'
at okhttp3.internal.ws.RealWebSocket.checkResponse(RealWebSocket.java:216)
at okhttp3.internal.ws.RealWebSocket$2.onResponse(RealWebSocket.java:183)
at okhttp3.RealCall$AsyncCall.execute(RealCall.java:141)
at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)

Query Constraints

How do I write a query as "query.whereGreaterThan (" playerAge ", 18)"

Exception: NullPointerException: value == null

Hi @TGIO,

I tried to add parse live query to my project. I got below issue:

  1. I added the library to gradle file, run the app. Every time I save an object to parse-server, I got NullPointerException: value == null.

  2. I thought that is because I didn't setup WS URL and APP ID. Then I setup them, I think I did correctly because I got below log when running the app:

    {"op":"connected","clientId":6}
    {"op":"subscribed","clientId":6,"requestId":1}
    {"op":"subscribed","clientId":6,"requestId":1}

But again, every time I save an object to parse-server, I got NullPointerException: value == null.

So my conclusion: This issue started happening from I add the library to gradle. Do you have any idea?

(I am using parse-server 2.2.17)

Unable to initialize livequery connect

https://github.com/shankarnat/ParseLive-Query - is my code. I had tried to do the same example as given in your repository.
Also, I used this backend for just Parse to Insert and read; it worked.

This is the example of the code with just Parse (and not live query against the same backend_ https://github.com/shankarnat/ParseExample and this works and ingests the data.
Now, I confused as to what I am missing.
I have updated the index.js file to ensure the API call and livequery parameters are added as per - this https://github.com/ParsePlatform/parse-server-example/blob/master/index.js and the websocket for the backend is also enabled.
Can you help?

11-26 02:50:30.024 21173-21173/com.example.shankan.querylive_example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shankan.querylive_example, PID: 21173
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at com.parse.Parse.getParseDir(Parse.java:516)
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:130)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:55)
at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:883)
at com.parse.ParseObject.saveInBackground(ParseObject.java:1405)
at com.example.shankan.querylive_example.MainActivity$7.onClick(MainActivity.java:138)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-26 02:51:07.743 21675-21675/com.example.shankan.querylive_example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shankan.querylive_example, PID: 21675
java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File com.parse.ParsePlugins.getParseDir()' on a null object reference
at com.parse.Parse.getParseDir(Parse.java:516)
at com.parse.ParseCorePlugins.getCurrentUserController(ParseCorePlugins.java:130)
at com.parse.ParseUser.getCurrentUserController(ParseUser.java:55)
at com.parse.ParseUser.getCurrentUserAsync(ParseUser.java:883)
at com.parse.ParseObject.saveInBackground(ParseObject.java:1405)
at com.example.shankan.querylive_example.MainActivity$7.onClick(MainActivity.java:138)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
11-26 02:54:00.050 21914-21914/com.example.shankan.querylive_example E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.shankan.querylive_example, PID: 21914
java.lang.NullPointerException: url == null
at okhttp3.Request$Builder.url(Request.java:131)
at tgio.parselivequery.LiveQueryClient.connectToServer(LiveQueryClient.java:63)
at tgio.parselivequery.LiveQueryClient.connect(LiveQueryClient.java:105)
at com.example.shankan.querylive_example.MainActivity$5.onClick(MainActivity.java:117)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

Can the where constraint also be an Object?

public Builder where(String key, String value) {
            this.baseQuery.whereKey = key;
            this.baseQuery.whereValue = value;
            return this;
        }

For example, I'm looking for Message objects where the field conversationObject (Pointer<Conversation>) matches a particular object, i.e. Conservation conservation = new Conversation();

final Subscription sub = new BaseQuery.Builder("Message")
                                .where("conversationObject", conservation)
                                // .addField("field_to_be_returned")
                                .build()
                                .subscribe();

Why can't I filter by objects instead of just strings?

App crashes when clientId is not set

Hi,

we have an app that works just fine with the current parse android version 1.13.1.

When adding the dependency for ParseLiveQuery version 1.0.3 the app won't start any more because of a null pointer crash in okhttp3:

W/System.err: com.parse.ParseException: java.lang.NullPointerException: value == null
W/System.err:     at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:114)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:739)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5417)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
W/System.err: Caused by: java.lang.NullPointerException: value == null
W/System.err:     at okhttp3.Headers$Builder.checkNameAndValue(Headers.java:316)
W/System.err:     at okhttp3.Headers$Builder.add(Headers.java:270)
W/System.err:     at com.parse.ParseOkHttpClient.getRequest(ParseOkHttpClient.java:138)
W/System.err:     at com.parse.ParseOkHttpClient.executeInternal(ParseOkHttpClient.java:64)
W/System.err:     at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:158)
W/System.err:     at com.parse.ParsePlugins$1.intercept(ParsePlugins.java:115)
W/System.err:     at com.parse.ParseHttpClient$ParseNetworkInterceptorChain.proceed(ParseHttpClient.java:147)
W/System.err:     at com.parse.ParseHttpClient.execute(ParseHttpClient.java:122)
W/System.err:     at com.parse.ParseRequest$3.then(ParseRequest.java:136)
W/System.err:     at com.parse.ParseRequest$3.then(ParseRequest.java:133)
W/System.err:     at bolts.Task$15.run(Task.java:917)
W/System.err:     at bolts.BoltsExecutors$ImmediateExecutor.execute(BoltsExecutors.java:105)
W/System.err:     at bolts.Task.completeAfterTask(Task.java:908)
W/System.err:     at bolts.Task.continueWithTask(Task.java:715)
W/System.err:     at bolts.Task.continueWithTask(Task.java:726)
W/System.err:     at bolts.Task$13.then(Task.java:818)
W/System.err:     at bolts.Task$13.then(Task.java:806)
W/System.err:     at bolts.Task$15.run(Task.java:917)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err:     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err:     at java.lang.Thread.run(Thread.java:818)

I investigated the issue. The NPE is thrown because our server and client does not set a clientId (which is optional with the new parse-server according to the guide). Thus, X-Parse-Client-Key is null which is actually logged in the working version:

W/System: Ignoring header X-Parse-Client-Key because its value was null.

I did not use any functionality of ParseLiveQuery. Still, ParseLiveQuery depends on okhttp3 version 3.4.0 while Parse-Android-SDK depends on okhttp3 version 3.3.1. Gradle seems to prefer the higher version which shows the mentioned behavior. okhttp3's changelog also describes a major change in HttpURLConnection in version 3.4.0.

Maybe, for now ParseLiveQuery could just downgrade okhttp3 to version 3.3.1?

Executing multiple times

I am using a recyclerView and I have two classes one which contains the recyclerView and were I set the adapter and one class for the adapter.

In the first class if I set this :

 final Subscription subscription = new BaseQuery.Builder("Posts")
                    .where("objectId", ratingSimplePost.getPostId())
                    .build()
                    .subscribe();

            //  Listen
            subscription.on(Subscription.UPDATE, new OnListener() {
                @Override
                public void on(final JSONObject object) {
                    Log.d(MainActivity.class.getSimpleName(),"Updated");
}
});

What's inside the on method gets executed one time but if I put it inside the adapter class in the onBindViewHolder method the on method gets executed multiple times? Any idea why this is happening and is there a way to fix it ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.