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
1a820d39
Commit
1a820d39
authored
Feb 19, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ChatMessageAdapter: chat messaged redesigned: outgoing messages are drawn to the right.
Name is not drawn.
parent
4ace1632
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
65 deletions
+116
-65
ChatMessageAdapter.java
...ava/com/xabber/android/ui/adapter/ChatMessageAdapter.java
+47
-59
chat_viewer_item.xml
app/src/main/res/layout/chat_viewer_item.xml
+2
-0
chat_viewer_message.xml
app/src/main/res/layout/chat_viewer_message.xml
+22
-6
chat_viewer_message_own.xml
app/src/main/res/layout/chat_viewer_message_own.xml
+45
-0
No files found.
app/src/main/java/com/xabber/android/ui/adapter/ChatMessageAdapter.java
View file @
1a820d39
...
...
@@ -25,7 +25,6 @@ import android.view.View;
import
android.view.ViewGroup
;
import
android.widget.BaseAdapter
;
import
android.widget.ImageView
;
import
android.widget.RelativeLayout
;
import
android.widget.TextView
;
import
com.xabber.android.data.SettingsManager
;
...
...
@@ -139,65 +138,51 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override
public
View
getView
(
int
position
,
View
convertView
,
ViewGroup
parent
)
{
final
int
type
=
getItemViewType
(
position
);
final
View
view
;
if
(
convertView
==
null
)
{
final
int
resource
;
switch
(
type
)
{
case
TYPE_MESSAGE:
resource
=
R
.
layout
.
chat_viewer_message
;
break
;
case
TYPE_HINT:
resource
=
R
.
layout
.
chat_viewer_info
;
break
;
case
TYPE_EMPTY:
resource
=
R
.
layout
.
chat_viewer_empty
;
break
;
default
:
throw
new
IllegalStateException
();
}
view
=
activity
.
getLayoutInflater
().
inflate
(
resource
,
parent
,
false
);
if
(
type
==
TYPE_MESSAGE
)
{
((
TextView
)
view
.
findViewById
(
R
.
id
.
text
)).
setTextAppearance
(
activity
,
appearanceStyle
);
}
}
else
{
view
=
convertView
;
}
if
(
type
==
TYPE_EMPTY
)
{
return
view
;
if
(
convertView
==
null
)
{
return
activity
.
getLayoutInflater
().
inflate
(
R
.
layout
.
chat_viewer_empty
,
parent
,
false
);
}
else
{
return
convertView
;
}
}
if
(
type
==
TYPE_HINT
)
{
View
view
=
convertView
;
if
(
convertView
==
null
)
{
view
=
activity
.
getLayoutInflater
().
inflate
(
R
.
layout
.
chat_viewer_info
,
parent
,
false
);
}
TextView
textView
=
((
TextView
)
view
.
findViewById
(
R
.
id
.
info
));
textView
.
setText
(
hint
);
textView
.
setTextAppearance
(
activity
,
R
.
style
.
ChatInfo_Warning
);
return
view
;
}
if
(
type
!=
TYPE_MESSAGE
)
{
throw
new
IllegalStateException
();
}
final
MessageItem
messageItem
=
(
MessageItem
)
getItem
(
position
);
final
String
name
;
final
boolean
incoming
=
((
MessageItem
)
getItem
(
position
)).
isIncoming
()
;
final
String
account
=
messageItem
.
getChat
().
getAccount
();
final
String
user
=
messageItem
.
getChat
().
getUser
();
final
String
resource
=
messageItem
.
getResource
();
final
boolean
incoming
=
messageItem
.
isIncoming
();
if
(
isMUC
)
{
name
=
resource
;
final
int
layoutId
;
if
(
incoming
)
{
layoutId
=
R
.
layout
.
chat_viewer_message
;
}
else
{
if
(
incoming
)
{
name
=
RosterManager
.
getInstance
().
getName
(
account
,
user
);
}
else
{
name
=
AccountManager
.
getInstance
().
getNickName
(
account
);
}
layoutId
=
R
.
layout
.
chat_viewer_message_own
;
}
View
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
((
TextView
)
view
.
findViewById
(
R
.
id
.
text
)).
setTextAppearance
(
activity
,
appearanceStyle
);
if
(
incoming
)
{
if
(
view
.
getBackground
()
==
null
)
{
view
.
setBackgroundResource
(
R
.
drawable
.
chat_bg
);
}
view
.
getBackground
().
setLevel
(
AccountManager
.
getInstance
().
getColorLevel
(
account
));
}
else
{
view
.
setBackgroundDrawable
(
null
);
view
.
findViewById
(
R
.
id
.
text
).
setBackgroundResource
(
R
.
drawable
.
chat_bg
);
view
.
findViewById
(
R
.
id
.
text
).
getBackground
().
setLevel
(
AccountManager
.
getInstance
().
getColorLevel
(
account
));
}
Spannable
text
=
messageItem
.
getSpannable
();
...
...
@@ -223,7 +208,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
append
(
builder
,
" "
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
append
(
builder
,
time
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Time
));
append
(
builder
,
" "
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
append
(
builder
,
name
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Name
));
if
(
isMUC
)
{
append
(
builder
,
resource
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Name
));
}
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
Date
timeStamp
=
messageItem
.
getDelayTimestamp
();
...
...
@@ -248,31 +235,32 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
}
else
{
append
(
builder
,
time
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Time
));
append
(
builder
,
" "
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
text
=
Emoticons
.
newSpannable
(
action
.
getText
(
activity
,
nam
e
,
text
.
toString
()));
text
=
Emoticons
.
newSpannable
(
action
.
getText
(
activity
,
resourc
e
,
text
.
toString
()));
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
append
(
builder
,
text
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
}
textView
.
setText
(
builder
);
textView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
if
(
SettingsManager
.
chatsShowAvatars
())
{
avatarView
.
setVisibility
(
View
.
VISIBLE
);
if
(!
incoming
||
(
isMUC
&&
MUCManager
.
getInstance
().
getNickname
(
account
,
user
).
equalsIgnoreCase
(
resource
)))
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getAccountAvatar
(
account
));
}
else
{
if
(
isMUC
)
{
if
(
""
.
equals
(
resource
))
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getRoomAvatar
(
user
));
if
(
incoming
)
{
if
(
SettingsManager
.
chatsShowAvatars
())
{
avatarView
.
setVisibility
(
View
.
VISIBLE
);
if
((
isMUC
&&
MUCManager
.
getInstance
().
getNickname
(
account
,
user
).
equalsIgnoreCase
(
resource
)))
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getAccountAvatar
(
account
));
}
else
{
if
(
isMUC
)
{
if
(
""
.
equals
(
resource
))
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getRoomAvatar
(
user
));
}
else
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getOccupantAvatar
(
user
+
"/"
+
resource
));
}
}
else
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
get
OccupantAvatar
(
user
+
"/"
+
resource
));
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
get
UserAvatar
(
user
));
}
}
else
{
avatarView
.
setImageDrawable
(
AvatarManager
.
getInstance
().
getUserAvatar
(
user
));
}
}
else
{
avatarView
.
setVisibility
(
View
.
GONE
);
}
((
RelativeLayout
.
LayoutParams
)
textView
.
getLayoutParams
()).
addRule
(
RelativeLayout
.
RIGHT_OF
,
R
.
id
.
avatar
);
}
else
{
avatarView
.
setVisibility
(
View
.
GONE
);
((
RelativeLayout
.
LayoutParams
)
textView
.
getLayoutParams
()).
addRule
(
RelativeLayout
.
RIGHT_OF
,
0
);
}
return
view
;
}
...
...
app/src/main/res/layout/chat_viewer_item.xml
View file @
1a820d39
...
...
@@ -32,6 +32,8 @@
android:stackFromBottom=
"true"
android:transcriptMode=
"normal"
android:smoothScrollbar=
"false"
android:divider=
"@null"
android:dividerHeight=
"0dp"
/>
<TextView
android:id=
"@+id/chat_page"
...
...
app/src/main/res/layout/chat_viewer_message.xml
View file @
1a820d39
...
...
@@ -14,19 +14,22 @@
-->
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/
background
"
android:id=
"@+id/
chat_message_incoming
"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingRight=
"4dip"
android:paddingBottom=
"4dip"
android:background=
"@drawable/chat_bg"
>
>
<ImageView
android:id=
"@+id/avatar"
android:layout_width=
"32dip"
android:layout_height=
"32dip"
android:layout_marginLeft=
"4dip"
android:src=
"@drawable/avatar_1_1"
android:layout_marginTop=
"4dp"
android:layout_marginBottom=
"4dp"
/>
<TextView
...
...
@@ -34,7 +37,20 @@
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_toRightOf=
"@id/avatar"
android:paddingLeft=
"4dip"
android:layout_toEndOf=
"@id/avatar"
android:padding=
"4dp"
android:layout_marginRight=
"48dp"
android:layout_marginEnd=
"48dp"
android:layout_marginTop=
"4dp"
android:layout_marginBottom=
"4dp"
android:layout_marginStart=
"4dp"
android:layout_marginLeft=
"4dp"
android:text=
"Some text\n line \nrgregrere"
android:background=
"@drawable/chat_bg"
/>
</RelativeLayout>
app/src/main/res/layout/chat_viewer_message_own.xml
0 → 100644
View file @
1a820d39
<?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/.
-->
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/chat_message_incoming"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
>
<TextView
android:id=
"@+id/text"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:padding=
"4dp"
android:layout_marginLeft=
"48dp"
android:layout_marginStart=
"48dp"
android:layout_marginTop=
"4dp"
android:layout_marginBottom=
"4dp"
android:layout_marginEnd=
"4dp"
android:layout_marginRight=
"4dp"
android:text=
"Some text\n line \nrgregrere"
android:background=
"@color/grey_600"
android:gravity=
"end"
android:layout_alignParentTop=
"true"
android:layout_alignParentRight=
"true"
android:layout_alignParentEnd=
"true"
/>
</RelativeLayout>
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