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
2a383afd
Commit
2a383afd
authored
Nov 05, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix checkstyle issues
parent
4e101ae7
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
150 additions
and
144 deletions
+150
-144
LaunchUtil.java
app/src/main/java/chat/rocket/android/LaunchUtil.java
+1
-1
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+11
-11
AbstractFragment.java
...n/java/chat/rocket/android/fragment/AbstractFragment.java
+5
-4
AbstractServerConfigFragment.java
.../fragment/server_config/AbstractServerConfigFragment.java
+3
-3
InputHostnameFragment.java
...android/fragment/server_config/InputHostnameFragment.java
+15
-15
TextUtils.java
app/src/main/java/chat/rocket/android/helper/TextUtils.java
+2
-1
MeteorLoginServiceConfiguration.java
...rocket/android/model/MeteorLoginServiceConfiguration.java
+3
-2
ServerConfig.java
...src/main/java/chat/rocket/android/model/ServerConfig.java
+3
-2
Registerable.java
...c/main/java/chat/rocket/android/service/Registerable.java
+4
-4
RocketChatService.java
...n/java/chat/rocket/android/service/RocketChatService.java
+11
-9
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+30
-30
AbstractDDPDocEventSubscriber.java
...service/ddp_subscriber/AbstractDDPDocEventSubscriber.java
+40
-40
AbstractModelObserver.java
...ocket/android/service/observer/AbstractModelObserver.java
+4
-4
FontAwesomeTextView.java
...in/java/chat/rocket/android/view/FontAwesomeTextView.java
+1
-1
FontelloTextView.java
.../main/java/chat/rocket/android/view/FontelloTextView.java
+1
-1
WaitingView.java
app/src/main/java/chat/rocket/android/view/WaitingView.java
+6
-6
RocketChatWebSocketAPI.java
...n/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
+10
-10
No files found.
app/src/main/java/chat/rocket/android/LaunchUtil.java
View file @
2a383afd
...
...
@@ -5,7 +5,7 @@ import android.content.Intent;
import
chat.rocket.android.activity.ServerConfigActivity
;
/**
* utility class for launching Activity
* utility class for launching Activity
.
*/
public
class
LaunchUtil
{
/**
...
...
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
2a383afd
...
...
@@ -24,11 +24,11 @@ import jp.co.crowdworks.realm_java_helpers.RealmObjectObserver;
*/
public
class
ServerConfigActivity
extends
AbstractFragmentActivity
{
private
String
mS
erverConfigId
;
private
RealmObjectObserver
<
ServerConfig
>
mS
erverConfigObserver
=
private
String
s
erverConfigId
;
private
RealmObjectObserver
<
ServerConfig
>
s
erverConfigObserver
=
new
RealmObjectObserver
<
ServerConfig
>()
{
@Override
protected
RealmQuery
<
ServerConfig
>
query
(
Realm
realm
)
{
return
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
mS
erverConfigId
);
return
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
s
erverConfigId
);
}
@Override
protected
void
onChange
(
ServerConfig
config
)
{
...
...
@@ -93,8 +93,8 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return
;
}
mS
erverConfigId
=
intent
.
getStringExtra
(
"id"
);
if
(
TextUtils
.
isEmpty
(
mS
erverConfigId
))
{
s
erverConfigId
=
intent
.
getStringExtra
(
"id"
);
if
(
TextUtils
.
isEmpty
(
s
erverConfigId
))
{
finish
();
return
;
}
...
...
@@ -105,11 +105,11 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
@Override
protected
void
onResume
()
{
super
.
onResume
();
RocketChatService
.
keepalive
(
this
);
mS
erverConfigObserver
.
sub
();
s
erverConfigObserver
.
sub
();
}
@Override
protected
void
onPause
()
{
mS
erverConfigObserver
.
unsub
();
s
erverConfigObserver
.
unsub
();
super
.
onPause
();
}
...
...
@@ -152,21 +152,21 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
}
@Override
protected
void
showFragment
(
Fragment
fragment
)
{
injectIdArgTo
(
fragment
);
inject
ServerConfig
IdArgTo
(
fragment
);
super
.
showFragment
(
fragment
);
}
@Override
protected
void
showFragmentWithBackStack
(
Fragment
fragment
)
{
injectIdArgTo
(
fragment
);
inject
ServerConfig
IdArgTo
(
fragment
);
super
.
showFragmentWithBackStack
(
fragment
);
}
private
void
injectIdArgTo
(
Fragment
fragment
)
{
private
void
inject
ServerConfig
IdArgTo
(
Fragment
fragment
)
{
Bundle
args
=
fragment
.
getArguments
();
if
(
args
==
null
)
{
args
=
new
Bundle
();
}
args
.
putString
(
"id"
,
mS
erverConfigId
);
args
.
putString
(
"id"
,
s
erverConfigId
);
fragment
.
setArguments
(
args
);
}
...
...
app/src/main/java/chat/rocket/android/fragment/AbstractFragment.java
View file @
2a383afd
...
...
@@ -12,18 +12,19 @@ import android.view.ViewGroup;
* Fragment base class for this Application.
*/
public
abstract
class
AbstractFragment
extends
Fragment
{
protected
View
mR
ootView
;
protected
View
r
ootView
;
protected
abstract
@LayoutRes
int
getLayout
();
protected
abstract
void
onSetupView
();
@Nullable
@Override
@Nullable
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
mR
ootView
=
inflater
.
inflate
(
getLayout
(),
container
,
false
);
r
ootView
=
inflater
.
inflate
(
getLayout
(),
container
,
false
);
onSetupView
();
return
mR
ootView
;
return
r
ootView
;
}
protected
void
finish
()
{
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/AbstractServerConfigFragment.java
View file @
2a383afd
...
...
@@ -6,7 +6,7 @@ import chat.rocket.android.fragment.AbstractFragment;
import
chat.rocket.android.helper.TextUtils
;
abstract
class
AbstractServerConfigFragment
extends
AbstractFragment
{
protected
String
mS
erverConfigId
;
protected
String
s
erverConfigId
;
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -17,8 +17,8 @@ abstract class AbstractServerConfigFragment extends AbstractFragment {
return
;
}
mS
erverConfigId
=
args
.
getString
(
"id"
);
if
(
TextUtils
.
isEmpty
(
mS
erverConfigId
))
{
s
erverConfigId
=
args
.
getString
(
"id"
);
if
(
TextUtils
.
isEmpty
(
s
erverConfigId
))
{
finish
();
return
;
}
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/InputHostnameFragment.java
View file @
2a383afd
...
...
@@ -18,14 +18,14 @@ import org.json.JSONObject;
* Input server host.
*/
public
class
InputHostnameFragment
extends
AbstractServerConfigFragment
{
private
Handler
mShowErro
r
=
new
Handler
()
{
private
Handler
errorShowingHandle
r
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
Toast
.
makeText
(
mR
ootView
.
getContext
(),
(
String
)
msg
.
obj
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
r
ootView
.
getContext
(),
(
String
)
msg
.
obj
,
Toast
.
LENGTH_SHORT
).
show
();
}
};
RealmObjectObserver
<
ServerConfig
>
m
Observer
=
new
RealmObjectObserver
<
ServerConfig
>()
{
RealmObjectObserver
<
ServerConfig
>
serverConfig
Observer
=
new
RealmObjectObserver
<
ServerConfig
>()
{
@Override
protected
RealmQuery
<
ServerConfig
>
query
(
Realm
realm
)
{
return
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
mS
erverConfigId
);
return
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
s
erverConfigId
);
}
@Override
protected
void
onChange
(
ServerConfig
config
)
{
...
...
@@ -41,42 +41,42 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
}
@Override
protected
void
onSetupView
()
{
mR
ootView
.
findViewById
(
R
.
id
.
btn_connect
).
setOnClickListener
(
view
->
handleConnect
());
r
ootView
.
findViewById
(
R
.
id
.
btn_connect
).
setOnClickListener
(
view
->
handleConnect
());
m
Observer
.
sub
();
serverConfig
Observer
.
sub
();
}
private
void
handleConnect
()
{
final
TextView
editor
=
(
TextView
)
mR
ootView
.
findViewById
(
R
.
id
.
editor_hostname
);
final
TextView
editor
=
(
TextView
)
r
ootView
.
findViewById
(
R
.
id
.
editor_hostname
);
final
String
hostname
=
TextUtils
.
or
(
TextUtils
.
or
(
editor
.
getText
(),
editor
.
getHint
()),
""
).
toString
();
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
().
put
(
"id"
,
mS
erverConfigId
)
new
JSONObject
().
put
(
"id"
,
s
erverConfigId
)
.
put
(
"hostname"
,
hostname
)
.
put
(
"connectionError"
,
JSONObject
.
NULL
))).
continueWith
(
new
LogcatIfError
());
}
@Override
public
void
onResume
()
{
super
.
onResume
();
m
Observer
.
keepalive
();
serverConfig
Observer
.
keepalive
();
}
@Override
public
void
onDestroyView
()
{
m
Observer
.
unsub
();
serverConfig
Observer
.
unsub
();
super
.
onDestroyView
();
}
private
void
showError
(
String
errString
)
{
mShowErro
r
.
removeMessages
(
0
);
Message
msg
=
Message
.
obtain
(
mShowErro
r
,
0
,
errString
);
mShowErro
r
.
sendMessageDelayed
(
msg
,
160
);
errorShowingHandle
r
.
removeMessages
(
0
);
Message
msg
=
Message
.
obtain
(
errorShowingHandle
r
,
0
,
errString
);
errorShowingHandle
r
.
sendMessageDelayed
(
msg
,
160
);
}
private
void
onRenderServerConfig
(
ServerConfig
config
)
{
final
TextView
editor
=
(
TextView
)
mR
ootView
.
findViewById
(
R
.
id
.
editor_hostname
);
final
TextView
editor
=
(
TextView
)
r
ootView
.
findViewById
(
R
.
id
.
editor_hostname
);
if
(!
TextUtils
.
isEmpty
(
config
.
getHostname
()))
{
editor
.
setText
(
config
.
getHostname
());
...
...
@@ -90,7 +90,7 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
private
void
clearConnectionErrorAndHostname
()
{
RealmHelperBolts
.
executeTransaction
(
realm
->
realm
.
createOrUpdateObjectFromJson
(
ServerConfig
.
class
,
new
JSONObject
().
put
(
"id"
,
mS
erverConfigId
)
new
JSONObject
().
put
(
"id"
,
s
erverConfigId
)
.
put
(
"hostname"
,
JSONObject
.
NULL
)
.
put
(
"connectionError"
,
JSONObject
.
NULL
))).
continueWith
(
new
LogcatIfError
());
}
...
...
app/src/main/java/chat/rocket/android/helper/TextUtils.java
View file @
2a383afd
...
...
@@ -19,7 +19,8 @@ public class TextUtils {
/**
* Returns str if it is not empty; otherwise defaultValue is returned.
*/
@SuppressWarnings
(
"PMD.ShortMethodName"
)
public
static
CharSequence
or
(
CharSequence
str
,
@SuppressWarnings
(
"PMD.ShortMethodName"
)
public
static
CharSequence
or
(
CharSequence
str
,
CharSequence
defaultValue
)
{
if
(
isEmpty
(
str
))
{
return
defaultValue
;
...
...
app/src/main/java/chat/rocket/android/model/MeteorLoginServiceConfiguration.java
View file @
2a383afd
...
...
@@ -4,9 +4,10 @@ import io.realm.RealmObject;
import
io.realm.annotations.PrimaryKey
;
/**
* subscription model for "meteor_accounts_loginServiceConfiguration"
* subscription model for "meteor_accounts_loginServiceConfiguration"
.
*/
@SuppressWarnings
(
"PMD.ShortVariable"
)
public
class
MeteorLoginServiceConfiguration
@SuppressWarnings
(
"PMD.ShortVariable"
)
public
class
MeteorLoginServiceConfiguration
extends
RealmObject
{
@PrimaryKey
private
String
id
;
private
String
service
;
...
...
app/src/main/java/chat/rocket/android/model/ServerConfig.java
View file @
2a383afd
...
...
@@ -12,9 +12,10 @@ import jp.co.crowdworks.realm_java_helpers_bolts.RealmHelperBolts;
import
org.json.JSONObject
;
/**
* Server configuration
* Server configuration
.
*/
@SuppressWarnings
(
"PMD.ShortVariable"
)
public
class
ServerConfig
extends
RealmObject
{
@SuppressWarnings
(
"PMD.ShortVariable"
)
public
class
ServerConfig
extends
RealmObject
{
@PrimaryKey
private
String
id
;
private
String
hostname
;
private
String
connectionError
;
...
...
app/src/main/java/chat/rocket/android/service/Registerable.java
View file @
2a383afd
package
chat
.
rocket
.
android
.
service
;
/**
* interface for observer and ddp_subscription
* interface for observer and ddp_subscription
.
*/
public
interface
Registerable
{
/**
* register
* register
.
*/
void
register
();
/**
* keepalive
* keepalive
.
*/
void
keepalive
();
/**
* unregister
* unregister
.
*/
void
unregister
();
}
app/src/main/java/chat/rocket/android/service/RocketChatService.java
View file @
2a383afd
...
...
@@ -20,8 +20,8 @@ import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
*/
public
class
RocketChatService
extends
Service
{
private
HashMap
<
String
,
RocketChatWebSocketThread
>
mW
ebSocketThreads
;
private
RealmListObserver
<
ServerConfig
>
mC
onnectionRequiredServerConfigObserver
=
private
HashMap
<
String
,
RocketChatWebSocketThread
>
w
ebSocketThreads
;
private
RealmListObserver
<
ServerConfig
>
c
onnectionRequiredServerConfigObserver
=
new
RealmListObserver
<
ServerConfig
>()
{
@Override
protected
RealmResults
<
ServerConfig
>
queryItems
(
Realm
realm
)
{
return
realm
.
where
(
ServerConfig
.
class
)
...
...
@@ -51,17 +51,17 @@ public class RocketChatService extends Service {
@Override
public
void
onCreate
()
{
super
.
onCreate
();
mW
ebSocketThreads
=
new
HashMap
<>();
w
ebSocketThreads
=
new
HashMap
<>();
}
@Override
public
int
onStartCommand
(
Intent
intent
,
int
flags
,
int
startId
)
{
mC
onnectionRequiredServerConfigObserver
.
keepalive
();
c
onnectionRequiredServerConfigObserver
.
keepalive
();
return
START_STICKY
;
}
private
void
syncWebSocketThreadsWith
(
List
<
ServerConfig
>
configList
)
{
final
Iterator
<
Map
.
Entry
<
String
,
RocketChatWebSocketThread
>>
iterator
=
mW
ebSocketThreads
.
entrySet
().
iterator
();
w
ebSocketThreads
.
entrySet
().
iterator
();
while
(
iterator
.
hasNext
())
{
Map
.
Entry
<
String
,
RocketChatWebSocketThread
>
entry
=
iterator
.
next
();
...
...
@@ -90,18 +90,20 @@ public class RocketChatService extends Service {
private
Task
<
RocketChatWebSocketThread
>
findOrCreateWebSocketThread
(
final
ServerConfig
config
)
{
final
String
serverConfigId
=
config
.
getId
();
if
(
mW
ebSocketThreads
.
containsKey
(
serverConfigId
))
{
return
Task
.
forResult
(
mW
ebSocketThreads
.
get
(
serverConfigId
));
if
(
w
ebSocketThreads
.
containsKey
(
serverConfigId
))
{
return
Task
.
forResult
(
w
ebSocketThreads
.
get
(
serverConfigId
));
}
else
{
return
RocketChatWebSocketThread
.
getStarted
(
getApplicationContext
(),
config
)
.
onSuccessTask
(
task
->
{
mW
ebSocketThreads
.
put
(
serverConfigId
,
task
.
getResult
());
w
ebSocketThreads
.
put
(
serverConfigId
,
task
.
getResult
());
return
task
;
});
}
}
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
@Nullable
@Override
public
IBinder
onBind
(
Intent
intent
)
{
return
null
;
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
2a383afd
...
...
@@ -24,17 +24,17 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
static
final
Class
[]
REGISTERABLE_CLASSES
=
{
LoginServiceConfigurationSubscriber
.
class
};
private
final
Context
mA
ppContext
;
private
final
String
mS
erverConfigId
;
private
final
ArrayList
<
Registerable
>
mL
isteners
=
new
ArrayList
<>();
private
RocketChatWebSocketAPI
mW
ebSocketAPI
;
private
boolean
mS
ocketExists
;
private
boolean
mL
istenersRegistered
;
private
final
Context
a
ppContext
;
private
final
String
s
erverConfigId
;
private
final
ArrayList
<
Registerable
>
l
isteners
=
new
ArrayList
<>();
private
RocketChatWebSocketAPI
w
ebSocketAPI
;
private
boolean
s
ocketExists
;
private
boolean
l
istenersRegistered
;
private
RocketChatWebSocketThread
(
Context
appContext
,
String
serverConfigId
)
{
super
(
"RC_thread_"
+
serverConfigId
);
mS
erverConfigId
=
serverConfigId
;
mA
ppContext
=
appContext
;
this
.
s
erverConfigId
=
serverConfigId
;
this
.
a
ppContext
=
appContext
;
}
/**
...
...
@@ -57,14 +57,14 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
/**
* terminate the thread
* terminate the thread
.
*/
@DebugLog
public
static
void
terminate
(
RocketChatWebSocketThread
thread
)
{
thread
.
quit
();
}
private
Task
<
Void
>
ensureConnection
()
{
if
(
mWebSocketAPI
==
null
||
!
mW
ebSocketAPI
.
isConnected
())
{
if
(
webSocketAPI
==
null
||
!
w
ebSocketAPI
.
isConnected
())
{
return
registerListeners
();
}
else
{
return
Task
.
forResult
(
null
);
...
...
@@ -113,21 +113,21 @@ public class RocketChatWebSocketThread extends HandlerThread {
private
void
prepareWebSocket
()
{
ServerConfig
config
=
RealmHelper
.
executeTransactionForRead
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
mS
erverConfigId
).
findFirst
());
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"id"
,
s
erverConfigId
).
findFirst
());
if
(
mWebSocketAPI
==
null
||
!
mW
ebSocketAPI
.
isConnected
())
{
mW
ebSocketAPI
=
RocketChatWebSocketAPI
.
create
(
config
.
getHostname
());
if
(
webSocketAPI
==
null
||
!
w
ebSocketAPI
.
isConnected
())
{
w
ebSocketAPI
=
RocketChatWebSocketAPI
.
create
(
config
.
getHostname
());
}
}
@DebugLog
private
Task
<
Void
>
registerListeners
()
{
if
(
mS
ocketExists
)
{
if
(
s
ocketExists
)
{
return
Task
.
forResult
(
null
);
}
mS
ocketExists
=
true
;
s
ocketExists
=
true
;
prepareWebSocket
();
return
mW
ebSocketAPI
.
connect
().
onSuccess
(
task
->
{
return
w
ebSocketAPI
.
connect
().
onSuccess
(
task
->
{
registerListenersActually
();
DDPClient
client
=
task
.
getResult
().
client
;
...
...
@@ -146,7 +146,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
return
null
;
}).
continueWith
(
task
->
{
if
(
task
.
isFaulted
())
{
ServerConfig
.
logError
(
mS
erverConfigId
,
task
.
getError
());
ServerConfig
.
logError
(
s
erverConfigId
,
task
.
getError
());
}
return
null
;
});
...
...
@@ -154,20 +154,20 @@ public class RocketChatWebSocketThread extends HandlerThread {
//@DebugLog
private
void
registerListenersActually
()
{
if
(
mL
istenersRegistered
)
{
if
(
l
istenersRegistered
)
{
return
;
}
mL
istenersRegistered
=
true
;
l
istenersRegistered
=
true
;
for
(
Class
clazz
:
REGISTERABLE_CLASSES
)
{
try
{
Constructor
ctor
=
clazz
.
getConstructor
(
Context
.
class
,
RocketChatWebSocketAPI
.
class
);
Object
obj
=
ctor
.
newInstance
(
mAppContext
,
mW
ebSocketAPI
);
Object
obj
=
ctor
.
newInstance
(
appContext
,
w
ebSocketAPI
);
if
(
obj
instanceof
Registerable
)
{
Registerable
registerable
=
(
Registerable
)
obj
;
registerable
.
register
();
mL
isteners
.
add
(
registerable
);
l
isteners
.
add
(
registerable
);
}
}
catch
(
Exception
exception
)
{
Timber
.
w
(
exception
,
"Failed to register listeners!!"
);
...
...
@@ -177,32 +177,32 @@ public class RocketChatWebSocketThread extends HandlerThread {
//@DebugLog
private
void
keepaliveListeners
()
{
if
(!
mSocketExists
||
!
mL
istenersRegistered
)
{
if
(!
socketExists
||
!
l
istenersRegistered
)
{
return
;
}
for
(
Registerable
registerable
:
mL
isteners
)
{
for
(
Registerable
registerable
:
l
isteners
)
{
registerable
.
keepalive
();
}
}
//@DebugLog
private
void
unregisterListeners
()
{
if
(!
mSocketExists
||
!
mL
istenersRegistered
)
{
if
(!
socketExists
||
!
l
istenersRegistered
)
{
return
;
}
Iterator
<
Registerable
>
iterator
=
mL
isteners
.
iterator
();
Iterator
<
Registerable
>
iterator
=
l
isteners
.
iterator
();
while
(
iterator
.
hasNext
())
{
Registerable
registerable
=
iterator
.
next
();
registerable
.
unregister
();
iterator
.
remove
();
}
if
(
mW
ebSocketAPI
!=
null
)
{
mW
ebSocketAPI
.
close
();
mW
ebSocketAPI
=
null
;
if
(
w
ebSocketAPI
!=
null
)
{
w
ebSocketAPI
.
close
();
w
ebSocketAPI
=
null
;
}
mL
istenersRegistered
=
false
;
mS
ocketExists
=
false
;
l
istenersRegistered
=
false
;
s
ocketExists
=
false
;
}
}
app/src/main/java/chat/rocket/android/service/ddp_subscriber/AbstractDDPDocEventSubscriber.java
View file @
2a383afd
...
...
@@ -16,14 +16,14 @@ import rx.Subscription;
import
timber.log.Timber
;
abstract
class
AbstractDDPDocEventSubscriber
implements
Registerable
{
protected
final
Context
mC
ontext
;
protected
final
RocketChatWebSocketAPI
m
API
;
private
String
mID
;
private
Subscription
m
Subscription
;
protected
final
Context
c
ontext
;
protected
final
RocketChatWebSocketAPI
webSocket
API
;
private
String
subscriptionId
;
private
Subscription
rx
Subscription
;
protected
AbstractDDPDocEventSubscriber
(
Context
context
,
RocketChatWebSocketAPI
api
)
{
mC
ontext
=
context
;
m
API
=
api
;
this
.
c
ontext
=
context
;
this
.
webSocket
API
=
api
;
}
protected
abstract
String
getSubscriptionName
();
...
...
@@ -32,13 +32,13 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
protected
abstract
Class
<?
extends
RealmObject
>
getModelClass
();
protected
JSONObject
customizeFieldJ
SON
(
JSONObject
json
)
{
protected
JSONObject
customizeFieldJ
son
(
JSONObject
json
)
{
return
json
;
}
@Override
public
void
register
()
{
m
API
.
subscribe
(
getSubscriptionName
(),
null
).
onSuccess
(
task
->
{
mID
=
task
.
getResult
().
id
;
webSocket
API
.
subscribe
(
getSubscriptionName
(),
null
).
onSuccess
(
task
->
{
subscriptionId
=
task
.
getResult
().
id
;
return
null
;
}).
continueWith
(
task
->
{
if
(
task
.
isFaulted
())
{
...
...
@@ -57,7 +57,7 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
private
void
registerSubscriptionCallback
()
{
mSubscription
=
m
API
.
getSubscriptionCallback
()
rxSubscription
=
webSocket
API
.
getSubscriptionCallback
()
.
filter
(
event
->
event
instanceof
DDPSubscription
.
DocEvent
)
.
cast
(
DDPSubscription
.
DocEvent
.
class
)
.
filter
(
event
->
getSubscriptionCallbackName
().
equals
(
event
.
collection
))
...
...
@@ -74,8 +74,8 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
else
if
(
docEvent
instanceof
DDPSubscription
.
MovedBefore
)
{
//ignore movedBefore
}
}
catch
(
Exception
e
)
{
Timber
.
w
(
e
,
"failed to handle subscription callback"
);
}
catch
(
Exception
e
xception
)
{
Timber
.
w
(
e
xception
,
"failed to handle subscription callback"
);
}
});
}
...
...
@@ -87,35 +87,20 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}).
continueWith
(
new
LogcatIfError
());
}
pr
otected
void
onDocumentChanged
(
DDPSubscription
.
Changed
docEvent
)
{
RealmHelperBolts
.
executeTransaction
(
realm
->
{
onDocumentChanged
(
realm
,
docEvent
);
return
null
;
}).
continueWith
(
new
LogcatIfError
(
));
pr
ivate
void
onDocumentAdded
(
Realm
realm
,
DDPSubscription
.
Added
docEvent
)
throws
JSONException
{
//executed in RealmTransaction
JSONObject
json
=
new
JSONObject
().
put
(
"id"
,
docEvent
.
docID
);
mergeJson
(
json
,
docEvent
.
fields
)
;
realm
.
createOrUpdateObjectFromJson
(
getModelClass
(),
customizeFieldJson
(
json
));
}
protected
void
onDocument
Removed
(
DDPSubscription
.
Remov
ed
docEvent
)
{
protected
void
onDocument
Changed
(
DDPSubscription
.
Chang
ed
docEvent
)
{
RealmHelperBolts
.
executeTransaction
(
realm
->
{
onDocument
Remov
ed
(
realm
,
docEvent
);
onDocument
Chang
ed
(
realm
,
docEvent
);
return
null
;
}).
continueWith
(
new
LogcatIfError
());
}
private
void
mergeJSON
(
JSONObject
target
,
JSONObject
src
)
throws
JSONException
{
Iterator
<
String
>
iterator
=
src
.
keys
();
while
(
iterator
.
hasNext
())
{
String
key
=
iterator
.
next
();
target
.
put
(
key
,
src
.
get
(
key
));
}
}
private
void
onDocumentAdded
(
Realm
realm
,
DDPSubscription
.
Added
docEvent
)
throws
JSONException
{
//executed in RealmTransaction
JSONObject
json
=
new
JSONObject
().
put
(
"id"
,
docEvent
.
docID
);
mergeJSON
(
json
,
docEvent
.
fields
);
realm
.
createOrUpdateObjectFromJson
(
getModelClass
(),
customizeFieldJSON
(
json
));
}
private
void
onDocumentChanged
(
Realm
realm
,
DDPSubscription
.
Changed
docEvent
)
throws
JSONException
{
//executed in RealmTransaction
...
...
@@ -124,8 +109,15 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
String
fieldToDelete
=
docEvent
.
cleared
.
getString
(
i
);
json
.
remove
(
fieldToDelete
);
}
mergeJSON
(
json
,
docEvent
.
fields
);
realm
.
createOrUpdateObjectFromJson
(
getModelClass
(),
customizeFieldJSON
(
json
));
mergeJson
(
json
,
docEvent
.
fields
);
realm
.
createOrUpdateObjectFromJson
(
getModelClass
(),
customizeFieldJson
(
json
));
}
protected
void
onDocumentRemoved
(
DDPSubscription
.
Removed
docEvent
)
{
RealmHelperBolts
.
executeTransaction
(
realm
->
{
onDocumentRemoved
(
realm
,
docEvent
);
return
null
;
}).
continueWith
(
new
LogcatIfError
());
}
private
void
onDocumentRemoved
(
Realm
realm
,
DDPSubscription
.
Removed
docEvent
)
...
...
@@ -134,16 +126,24 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
realm
.
where
(
getModelClass
()).
equalTo
(
"id"
,
docEvent
.
docID
).
findAll
().
deleteAllFromRealm
();
}
private
void
mergeJson
(
JSONObject
target
,
JSONObject
src
)
throws
JSONException
{
Iterator
<
String
>
iterator
=
src
.
keys
();
while
(
iterator
.
hasNext
())
{
String
key
=
iterator
.
next
();
target
.
put
(
key
,
src
.
get
(
key
));
}
}
@Override
public
void
keepalive
()
{
}
@Override
public
void
unregister
()
{
if
(
m
Subscription
!=
null
)
{
m
Subscription
.
unsubscribe
();
if
(
rx
Subscription
!=
null
)
{
rx
Subscription
.
unsubscribe
();
}
if
(!
TextUtils
.
isEmpty
(
mID
))
{
mAPI
.
unsubscribe
(
mID
).
continueWith
(
new
LogcatIfError
());
if
(!
TextUtils
.
isEmpty
(
subscriptionId
))
{
webSocketAPI
.
unsubscribe
(
subscriptionId
).
continueWith
(
new
LogcatIfError
());
}
}
}
app/src/main/java/chat/rocket/android/service/observer/AbstractModelObserver.java
View file @
2a383afd
...
...
@@ -9,12 +9,12 @@ import jp.co.crowdworks.realm_java_helpers.RealmListObserver;
abstract
class
AbstractModelObserver
<
T
extends
RealmObject
>
extends
RealmListObserver
<
T
>
implements
Registerable
{
protected
final
Context
mC
ontext
;
protected
final
RocketChatWebSocketAPI
m
API
;
protected
final
Context
c
ontext
;
protected
final
RocketChatWebSocketAPI
webSocket
API
;
protected
AbstractModelObserver
(
Context
context
,
RocketChatWebSocketAPI
api
)
{
mC
ontext
=
context
;
m
API
=
api
;
this
.
c
ontext
=
context
;
webSocket
API
=
api
;
}
@Override
public
void
register
()
{
...
...
app/src/main/java/chat/rocket/android/view/FontAwesomeTextView.java
View file @
2a383afd
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
android.util.AttributeSet
;
/**
* TextView with font-awesome
* TextView with font-awesome
.
*/
public
class
FontAwesomeTextView
extends
AbstractCustomFontTextView
{
public
FontAwesomeTextView
(
Context
context
,
AttributeSet
attrs
,
int
defStyle
)
{
...
...
app/src/main/java/chat/rocket/android/view/FontelloTextView.java
View file @
2a383afd
...
...
@@ -4,7 +4,7 @@ import android.content.Context;
import
android.util.AttributeSet
;
/**
* TextView with fontello
* TextView with fontello
.
*/
public
class
FontelloTextView
extends
AbstractCustomFontTextView
{
public
FontelloTextView
(
Context
context
,
AttributeSet
attrs
,
int
defStyle
)
{
...
...
app/src/main/java/chat/rocket/android/view/WaitingView.java
View file @
2a383afd
...
...
@@ -18,7 +18,7 @@ import java.util.ArrayList;
* View for indicating "waiting for connection ..." and so on.
*/
public
class
WaitingView
extends
LinearLayout
{
private
ArrayList
<
View
>
mD
ots
;
private
ArrayList
<
View
>
d
ots
;
public
WaitingView
(
Context
context
)
{
super
(
context
);
...
...
@@ -53,7 +53,7 @@ public class WaitingView extends LinearLayout {
array
.
recycle
();
}
mD
ots
=
new
ArrayList
<>();
d
ots
=
new
ArrayList
<>();
setOrientation
(
HORIZONTAL
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
addDot
(
context
,
size
);
...
...
@@ -78,12 +78,12 @@ public class WaitingView extends LinearLayout {
dot
.
setLayoutParams
(
new
FrameLayout
.
LayoutParams
(
size
,
size
,
Gravity
.
CENTER
));
frameLayout
.
addView
(
dot
);
addView
(
frameLayout
);
mD
ots
.
add
(
dot
);
d
ots
.
add
(
dot
);
}
private
void
start
()
{
for
(
int
i
=
0
;
i
<
mD
ots
.
size
();
i
++)
{
animateDot
(
mD
ots
.
get
(
i
),
160
*
i
,
480
,
480
);
for
(
int
i
=
0
;
i
<
d
ots
.
size
();
i
++)
{
animateDot
(
d
ots
.
get
(
i
),
160
*
i
,
480
,
480
);
}
}
...
...
@@ -111,7 +111,7 @@ public class WaitingView extends LinearLayout {
}
private
void
cancel
()
{
for
(
View
dot
:
mD
ots
)
{
for
(
View
dot
:
d
ots
)
{
dot
.
clearAnimation
();
}
}
...
...
app/src/main/java/chat/rocket/android/ws/RocketChatWebSocketAPI.java
View file @
2a383afd
...
...
@@ -13,12 +13,12 @@ import rx.Observable;
* API for several POST actions.
*/
public
class
RocketChatWebSocketAPI
{
private
final
DDPClient
mDDP
Client
;
private
final
String
mHostN
ame
;
private
final
DDPClient
ddp
Client
;
private
final
String
hostn
ame
;
private
RocketChatWebSocketAPI
(
String
hostname
)
{
mDDP
Client
=
new
DDPClient
(
OkHttpHelper
.
getClientForWebSocket
());
mHostN
ame
=
hostname
;
ddp
Client
=
new
DDPClient
(
OkHttpHelper
.
getClientForWebSocket
());
this
.
hostn
ame
=
hostname
;
}
/**
...
...
@@ -32,41 +32,41 @@ public class RocketChatWebSocketAPI {
* Connect to WebSocket server with DDP client.
*/
public
Task
<
DDPClientCallback
.
Connect
>
connect
()
{
return
mDDPClient
.
connect
(
"wss://"
+
mHostN
ame
+
"/websocket"
);
return
ddpClient
.
connect
(
"wss://"
+
hostn
ame
+
"/websocket"
);
}
/**
* Returns whether DDP client is connected to WebSocket server.
*/
public
boolean
isConnected
()
{
return
mDDP
Client
.
isConnected
();
return
ddp
Client
.
isConnected
();
}
/**
* close connection.
*/
public
void
close
()
{
mDDP
Client
.
close
();
ddp
Client
.
close
();
}
/**
* Subscribe with DDP client.
*/
public
Task
<
DDPSubscription
.
Ready
>
subscribe
(
final
String
name
,
JSONArray
param
)
{
return
mDDP
Client
.
sub
(
UUID
.
randomUUID
().
toString
(),
name
,
param
);
return
ddp
Client
.
sub
(
UUID
.
randomUUID
().
toString
(),
name
,
param
);
}
/**
* Unsubscribe with DDP client.
*/
public
Task
<
DDPSubscription
.
NoSub
>
unsubscribe
(
final
String
subscriptionId
)
{
return
mDDP
Client
.
unsub
(
subscriptionId
);
return
ddp
Client
.
unsub
(
subscriptionId
);
}
/**
* Returns Observable for handling DDP subscription.
*/
public
Observable
<
DDPSubscription
.
Event
>
getSubscriptionCallback
()
{
return
mDDP
Client
.
getSubscriptionCallback
();
return
ddp
Client
.
getSubscriptionCallback
();
}
}
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