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
0580f1a6
Commit
0580f1a6
authored
Dec 18, 2016
by
Yusuke Iwaki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix infinite error looping.
parent
9c00b01c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
110 additions
and
7 deletions
+110
-7
ServerConfigActivity.java
...va/chat/rocket/android/activity/ServerConfigActivity.java
+21
-1
RetryConnectFragment.java
.../android/fragment/server_config/RetryConnectFragment.java
+83
-0
RocketChatWebSocketThread.java
...hat/rocket/android/service/RocketChatWebSocketThread.java
+6
-6
No files found.
app/src/main/java/chat/rocket/android/activity/ServerConfigActivity.java
View file @
0580f1a6
...
@@ -7,9 +7,11 @@ import android.support.v4.app.Fragment;
...
@@ -7,9 +7,11 @@ import android.support.v4.app.Fragment;
import
chat.rocket.android.R
;
import
chat.rocket.android.R
;
import
chat.rocket.android.fragment.server_config.LoginFragment
;
import
chat.rocket.android.fragment.server_config.LoginFragment
;
import
chat.rocket.android.fragment.server_config.RetryConnectFragment
;
import
chat.rocket.android.fragment.server_config.RetryLoginFragment
;
import
chat.rocket.android.fragment.server_config.RetryLoginFragment
;
import
chat.rocket.android.fragment.server_config.WaitingFragment
;
import
chat.rocket.android.fragment.server_config.WaitingFragment
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.model.internal.Session
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
import
chat.rocket.android.realm_helper.RealmStore
;
...
@@ -21,6 +23,7 @@ import chat.rocket.android.service.RocketChatService;
...
@@ -21,6 +23,7 @@ import chat.rocket.android.service.RocketChatService;
public
class
ServerConfigActivity
extends
AbstractFragmentActivity
{
public
class
ServerConfigActivity
extends
AbstractFragmentActivity
{
private
String
serverConfigId
;
private
String
serverConfigId
;
private
RealmObjectObserver
<
ServerConfig
>
serverConfigErrorObserver
;
private
RealmObjectObserver
<
Session
>
sessionObserver
;
private
RealmObjectObserver
<
Session
>
sessionObserver
;
@Override
@Override
...
@@ -44,6 +47,13 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
...
@@ -44,6 +47,13 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
return
;
return
;
}
}
serverConfigErrorObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
)
.
equalTo
(
"state"
,
ServerConfig
.
STATE_CONNECTION_ERROR
))
.
setOnUpdateListener
(
this
::
onRenderServerConfigError
);
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
sessionObserver
=
RealmStore
.
get
(
serverConfigId
)
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
.
createObjectObserver
(
Session:
:
queryDefaultSession
)
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
.
setOnUpdateListener
(
this
::
onRenderServerConfigSession
);
...
@@ -56,15 +66,25 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
...
@@ -56,15 +66,25 @@ public class ServerConfigActivity extends AbstractFragmentActivity {
protected
void
onResume
()
{
protected
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
RocketChatService
.
keepalive
(
this
);
RocketChatService
.
keepalive
(
this
);
se
ssion
Observer
.
sub
();
se
rverConfigError
Observer
.
sub
();
}
}
@Override
@Override
protected
void
onPause
()
{
protected
void
onPause
()
{
sessionObserver
.
unsub
();
sessionObserver
.
unsub
();
serverConfigErrorObserver
.
unsub
();
super
.
onPause
();
super
.
onPause
();
}
}
private
void
onRenderServerConfigError
(
ServerConfig
config
)
{
if
(
config
!=
null
)
{
sessionObserver
.
unsub
();
showFragment
(
new
RetryConnectFragment
());
}
else
{
sessionObserver
.
sub
();
}
}
private
void
onRenderServerConfigSession
(
Session
session
)
{
private
void
onRenderServerConfigSession
(
Session
session
)
{
if
(
session
==
null
)
{
if
(
session
==
null
)
{
showFragment
(
new
LoginFragment
());
showFragment
(
new
LoginFragment
());
...
...
app/src/main/java/chat/rocket/android/fragment/server_config/RetryConnectFragment.java
0 → 100644
View file @
0580f1a6
package
chat
.
rocket
.
android
.
fragment
.
server_config
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.view.View
;
import
android.widget.TextView
;
import
chat.rocket.android.R
;
import
chat.rocket.android.helper.LogcatIfError
;
import
chat.rocket.android.helper.TextUtils
;
import
chat.rocket.android.model.ServerConfig
;
import
chat.rocket.android.realm_helper.RealmObjectObserver
;
import
chat.rocket.android.realm_helper.RealmStore
;
/**
* Login screen.
*/
public
class
RetryConnectFragment
extends
AbstractServerConfigFragment
{
private
RealmObjectObserver
<
ServerConfig
>
serverConfigObserver
;
@Override
protected
int
getLayout
()
{
return
R
.
layout
.
fragment_retry_login
;
}
@Override
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
serverConfigObserver
=
RealmStore
.
getDefault
()
.
createObjectObserver
(
realm
->
realm
.
where
(
ServerConfig
.
class
).
equalTo
(
"serverConfigId"
,
serverConfigId
))
.
setOnUpdateListener
(
this
::
onRenderServerConfig
);
}
@Override
protected
void
onSetupView
()
{
rootView
.
findViewById
(
R
.
id
.
waiting
).
setVisibility
(
View
.
GONE
);
final
View
btnRetry
=
rootView
.
findViewById
(
R
.
id
.
btn_retry_login
);
btnRetry
.
setOnClickListener
(
view
->
{
RealmStore
.
getDefault
()
.
executeTransaction
(
realm
->
{
ServerConfig
config
=
realm
.
where
(
ServerConfig
.
class
)
.
equalTo
(
"serverConfigId"
,
serverConfigId
).
findFirst
();
if
(
config
!=
null
&&
config
.
getState
()
==
ServerConfig
.
STATE_CONNECTION_ERROR
)
{
config
.
setState
(
ServerConfig
.
STATE_READY
);
}
return
null
;
}).
continueWith
(
new
LogcatIfError
());
});
}
private
void
onRenderServerConfig
(
ServerConfig
config
)
{
if
(
config
==
null
)
{
return
;
}
final
String
error
=
config
.
getError
();
final
TextView
txtError
=
(
TextView
)
rootView
.
findViewById
(
R
.
id
.
txt_error_description
);
if
(!
TextUtils
.
isEmpty
(
error
))
{
txtError
.
setText
(
error
);
}
final
int
state
=
config
.
getState
();
if
(
state
==
ServerConfig
.
STATE_CONNECTED
)
{
finish
();
}
rootView
.
findViewById
(
R
.
id
.
btn_retry_login
)
.
setEnabled
(
state
==
ServerConfig
.
STATE_CONNECTION_ERROR
);
}
@Override
public
void
onResume
()
{
super
.
onResume
();
serverConfigObserver
.
sub
();
}
@Override
public
void
onPause
()
{
serverConfigObserver
.
unsub
();
super
.
onPause
();
}
}
app/src/main/java/chat/rocket/android/service/RocketChatWebSocketThread.java
View file @
0580f1a6
...
@@ -183,10 +183,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -183,10 +183,10 @@ public class RocketChatWebSocketThread extends HandlerThread {
return
null
;
return
null
;
})).
continueWith
(
new
LogcatIfError
());
})).
continueWith
(
new
LogcatIfError
());
return
task
;
return
task
;
}).
onSuccess
(
new
Continuation
<
DDPClientCallback
.
Connect
,
Object
>()
{
}).
onSuccess
(
new
Continuation
<
DDPClientCallback
.
Connect
,
Void
>()
{
// TODO type detection doesn't work due to retrolambda's bug...
// TODO type detection doesn't work due to retrolambda's bug...
@Override
@Override
public
Object
then
(
Task
<
DDPClientCallback
.
Connect
>
task
)
public
Void
then
(
Task
<
DDPClientCallback
.
Connect
>
task
)
throws
Exception
{
throws
Exception
{
registerListeners
();
registerListeners
();
...
@@ -194,20 +194,20 @@ public class RocketChatWebSocketThread extends HandlerThread {
...
@@ -194,20 +194,20 @@ public class RocketChatWebSocketThread extends HandlerThread {
task
.
getResult
().
client
.
getOnCloseCallback
().
onSuccess
(
_task
->
{
task
.
getResult
().
client
.
getOnCloseCallback
().
onSuccess
(
_task
->
{
quit
();
quit
();
return
null
;
return
null
;
}).
continueWith
(
_task
->
{
}).
continueWith
Task
(
_task
->
{
if
(
_task
.
isFaulted
())
{
if
(
_task
.
isFaulted
())
{
ServerConfig
.
logConnectionError
(
serverConfigId
,
_task
.
getError
());
ServerConfig
.
logConnectionError
(
serverConfigId
,
_task
.
getError
());
}
}
return
null
;
return
_task
;
});
});
return
null
;
return
null
;
}
}
}).
continueWith
(
task
->
{
}).
continueWith
Task
(
task
->
{
if
(
task
.
isFaulted
())
{
if
(
task
.
isFaulted
())
{
ServerConfig
.
logConnectionError
(
serverConfigId
,
task
.
getError
());
ServerConfig
.
logConnectionError
(
serverConfigId
,
task
.
getError
());
}
}
return
null
;
return
task
;
});
});
}
}
...
...
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