-
-
Notifications
You must be signed in to change notification settings - Fork 32
Add an initial test app #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rogerhu
wants to merge
5
commits into
parse-community:master
Choose a base branch
from
rogerhu:testapp
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.parse.example" xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET"/> | ||
|
||
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" android:theme="@style/AppTheme"> | ||
<activity android:name=".MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.parse.example; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
|
||
import com.parse.GetCallback; | ||
import com.parse.Parse; | ||
import com.parse.ParseException; | ||
import com.parse.ParseLiveQueryClient; | ||
import com.parse.ParseObject; | ||
import com.parse.ParseQuery; | ||
import com.parse.SubscriptionHandling; | ||
import com.parse.interceptors.ParseLogInterceptor; | ||
|
||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
String URL = "http://192.168.3.9:1337/parse/"; | ||
String wsURL = "ws://192.168.3.9:1337/parse/"; | ||
String applicationId = "mytest"; | ||
String DEBUG_TAG = "debug"; | ||
|
||
Room mRoom; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
ParseObject.registerSubclass(Room.class); | ||
ParseObject.registerSubclass(Message.class); | ||
|
||
Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG); | ||
Parse.initialize(new Parse.Configuration.Builder(this) | ||
.applicationId(applicationId) // should correspond to APP_ID env variable | ||
.clientKey("clientKey") // set explicitly blank unless clientKey is configured on Parse server | ||
.addNetworkInterceptor(new ParseLogInterceptor()) | ||
.server(URL).build()); | ||
|
||
ParseQuery<Room> roomParseQuery = ParseQuery.getQuery(Room.class); | ||
// fixme - why isn't it retrieving | ||
roomParseQuery.whereEqualTo("name", "test"); | ||
roomParseQuery.getFirstInBackground(new GetCallback<Room>() { | ||
@Override | ||
public void done(Room room, ParseException e) { | ||
if (e != null) { | ||
Log.d(DEBUG_TAG, "Found exception" + e); | ||
e.printStackTrace(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need deal with the exceptions? |
||
} else { | ||
Log.d(DEBUG_TAG, "Found room: " + room); | ||
} | ||
mRoom = room; | ||
|
||
ParseLiveQueryClient parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(); | ||
|
||
if (parseLiveQueryClient != null) { | ||
// op=subscribe, className=Message, roomName=test, requestId=1 | ||
// op=subscribe, className=Message, roomName=null, requestId=1, order=createdAt | ||
ParseQuery<Message> parseQuery = ParseQuery.getQuery(Message.class); | ||
// FIXME | ||
parseQuery.whereEqualTo("roomName", "test"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should |
||
|
||
// FIXME (rhu) - parse query hates created at | ||
// parseQuery.orderByAscending("createdAt"); | ||
|
||
SubscriptionHandling<Message> subscriptionHandling = parseLiveQueryClient | ||
.subscribe(parseQuery); | ||
subscriptionHandling.handleEvent(SubscriptionHandling.Event.CREATE, | ||
new SubscriptionHandling.HandleEventCallback<Message>() { | ||
@Override | ||
public void onEvent(ParseQuery<Message> query, Message object) { | ||
Log.d(DEBUG_TAG, "Message" + object); | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.parse.example; | ||
|
||
|
||
import com.parse.ParseClassName; | ||
import com.parse.ParseObject; | ||
import com.parse.ParseUser; | ||
|
||
@ParseClassName("Message") | ||
public class Message extends ParseObject { | ||
|
||
private final String PARSE_USER_KEY = "parseUser"; | ||
private final String AUTHOR_KEY = "author"; | ||
private final String MESSAGE_KEY = "message"; | ||
private final String ROOM_KEY = "room"; | ||
|
||
public Message() { | ||
|
||
} | ||
|
||
public ParseUser getParseUser() { | ||
return getParseUser(PARSE_USER_KEY); | ||
} | ||
|
||
public void setParseUser(ParseUser parseUser) { | ||
put(PARSE_USER_KEY, parseUser); | ||
} | ||
|
||
public String getAuthorName() { | ||
return getString(AUTHOR_KEY); | ||
} | ||
|
||
public void setAuthorName(String authorName) { | ||
put(AUTHOR_KEY, authorName); | ||
} | ||
|
||
public String getMessage() { | ||
return getString(MESSAGE_KEY); | ||
} | ||
|
||
public void setMessage(String message) { | ||
put(MESSAGE_KEY, message); | ||
} | ||
|
||
public Room getRoom() { | ||
return (Room) get(ROOM_KEY); | ||
} | ||
|
||
public void setRoom(Room room) { | ||
put(ROOM_KEY, room); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("objectId=%s: message=%s room=%s", getObjectId(), getMessage(), getRoom()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.parse.example; | ||
|
||
import com.parse.ParseClassName; | ||
import com.parse.ParseObject; | ||
|
||
@ParseClassName("Room") | ||
public class Room extends ParseObject { | ||
|
||
private final String NAME_KEY = "name"; | ||
|
||
public Room() { | ||
|
||
} | ||
|
||
String name; | ||
|
||
public String getName() { | ||
return getString(NAME_KEY); | ||
} | ||
|
||
public void setName(String name) { | ||
put(NAME_KEY, name); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return String.format("objectId=%s: name=%s", getObjectId(), getName()); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" | ||
android:layout_height="match_parent" tools:context="com.parse.example.MainActivity"> | ||
|
||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" | ||
android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">Example</string> | ||
</resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
104 changes: 104 additions & 0 deletions
104
ParseLiveQuery/src/main/java/com/parse/OkHttp3WebSocketClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.parse; | ||
|
||
import android.util.Log; | ||
|
||
import java.net.URI; | ||
import java.util.Locale; | ||
|
||
import okhttp3.OkHttpClient; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import okhttp3.WebSocketListener; | ||
import okio.ByteString; | ||
|
||
/* package */ class OkHttp3WebSocketClient implements WebSocketClient { | ||
|
||
private static final String LOG_TAG = "OkHttpWebSocketClient"; | ||
|
||
private final WebSocketClientCallback webSocketClientCallback; | ||
private okhttp3.WebSocket webSocket; | ||
private State state = State.NONE; | ||
private OkHttpClient client; | ||
private final String url; | ||
private final int STATUS_CODE = 200; | ||
private final String CLOSING_MSG = "User invoked close"; | ||
|
||
private final WebSocketListener handler = new WebSocketListener() { | ||
@Override | ||
public void onOpen(okhttp3.WebSocket webSocket, Response response) { | ||
setState(State.CONNECTED); | ||
webSocketClientCallback.onOpen(); | ||
} | ||
|
||
@Override | ||
public void onMessage(okhttp3.WebSocket webSocket, String text) { | ||
webSocketClientCallback.onMessage(text); | ||
} | ||
|
||
@Override | ||
public void onMessage(okhttp3.WebSocket webSocket, ByteString bytes) { | ||
Log.w(LOG_TAG, String.format(Locale.US, "Socket got into inconsistent state and received %s instead.", bytes.toString())); | ||
} | ||
|
||
@Override | ||
public void onClosed(okhttp3.WebSocket webSocket, int code, String reason) { | ||
setState(State.DISCONNECTED); | ||
webSocketClientCallback.onClose(); | ||
} | ||
|
||
@Override | ||
public void onFailure(okhttp3.WebSocket webSocket, Throwable t, Response response) { | ||
webSocketClientCallback.onError(t); | ||
} | ||
}; | ||
|
||
private OkHttp3WebSocketClient(WebSocketClientCallback webSocketClientCallback, URI hostUrl) { | ||
this.webSocketClientCallback = webSocketClientCallback; | ||
client = new OkHttpClient(); | ||
url = hostUrl.toString(); | ||
} | ||
|
||
@Override | ||
public synchronized void open() { | ||
if (State.NONE == state) { | ||
// OkHttp3 connects as soon as the socket is created so do it here. | ||
Request request = new Request.Builder() | ||
.url(url) | ||
.build(); | ||
|
||
webSocket = client.newWebSocket(request, handler); | ||
setState(State.CONNECTING); | ||
} | ||
} | ||
|
||
@Override | ||
public synchronized void close() { | ||
setState(State.DISCONNECTING); | ||
webSocket.close(STATUS_CODE, CLOSING_MSG); | ||
} | ||
|
||
@Override | ||
public void send(String message) { | ||
if (state == State.CONNECTED) { | ||
webSocket.send(message); | ||
} | ||
} | ||
|
||
@Override | ||
public State getState() { | ||
return state; | ||
} | ||
|
||
private synchronized void setState(State newState) { | ||
this.state = newState; | ||
this.webSocketClientCallback.stateChanged(); | ||
} | ||
|
||
/* package */ static class OkHttp3SocketClientFactory implements WebSocketClientFactory { | ||
@Override | ||
public WebSocketClient createInstance(WebSocketClientCallback webSocketClientCallback, URI hostUrl) { | ||
return new OkHttp3WebSocketClient(webSocketClientCallback, hostUrl); | ||
} | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
include ':ParseLiveQuery' | ||
include ':ParseLiveQuery', ':Example' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable named uppercase URL may be confused with the URL class.
String url
I recommend using lowercase to improve readability.