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
227cdda6
Commit
227cdda6
authored
Apr 06, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapters: light refactoring.
parent
251955a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
67 deletions
+84
-67
AccountConfiguration.java
...a/com/xabber/android/ui/adapter/AccountConfiguration.java
+1
-1
ContactListAdapter.java
...ava/com/xabber/android/ui/adapter/ContactListAdapter.java
+51
-44
GroupConfiguration.java
...ava/com/xabber/android/ui/adapter/GroupConfiguration.java
+23
-12
GroupedContactAdapter.java
.../com/xabber/android/ui/adapter/GroupedContactAdapter.java
+9
-10
No files found.
app/src/main/java/com/xabber/android/ui/adapter/AccountConfiguration.java
View file @
227cdda6
...
...
@@ -31,7 +31,7 @@ public class AccountConfiguration extends GroupConfiguration {
public
AccountConfiguration
(
String
account
,
String
user
,
GroupStateProvider
groupStateProvider
)
{
super
(
account
,
user
,
groupStateProvider
);
groups
=
new
TreeMap
<
String
,
GroupConfiguration
>();
groups
=
new
TreeMap
<>();
}
/**
...
...
app/src/main/java/com/xabber/android/ui/adapter/ContactListAdapter.java
View file @
227cdda6
...
...
@@ -37,6 +37,8 @@ import java.util.Collection;
import
java.util.Collections
;
import
java.util.Comparator
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.TreeMap
;
...
...
@@ -138,31 +140,22 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
final
CommonState
commonState
=
AccountManager
.
getInstance
().
getCommonState
();
final
String
selectedAccount
=
AccountManager
.
getInstance
().
getSelectedAccount
();
/**
* Accounts.
*/
final
TreeMap
<
String
,
AccountConfiguration
>
accounts
=
new
TreeMap
<>();
/**
* Groups.
*/
final
Tree
Map
<
String
,
GroupConfiguration
>
groups
;
final
Map
<
String
,
GroupConfiguration
>
groups
;
/**
* Contacts.
*/
final
Array
List
<
AbstractContact
>
contacts
;
final
List
<
AbstractContact
>
contacts
;
/**
* List of active chats.
*/
final
GroupConfiguration
activeChats
;
/**
* List of rooms and active chats grouped by users inside accounts.
*/
final
TreeMap
<
String
,
TreeMap
<
String
,
AbstractChat
>>
abstractChats
=
new
TreeMap
<>();
/**
* Whether there is at least one contact.
*/
...
...
@@ -173,15 +166,22 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
*/
boolean
hasVisibleContacts
=
false
;
final
Map
<
String
,
AccountConfiguration
>
accounts
=
new
TreeMap
<>();
for
(
String
account
:
AccountManager
.
getInstance
().
getAccounts
())
{
accounts
.
put
(
account
,
null
);
}
/**
* List of rooms and active chats grouped by users inside accounts.
*/
final
Map
<
String
,
Map
<
String
,
AbstractChat
>>
abstractChats
=
new
TreeMap
<>();
for
(
AbstractChat
abstractChat
:
MessageManager
.
getInstance
().
getChats
())
{
if
((
abstractChat
instanceof
RoomChat
||
abstractChat
.
isActive
())
&&
accounts
.
containsKey
(
abstractChat
.
getAccount
()))
{
final
String
account
=
abstractChat
.
getAccount
();
Tree
Map
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
Map
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
if
(
users
==
null
)
{
users
=
new
TreeMap
<>();
abstractChats
.
put
(
account
,
users
);
...
...
@@ -223,7 +223,7 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
hasContacts
=
true
;
final
boolean
online
=
rosterContact
.
getStatusMode
().
isOnline
();
final
String
account
=
rosterContact
.
getAccount
();
final
Tree
Map
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
final
Map
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
final
AbstractChat
abstractChat
;
if
(
users
==
null
)
{
abstractChat
=
null
;
...
...
@@ -249,7 +249,7 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
hasVisibleContacts
=
true
;
}
}
for
(
Tree
Map
<
String
,
AbstractChat
>
users
:
abstractChats
.
values
())
{
for
(
Map
<
String
,
AbstractChat
>
users
:
abstractChats
.
values
())
{
for
(
AbstractChat
abstractChat
:
users
.
values
())
{
final
AbstractContact
abstractContact
;
if
(
abstractChat
instanceof
RoomChat
)
{
...
...
@@ -333,36 +333,7 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
}
}
}
else
{
// Search
final
ArrayList
<
AbstractContact
>
baseEntities
=
new
ArrayList
<>();
// Build structure.
for
(
RosterContact
rosterContact
:
rosterContacts
)
{
if
(!
rosterContact
.
isEnabled
())
{
continue
;
}
final
String
account
=
rosterContact
.
getAccount
();
final
TreeMap
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
if
(
users
!=
null
)
{
users
.
remove
(
rosterContact
.
getUser
());
}
if
(
rosterContact
.
getName
().
toLowerCase
(
locale
).
contains
(
filterString
))
{
baseEntities
.
add
(
rosterContact
);
}
}
for
(
TreeMap
<
String
,
AbstractChat
>
users
:
abstractChats
.
values
())
{
for
(
AbstractChat
abstractChat
:
users
.
values
())
{
final
AbstractContact
abstractContact
;
if
(
abstractChat
instanceof
RoomChat
)
{
abstractContact
=
new
RoomContact
((
RoomChat
)
abstractChat
);
}
else
{
abstractContact
=
new
ChatContact
(
abstractChat
);
}
if
(
abstractContact
.
getName
().
toLowerCase
(
locale
).
contains
(
filterString
))
{
baseEntities
.
add
(
abstractContact
);
}
}
}
Collections
.
sort
(
baseEntities
,
comparator
);
final
ArrayList
<
AbstractContact
>
baseEntities
=
getSearchResults
(
rosterContacts
,
comparator
,
abstractChats
);
this
.
baseEntities
.
clear
();
this
.
baseEntities
.
addAll
(
baseEntities
);
hasVisibleContacts
=
baseEntities
.
size
()
>
0
;
...
...
@@ -382,6 +353,42 @@ public class ContactListAdapter extends GroupedContactAdapter<ChatContactInflate
}
}
private
ArrayList
<
AbstractContact
>
getSearchResults
(
Collection
<
RosterContact
>
rosterContacts
,
Comparator
<
AbstractContact
>
comparator
,
Map
<
String
,
Map
<
String
,
AbstractChat
>>
abstractChats
)
{
final
ArrayList
<
AbstractContact
>
baseEntities
=
new
ArrayList
<>();
// Build structure.
for
(
RosterContact
rosterContact
:
rosterContacts
)
{
if
(!
rosterContact
.
isEnabled
())
{
continue
;
}
final
String
account
=
rosterContact
.
getAccount
();
final
Map
<
String
,
AbstractChat
>
users
=
abstractChats
.
get
(
account
);
if
(
users
!=
null
)
{
users
.
remove
(
rosterContact
.
getUser
());
}
if
(
rosterContact
.
getName
().
toLowerCase
(
locale
).
contains
(
filterString
))
{
baseEntities
.
add
(
rosterContact
);
}
}
for
(
Map
<
String
,
AbstractChat
>
users
:
abstractChats
.
values
())
{
for
(
AbstractChat
abstractChat
:
users
.
values
())
{
final
AbstractContact
abstractContact
;
if
(
abstractChat
instanceof
RoomChat
)
{
abstractContact
=
new
RoomContact
((
RoomChat
)
abstractChat
);
}
else
{
abstractContact
=
new
ChatContact
(
abstractChat
);
}
if
(
abstractContact
.
getName
().
toLowerCase
(
locale
).
contains
(
filterString
))
{
baseEntities
.
add
(
abstractContact
);
}
}
}
Collections
.
sort
(
baseEntities
,
comparator
);
return
baseEntities
;
}
@Override
public
void
run
()
{
onChange
();
...
...
app/src/main/java/com/xabber/android/ui/adapter/GroupConfiguration.java
View file @
227cdda6
...
...
@@ -63,7 +63,7 @@ public class GroupConfiguration extends BaseEntity {
public
GroupConfiguration
(
String
account
,
String
group
,
GroupStateProvider
groupStateProvider
)
{
super
(
account
,
group
);
abstractContacts
=
new
ArrayList
<
AbstractContact
>();
abstractContacts
=
new
ArrayList
<>();
expanded
=
groupStateProvider
.
isExpanded
(
account
,
group
);
showOfflineMode
=
groupStateProvider
.
getShowOfflineMode
(
account
,
group
);
empty
=
true
;
...
...
@@ -105,8 +105,9 @@ public class GroupConfiguration extends BaseEntity {
*/
public
void
increment
(
boolean
online
)
{
this
.
total
++;
if
(
online
)
if
(
online
)
{
this
.
online
++;
}
}
/**
...
...
@@ -157,31 +158,41 @@ public class GroupConfiguration extends BaseEntity {
int
result
=
account
.
compareTo
(
another
.
getAccount
());
if
(
result
!=
0
)
{
if
(
user
.
compareTo
(
another
.
getUser
())
!=
0
)
{
if
(
user
==
GroupManager
.
ACTIVE_CHATS
)
if
(
user
.
equals
(
GroupManager
.
ACTIVE_CHATS
))
{
return
-
1
;
if
(
anotherUser
==
GroupManager
.
ACTIVE_CHATS
)
}
if
(
anotherUser
.
equals
(
GroupManager
.
ACTIVE_CHATS
))
{
return
1
;
}
}
return
result
;
}
result
=
user
.
compareTo
(
anotherUser
);
if
(
result
!=
0
)
{
if
(
user
==
GroupManager
.
ACTIVE_CHATS
)
if
(
user
.
equals
(
GroupManager
.
ACTIVE_CHATS
))
{
return
-
1
;
if
(
anotherUser
==
GroupManager
.
ACTIVE_CHATS
)
}
if
(
anotherUser
.
equals
(
GroupManager
.
ACTIVE_CHATS
))
{
return
1
;
if
(
user
==
GroupManager
.
IS_ACCOUNT
)
}
if
(
user
.
equals
(
GroupManager
.
IS_ACCOUNT
))
{
return
-
1
;
if
(
anotherUser
==
GroupManager
.
IS_ACCOUNT
)
}
if
(
anotherUser
.
equals
(
GroupManager
.
IS_ACCOUNT
))
{
return
1
;
if
(
user
==
GroupManager
.
NO_GROUP
)
}
if
(
user
.
equals
(
GroupManager
.
NO_GROUP
))
{
return
-
1
;
if
(
anotherUser
==
GroupManager
.
NO_GROUP
)
}
if
(
anotherUser
.
equals
(
GroupManager
.
NO_GROUP
))
{
return
1
;
if
(
user
==
GroupManager
.
IS_ROOM
)
}
if
(
user
.
equals
(
GroupManager
.
IS_ROOM
))
{
return
-
1
;
if
(
anotherUser
==
GroupManager
.
IS_ROOM
)
}
if
(
anotherUser
.
equals
(
GroupManager
.
IS_ROOM
))
{
return
1
;
}
return
result
;
}
return
0
;
...
...
app/src/main/java/com/xabber/android/ui/adapter/GroupedContactAdapter.java
View file @
227cdda6
...
...
@@ -39,7 +39,8 @@ import com.xabber.androiddev.R;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.TreeMap
;
import
java.util.List
;
import
java.util.Map
;
/**
* Provide grouping implementation for the list of contacts.
...
...
@@ -245,8 +246,7 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
* @param name
* @return
*/
protected
GroupConfiguration
getGroupConfiguration
(
AccountConfiguration
accountConfiguration
,
String
name
)
{
protected
GroupConfiguration
getGroupConfiguration
(
AccountConfiguration
accountConfiguration
,
String
name
)
{
GroupConfiguration
groupConfiguration
=
accountConfiguration
.
getGroupConfiguration
(
name
);
if
(
groupConfiguration
!=
null
)
{
return
groupConfiguration
;
...
...
@@ -264,8 +264,7 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
* @param name
* @return
*/
protected
GroupConfiguration
getGroupConfiguration
(
TreeMap
<
String
,
GroupConfiguration
>
groups
,
String
name
)
{
protected
GroupConfiguration
getGroupConfiguration
(
Map
<
String
,
GroupConfiguration
>
groups
,
String
name
)
{
GroupConfiguration
groupConfiguration
=
groups
.
get
(
name
);
if
(
groupConfiguration
!=
null
)
{
return
groupConfiguration
;
...
...
@@ -288,8 +287,8 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
* @param showGroups
*/
protected
void
addContact
(
AbstractContact
abstractContact
,
String
group
,
boolean
online
,
TreeMap
<
String
,
AccountConfiguration
>
accounts
,
Tree
Map
<
String
,
GroupConfiguration
>
groups
,
ArrayList
<
AbstractContact
>
contacts
,
boolean
showAccounts
,
boolean
showGroups
)
{
Map
<
String
,
AccountConfiguration
>
accounts
,
Map
<
String
,
GroupConfiguration
>
groups
,
List
<
AbstractContact
>
contacts
,
boolean
showAccounts
,
boolean
showGroups
)
{
if
(
showAccounts
)
{
final
String
account
=
abstractContact
.
getAccount
();
final
AccountConfiguration
accountConfiguration
;
...
...
@@ -341,9 +340,9 @@ public abstract class GroupedContactAdapter<Inflater extends BaseContactInflater
* @return whether contact is visible.
*/
protected
boolean
addContact
(
AbstractContact
abstractContact
,
boolean
online
,
Tree
Map
<
String
,
AccountConfiguration
>
accounts
,
Tree
Map
<
String
,
GroupConfiguration
>
groups
,
Array
List
<
AbstractContact
>
contacts
,
boolean
showAccounts
,
boolean
online
,
Map
<
String
,
AccountConfiguration
>
accounts
,
Map
<
String
,
GroupConfiguration
>
groups
,
List
<
AbstractContact
>
contacts
,
boolean
showAccounts
,
boolean
showGroups
,
boolean
showOffline
)
{
boolean
hasVisible
=
false
;
if
(
showAccounts
)
{
...
...
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