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
08d03ebb
Commit
08d03ebb
authored
Feb 25, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ChatMessageAdapter: action message extracted to separate layout.
ChatViewerFragment: context menu fixed.
parent
c8f653e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
100 additions
and
68 deletions
+100
-68
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+22
-32
ChatMessageAdapter.java
...ava/com/xabber/android/ui/adapter/ChatMessageAdapter.java
+58
-36
chat_viewer_action_message.xml
app/src/main/res/layout/chat_viewer_action_message.xml
+19
-0
chat_viewer_item.xml
app/src/main/res/layout/chat_viewer_item.xml
+1
-0
No files found.
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
08d03ebb
...
...
@@ -139,10 +139,7 @@ public class ChatViewerFragment extends Fragment {
});
updateView
();
chatMessageAdapter
.
onChange
();
updateChat
();
return
view
;
}
...
...
@@ -222,23 +219,25 @@ public class ChatViewerFragment extends Fragment {
updateChat
();
}
private
void
updateView
()
{
chatMessageAdapter
.
onChange
();
}
@Override
public
void
onCreateContextMenu
(
ContextMenu
menu
,
View
view
,
ContextMenu
.
ContextMenuInfo
menuInfo
)
{
super
.
onCreateContextMenu
(
menu
,
view
,
menuInfo
);
AdapterView
.
AdapterContextMenuInfo
info
=
(
AdapterView
.
AdapterContextMenuInfo
)
menuInfo
;
final
MessageItem
message
=
(
MessageItem
)
listView
.
getAdapter
().
getItem
(
info
.
position
);
ChatMessageAdapter
chatMessageAdapter
=
(
ChatMessageAdapter
)
listView
.
getAdapter
();
int
itemViewType
=
chatMessageAdapter
.
getItemViewType
(
info
.
position
);
MenuInflater
inflater
=
getActivity
().
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
chat_context_menu
,
menu
);
if
(
itemViewType
==
ChatMessageAdapter
.
VIEW_TYPE_INCOMING_MESSAGE
||
itemViewType
==
ChatMessageAdapter
.
VIEW_TYPE_OUTGOING_MESSAGE
)
{
if
(
message
.
isError
())
{
menu
.
findItem
(
R
.
id
.
action_message_repeat
).
setVisible
(
true
);
MenuInflater
inflater
=
getActivity
().
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
chat_context_menu
,
menu
);
if
(((
MessageItem
)
chatMessageAdapter
.
getItem
(
info
.
position
)).
isError
())
{
menu
.
findItem
(
R
.
id
.
action_message_repeat
).
setVisible
(
true
);
}
}
}
...
...
@@ -258,7 +257,7 @@ public class ChatViewerFragment extends Fragment {
return
true
;
case
R
.
id
.
action_message_quote
:
inser
tText
(
"> "
+
message
.
getText
()
+
"\n"
);
setInpu
tText
(
"> "
+
message
.
getText
()
+
"\n"
);
return
true
;
case
R
.
id
.
action_message_remove
:
...
...
@@ -271,12 +270,15 @@ public class ChatViewerFragment extends Fragment {
}
}
/**
* Insert additional text to the input.
*
* @param additional
*/
private
void
insertText
(
String
additional
)
{
public
void
updateChat
()
{
chatMessageAdapter
.
onChange
();
}
public
boolean
isEqual
(
String
account
,
String
user
)
{
return
this
.
account
.
equals
(
account
)
&&
this
.
user
.
equals
(
user
);
}
public
void
setInputText
(
String
additional
)
{
String
source
=
inputView
.
getText
().
toString
();
int
selection
=
inputView
.
getSelectionEnd
();
if
(
selection
==
-
1
)
...
...
@@ -291,18 +293,6 @@ public class ChatViewerFragment extends Fragment {
inputView
.
setSelection
(
selection
+
additional
.
length
());
}
public
void
updateChat
()
{
updateView
();
}
public
boolean
isEqual
(
String
account
,
String
user
)
{
return
this
.
account
.
equals
(
account
)
&&
this
.
user
.
equals
(
user
);
}
public
void
setInputText
(
String
text
)
{
insertText
(
text
);
}
public
String
getAccount
()
{
return
account
;
}
...
...
app/src/main/java/com/xabber/android/ui/adapter/ChatMessageAdapter.java
View file @
08d03ebb
...
...
@@ -54,12 +54,13 @@ import java.util.List;
*/
public
class
ChatMessageAdapter
extends
BaseAdapter
implements
UpdatableAdapter
{
private
static
final
int
VIEW_TYPE_COUNT
=
4
;
private
static
final
int
VIEW_TYPE_COUNT
=
5
;
private
static
final
int
VIEW_TYPE_EMPTY
=
0
;
private
static
final
int
VIEW_TYPE_HINT
=
1
;
private
static
final
int
VIEW_TYPE_INCOMING_MESSAGE
=
2
;
private
static
final
int
VIEW_TYPE_OUTGOING_MESSAGE
=
3
;
public
static
final
int
VIEW_TYPE_INCOMING_MESSAGE
=
2
;
public
static
final
int
VIEW_TYPE_OUTGOING_MESSAGE
=
3
;
private
static
final
int
VIEW_TYPE_ACTION_MESSAGE
=
4
;
private
final
Activity
activity
;
private
String
account
;
...
...
@@ -129,8 +130,12 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
return
hint
==
null
?
VIEW_TYPE_EMPTY
:
VIEW_TYPE_HINT
;
}
final
boolean
incoming
=
((
MessageItem
)
getItem
(
position
)).
isIncoming
();
return
incoming
?
VIEW_TYPE_INCOMING_MESSAGE
:
VIEW_TYPE_OUTGOING_MESSAGE
;
MessageItem
messageItem
=
(
MessageItem
)
getItem
(
position
);
if
(
messageItem
.
getAction
()
!=
null
)
{
return
VIEW_TYPE_ACTION_MESSAGE
;
}
return
messageItem
.
isIncoming
()
?
VIEW_TYPE_INCOMING_MESSAGE
:
VIEW_TYPE_OUTGOING_MESSAGE
;
}
@Override
...
...
@@ -157,6 +162,28 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
return
view
;
}
MessageItem
messageItem
=
(
MessageItem
)
getItem
(
position
);
if
(
type
==
VIEW_TYPE_ACTION_MESSAGE
)
{
View
view
=
convertView
;
if
(
convertView
==
null
)
{
view
=
activity
.
getLayoutInflater
().
inflate
(
R
.
layout
.
chat_viewer_action_message
,
parent
,
false
);
}
ChatAction
action
=
messageItem
.
getAction
();
Spannable
text
=
Emoticons
.
newSpannable
(
action
.
getText
(
activity
,
messageItem
.
getResource
(),
messageItem
.
getSpannable
().
toString
()));
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
String
time
=
StringUtils
.
getSmartTimeText
(
activity
,
messageItem
.
getTimestamp
());
((
TextView
)
view
.
findViewById
(
R
.
id
.
action_message_text
)).
setText
(
time
+
": "
+
text
);
return
view
;
}
View
view
=
convertView
;
if
(
convertView
==
null
)
{
...
...
@@ -173,51 +200,46 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
}
return
setUpMessageView
(
(
MessageItem
)
getItem
(
position
)
,
view
);
return
setUpMessageView
(
messageItem
,
view
);
}
private
View
setUpMessageView
(
MessageItem
messageItem
,
View
view
)
{
final
boolean
incoming
=
messageItem
.
isIncoming
();
ChatAction
action
=
messageItem
.
getAction
();
Spannable
text
=
messageItem
.
getSpannable
();
SpannableStringBuilder
builder
=
new
SpannableStringBuilder
();
final
String
resource
=
messageItem
.
getResource
();
if
(
action
==
null
)
{
if
(!
incoming
)
{
setStatusIcon
(
messageItem
,
view
);
}
if
(!
incoming
)
{
setStatusIcon
(
messageItem
,
view
);
}
if
(
isMUC
)
{
append
(
builder
,
resource
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Name
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
if
(
isMUC
)
{
append
(
builder
,
resource
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Name
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
Date
delayTimestamp
=
messageItem
.
getDelayTimestamp
();
Date
timeStamp
=
messageItem
.
getDelayTimestamp
();
if
(
delayTimestamp
!=
null
)
{
String
delay
=
activity
.
getString
(
incoming
?
R
.
string
.
chat_delay
:
R
.
string
.
chat_typed
,
StringUtils
.
getSmartTimeText
(
activity
,
delayTimestamp
));
append
(
builder
,
delay
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
if
(
timeStamp
!=
null
)
{
String
delay
=
activity
.
getString
(
incoming
?
R
.
string
.
chat_delay
:
R
.
string
.
chat_typed
,
StringUtils
.
getSmartTimeText
(
activity
,
timeStamp
));
append
(
builder
,
delay
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
if
(
messageItem
.
isUnencypted
())
{
append
(
builder
,
activity
.
getString
(
R
.
string
.
otr_unencrypted_message
),
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
if
(
messageItem
.
isUnencypted
())
{
append
(
builder
,
activity
.
getString
(
R
.
string
.
otr_unencrypted_message
),
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
if
(
messageItem
.
getTag
()
==
null
)
{
builder
.
append
(
text
);
}
else
{
append
(
builder
,
text
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatRead
));
}
Spannable
text
=
messageItem
.
getSpannable
();
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
if
(
messageItem
.
getTag
()
==
null
)
{
builder
.
append
(
text
);
}
else
{
text
=
Emoticons
.
newSpannable
(
action
.
getText
(
activity
,
resource
,
text
.
toString
()));
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
append
(
builder
,
text
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatRead
));
}
TextView
textView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
message_text
);
...
...
app/src/main/res/layout/chat_viewer_action_message.xml
0 → 100644
View file @
08d03ebb
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:orientation=
"horizontal"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_gravity=
"center_horizontal"
android:gravity=
"center_horizontal"
>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:id=
"@+id/action_message_text"
android:textAppearance=
"@style/ChatHeader.Delay"
android:background=
"@color/blue_grey_500"
android:padding=
"6dp"
android:layout_margin=
"3dp"
android:text=
"Message"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/chat_viewer_item.xml
View file @
08d03ebb
...
...
@@ -30,6 +30,7 @@
android:dividerHeight=
"0dp"
android:layout_above=
"@+id/chat_input"
tools:listitem=
"@layout/chat_viewer_outgoing_message"
android:listSelector=
"@android:color/transparent"
/>
<EditText
...
...
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