Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
AloqaIM-Android
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
AloqaIM-Android
Commits
888c28ec
Commit
888c28ec
authored
Nov 06, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement connecting with session.
parent
5f138f58
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
149 additions
and
43 deletions
+149
-43
build.gradle
app/build.gradle
+1
-1
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+4
-6
InputHostnameFragment.java
...android/fragment/server_config/InputHostnameFragment.java
+2
-1
LoginFragment.java
.../rocket/android/fragment/server_config/LoginFragment.java
+16
-0
MeteorLoginServiceConfiguration.java
...rocket/android/model/MeteorLoginServiceConfiguration.java
+1
-0
ServerConfig.java
...src/main/java/chat/rocket/android/model/ServerConfig.java
+13
-12
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+30
-21
RocketChatWebSocketAPI.java
...n/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
+3
-2
fragment_login.xml
app/src/main/res/layout/fragment_login.xml
+79
-0
No files found.
app/build.gradle
View file @
888c28ec
...
...
@@ -53,7 +53,7 @@ dependencies {
compile
'com.facebook.stetho:stetho-okhttp3:1.4.1'
compile
'com.uphyca:stetho_realm:2.0.0'
compile
'chat.rocket:android-ddp:0.0.
5
'
compile
'chat.rocket:android-ddp:0.0.
6
'
compile
'com.jakewharton.timber:timber:4.3.1'
compile
'com.jakewharton.rxbinding:rxbinding:0.4.0'
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
888c28ec
...
...
@@ -9,12 +9,11 @@ import chat.rocket.android.LaunchUtil;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.server_config.ConnectingToHostFragment
;
import
chat.rocket.android.fragment.server_config.InputHostnameFragment
;
import
chat.rocket.android.fragment.server_config.LoginFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.MeteorLoginServiceConfiguration
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.service.RocketChatService
;
import
io.realm.Realm
;
import
io.realm.RealmList
;
import
io.realm.RealmQuery
;
import
java.util.List
;
import
jp.co.crowdworks.realm_java_helpers.RealmObjectObserver
;
...
...
@@ -49,7 +48,7 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
for
(
ServerConfig
config
:
configList
)
{
if
(
config
.
getAuthProviders
().
isEmpty
(
))
{
if
(
TextUtils
.
isEmpty
(
config
.
getSession
()
))
{
return
launchFor
(
context
,
config
);
}
}
...
...
@@ -135,9 +134,8 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return
;
}
RealmList
<
MeteorLoginServiceConfiguration
>
providers
=
config
.
getAuthProviders
();
if
(!
providers
.
isEmpty
())
{
if
(!
TextUtils
.
isEmpty
(
config
.
getSession
()))
{
showFragment
(
new
LoginFragment
());
return
;
}
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/InputHostnameFragment.java
View file @
888c28ec
...
...
@@ -56,7 +56,8 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
().
put
(
"id"
,
serverConfigId
)
.
put
(
"hostname"
,
hostname
)
.
put
(
"connectionError"
,
JSONObject
.
NULL
))).
continueWith
(
new
LogcatIfError
());
.
put
(
"connectionError"
,
JSONObject
.
NULL
)
.
put
(
"session"
,
JSONObject
.
NULL
))).
continueWith
(
new
LogcatIfError
());
}
@Override
public
void
onResume
()
{
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/LoginFragment.java
0 → 100644
View file @
888c28ec
package
chat
.
rocket
.
android
.
fragment
.
server_config
;
import
chat.rocket.android.R
;
/**
* Login screen.
*/
public
class
LoginFragment
extends
AbstractServerConfigFragment
{
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
fragment_login
;
}
@Override
protected
void
onSetupView
()
{
}
}
app/src/main/java/chat/rocket/android/model/MeteorLoginServiceConfiguration.java
View file @
888c28ec
...
...
@@ -10,6 +10,7 @@ import io.realm.annotations.PrimaryKey;
public
class
MeteorLoginServiceConfiguration
extends
RealmObject
{
@PrimaryKey
private
String
id
;
private
ServerConfig
serverConfig
;
private
String
service
;
private
String
consumerKey
;
//for Twitter
private
String
appId
;
//for Facebook
...
...
app/src/main/java/chat/rocket/android/model/ServerConfig.java
View file @
888c28ec
...
...
@@ -3,7 +3,6 @@ package chat.rocket.android.model;
import
chat.rocket.android.helper.LogcatIfError
;
import
hugo.weaving.DebugLog
;
import
io.realm.Realm
;
import
io.realm.RealmList
;
import
io.realm.RealmObject
;
import
io.realm.RealmQuery
;
import
io.realm.annotations.PrimaryKey
;
...
...
@@ -19,9 +18,9 @@ public class ServerConfig extends RealmObject {
@PrimaryKey
private
String
id
;
private
String
hostname
;
private
String
connectionError
;
private
String
session
;
private
String
token
;
private
boolean
tokenVerified
;
private
RealmList
<
MeteorLoginServiceConfiguration
>
authProviders
;
private
String
selectedProviderName
;
public
static
RealmQuery
<
ServerConfig
>
queryLoginRequiredConnections
(
Realm
realm
)
{
...
...
@@ -41,8 +40,10 @@ public class ServerConfig extends RealmObject {
@DebugLog
public
static
void
logError
(
String
id
,
Exception
exception
)
{
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
().
put
(
"id"
,
id
).
put
(
"connectionError"
,
exception
.
getMessage
())))
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
()
.
put
(
"id"
,
id
)
.
put
(
"connectionError"
,
exception
.
getMessage
())
.
put
(
"session"
,
JSONObject
.
NULL
)))
.
continueWith
(
new
LogcatIfError
());
}
...
...
@@ -70,6 +71,14 @@ public class ServerConfig extends RealmObject {
this
.
connectionError
=
connectionError
;
}
public
String
getSession
()
{
return
session
;
}
public
void
setSession
(
String
session
)
{
this
.
session
=
session
;
}
public
String
getToken
()
{
return
token
;
}
...
...
@@ -86,14 +95,6 @@ public class ServerConfig extends RealmObject {
this
.
tokenVerified
=
tokenVerified
;
}
public
RealmList
<
MeteorLoginServiceConfiguration
>
getAuthProviders
()
{
return
authProviders
;
}
public
void
setAuthProviders
(
RealmList
<
MeteorLoginServiceConfiguration
>
authProviders
)
{
this
.
authProviders
=
authProviders
;
}
public
String
getSelectedProviderName
()
{
return
selectedProviderName
;
}
...
...
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
888c28ec
...
...
@@ -3,18 +3,22 @@ package chat.rocket.android.service;
import
android.content.Context
;
import
android.os.Handler
;
import
android.os.HandlerThread
;
import
bolts.Continuation
;
import
bolts.Task
;
import
bolts.TaskCompletionSource
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.service.ddp_subscriber.LoginServiceConfigurationSubscriber
;
import
chat.rocket.android.ws.RocketChatWebSocketAPI
;
import
chat.rocket.android_ddp.DDPClient
;
import
chat.rocket.android_ddp.DDPClient
Callback
;
import
hugo.weaving.DebugLog
;
import
java.lang.reflect.Constructor
;
import
java.util.ArrayList
;
import
java.util.Iterator
;
import
jp.co.crowdworks.realm_java_helpers.RealmHelper
;
import
jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts
;
import
org.json.JSONObject
;
import
timber.log.Timber
;
/**
...
...
@@ -111,10 +115,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
}
private
void
prepareWebSocket
()
{
ServerConfig
config
=
RealmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
serverConfigId
).
findFirst
());
private
void
prepareWebSocket
(
ServerConfig
config
)
{
if
(
webSocketAPI
==
null
||
!
webSocketAPI
.
isConnected
())
{
webSocketAPI
=
RocketChatWebSocketAPI
.
create
(
config
.
getHostname
());
}
...
...
@@ -124,26 +125,34 @@ public class RocketChatWebSocketThread extends HandlerThread {
if
(
socketExists
)
{
return
Task
.
forResult
(
null
);
}
socketExists
=
true
;
prepareWebSocket
();
return
webSocketAPI
.
connect
().
onSuccess
(
task
->
{
registerListenersActually
();
DDPClient
client
=
task
.
getResult
().
client
;
// handling WebSocket#onClose() callback.
client
.
getOnCloseCallback
().
onSuccess
(
_task
->
{
quit
();
return
null
;
});
final
ServerConfig
config
=
RealmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
serverConfigId
).
findFirst
());
// just for debugging.
client
.
getSubscriptionCallback
().
subscribe
(
event
->
{
Timber
.
d
(
"Callback [DEBUG] < "
+
event
);
});
prepareWebSocket
(
config
);
return
webSocketAPI
.
connect
(
config
.
getSession
()).
onSuccessTask
(
task
->
{
final
String
session
=
task
.
getResult
().
session
;
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
()
.
put
(
"id"
,
serverConfigId
)
.
put
(
"session"
,
session
))
).
continueWith
(
new
LogcatIfError
());
return
task
;
}).
onSuccess
(
new
Continuation
<
DDPClientCallback
.
Connect
,
Object
>()
{
// TODO type detection doesn't work due to retrolambda's bug...
@Override
public
Object
then
(
Task
<
DDPClientCallback
.
Connect
>
task
)
throws
Exception
{
registerListenersActually
();
// handling WebSocket#onClose() callback.
task
.
getResult
().
client
.
getOnCloseCallback
().
onSuccess
(
_task
->
{
quit
();
return
null
;
});
return
null
;
return
null
;
}
}).
continueWith
(
task
->
{
if
(
task
.
isFaulted
())
{
ServerConfig
.
logError
(
serverConfigId
,
task
.
getError
());
...
...
app/src/main/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
View file @
888c28ec
package
chat
.
rocket
.
android
.
ws
;
import
android.support.annotation.Nullable
;
import
bolts.Task
;
import
chat.rocket.android.helper.OkHttpHelper
;
import
chat.rocket.android_ddp.DDPClient
;
...
...
@@ -31,8 +32,8 @@ public class RocketChatWebSocketAPI {
/**
* Connect to WebSocket server with DDP client.
*/
public
Task
<
DDPClientCallback
.
Connect
>
connect
()
{
return
ddpClient
.
connect
(
"wss://"
+
hostname
+
"/websocket"
);
public
Task
<
DDPClientCallback
.
Connect
>
connect
(
@Nullable
String
session
)
{
return
ddpClient
.
connect
(
"wss://"
+
hostname
+
"/websocket"
,
session
);
}
/**
...
...
app/src/main/res/layout/fragment_login.xml
0 → 100644
View file @
888c28ec
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"?attr/colorPrimaryDark"
>
<LinearLayout
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center"
android:background=
"@color/white"
android:minWidth=
"288dp"
android:orientation=
"horizontal"
android:padding=
"@dimen/margin_24"
>
<LinearLayout
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:orientation=
"vertical"
>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/text_input_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<android.support.design.widget.TextInputEditText
android:id=
"@+id/editor_username"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"username or email"
android:imeOptions=
"actionNext"
android:inputType=
"textWebEmailAddress"
android:singleLine=
"true"
/>
</android.support.design.widget.TextInputLayout>
<Space
android:layout_width=
"wrap_content"
android:layout_height=
"@dimen/margin_8"
/>
<android.support.design.widget.TextInputLayout
android:id=
"@+id/text_input_passwd"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
app:passwordToggleEnabled=
"true"
>
<android.support.design.widget.TextInputEditText
android:id=
"@+id/editor_passwd"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:hint=
"password"
android:imeOptions=
"actionNext"
android:inputType=
"textWebPassword"
android:singleLine=
"true"
/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
<Space
android:layout_width=
"@dimen/margin_8"
android:layout_height=
"wrap_content"
/>
<android.support.design.widget.FloatingActionButton
android:id=
"@+id/btn_connect"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_gravity=
"end|bottom"
app:elevation=
"2dp"
app:fabSize=
"mini"
app:srcCompat=
"@drawable/ic_arrow_forward_white_24dp"
/>
</LinearLayout>
</FrameLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment