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
f6e4a957
Commit
f6e4a957
authored
Feb 26, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ChatViewerFragment: message context menu called on short click also.
parent
df2dd03e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
19 deletions
+26
-19
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+23
-14
ChatMessageAdapter.java
...ava/com/xabber/android/ui/adapter/ChatMessageAdapter.java
+3
-5
No files found.
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
f6e4a957
...
@@ -31,7 +31,7 @@ import com.xabber.android.data.message.chat.ChatManager;
...
@@ -31,7 +31,7 @@ import com.xabber.android.data.message.chat.ChatManager;
import
com.xabber.android.ui.adapter.ChatMessageAdapter
;
import
com.xabber.android.ui.adapter.ChatMessageAdapter
;
import
com.xabber.androiddev.R
;
import
com.xabber.androiddev.R
;
public
class
ChatViewerFragment
extends
Fragment
{
public
class
ChatViewerFragment
extends
Fragment
implements
AdapterView
.
OnItemClickListener
{
public
static
final
String
ARGUMENT_ACCOUNT
=
"ARGUMENT_ACCOUNT"
;
public
static
final
String
ARGUMENT_ACCOUNT
=
"ARGUMENT_ACCOUNT"
;
public
static
final
String
ARGUMENT_USER
=
"ARGUMENT_USER"
;
public
static
final
String
ARGUMENT_USER
=
"ARGUMENT_USER"
;
...
@@ -74,6 +74,7 @@ public class ChatViewerFragment extends Fragment {
...
@@ -74,6 +74,7 @@ public class ChatViewerFragment extends Fragment {
listView
=
(
ListView
)
view
.
findViewById
(
android
.
R
.
id
.
list
);
listView
=
(
ListView
)
view
.
findViewById
(
android
.
R
.
id
.
list
);
listView
.
setAdapter
(
chatMessageAdapter
);
listView
.
setAdapter
(
chatMessageAdapter
);
listView
.
setOnItemClickListener
(
this
);
ColorDrawable
background
=
new
ColorDrawable
(
getActivity
().
getResources
().
getIntArray
(
ColorDrawable
background
=
new
ColorDrawable
(
getActivity
().
getResources
().
getIntArray
(
R
.
array
.
account_chat_background
)[
AccountManager
.
getInstance
().
getColorLevel
(
account
)]);
R
.
array
.
account_chat_background
)[
AccountManager
.
getInstance
().
getColorLevel
(
account
)]);
...
@@ -132,8 +133,9 @@ public class ChatViewerFragment extends Fragment {
...
@@ -132,8 +133,9 @@ public class ChatViewerFragment extends Fragment {
@Override
@Override
public
void
afterTextChanged
(
Editable
text
)
{
public
void
afterTextChanged
(
Editable
text
)
{
if
(
skipOnTextChanges
)
if
(
skipOnTextChanges
)
{
return
;
return
;
}
ChatStateManager
.
getInstance
().
onComposing
(
account
,
user
,
text
);
ChatStateManager
.
getInstance
().
onComposing
(
account
,
user
,
text
);
}
}
...
@@ -147,15 +149,11 @@ public class ChatViewerFragment extends Fragment {
...
@@ -147,15 +149,11 @@ public class ChatViewerFragment extends Fragment {
@Override
@Override
public
void
onResume
()
{
public
void
onResume
()
{
super
.
onResume
();
super
.
onResume
();
((
ChatViewer
)
getActivity
()).
registerChat
(
this
);
((
ChatViewer
)
getActivity
()).
registerChat
(
this
);
registerForContextMenu
(
listView
);
restoreInputState
();
restoreInputState
();
}
}
p
rivate
void
restoreInputState
()
{
p
ublic
void
restoreInputState
()
{
skipOnTextChanges
=
true
;
skipOnTextChanges
=
true
;
inputView
.
setText
(
ChatManager
.
getInstance
().
getTypedMessage
(
account
,
user
));
inputView
.
setText
(
ChatManager
.
getInstance
().
getTypedMessage
(
account
,
user
));
...
@@ -163,22 +161,24 @@ public class ChatViewerFragment extends Fragment {
...
@@ -163,22 +161,24 @@ public class ChatViewerFragment extends Fragment {
ChatManager
.
getInstance
().
getSelectionEnd
(
account
,
user
));
ChatManager
.
getInstance
().
getSelectionEnd
(
account
,
user
));
skipOnTextChanges
=
false
;
skipOnTextChanges
=
false
;
if
(!
inputView
.
getText
().
toString
().
isEmpty
())
{
inputView
.
requestFocus
();
}
}
}
@Override
@Override
public
void
onPause
()
{
public
void
onPause
()
{
super
.
onPause
();
super
.
onPause
();
saveInputState
();
saveInputState
();
((
ChatViewer
)
getActivity
()).
unregisterChat
(
this
);
((
ChatViewer
)
getActivity
()).
unregisterChat
(
this
);
unregisterForContextMenu
(
listView
);
}
}
public
void
saveInputState
()
{
public
void
saveInputState
()
{
ChatManager
.
getInstance
().
setTyped
(
account
,
user
,
inputView
.
getText
().
toString
(),
ChatManager
.
getInstance
().
setTyped
(
account
,
user
,
inputView
.
getText
().
toString
(),
inputView
.
getSelectionStart
(),
inputView
.
getSelectionEnd
());
inputView
.
getSelectionStart
(),
inputView
.
getSelectionEnd
());
inputView
.
clearFocus
();
}
}
private
void
sendMessage
()
{
private
void
sendMessage
()
{
...
@@ -281,14 +281,16 @@ public class ChatViewerFragment extends Fragment {
...
@@ -281,14 +281,16 @@ public class ChatViewerFragment extends Fragment {
public
void
setInputText
(
String
additional
)
{
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
)
{
selection
=
source
.
length
();
selection
=
source
.
length
();
else
if
(
selection
>
source
.
length
())
}
else
if
(
selection
>
source
.
length
())
{
selection
=
source
.
length
();
selection
=
source
.
length
();
}
String
before
=
source
.
substring
(
0
,
selection
);
String
before
=
source
.
substring
(
0
,
selection
);
String
after
=
source
.
substring
(
selection
);
String
after
=
source
.
substring
(
selection
);
if
(
before
.
length
()
>
0
&&
!
before
.
endsWith
(
"\n"
))
if
(
before
.
length
()
>
0
&&
!
before
.
endsWith
(
"\n"
))
{
additional
=
"\n"
+
additional
;
additional
=
"\n"
+
additional
;
}
inputView
.
setText
(
before
+
additional
+
after
);
inputView
.
setText
(
before
+
additional
+
after
);
inputView
.
setSelection
(
selection
+
additional
.
length
());
inputView
.
setSelection
(
selection
+
additional
.
length
());
}
}
...
@@ -311,4 +313,11 @@ public class ChatViewerFragment extends Fragment {
...
@@ -311,4 +313,11 @@ public class ChatViewerFragment extends Fragment {
listView
.
setSelection
(
size
-
1
);
listView
.
setSelection
(
size
-
1
);
}
}
}
}
@Override
public
void
onItemClick
(
AdapterView
<?>
parent
,
View
view
,
int
position
,
long
id
)
{
registerForContextMenu
(
listView
);
listView
.
showContextMenuForChild
(
view
);
unregisterForContextMenu
(
listView
);
}
}
}
app/src/main/java/com/xabber/android/ui/adapter/ChatMessageAdapter.java
View file @
f6e4a957
...
@@ -17,7 +17,6 @@ package com.xabber.android.ui.adapter;
...
@@ -17,7 +17,6 @@ package com.xabber.android.ui.adapter;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.text.Spannable
;
import
android.text.Spannable
;
import
android.text.SpannableStringBuilder
;
import
android.text.SpannableStringBuilder
;
import
android.text.method.LinkMovementMethod
;
import
android.text.style.CharacterStyle
;
import
android.text.style.CharacterStyle
;
import
android.text.style.TextAppearanceSpan
;
import
android.text.style.TextAppearanceSpan
;
import
android.view.View
;
import
android.view.View
;
...
@@ -200,10 +199,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -200,10 +199,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
view
=
activity
.
getLayoutInflater
().
inflate
(
layoutId
,
parent
,
false
);
}
}
return
setUpMessageView
(
messageItem
,
view
);
setUpMessageView
(
messageItem
,
view
);
return
view
;
}
}
private
View
setUpMessageView
(
MessageItem
messageItem
,
View
view
)
{
private
void
setUpMessageView
(
MessageItem
messageItem
,
View
view
)
{
final
boolean
incoming
=
messageItem
.
isIncoming
();
final
boolean
incoming
=
messageItem
.
isIncoming
();
...
@@ -240,7 +240,6 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -240,7 +240,6 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
textView
.
setTextAppearance
(
activity
,
appearanceStyle
);
textView
.
setTextAppearance
(
activity
,
appearanceStyle
);
textView
.
getBackground
().
setAlpha
(
127
);
textView
.
getBackground
().
setAlpha
(
127
);
textView
.
setText
(
builder
);
textView
.
setText
(
builder
);
textView
.
setMovementMethod
(
LinkMovementMethod
.
getInstance
());
String
time
=
StringUtils
.
getSmartTimeText
(
activity
,
messageItem
.
getTimestamp
());
String
time
=
StringUtils
.
getSmartTimeText
(
activity
,
messageItem
.
getTimestamp
());
...
@@ -255,7 +254,6 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
...
@@ -255,7 +254,6 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
if
(
incoming
)
{
if
(
incoming
)
{
setUpAvatar
(
messageItem
,
view
);
setUpAvatar
(
messageItem
,
view
);
}
}
return
view
;
}
}
private
void
setStatusIcon
(
MessageItem
messageItem
,
View
view
)
{
private
void
setStatusIcon
(
MessageItem
messageItem
,
View
view
)
{
...
...
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