Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-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
xabber-android
Commits
e3de3ad8
Commit
e3de3ad8
authored
Jul 10, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ConnectionItem: light refactoring.
parent
4a1fae99
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
28 deletions
+35
-28
ConnectionItem.java
...va/com/xabber/android/data/connection/ConnectionItem.java
+34
-26
ConnectionManager.java
...com/xabber/android/data/connection/ConnectionManager.java
+1
-2
No files found.
app/src/main/java/com/xabber/android/data/connection/ConnectionItem.java
View file @
e3de3ad8
...
...
@@ -116,14 +116,17 @@ public abstract class ConnectionItem {
*/
public
String
getRealJid
()
{
ConnectionThread
connectionThread
=
getConnectionThread
();
if
(
connectionThread
==
null
)
if
(
connectionThread
==
null
)
{
return
null
;
}
XMPPConnection
xmppConnection
=
connectionThread
.
getXMPPConnection
();
if
(
xmppConnection
==
null
)
if
(
xmppConnection
==
null
)
{
return
null
;
}
String
user
=
xmppConnection
.
getUser
();
if
(
user
==
null
)
if
(
user
==
null
)
{
return
null
;
}
return
user
;
}
...
...
@@ -145,13 +148,12 @@ public abstract class ConnectionItem {
boolean
available
=
isConnectionAvailable
(
userRequest
);
if
(
NetworkManager
.
getInstance
().
getState
()
!=
NetworkState
.
available
||
!
available
||
disconnectionRequested
)
{
ConnectionState
target
=
available
?
ConnectionState
.
waiting
:
ConnectionState
.
offline
;
if
(
state
==
ConnectionState
.
connected
||
state
==
ConnectionState
.
authentication
ConnectionState
target
=
available
?
ConnectionState
.
waiting
:
ConnectionState
.
offline
;
if
(
state
==
ConnectionState
.
connected
||
state
==
ConnectionState
.
authentication
||
state
==
ConnectionState
.
connecting
)
{
if
(
userRequest
)
if
(
userRequest
)
{
connectionRequest
=
false
;
}
if
(
connectionThread
!=
null
)
{
disconnect
(
connectionThread
);
// Force remove managed connection thread.
...
...
@@ -164,18 +166,19 @@ public abstract class ConnectionItem {
state
=
target
;
return
true
;
}
else
{
if
(
state
==
ConnectionState
.
offline
||
state
==
ConnectionState
.
waiting
)
{
if
(
userRequest
)
if
(
state
==
ConnectionState
.
offline
||
state
==
ConnectionState
.
waiting
)
{
if
(
userRequest
)
{
connectionRequest
=
true
;
}
state
=
ConnectionState
.
connecting
;
connectionThread
=
new
ConnectionThread
(
this
);
if
(
connectionSettings
.
isCustom
())
if
(
connectionSettings
.
isCustom
())
{
connectionThread
.
start
(
connectionSettings
.
getHost
(),
connectionSettings
.
getPort
(),
false
,
registerNewAccount
);
else
}
else
{
connectionThread
.
start
(
connectionSettings
.
getServerName
(),
5222
,
true
,
registerNewAccount
);
}
return
true
;
}
else
{
return
false
;
...
...
@@ -187,8 +190,9 @@ public abstract class ConnectionItem {
* Disconnect and connect using new connection.
*/
public
void
forceReconnect
()
{
if
(!
getState
().
isConnectable
())
if
(!
getState
().
isConnectable
())
{
return
;
}
disconnectionRequested
=
true
;
boolean
request
=
connectionRequest
;
connectionRequest
=
false
;
...
...
@@ -253,20 +257,22 @@ public abstract class ConnectionItem {
* Connection has been established.
*/
protected
void
onConnected
(
ConnectionThread
connectionThread
)
{
if
(
isRegisterAccount
())
if
(
isRegisterAccount
())
{
state
=
ConnectionState
.
registration
;
else
if
(
isManaged
(
connectionThread
))
}
else
if
(
isManaged
(
connectionThread
))
{
state
=
ConnectionState
.
authentication
;
}
}
/**
* New account has been registered on XMPP server.
*/
protected
void
onAccountRegistered
(
ConnectionThread
connectionThread
)
{
registerNewAccount
=
false
;
if
(
isManaged
(
connectionThread
))
if
(
isManaged
(
connectionThread
))
{
state
=
ConnectionState
.
authentication
;
}
}
/**
* Authorization failed.
...
...
@@ -278,9 +284,10 @@ public abstract class ConnectionItem {
* Authorization passed.
*/
protected
void
onAuthorized
(
ConnectionThread
connectionThread
)
{
if
(
isManaged
(
connectionThread
))
if
(
isManaged
(
connectionThread
))
{
state
=
ConnectionState
.
connected
;
}
}
/**
* Called when disconnect should occur.
...
...
@@ -291,17 +298,17 @@ public abstract class ConnectionItem {
private
boolean
onDisconnect
(
ConnectionThread
connectionThread
)
{
XMPPConnection
xmppConnection
=
connectionThread
.
getXMPPConnection
();
boolean
acceptable
=
isManaged
(
connectionThread
);
if
(
xmppConnection
==
null
)
if
(
xmppConnection
==
null
)
{
LogManager
.
i
(
this
,
"onClose "
+
acceptable
);
else
LogManager
.
i
(
this
,
"onClose "
+
xmppConnection
.
hashCode
()
+
" - "
+
xmppConnection
.
getConnectionCounter
()
+
", "
+
acceptable
);
}
else
{
LogManager
.
i
(
this
,
"onClose "
+
xmppConnection
.
hashCode
()
+
" - "
+
xmppConnection
.
getConnectionCounter
()
+
", "
+
acceptable
);
}
ConnectionManager
.
getInstance
().
onDisconnect
(
connectionThread
);
if
(
acceptable
)
if
(
acceptable
)
{
connectionThread
.
shutdown
();
}
return
acceptable
;
}
...
...
@@ -312,8 +319,9 @@ public abstract class ConnectionItem {
if
(
onDisconnect
(
connectionThread
))
{
state
=
ConnectionState
.
waiting
;
this
.
connectionThread
=
null
;
if
(
connectionRequest
)
if
(
connectionRequest
)
{
Application
.
getInstance
().
onError
(
R
.
string
.
CONNECTION_FAILED
);
}
connectionRequest
=
false
;
}
}
...
...
app/src/main/java/com/xabber/android/data/connection/ConnectionManager.java
View file @
e3de3ad8
...
...
@@ -48,8 +48,7 @@ import java.util.Map.Entry;
*
* @author alexander.ivanov
*/
public
class
ConnectionManager
implements
OnInitializedListener
,
OnCloseListener
,
OnTimerListener
{
public
class
ConnectionManager
implements
OnInitializedListener
,
OnCloseListener
,
OnTimerListener
{
/**
* Timeout for receiving reply from server.
...
...
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