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
Show 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 {
...
@@ -139,10 +139,7 @@ public class ChatViewerFragment extends Fragment {
});
});
updateView
();
updateChat
();
chatMessageAdapter
.
onChange
();
return
view
;
return
view
;
}
}
...
@@ -222,25 +219,27 @@ public class ChatViewerFragment extends Fragment {
...
@@ -222,25 +219,27 @@ public class ChatViewerFragment extends Fragment {
updateChat
();
updateChat
();
}
}
private
void
updateView
()
{
chatMessageAdapter
.
onChange
();
}
@Override
@Override
public
void
onCreateContextMenu
(
ContextMenu
menu
,
View
view
,
public
void
onCreateContextMenu
(
ContextMenu
menu
,
View
view
,
ContextMenu
.
ContextMenuInfo
menuInfo
)
{
ContextMenu
.
ContextMenuInfo
menuInfo
)
{
super
.
onCreateContextMenu
(
menu
,
view
,
menuInfo
);
super
.
onCreateContextMenu
(
menu
,
view
,
menuInfo
);
AdapterView
.
AdapterContextMenuInfo
info
=
(
AdapterView
.
AdapterContextMenuInfo
)
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
);
if
(
itemViewType
==
ChatMessageAdapter
.
VIEW_TYPE_INCOMING_MESSAGE
||
itemViewType
==
ChatMessageAdapter
.
VIEW_TYPE_OUTGOING_MESSAGE
)
{
MenuInflater
inflater
=
getActivity
().
getMenuInflater
();
MenuInflater
inflater
=
getActivity
().
getMenuInflater
();
inflater
.
inflate
(
R
.
menu
.
chat_context_menu
,
menu
);
inflater
.
inflate
(
R
.
menu
.
chat_context_menu
,
menu
);
if
(
message
.
isError
())
{
if
(((
MessageItem
)
chatMessageAdapter
.
getItem
(
info
.
position
))
.
isError
())
{
menu
.
findItem
(
R
.
id
.
action_message_repeat
).
setVisible
(
true
);
menu
.
findItem
(
R
.
id
.
action_message_repeat
).
setVisible
(
true
);
}
}
}
}
}
@Override
@Override
public
boolean
onContextItemSelected
(
MenuItem
item
)
{
public
boolean
onContextItemSelected
(
MenuItem
item
)
{
...
@@ -258,7 +257,7 @@ public class ChatViewerFragment extends Fragment {
...
@@ -258,7 +257,7 @@ public class ChatViewerFragment extends Fragment {
return
true
;
return
true
;
case
R
.
id
.
action_message_quote
:
case
R
.
id
.
action_message_quote
:
inser
tText
(
"> "
+
message
.
getText
()
+
"\n"
);
setInpu
tText
(
"> "
+
message
.
getText
()
+
"\n"
);
return
true
;
return
true
;
case
R
.
id
.
action_message_remove
:
case
R
.
id
.
action_message_remove
:
...
@@ -271,12 +270,15 @@ public class ChatViewerFragment extends Fragment {
...
@@ -271,12 +270,15 @@ public class ChatViewerFragment extends Fragment {
}
}
}
}
/**
public
void
updateChat
()
{
* Insert additional text to the input.
chatMessageAdapter
.
onChange
();
*
}
* @param additional
*/
public
boolean
isEqual
(
String
account
,
String
user
)
{
private
void
insertText
(
String
additional
)
{
return
this
.
account
.
equals
(
account
)
&&
this
.
user
.
equals
(
user
);
}
public
void
setInputText
(
String
additional
)
{
String
source
=
inputView
.
getText
().
toString
();
String
source
=
inputView
.
getText
().
toString
();
int
selection
=
inputView
.
getSelectionEnd
();
int
selection
=
inputView
.
getSelectionEnd
();
if
(
selection
==
-
1
)
if
(
selection
==
-
1
)
...
@@ -291,18 +293,6 @@ public class ChatViewerFragment extends Fragment {
...
@@ -291,18 +293,6 @@ public class ChatViewerFragment extends Fragment {
inputView
.
setSelection
(
selection
+
additional
.
length
());
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
()
{
public
String
getAccount
()
{
return
account
;
return
account
;
}
}
...
...
app/src/main/java/com/xabber/android/ui/adapter/ChatMessageAdapter.java
View file @
08d03ebb
...
@@ -54,12 +54,13 @@ import java.util.List;
...
@@ -54,12 +54,13 @@ import java.util.List;
*/
*/
public
class
ChatMessageAdapter
extends
BaseAdapter
implements
UpdatableAdapter
{
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_EMPTY
=
0
;
private
static
final
int
VIEW_TYPE_HINT
=
1
;
private
static
final
int
VIEW_TYPE_HINT
=
1
;
private
static
final
int
VIEW_TYPE_INCOMING_MESSAGE
=
2
;
public
static
final
int
VIEW_TYPE_INCOMING_MESSAGE
=
2
;
private
static
final
int
VIEW_TYPE_OUTGOING_MESSAGE
=
3
;
public
static
final
int
VIEW_TYPE_OUTGOING_MESSAGE
=
3
;
private
static
final
int
VIEW_TYPE_ACTION_MESSAGE
=
4
;
private
final
Activity
activity
;
private
final
Activity
activity
;
private
String
account
;
private
String
account
;
...
@@ -129,8 +130,12 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -129,8 +130,12 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
return
hint
==
null
?
VIEW_TYPE_EMPTY
:
VIEW_TYPE_HINT
;
return
hint
==
null
?
VIEW_TYPE_EMPTY
:
VIEW_TYPE_HINT
;
}
}
final
boolean
incoming
=
((
MessageItem
)
getItem
(
position
)).
isIncoming
();
MessageItem
messageItem
=
(
MessageItem
)
getItem
(
position
);
return
incoming
?
VIEW_TYPE_INCOMING_MESSAGE
:
VIEW_TYPE_OUTGOING_MESSAGE
;
if
(
messageItem
.
getAction
()
!=
null
)
{
return
VIEW_TYPE_ACTION_MESSAGE
;
}
return
messageItem
.
isIncoming
()
?
VIEW_TYPE_INCOMING_MESSAGE
:
VIEW_TYPE_OUTGOING_MESSAGE
;
}
}
@Override
@Override
...
@@ -157,6 +162,28 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -157,6 +162,28 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
return
view
;
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
;
View
view
=
convertView
;
if
(
convertView
==
null
)
{
if
(
convertView
==
null
)
{
...
@@ -173,19 +200,16 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -173,19 +200,16 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
}
}
return
setUpMessageView
(
(
MessageItem
)
getItem
(
position
)
,
view
);
return
setUpMessageView
(
messageItem
,
view
);
}
}
private
View
setUpMessageView
(
MessageItem
messageItem
,
View
view
)
{
private
View
setUpMessageView
(
MessageItem
messageItem
,
View
view
)
{
final
boolean
incoming
=
messageItem
.
isIncoming
();
final
boolean
incoming
=
messageItem
.
isIncoming
();
ChatAction
action
=
messageItem
.
getAction
();
Spannable
text
=
messageItem
.
getSpannable
();
SpannableStringBuilder
builder
=
new
SpannableStringBuilder
();
SpannableStringBuilder
builder
=
new
SpannableStringBuilder
();
final
String
resource
=
messageItem
.
getResource
();
final
String
resource
=
messageItem
.
getResource
();
if
(
action
==
null
)
{
if
(!
incoming
)
{
if
(!
incoming
)
{
setStatusIcon
(
messageItem
,
view
);
setStatusIcon
(
messageItem
,
view
);
}
}
...
@@ -195,11 +219,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -195,11 +219,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
}
Date
timeS
tamp
=
messageItem
.
getDelayTimestamp
();
Date
delayTimes
tamp
=
messageItem
.
getDelayTimestamp
();
if
(
timeS
tamp
!=
null
)
{
if
(
delayTimes
tamp
!=
null
)
{
String
delay
=
activity
.
getString
(
incoming
?
R
.
string
.
chat_delay
:
R
.
string
.
chat_typed
,
String
delay
=
activity
.
getString
(
incoming
?
R
.
string
.
chat_delay
:
R
.
string
.
chat_typed
,
StringUtils
.
getSmartTimeText
(
activity
,
timeS
tamp
));
StringUtils
.
getSmartTimeText
(
activity
,
delayTimes
tamp
));
append
(
builder
,
delay
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
delay
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
}
...
@@ -209,16 +233,14 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -209,16 +233,14 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader_Delay
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
append
(
builder
,
divider
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatHeader
));
}
}
Spannable
text
=
messageItem
.
getSpannable
();
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
if
(
messageItem
.
getTag
()
==
null
)
{
if
(
messageItem
.
getTag
()
==
null
)
{
builder
.
append
(
text
);
builder
.
append
(
text
);
}
else
{
}
else
{
append
(
builder
,
text
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatRead
));
append
(
builder
,
text
,
new
TextAppearanceSpan
(
activity
,
R
.
style
.
ChatRead
));
}
}
}
else
{
text
=
Emoticons
.
newSpannable
(
action
.
getText
(
activity
,
resource
,
text
.
toString
()));
Emoticons
.
getSmiledText
(
activity
.
getApplication
(),
text
);
}
TextView
textView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
message_text
);
TextView
textView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
message_text
);
textView
.
setTextAppearance
(
activity
,
appearanceStyle
);
textView
.
setTextAppearance
(
activity
,
appearanceStyle
);
...
...
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 @@
...
@@ -30,6 +30,7 @@
android:dividerHeight=
"0dp"
android:dividerHeight=
"0dp"
android:layout_above=
"@+id/chat_input"
android:layout_above=
"@+id/chat_input"
tools:listitem=
"@layout/chat_viewer_outgoing_message"
tools:listitem=
"@layout/chat_viewer_outgoing_message"
android:listSelector=
"@android:color/transparent"
/>
/>
<EditText
<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