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
1681a8e3
Commit
1681a8e3
authored
Apr 16, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Recent chats and contacts drawn with the same ContactItemInflater.
Background do not move while chat scrolling.
parent
9d903829
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
147 additions
and
219 deletions
+147
-219
ChatViewer.java
app/src/main/java/com/xabber/android/ui/ChatViewer.java
+1
-0
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+0
-2
ChatListAdapter.java
...n/java/com/xabber/android/ui/adapter/ChatListAdapter.java
+3
-34
ContactItemInflater.java
...va/com/xabber/android/ui/adapter/ContactItemInflater.java
+129
-0
GroupedContactAdapter.java
.../com/xabber/android/ui/adapter/GroupedContactAdapter.java
+6
-101
activity_chat_viewer.xml
app/src/main/res/layout/activity_chat_viewer.xml
+3
-2
base_contact_item.xml
app/src/main/res/layout/base_contact_item.xml
+1
-2
chat_list_item.xml
app/src/main/res/layout/chat_list_item.xml
+0
-75
chat_viewer_item.xml
app/src/main/res/layout/chat_viewer_item.xml
+0
-1
recent_chats.xml
app/src/main/res/layout/recent_chats.xml
+4
-2
No files found.
app/src/main/java/com/xabber/android/ui/ChatViewer.java
View file @
1681a8e3
...
...
@@ -129,6 +129,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
viewPager
=
(
ViewPager
)
findViewById
(
R
.
id
.
pager
);
viewPager
.
setAdapter
(
chatViewerAdapter
);
viewPager
.
setOnPageChangeListener
(
this
);
viewPager
.
getBackground
().
setAlpha
(
30
);
selectPage
(
account
,
user
,
false
);
}
...
...
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
1681a8e3
...
...
@@ -125,8 +125,6 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
}
});
view
.
getBackground
().
setAlpha
(
40
);
sendButton
=
(
ImageButton
)
view
.
findViewById
(
R
.
id
.
button_send_message
);
sendButton
.
setImageResource
(
R
.
drawable
.
ic_button_send_inactive_24dp
);
...
...
app/src/main/java/com/xabber/android/ui/adapter/ChatListAdapter.java
View file @
1681a8e3
package
com
.
xabber
.
android
.
ui
.
adapter
;
import
android.content.Context
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.xabber.android.data.message.AbstractChat
;
import
com.xabber.android.data.message.MessageManager
;
import
com.xabber.android.data.notification.NotificationManager
;
import
com.xabber.android.data.roster.AbstractContact
;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.androiddev.R
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -22,12 +16,11 @@ public class ChatListAdapter extends BaseAdapter {
private
List
<
AbstractChat
>
chats
;
private
final
Context
context
;
private
final
ContactItemInflater
contactItemInflater
;
public
ChatListAdapter
(
Context
context
)
{
this
.
context
=
context
;
chats
=
new
ArrayList
<>();
contactItemInflater
=
new
ContactItemInflater
(
context
);
}
public
void
updateChats
(
List
<
AbstractChat
>
chats
)
{
...
...
@@ -53,33 +46,9 @@ public class ChatListAdapter extends BaseAdapter {
@Override
public
View
getView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
final
View
view
;
if
(
convertView
==
null
)
{
view
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
chat_list_item
,
parent
,
false
);
}
else
{
view
=
convertView
;
}
final
AbstractChat
abstractChat
=
(
AbstractChat
)
getItem
(
position
);
final
AbstractContact
abstractContact
=
RosterManager
.
getInstance
()
.
getBestContact
(
abstractChat
.
getAccount
(),
abstractChat
.
getUser
());
((
TextView
)
view
.
findViewById
(
R
.
id
.
name
)).
setText
(
abstractContact
.
getName
());
((
ImageView
)
view
.
findViewById
(
R
.
id
.
color
)).
setImageLevel
(
abstractContact
.
getColorLevel
());
final
ImageView
avatarView
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
avatar
);
avatarView
.
setImageDrawable
(
abstractContact
.
getAvatar
());
final
TextView
textView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
text
);
String
statusText
=
MessageManager
.
getInstance
().
getLastText
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
());
textView
.
setText
(
statusText
);
boolean
newMessages
=
NotificationManager
.
getInstance
()
.
getNotificationMessageCount
(
abstractChat
.
getAccount
(),
abstractChat
.
getUser
())
>
0
;
textView
.
setTextAppearance
(
context
,
newMessages
?
R
.
style
.
ChatList_Notification
:
R
.
style
.
ChatList_Normal
);
return
view
;
return
contactItemInflater
.
setUpContactView
(
convertView
,
parent
,
abstractContact
);
}
}
app/src/main/java/com/xabber/android/ui/adapter/ContactItemInflater.java
0 → 100644
View file @
1681a8e3
package
com
.
xabber
.
android
.
ui
.
adapter
;
import
android.content.Context
;
import
android.graphics.drawable.ColorDrawable
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.extension.capability.ClientSoftware
;
import
com.xabber.android.data.extension.muc.MUCManager
;
import
com.xabber.android.data.message.MessageManager
;
import
com.xabber.android.data.roster.AbstractContact
;
import
com.xabber.android.ui.ContactEditor
;
import
com.xabber.android.ui.ContactViewer
;
import
com.xabber.androiddev.R
;
public
class
ContactItemInflater
{
static
class
ContactViewHolder
{
final
ImageView
color
;
final
ImageView
avatar
;
final
TextView
name
;
final
TextView
status
;
final
ImageView
offlineShadow
;
final
ImageView
statusMode
;
final
ImageView
clientSoftware
;
public
ContactViewHolder
(
View
view
)
{
color
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
color
);
avatar
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
avatar
);
name
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
name
);
status
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
status
);
offlineShadow
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
offline_shadow
);
statusMode
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
status_icon
);
clientSoftware
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
client_software
);
}
}
final
Context
context
;
private
int
[]
accountMainColors
;
public
ContactItemInflater
(
Context
context
)
{
this
.
context
=
context
;
accountMainColors
=
context
.
getResources
().
getIntArray
(
R
.
array
.
account_action_bar
);
}
public
View
setUpContactView
(
View
convertView
,
ViewGroup
parent
,
final
AbstractContact
abstractContact
)
{
final
View
view
;
final
ContactViewHolder
viewHolder
;
if
(
convertView
==
null
)
{
view
=
LayoutInflater
.
from
(
context
).
inflate
(
R
.
layout
.
base_contact_item
,
parent
,
false
);
viewHolder
=
new
ContactViewHolder
(
view
);
view
.
setTag
(
viewHolder
);
}
else
{
view
=
convertView
;
viewHolder
=
(
ContactViewHolder
)
view
.
getTag
();
}
if
(
abstractContact
.
isConnected
())
{
viewHolder
.
offlineShadow
.
setVisibility
(
View
.
GONE
);
}
else
{
viewHolder
.
offlineShadow
.
setVisibility
(
View
.
VISIBLE
);
}
int
colorLevel
=
abstractContact
.
getColorLevel
();
viewHolder
.
color
.
setImageDrawable
(
new
ColorDrawable
(
accountMainColors
[
colorLevel
]));
if
(
SettingsManager
.
contactsShowAvatars
())
{
viewHolder
.
avatar
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
avatar
.
setImageDrawable
(
abstractContact
.
getAvatarForContactList
());
}
else
{
viewHolder
.
avatar
.
setVisibility
(
View
.
GONE
);
}
viewHolder
.
avatar
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
MUCManager
.
getInstance
().
hasRoom
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
context
.
startActivity
(
ContactViewer
.
createIntent
(
context
,
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()));
}
else
{
context
.
startActivity
(
ContactEditor
.
createIntent
(
context
,
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()));
}
}
});
viewHolder
.
name
.
setText
(
abstractContact
.
getName
());
String
statusText
;
if
(
MessageManager
.
getInstance
()
.
hasActiveChat
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
statusText
=
MessageManager
.
getInstance
()
.
getLastText
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
());
}
else
{
statusText
=
abstractContact
.
getStatusText
();
}
statusText
=
statusText
.
trim
();
if
(
""
.
equals
(
statusText
))
{
viewHolder
.
status
.
setVisibility
(
View
.
GONE
);
}
else
{
viewHolder
.
status
.
setText
(
statusText
);
viewHolder
.
status
.
setVisibility
(
View
.
VISIBLE
);
}
viewHolder
.
statusMode
.
setImageLevel
(
abstractContact
.
getStatusMode
().
getStatusLevel
());
ClientSoftware
clientSoftware
=
abstractContact
.
getClientSoftware
();
if
(
clientSoftware
==
ClientSoftware
.
unknown
)
{
viewHolder
.
clientSoftware
.
setVisibility
(
View
.
INVISIBLE
);
}
else
{
viewHolder
.
clientSoftware
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
clientSoftware
.
setImageLevel
(
clientSoftware
.
ordinal
());
}
if
(
MessageManager
.
getInstance
().
hasActiveChat
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
view
.
setBackgroundColor
(
context
.
getResources
().
getColor
(
R
.
color
.
grey_50
));
}
else
{
view
.
setBackgroundColor
(
context
.
getResources
().
getColor
(
R
.
color
.
grey_300
));
}
return
view
;
}
}
app/src/main/java/com/xabber/android/ui/adapter/GroupedContactAdapter.java
View file @
1681a8e3
...
...
@@ -93,7 +93,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
private
final
LayoutInflater
layoutInflater
;
private
final
Activity
activity
;
private
int
[]
accountMainColors
;
private
int
[]
accountGroupColors
;
private
final
int
[]
accountSubgroupColors
;
private
final
int
activeChatsColor
;
...
...
@@ -101,6 +101,7 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
final
ArrayList
<
BaseEntity
>
baseEntities
=
new
ArrayList
<>();
protected
Locale
locale
=
Locale
.
getDefault
();
private
final
ContactItemInflater
contactItemInflater
;
public
GroupedContactAdapter
(
Activity
activity
,
OnClickListener
onClickListener
)
{
this
.
activity
=
activity
;
...
...
@@ -109,11 +110,13 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
Resources
resources
=
activity
.
getResources
();
accountMainColors
=
resources
.
getIntArray
(
R
.
array
.
account_action_bar
);
accountGroupColors
=
resources
.
getIntArray
(
R
.
array
.
account_200
);
accountSubgroupColors
=
resources
.
getIntArray
(
R
.
array
.
account_50
);
activeChatsColor
=
resources
.
getColor
(
R
.
color
.
color_primary_light
);
contactItemInflater
=
new
ContactItemInflater
(
activity
);
this
.
onClickListener
=
onClickListener
;
}
...
...
@@ -351,85 +354,8 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
}
private
View
getContactView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
final
View
view
;
final
ContactViewHolder
viewHolder
;
if
(
convertView
==
null
)
{
view
=
layoutInflater
.
inflate
(
R
.
layout
.
base_contact_item
,
parent
,
false
);
viewHolder
=
new
ContactViewHolder
(
view
);
view
.
setTag
(
viewHolder
);
}
else
{
view
=
convertView
;
viewHolder
=
(
ContactViewHolder
)
view
.
getTag
();
}
final
AbstractContact
abstractContact
=
(
AbstractContact
)
getItem
(
position
);
if
(
abstractContact
.
isConnected
())
{
viewHolder
.
offlineShadow
.
setVisibility
(
View
.
GONE
);
}
else
{
viewHolder
.
offlineShadow
.
setVisibility
(
View
.
VISIBLE
);
}
int
colorLevel
=
abstractContact
.
getColorLevel
();
viewHolder
.
color
.
setImageDrawable
(
new
ColorDrawable
(
accountMainColors
[
colorLevel
]));
if
(
SettingsManager
.
contactsShowAvatars
())
{
viewHolder
.
avatar
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
avatar
.
setImageDrawable
(
abstractContact
.
getAvatarForContactList
());
}
else
{
viewHolder
.
avatar
.
setVisibility
(
View
.
GONE
);
}
viewHolder
.
avatar
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
if
(
MUCManager
.
getInstance
().
hasRoom
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
activity
.
startActivity
(
ContactViewer
.
createIntent
(
activity
,
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()));
}
else
{
activity
.
startActivity
(
ContactEditor
.
createIntent
(
activity
,
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()));
}
}
});
viewHolder
.
name
.
setText
(
abstractContact
.
getName
());
String
statusText
;
if
(
MessageManager
.
getInstance
()
.
hasActiveChat
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
statusText
=
MessageManager
.
getInstance
()
.
getLastText
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
());
}
else
{
statusText
=
abstractContact
.
getStatusText
();
}
statusText
=
statusText
.
trim
();
if
(
""
.
equals
(
statusText
))
{
viewHolder
.
status
.
setVisibility
(
View
.
GONE
);
}
else
{
viewHolder
.
status
.
setText
(
statusText
);
viewHolder
.
status
.
setVisibility
(
View
.
VISIBLE
);
}
viewHolder
.
statusMode
.
setImageLevel
(
abstractContact
.
getStatusMode
().
getStatusLevel
());
ClientSoftware
clientSoftware
=
abstractContact
.
getClientSoftware
();
if
(
clientSoftware
==
ClientSoftware
.
unknown
)
{
viewHolder
.
clientSoftware
.
setVisibility
(
View
.
INVISIBLE
);
}
else
{
viewHolder
.
clientSoftware
.
setVisibility
(
View
.
VISIBLE
);
viewHolder
.
clientSoftware
.
setImageLevel
(
clientSoftware
.
ordinal
());
}
if
(
MessageManager
.
getInstance
().
hasActiveChat
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
()))
{
view
.
setBackgroundColor
(
activity
.
getResources
().
getColor
(
R
.
color
.
grey_50
));
}
else
{
view
.
setBackgroundColor
(
activity
.
getResources
().
getColor
(
R
.
color
.
grey_300
));
}
return
view
;
return
contactItemInflater
.
setUpContactView
(
convertView
,
parent
,
abstractContact
);
}
/**
...
...
@@ -620,27 +546,6 @@ public abstract class GroupedContactAdapter extends BaseAdapter implements Updat
onChange
();
}
static
class
ContactViewHolder
{
final
ImageView
color
;
final
ImageView
avatar
;
final
TextView
name
;
final
TextView
status
;
final
ImageView
offlineShadow
;
final
ImageView
statusMode
;
final
ImageView
clientSoftware
;
public
ContactViewHolder
(
View
view
)
{
color
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
color
);
avatar
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
avatar
);
name
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
name
);
status
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
status
);
offlineShadow
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
offline_shadow
);
statusMode
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
status_icon
);
clientSoftware
=
(
ImageView
)
view
.
findViewById
(
R
.
id
.
client_software
);
}
}
/**
* Holder for views in contact list group.
*/
...
...
app/src/main/res/layout/activity_chat_viewer.xml
View file @
1681a8e3
...
...
@@ -2,7 +2,8 @@
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
...
...
@@ -10,7 +11,7 @@
android:id=
"@+id/pager"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/chat_background_repeat"
/>
<LinearLayout
...
...
app/src/main/res/layout/base_contact_item.xml
View file @
1681a8e3
...
...
@@ -18,8 +18,7 @@
android:layout_width=
"match_parent"
android:layout_height=
"@dimen/contact_list_item_height"
android:elevation=
"1dp"
android:background=
"@color/grey_300"
>
>
<LinearLayout
android:layout_width=
"match_parent"
...
...
app/src/main/res/layout/chat_list_item.xml
deleted
100644 → 0
View file @
9d903829
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2013, Redsolution LTD. All rights reserved.
This file is part of Xabber project; you can redistribute it and/or
modify it under the terms of the GNU General Public License, Version 3.
Xabber is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License,
along with this program. If not, see http://www.gnu.org/licenses/.
-->
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingLeft=
"6dip"
android:paddingTop=
"4dip"
android:paddingRight=
"6dip"
android:paddingBottom=
"4dip"
android:gravity=
"center_vertical"
>
<ImageView
android:id=
"@+id/color"
android:layout_width=
"wrap_content"
android:layout_height=
"32dip"
android:visibility=
"gone"
android:src=
"@android:color/transparent"
/>
<ImageView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/avatar"
android:layout_width=
"@dimen/avatar_size_toolbar"
android:layout_height=
"@dimen/avatar_size_toolbar"
android:layout_toRightOf=
"@id/color"
android:src=
"@drawable/ic_avatar_1"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginLeft=
"8dip"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/name"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"bottom"
android:textStyle=
"bold"
android:singleLine=
"true"
android:ellipsize=
"marquee"
android:text=
"name"
android:textColor=
"?android:attr/textColorPrimary"
/>
<TextView
android:id=
"@+id/text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:gravity=
"top"
android:singleLine=
"true"
android:ellipsize=
"marquee"
android:text=
"message"
android:textColor=
"?android:attr/textColorSecondary"
/>
</LinearLayout>
</LinearLayout>
app/src/main/res/layout/chat_viewer_item.xml
View file @
1681a8e3
...
...
@@ -17,7 +17,6 @@
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/chat_background_repeat"
>
<android.support.v7.widget.Toolbar
xmlns:app=
"http://schemas.android.com/apk/res-auto"
...
...
app/src/main/res/layout/recent_chats.xml
View file @
1681a8e3
...
...
@@ -2,7 +2,7 @@
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@
drawable/chat_background_repeat
"
android:background=
"@
color/grey_300
"
>
<include
layout=
"@layout/toolbar_default"
/>
...
...
@@ -11,6 +11,8 @@
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:id=
"@android:id/list"
android:layout_marginTop=
"15dp"
android:layout_marginTop=
"20dp"
android:divider=
"@null"
android:dividerHeight=
"0dp"
/>
</LinearLayout>
\ 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