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
a405f276
Commit
a405f276
authored
Mar 02, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chat: work with input text simplified and refactored. Keyboard hided every chat change now.
parent
10a835c5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
84 deletions
+62
-84
ChatStateManager.java
...om/xabber/android/data/extension/cs/ChatStateManager.java
+15
-15
ComposingPausedReceiver.java
.../com/xabber/android/receiver/ComposingPausedReceiver.java
+1
-2
ChatViewer.java
app/src/main/java/com/xabber/android/ui/ChatViewer.java
+15
-7
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+25
-58
RecentChatFragment.java
...c/main/java/com/xabber/android/ui/RecentChatFragment.java
+2
-2
ChatViewerAdapter.java
...java/com/xabber/android/ui/adapter/ChatViewerAdapter.java
+4
-0
No files found.
app/src/main/java/com/xabber/android/data/extension/cs/ChatStateManager.java
View file @
a405f276
...
...
@@ -14,20 +14,6 @@
*/
package
com
.
xabber
.
android
.
data
.
extension
.
cs
;
import
java.util.Calendar
;
import
java.util.Map
;
import
org.jivesoftware.smack.Connection
;
import
org.jivesoftware.smack.ConnectionCreationListener
;
import
org.jivesoftware.smack.packet.Message
;
import
org.jivesoftware.smack.packet.Packet
;
import
org.jivesoftware.smack.packet.PacketExtension
;
import
org.jivesoftware.smack.packet.Presence
;
import
org.jivesoftware.smack.packet.Presence.Type
;
import
org.jivesoftware.smackx.ChatState
;
import
org.jivesoftware.smackx.ServiceDiscoveryManager
;
import
org.jivesoftware.smackx.packet.ChatStateExtension
;
import
android.app.AlarmManager
;
import
android.app.PendingIntent
;
import
android.content.Context
;
...
...
@@ -52,6 +38,20 @@ import com.xabber.android.data.roster.RosterManager;
import
com.xabber.android.receiver.ComposingPausedReceiver
;
import
com.xabber.xmpp.address.Jid
;
import
org.jivesoftware.smack.Connection
;
import
org.jivesoftware.smack.ConnectionCreationListener
;
import
org.jivesoftware.smack.packet.Message
;
import
org.jivesoftware.smack.packet.Packet
;
import
org.jivesoftware.smack.packet.PacketExtension
;
import
org.jivesoftware.smack.packet.Presence
;
import
org.jivesoftware.smack.packet.Presence.Type
;
import
org.jivesoftware.smackx.ChatState
;
import
org.jivesoftware.smackx.ServiceDiscoveryManager
;
import
org.jivesoftware.smackx.packet.ChatStateExtension
;
import
java.util.Calendar
;
import
java.util.Map
;
/**
* Provide information about chat state.
*
...
...
@@ -260,7 +260,7 @@ public class ChatStateManager implements OnDisconnectListener,
pauseIntents
.
put
(
account
,
user
,
pendingIntent
);
}
public
void
onPaused
(
Intent
intent
,
String
account
,
String
user
)
{
public
void
onPaused
(
String
account
,
String
user
)
{
if
(
account
==
null
||
user
==
null
)
return
;
updateChatState
(
account
,
user
,
ChatState
.
paused
);
...
...
app/src/main/java/com/xabber/android/receiver/ComposingPausedReceiver.java
View file @
a405f276
...
...
@@ -30,8 +30,7 @@ public class ComposingPausedReceiver extends BroadcastReceiver {
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
ChatStateManager
.
getInstance
().
onPaused
(
intent
,
getAccount
(
intent
),
getUser
(
intent
));
ChatStateManager
.
getInstance
().
onPaused
(
getAccount
(
intent
),
getUser
(
intent
));
}
public
static
Intent
createIntent
(
Context
context
,
String
account
,
...
...
app/src/main/java/com/xabber/android/ui/ChatViewer.java
View file @
a405f276
...
...
@@ -14,6 +14,7 @@
*/
package
com
.
xabber
.
android
.
ui
;
import
android.app.Activity
;
import
android.app.AlertDialog
;
import
android.app.Fragment
;
import
android.content.Context
;
...
...
@@ -24,6 +25,7 @@ import android.support.v4.view.ViewPager;
import
android.view.Menu
;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.ImageView
;
import
com.xabber.android.data.ActivityManager
;
...
...
@@ -390,7 +392,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private
void
cleatInputText
(
String
account
,
String
user
)
{
for
(
ChatViewerFragment
chat
:
registeredChats
)
{
if
(
chat
.
isEqual
(
account
,
user
))
{
chat
.
clearInput
View
();
chat
.
clearInput
Text
();
}
}
}
...
...
@@ -600,6 +602,8 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
public
void
onPageSelected
(
int
position
)
{
hideKeyboard
(
this
);
AbstractChat
selectedChat
=
chatViewerAdapter
.
getChatByPageNumber
(
position
);
isChatSelected
=
selectedChat
!=
null
;
...
...
@@ -694,11 +698,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
Fragment
currentFragment
=
chatViewerAdapter
.
getCurrentFragment
();
if
(
isChatSelected
)
{
if
(!(
currentFragment
instanceof
ChatViewerFragment
))
{
AlertDialog
.
Builder
builder
=
new
AlertDialog
.
Builder
(
this
);
...
...
@@ -762,7 +761,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
}
@Override
public
void
on
Recent
ChatSelected
(
AbstractChat
chat
)
{
public
void
onChatSelected
(
AbstractChat
chat
)
{
selectPage
(
chat
.
getAccount
(),
chat
.
getUser
(),
true
);
}
...
...
@@ -773,4 +772,13 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
public
ChatViewerAdapter
getChatViewerAdapter
()
{
return
chatViewerAdapter
;
}
public
static
void
hideKeyboard
(
Activity
activity
)
{
// Check if no view has focus:
View
view
=
activity
.
getCurrentFocus
();
if
(
view
!=
null
)
{
InputMethodManager
inputManager
=
(
InputMethodManager
)
activity
.
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
inputManager
.
hideSoftInputFromWindow
(
view
.
getWindowToken
(),
InputMethodManager
.
HIDE_NOT_ALWAYS
);
}
}
}
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
a405f276
...
...
@@ -14,14 +14,12 @@ import android.view.MenuInflater;
import
android.view.MenuItem
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.inputmethod.EditorInfo
;
import
android.view.inputmethod.InputMethodManager
;
import
android.widget.AdapterView
;
import
android.widget.EditText
;
import
android.widget.ImageButton
;
import
android.widget.ListView
;
import
android.widget.TextView
;
import
com.xabber.android.data.LogManager
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.account.AccountManager
;
import
com.xabber.android.data.extension.cs.ChatStateManager
;
...
...
@@ -96,32 +94,27 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
});
inputView
.
setOnKeyListener
(
new
View
.
OnKeyListener
()
{
@Override
public
boolean
onKey
(
View
view
,
int
keyCode
,
KeyEvent
event
)
{
if
(
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
&&
keyCode
==
KeyEvent
.
KEYCODE_ENTER
&&
SettingsManager
.
chatsSendByEnter
()
)
{
if
(
SettingsManager
.
chatsSendByEnter
()
&&
event
.
getAction
()
==
KeyEvent
.
ACTION_DOWN
&&
keyCode
==
KeyEvent
.
KEYCODE_ENTER
)
{
sendMessage
();
return
true
;
}
return
false
;
}
});
inputView
.
setOnEditorActionListener
(
new
TextView
.
OnEditorActionListener
()
{
inputView
.
setOnFocusChangeListener
(
new
View
.
OnFocusChangeListener
()
{
@Override
public
boolean
onEditorAction
(
TextView
view
,
int
actionId
,
KeyEvent
event
)
{
if
(
actionId
==
EditorInfo
.
IME_ACTION_SEND
)
{
sendMessage
();
return
true
;
public
void
onFocusChange
(
View
v
,
boolean
hasFocus
)
{
if
(!
hasFocus
)
{
ChatStateManager
.
getInstance
().
onPaused
(
account
,
user
);
}
return
false
;
}
});
inputView
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
...
...
@@ -134,12 +127,13 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
@Override
public
void
afterTextChanged
(
Editable
text
)
{
if
(
skipOnTextChanges
)
{
return
;
}
ChatStateManager
.
getInstance
().
onComposing
(
account
,
user
,
text
);
LogManager
.
i
(
this
,
"afterTextChanged"
);
setSendButtonColor
();
if
(!
skipOnTextChanges
)
{
ChatStateManager
.
getInstance
().
onComposing
(
account
,
user
,
text
);
}
}
});
...
...
@@ -178,7 +172,6 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
inputView
.
setText
(
ChatManager
.
getInstance
().
getTypedMessage
(
account
,
user
));
inputView
.
setSelection
(
ChatManager
.
getInstance
().
getSelectionStart
(
account
,
user
),
ChatManager
.
getInstance
().
getSelectionEnd
(
account
,
user
));
setSendButtonColor
();
skipOnTextChanges
=
false
;
...
...
@@ -197,31 +190,16 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
public
void
saveInputState
()
{
ChatManager
.
getInstance
().
setTyped
(
account
,
user
,
inputView
.
getText
().
toString
(),
inputView
.
getSelectionStart
(),
inputView
.
getSelectionEnd
());
inputView
.
clearFocus
();
}
private
void
sendMessage
()
{
String
text
=
inputView
.
getText
().
toString
();
int
start
=
0
;
int
end
=
text
.
length
();
while
(
start
<
end
&&
(
text
.
charAt
(
start
)
==
' '
||
text
.
charAt
(
start
)
==
'\n'
))
{
start
+=
1
;
}
while
(
start
<
end
&&
(
text
.
charAt
(
end
-
1
)
==
' '
||
text
.
charAt
(
end
-
1
)
==
'\n'
))
{
end
-=
1
;
}
text
=
text
.
substring
(
start
,
end
);
String
text
=
inputView
.
getText
().
toString
().
trim
();
if
(
""
.
equals
(
text
))
{
if
(
text
.
isEmpty
(
))
{
return
;
}
skipOnTextChanges
=
true
;
inputView
.
getText
().
clear
();
setSendButtonColor
();
skipOnTextChanges
=
false
;
clearInputText
();
sendMessage
(
text
);
...
...
@@ -230,8 +208,7 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
if
(
SettingsManager
.
chatsHideKeyboard
()
==
SettingsManager
.
ChatsHideKeyboard
.
always
||
(
getActivity
().
getResources
().
getBoolean
(
R
.
bool
.
landscape
)
&&
SettingsManager
.
chatsHideKeyboard
()
==
SettingsManager
.
ChatsHideKeyboard
.
landscape
))
{
InputMethodManager
imm
=
(
InputMethodManager
)
getActivity
().
getSystemService
(
Context
.
INPUT_METHOD_SERVICE
);
imm
.
hideSoftInputFromWindow
(
inputView
.
getWindowToken
(),
0
);
ChatViewer
.
hideKeyboard
(
getActivity
());
}
}
...
...
@@ -300,22 +277,10 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
}
public
void
setInputText
(
String
additional
)
{
String
source
=
inputView
.
getText
().
toString
();
int
selection
=
inputView
.
getSelectionEnd
();
if
(
selection
==
-
1
)
{
selection
=
source
.
length
();
}
else
if
(
selection
>
source
.
length
())
{
selection
=
source
.
length
();
}
String
before
=
source
.
substring
(
0
,
selection
);
String
after
=
source
.
substring
(
selection
);
if
(
before
.
length
()
>
0
&&
!
before
.
endsWith
(
"\n"
))
{
additional
=
"\n"
+
additional
;
}
inputView
.
setText
(
before
+
additional
+
after
);
inputView
.
setSelection
(
selection
+
additional
.
length
());
setSendButtonColor
();
skipOnTextChanges
=
true
;
inputView
.
setText
(
additional
);
inputView
.
setSelection
(
additional
.
length
());
skipOnTextChanges
=
false
;
}
public
String
getAccount
()
{
...
...
@@ -326,8 +291,10 @@ public class ChatViewerFragment extends Fragment implements AdapterView.OnItemCl
return
user
;
}
public
void
clearInputView
()
{
public
void
clearInputText
()
{
skipOnTextChanges
=
true
;
inputView
.
getText
().
clear
();
skipOnTextChanges
=
false
;
}
public
void
scrollChat
()
{
...
...
app/src/main/java/com/xabber/android/ui/RecentChatFragment.java
View file @
a405f276
...
...
@@ -92,12 +92,12 @@ public class RecentChatFragment extends ListFragment {
super
.
onListItemClick
(
l
,
v
,
position
,
id
);
if
(
null
!=
listener
)
{
listener
.
on
Recent
ChatSelected
((
AbstractChat
)
getListAdapter
().
getItem
(
position
));
listener
.
onChatSelected
((
AbstractChat
)
getListAdapter
().
getItem
(
position
));
}
}
public
interface
RecentChatFragmentInteractionListener
{
public
void
on
Recent
ChatSelected
(
AbstractChat
chat
);
public
void
onChatSelected
(
AbstractChat
chat
);
}
public
void
updateChats
(
List
<
AbstractChat
>
chats
)
{
...
...
app/src/main/java/com/xabber/android/ui/adapter/ChatViewerAdapter.java
View file @
a405f276
...
...
@@ -184,6 +184,10 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter {
public
void
setPrimaryItem
(
ViewGroup
container
,
int
position
,
Object
object
)
{
super
.
setPrimaryItem
(
container
,
position
,
object
);
if
(
currentFragment
instanceof
ChatViewerFragment
)
{
((
ChatViewerFragment
)
currentFragment
).
saveInputState
();
}
currentFragment
=
(
Fragment
)
object
;
}
...
...
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