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
f24bde0c
Commit
f24bde0c
authored
Jan 30, 2015
by
Grigory Fedorov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
View pager and FragmentStatePagerAdapter used to scroll active chats.
parent
68946a30
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
313 additions
and
174 deletions
+313
-174
build.gradle
app/build.gradle
+1
-0
ChatViewer.java
app/src/main/java/com/xabber/android/ui/ChatViewer.java
+109
-54
ChatViewerFragment.java
...c/main/java/com/xabber/android/ui/ChatViewerFragment.java
+80
-53
ChatMessageAdapter.java
...ava/com/xabber/android/ui/adapter/ChatMessageAdapter.java
+1
-2
ChatViewerAdapter.java
...java/com/xabber/android/ui/adapter/ChatViewerAdapter.java
+83
-0
ContactTitleInflater.java
...va/com/xabber/android/ui/helper/ContactTitleInflater.java
+31
-24
activity_chat_viewer.xml
app/src/main/res/layout/activity_chat_viewer.xml
+8
-0
chat_viewer.xml
app/src/main/res/layout/chat_viewer.xml
+0
-20
chat_viewer_container.xml
app/src/main/res/layout/chat_viewer_container.xml
+0
-21
No files found.
app/build.gradle
View file @
f24bde0c
...
...
@@ -27,4 +27,5 @@ android {
dependencies
{
compile
files
(
'libs/otr4j.jar'
)
compile
'com.android.support:appcompat-v7:21.0.3'
compile
'com.android.support:support-v13:21.0.3'
}
app/src/main/java/com/xabber/android/ui/ChatViewer.java
View file @
f24bde0c
...
...
@@ -17,6 +17,7 @@ package com.xabber.android.ui;
import
android.content.Context
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.support.v4.view.ViewPager
;
import
com.xabber.android.data.ActivityManager
;
import
com.xabber.android.data.Application
;
...
...
@@ -26,14 +27,17 @@ import com.xabber.android.data.entity.BaseEntity;
import
com.xabber.android.data.extension.archive.MessageArchiveManager
;
import
com.xabber.android.data.extension.attention.AttentionManager
;
import
com.xabber.android.data.intent.EntityIntentBuilder
;
import
com.xabber.android.data.message.AbstractChat
;
import
com.xabber.android.data.message.MessageManager
;
import
com.xabber.android.data.message.OnChatChangedListener
;
import
com.xabber.android.data.notification.NotificationManager
;
import
com.xabber.android.data.roster.OnContactChangedListener
;
import
com.xabber.android.ui.adapter.ChatViewerAdapter
;
import
com.xabber.android.ui.helper.ManagedActivity
;
import
com.xabber.androiddev.R
;
import
java.util.Collection
;
import
java.util.HashSet
;
/**
* Chat activity.
...
...
@@ -42,7 +46,7 @@ import java.util.Collection;
* @author alexander.ivanov
*/
public
class
ChatViewer
extends
ManagedActivity
implements
OnChatChangedListener
,
OnContactChangedListener
,
OnAccountChangedListener
{
OnContactChangedListener
,
OnAccountChangedListener
,
ViewPager
.
OnPageChangeListener
{
/**
* Attention request.
...
...
@@ -53,11 +57,18 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
private
static
final
String
SAVED_USER
=
"com.xabber.android.ui.ChatViewer.SAVED_USER"
;
private
static
final
String
SAVED_EXIT_ON_SEND
=
"com.xabber.android.ui.ChatViewer.EXIT_ON_SEND"
;
private
String
actionWithAccount
;
private
String
actionWithUser
;
private
boolean
exitOnSend
;
ChatViewerAdapter
chatViewerAdapter
;
ViewPager
viewPager
;
Collection
<
CurrentUpdatableChat
>
registeredChats
=
new
HashSet
<>();
private
String
actionWithAccount
=
null
;
private
String
actionWithUser
=
null
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
...
...
@@ -69,7 +80,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
Intent
intent
=
getIntent
();
String
account
=
getAccount
(
intent
);
String
user
=
getUser
(
intent
);
LogManager
.
i
(
this
,
"
Intent: "
+
account
+
":
"
+
user
);
LogManager
.
i
(
this
,
"
onCreate account: "
+
account
+
", user:
"
+
user
);
if
(
account
==
null
||
user
==
null
)
{
Application
.
getInstance
().
onError
(
R
.
string
.
ENTRY_IS_NOT_FOUND
);
...
...
@@ -82,8 +93,6 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
actionWithAccount
=
null
;
actionWithUser
=
null
;
setContentView
(
R
.
layout
.
activity_preferences
);
if
(
savedInstanceState
!=
null
)
{
actionWithAccount
=
savedInstanceState
.
getString
(
SAVED_ACCOUNT
);
actionWithUser
=
savedInstanceState
.
getString
(
SAVED_USER
);
...
...
@@ -98,26 +107,24 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
getSupportActionBar
().
setDisplayHomeAsUpEnabled
(
true
);
if
(
savedInstanceState
==
null
)
{
getFragmentManager
().
beginTransaction
()
.
add
(
R
.
id
.
preferences_activity_container
,
ChatViewerFragment
.
newInstance
(
actionWithAccount
,
actionWithUser
)).
commit
();
setContentView
(
R
.
layout
.
activity_chat_viewer
);
}
chatViewerAdapter
=
new
ChatViewerAdapter
(
getFragmentManager
());
viewPager
=
(
ViewPager
)
findViewById
(
R
.
id
.
pager
);
viewPager
.
setAdapter
(
chatViewerAdapter
);
viewPager
.
setOnPageChangeListener
(
this
);
selectPage
(
actionWithAccount
,
actionWithUser
);
}
@Override
protected
void
onResume
()
{
super
.
onResume
();
Application
.
getInstance
().
addUIListener
(
OnChatChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnAccountChangedListener
.
class
,
this
);
((
ChatViewerFragment
)
getFragmentManager
()
.
findFragmentById
(
R
.
id
.
preferences_activity_container
)).
onChange
();
Application
.
getInstance
().
addUIListener
(
OnChatChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
addUIListener
(
OnAccountChangedListener
.
class
,
this
);
Intent
intent
=
getIntent
();
if
(
Intent
.
ACTION_SEND
.
equals
(
intent
.
getAction
()))
{
...
...
@@ -128,13 +135,14 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
}
}
update
();
// selectPage(actionWithAccount, actionWithUser);
}
@Override
protected
void
onSaveInstanceState
(
Bundle
outState
)
{
super
.
onSaveInstanceState
(
outState
);
LogManager
.
i
(
this
,
"onSave: "
+
actionWithAccount
+
":"
+
actionWithUser
);
//
LogManager.i(this, "onSave: " + actionWithAccount + ":" + actionWithUser);
outState
.
putString
(
SAVED_ACCOUNT
,
actionWithAccount
);
outState
.
putString
(
SAVED_USER
,
actionWithUser
);
outState
.
putBoolean
(
SAVED_EXIT_ON_SEND
,
exitOnSend
);
...
...
@@ -143,12 +151,9 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
protected
void
onPause
()
{
super
.
onPause
();
Application
.
getInstance
().
removeUIListener
(
OnChatChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnAccountChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnChatChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnContactChangedListener
.
class
,
this
);
Application
.
getInstance
().
removeUIListener
(
OnAccountChangedListener
.
class
,
this
);
MessageManager
.
getInstance
().
removeVisibleChat
();
}
...
...
@@ -164,14 +169,21 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
return
;
}
actionWithAccount
=
account
;
actionWithUser
=
user
;
LogManager
.
i
(
this
,
"onNewIntent account: "
+
account
+
", user: "
+
user
);
selectPage
(
account
,
user
);
if
(
hasAttention
(
intent
))
AttentionManager
.
getInstance
().
removeAccountNotifications
(
account
,
user
);
getFragmentManager
().
beginTransaction
().
replace
(
R
.
id
.
preferences_activity_container
,
ChatViewerFragment
.
newInstance
(
actionWithAccount
,
actionWithUser
)).
commit
();
}
private
void
selectPage
(
String
account
,
String
user
)
{
LogManager
.
i
(
this
,
"selectPage: account: "
+
account
+
", user: "
+
user
);
int
position
=
chatViewerAdapter
.
getPosition
(
account
,
user
);
viewPager
.
setCurrentItem
(
position
);
onChatSelected
(
account
,
user
);
}
private
static
String
getAccount
(
Intent
intent
)
{
...
...
@@ -236,27 +248,35 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
public
void
onChatChanged
(
final
String
account
,
final
String
user
,
final
boolean
incoming
)
{
LogManager
.
i
(
this
,
"updateChat account: "
+
account
+
", user: "
+
user
);
chatViewerAdapter
.
onChange
();
update
();
((
ChatViewerFragment
)
getFragmentManager
()
.
findFragmentById
(
R
.
id
.
preferences_activity_container
)).
onChatChange
(
incoming
);
for
(
CurrentUpdatableChat
chat
:
registeredChats
)
{
if
(
chat
.
isEqual
(
account
,
user
))
{
chat
.
updateChat
(
incoming
);
}
}
}
@Override
public
void
onContactsChanged
(
Collection
<
BaseEntity
>
entities
)
{
updat
e
();
chatViewerAdapter
.
onChang
e
();
((
ChatViewerFragment
)
getFragmentManager
()
.
findFragmentById
(
R
.
id
.
preferences_activity_container
)).
onChange
();
for
(
CurrentUpdatableChat
chat
:
registeredChats
)
{
chat
.
updateChat
(
false
);
}
}
@Override
public
void
onAccountsChanged
(
Collection
<
String
>
accounts
)
{
updat
e
();
chatViewerAdapter
.
onChang
e
();
((
ChatViewerFragment
)
getFragmentManager
()
.
findFragmentById
(
R
.
id
.
preferences_activity_container
)).
onChange
();
for
(
CurrentUpdatableChat
chat
:
registeredChats
)
{
chat
.
updateChat
(
false
);
}
}
void
onSent
()
{
...
...
@@ -275,17 +295,52 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
}
}
void
update
()
{
MessageManager
.
getInstance
().
setVisibleChat
(
actionWithAccount
,
actionWithUser
);
@Override
public
void
onPageScrolled
(
int
position
,
float
positionOffset
,
int
positionOffsetPixels
)
{
}
@Override
public
void
onPageSelected
(
int
position
)
{
LogManager
.
i
(
this
,
"onPageSelected: "
+
position
);
AbstractChat
chat
=
chatViewerAdapter
.
getChat
(
position
);
String
account
=
chat
.
getAccount
();
String
user
=
chat
.
getUser
();
actionWithAccount
=
account
;
actionWithUser
=
user
;
onChatSelected
(
account
,
user
);
}
private
void
onChatSelected
(
String
account
,
String
user
)
{
LogManager
.
i
(
this
,
"onChatSelected. account: "
+
account
+
"; user: "
+
user
);
MessageManager
.
getInstance
().
setVisibleChat
(
account
,
user
);
MessageArchiveManager
.
getInstance
().
requestHistory
(
actionWithAccount
,
actionWithUser
,
0
,
MessageManager
.
getInstance
()
.
getChat
(
actionWithAccount
,
actionWithUser
)
.
getRequiredMessageCount
());
NotificationManager
.
getInstance
().
removeMessageNotification
(
actionWithAccount
,
actionWithUser
);
account
,
user
,
0
,
MessageManager
.
getInstance
().
getChat
(
account
,
user
).
getRequiredMessageCount
());
NotificationManager
.
getInstance
().
removeMessageNotification
(
account
,
user
);
}
@Override
public
void
onPageScrollStateChanged
(
int
state
)
{
}
public
void
registerChat
(
CurrentUpdatableChat
chat
)
{
registeredChats
.
add
(
chat
);
}
public
void
unregisterChat
(
CurrentUpdatableChat
chat
)
{
registeredChats
.
remove
(
chat
);
}
public
interface
CurrentUpdatableChat
{
public
void
updateChat
(
final
boolean
incoming
);
public
boolean
isEqual
(
String
account
,
String
user
);
}
}
app/src/main/java/com/xabber/android/ui/ChatViewerFragment.java
View file @
f24bde0c
...
...
@@ -25,7 +25,6 @@ import android.widget.ListView;
import
android.widget.TextView
;
import
com.xabber.android.data.Application
;
import
com.xabber.android.data.LogManager
;
import
com.xabber.android.data.NetworkException
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.extension.archive.MessageArchiveManager
;
...
...
@@ -51,10 +50,13 @@ import com.xabber.android.ui.helper.ContactTitleInflater;
import
com.xabber.android.ui.preferences.ChatEditor
;
import
com.xabber.androiddev.R
;
public
class
ChatViewerFragment
extends
Fragment
{
public
class
ChatViewerFragment
extends
Fragment
implements
ChatViewer
.
CurrentUpdatableChat
{
public
static
final
String
ARGUMENT_ACCOUNT
=
"ARGUMENT_ACCOUNT"
;
public
static
final
String
ARGUMENT_USER
=
"ARGUMENT_USER"
;
private
static
final
int
MINIMUM_MESSAGES_TO_LOAD
=
10
;
private
TextView
pageView
;
private
View
titleView
;
private
EditText
inputView
;
...
...
@@ -70,18 +72,16 @@ public class ChatViewerFragment extends Fragment {
private
AbstractAvatarInflaterHelper
avatarInflaterHelper
;
private
static
final
int
MINIMUM_MESSAGES_TO_LOAD
=
10
;
private
String
account
;
private
String
user
;
public
static
ChatViewerFragment
newInstance
(
String
account
,
String
user
)
{
ChatViewerFragment
fragment
=
new
ChatViewerFragment
();
Bundle
args
=
new
Bundle
();
args
.
putString
(
ARGUMENT_ACCOUNT
,
account
);
args
.
putString
(
ARGUMENT_USER
,
user
);
fragment
.
setArguments
(
args
);
Bundle
arg
ument
s
=
new
Bundle
();
arg
ument
s
.
putString
(
ARGUMENT_ACCOUNT
,
account
);
arg
ument
s
.
putString
(
ARGUMENT_USER
,
user
);
fragment
.
setArguments
(
arg
ument
s
);
return
fragment
;
}
...
...
@@ -90,6 +90,10 @@ public class ChatViewerFragment extends Fragment {
super
.
onCreate
(
savedInstanceState
);
avatarInflaterHelper
=
AbstractAvatarInflaterHelper
.
createAbstractContactInflaterHelper
();
Bundle
args
=
getArguments
();
account
=
args
.
getString
(
ARGUMENT_ACCOUNT
,
null
);
user
=
args
.
getString
(
ARGUMENT_USER
,
null
);
}
@Override
...
...
@@ -118,14 +122,19 @@ public class ChatViewerFragment extends Fragment {
}
});
View
view
=
inflater
.
inflate
(
R
.
layout
.
chat_viewer_item
,
container
,
false
);
chatMessageAdapter
=
new
ChatMessageAdapter
(
getActivity
());
chatMessageAdapter
.
setChat
(
account
,
user
);
listView
=
(
ListView
)
view
.
findViewById
(
android
.
R
.
id
.
list
);
listView
.
setAdapter
(
chatMessageAdapter
);
pageView
=
(
TextView
)
view
.
findViewById
(
R
.
id
.
chat_page
);
titleView
=
view
.
findViewById
(
R
.
id
.
title
);
inputView
=
(
EditText
)
view
.
findViewById
(
R
.
id
.
chat_input
);
listView
=
(
ListView
)
view
.
findViewById
(
android
.
R
.
id
.
list
);
listView
.
setAdapter
(
chatMessageAdapter
);
view
.
findViewById
(
R
.
id
.
chat_send
).
setOnClickListener
(
new
View
.
OnClickListener
()
{
...
...
@@ -175,13 +184,11 @@ public class ChatViewerFragment extends Fragment {
inputView
.
addTextChangedListener
(
new
TextWatcher
()
{
@Override
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
public
void
onTextChanged
(
CharSequence
s
,
int
start
,
int
before
,
int
count
)
{
}
@Override
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
public
void
beforeTextChanged
(
CharSequence
s
,
int
start
,
int
count
,
int
after
)
{
}
@Override
...
...
@@ -196,87 +203,92 @@ public class ChatViewerFragment extends Fragment {
});
registerForContextMenu
(
listView
);
Bundle
args
=
getArguments
();
account
=
args
.
getString
(
ARGUMENT_ACCOUNT
,
null
);
user
=
args
.
getString
(
ARGUMENT_USER
,
null
);
setHasOptionsMenu
(
true
);
setChat
(
account
,
user
);
updateView
();
chatMessageAdapter
.
onChange
();
return
view
;
}
@Override
public
void
onResume
()
{
super
.
onResume
();
((
ChatViewer
)
getActivity
()).
registerChat
(
this
);
}
@Override
public
void
onPause
()
{
super
.
onPause
();
((
ChatViewer
)
getActivity
()).
unregisterChat
(
this
);
}
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'
))
while
(
start
<
end
&&
(
text
.
charAt
(
start
)
==
' '
||
text
.
charAt
(
start
)
==
'\n'
))
{
start
+=
1
;
while
(
start
<
end
&&
(
text
.
charAt
(
end
-
1
)
==
' '
||
text
.
charAt
(
end
-
1
)
==
'\n'
))
}
while
(
start
<
end
&&
(
text
.
charAt
(
end
-
1
)
==
' '
||
text
.
charAt
(
end
-
1
)
==
'\n'
))
{
end
-=
1
;
}
text
=
text
.
substring
(
start
,
end
);
if
(
""
.
equals
(
text
))
if
(
""
.
equals
(
text
))
{
return
;
}
skipOnTextChanges
=
true
;
inputView
.
setText
(
""
);
skipOnTextChanges
=
false
;
sendMessage
(
text
);
((
ChatViewer
)
getActivity
()).
onSent
();
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
);
||
(
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
);
}
}
private
void
sendMessage
(
String
text
)
{
final
String
account
=
chatMessageAdapter
.
getAccount
();
final
String
user
=
chatMessageAdapter
.
getUser
();
MessageManager
.
getInstance
().
sendMessage
(
account
,
user
,
text
);
onChatChange
(
false
);
updateChat
(
false
);
}
public
void
onChatChange
(
boolean
incomingMessage
)
{
if
(
incomingMessage
)
{
titleView
.
findViewById
(
R
.
id
.
name_holder
).
startAnimation
(
shakeAnimation
);
}
setChat
(
account
,
user
);
chatMessageAdapter
.
onChange
();
}
public
void
onChange
()
{
setChat
(
account
,
user
);
private
void
updateMessages
()
{
chatMessageAdapter
.
onChange
();
}
public
void
setChat
(
String
account
,
String
user
)
{
final
AbstractContact
abstractContact
=
RosterManager
.
getInstance
()
.
getBestContact
(
account
,
user
);
private
void
updateView
()
{
final
AbstractContact
abstractContact
=
RosterManager
.
getInstance
().
getBestContact
(
account
,
user
);
LogManager
.
i
(
this
,
"setChat "
+
chatMessageAdapter
.
getUser
()
+
" in "
+
chatMessageAdapter
.
getAccount
());
skipOnTextChanges
=
true
;
inputView
.
setText
(
ChatManager
.
getInstance
().
getTypedMessage
(
account
,
user
));
inputView
.
setSelection
(
ChatManager
.
getInstance
().
getSelectionStart
(
account
,
user
),
ChatManager
.
getInstance
().
getSelectionEnd
(
account
,
user
));
skipOnTextChanges
=
false
;
chatMessageAdapter
.
setChat
(
account
,
user
);
listView
.
setAdapter
(
listView
.
getAdapter
());
ContactTitleInflater
.
updateTitle
(
titleView
,
getActivity
(),
abstractContact
);
avatarInflaterHelper
.
updateAvatar
((
ImageView
)
titleView
.
findViewById
(
R
.
id
.
avatar
),
abstractContact
);
SecurityLevel
securityLevel
=
OTRManager
.
getInstance
().
getSecurityLevel
(
account
,
user
);
SettingsManager
.
SecurityOtrMode
securityOtrMode
=
SettingsManager
.
securityOtrMode
();
ImageView
securityView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
security
);
ImageView
securityView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
security
);
if
(
securityLevel
==
SecurityLevel
.
plain
&&
(
securityOtrMode
==
SettingsManager
.
SecurityOtrMode
.
disabled
||
securityOtrMode
==
SettingsManager
.
SecurityOtrMode
.
manual
))
{
...
...
@@ -329,7 +341,7 @@ public class ChatViewerFragment extends Fragment {
MessageManager
.
getInstance
().
requestToLoadLocalHistory
(
account
,
user
);
MessageArchiveManager
.
getInstance
()
.
requestHistory
(
account
,
user
,
MINIMUM_MESSAGES_TO_LOAD
,
0
);
onChatChange
(
false
);
updateChat
(
false
);
return
true
;
}
});
...
...
@@ -383,7 +395,7 @@ public class ChatViewerFragment extends Fragment {
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MessageManager
.
getInstance
()
.
clearHistory
(
account
,
user
);
onChatChange
(
false
);
updateChat
(
false
);
return
false
;
}
});
...
...
@@ -537,7 +549,7 @@ public class ChatViewerFragment extends Fragment {
@Override
public
boolean
onMenuItemClick
(
MenuItem
item
)
{
MessageManager
.
getInstance
().
removeMessage
(
message
);
onChatChange
(
false
);
updateChat
(
false
);
return
true
;
}
...
...
@@ -563,4 +575,19 @@ public class ChatViewerFragment extends Fragment {
inputView
.
setText
(
before
+
additional
+
after
);
inputView
.
setSelection
(
selection
+
additional
.
length
());
}
@Override
public
void
updateChat
(
boolean
incomingMessage
)
{
if
(
incomingMessage
)
{
titleView
.
findViewById
(
R
.
id
.
name_holder
).
startAnimation
(
shakeAnimation
);
}
updateMessages
();
updateView
();
}
@Override
public
boolean
isEqual
(
String
account
,
String
user
)
{
return
this
.
account
.
equals
(
account
)
&&
this
.
user
.
equals
(
user
);
}
}
app/src/main/java/com/xabber/android/ui/adapter/ChatMessageAdapter.java
View file @
f24bde0c
...
...
@@ -309,8 +309,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override
public
void
onChange
()
{
messages
=
new
ArrayList
<>(
MessageManager
.
getInstance
()
.
getMessages
(
account
,
user
));
messages
=
new
ArrayList
<>(
MessageManager
.
getInstance
().
getMessages
(
account
,
user
));
hint
=
getHint
();
notifyDataSetChanged
();
}
...
...
app/src/main/java/com/xabber/android/ui/adapter/ChatViewerAdapter.java
0 → 100644
View file @
f24bde0c
package
com
.
xabber
.
android
.
ui
.
adapter
;
import
android.app.Fragment
;
import
android.app.FragmentManager
;
import
android.support.v13.app.FragmentStatePagerAdapter
;
import
android.view.ViewGroup
;
import
com.xabber.android.data.LogManager
;
import
com.xabber.android.data.message.AbstractChat
;
import
com.xabber.android.data.message.MessageManager
;
import
com.xabber.android.ui.ChatViewerFragment
;
import
com.xabber.xmpp.address.Jid
;
import
java.util.ArrayList
;
public
class
ChatViewerAdapter
extends
FragmentStatePagerAdapter
implements
UpdatableAdapter
{
private
ArrayList
<
AbstractChat
>
activeChats
;
public
ChatViewerAdapter
(
FragmentManager
fragmentManager
)
{
super
(
fragmentManager
);
LogManager
.
i
(
this
,
"ChatViewerAdapter"
);
onChange
();
}
@Override
public
int
getCount
()
{
return
activeChats
.
size
();
}
@Override
public
Fragment
getItem
(
int
i
)
{
LogManager
.
i
(
this
,
"getItem: "
+
i
);
AbstractChat
abstractChat
=
getChat
(
i
);
return
ChatViewerFragment
.
newInstance
(
abstractChat
.
getAccount
(),
abstractChat
.
getUser
());
}
public
AbstractChat
getChat
(
int
i
)
{
return
activeChats
.
get
(
i
);
}
@Override
public
void
onChange
()
{
LogManager
.
i
(
this
,
"onChange: "
);
activeChats
=
new
ArrayList
<>(
MessageManager
.
getInstance
().
getActiveChats
());
notifyDataSetChanged
();
}
public
int
getPosition
(
String
account
,
String
user
)
{
LogManager
.
i
(
this
,
"getPosition: "
+
account
+
" : "
+
user
);
activeChats
=
new
ArrayList
<>(
MessageManager
.
getInstance
().
getActiveChats
());
for
(
int
position
=
0
;
position
<
activeChats
.
size
();
position
++)
{
if
(
activeChats
.
get
(
position
).
equals
(
account
,
user
))
{
return
position
;
}
}
LogManager
.
i
(
this
,
"creating new chat: "
+
account
+
" : "
+
user
);
AbstractChat
chat
=
MessageManager
.
getInstance
().
getOrCreateChat
(
account
,
Jid
.
getBareAddress
(
user
));
activeChats
.
add
(
chat
);
notifyDataSetChanged
();
return
activeChats
.
indexOf
(
chat
);
}
@Override
public
void
setPrimaryItem
(
ViewGroup
container
,
int
position
,
Object
object
)
{
super
.
setPrimaryItem
(
container
,
position
,
object
);
LogManager
.
i
(
this
,
"setPrimaryItem position: "
+
position
);
}
}
\ No newline at end of file
app/src/main/java/com/xabber/android/ui/helper/ContactTitleInflater.java
View file @
f24bde0c
...
...
@@ -50,46 +50,53 @@ public class ContactTitleInflater {
*/
public
static
void
updateTitle
(
View
titleView
,
final
Activity
activity
,
AbstractContact
abstractContact
)
{
final
TypedArray
typedArray
=
activity
.
obtainStyledAttributes
(
R
.
styleable
.
ContactList
);
final
TypedArray
typedArray
=
activity
.
obtainStyledAttributes
(
R
.
styleable
.
ContactList
);
final
Drawable
titleAccountBackground
=
typedArray
.
getDrawable
(
R
.
styleable
.
ContactList_titleAccountBackground
);
typedArray
.
recycle
();
final
TextView
nameView
=
(
TextView
)
titleView
.
findViewById
(
R
.
id
.
name
);
final
ImageView
avatarView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
avatar
);
final
ImageView
statusModeView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
status_mode
);
final
ImageView
avatarView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
avatar
);
final
ImageView
statusModeView
=
(
ImageView
)
titleView
.
findViewById
(
R
.
id
.
status_mode
);
final
TextView
statusTextView
=
(
TextView
)
titleView
.
findViewById
(
R
.
id
.
status_text
);
final
View
shadowView
=
titleView
.
findViewById
(
R
.
id
.
shadow
);
titleView
.
setBackgroundDrawable
(
titleAccountBackground
);
nameView
.
setText
(
abstractContact
.
getName
());
statusModeView
.
setImageLevel
(
abstractContact
.
getStatusMode
()
.
getStatusLevel
());
titleView
.
getBackground
().
setLevel
(
AccountManager
.
getInstance
().
getColorLevel
(
statusModeView
.
setImageLevel
(
abstractContact
.
getStatusMode
().
getStatusLevel
());
titleView
.
getBackground
().
setLevel
(
AccountManager
.
getInstance
().
getColorLevel
(
abstractContact
.
getAccount
()));
avatarView
.
setImageDrawable
(
abstractContact
.
getAvatar
());
setStatusText
(
activity
,
abstractContact
,
statusTextView
);
final
Bitmap
bitmap
=
BitmapFactory
.
decodeResource
(
activity
.
getResources
(),
R
.
drawable
.
shadow
);
final
BitmapDrawable
shadowDrawable
=
new
BitmapDrawable
(
bitmap
);
shadowDrawable
.
setTileModeXY
(
TileMode
.
REPEAT
,
TileMode
.
REPEAT
);
shadowView
.
setBackgroundDrawable
(
shadowDrawable
);
if
(
abstractContact
.
isConnected
())
{
shadowView
.
setVisibility
(
View
.
GONE
);
}
else
{
shadowView
.
setVisibility
(
View
.
VISIBLE
);
}
}
private
static
void
setStatusText
(
Activity
activity
,
AbstractContact
abstractContact
,
TextView
statusTextView
)
{
ChatState
chatState
=
ChatStateManager
.
getInstance
().
getChatState
(
abstractContact
.
getAccount
(),
abstractContact
.
getUser
());
final
CharSequence
statusText
;
if
(
chatState
==
ChatState
.
composing
)
if
(
chatState
==
ChatState
.
composing
)
{
statusText
=
activity
.
getString
(
R
.
string
.
chat_state_composing
);
else
if
(
chatState
==
ChatState
.
paused
)
}
else
if
(
chatState
==
ChatState
.
paused
)
{
statusText
=
activity
.
getString
(
R
.
string
.
chat_state_paused
);
else
statusText
=
Emoticons
.
getSmiledText
(
activity
,
abstractContact
.
getStatusText
());
}
else
{
statusText
=
Emoticons
.
getSmiledText
(
activity
,
abstractContact
.
getStatusText
());
}
statusTextView
.
setText
(
statusText
);
final
Bitmap
bitmap
=
BitmapFactory
.
decodeResource
(
activity
.
getResources
(),
R
.
drawable
.
shadow
);
final
BitmapDrawable
shadowDrawable
=
new
BitmapDrawable
(
bitmap
);
shadowDrawable
.
setTileModeXY
(
TileMode
.
REPEAT
,
TileMode
.
REPEAT
);
shadowView
.
setBackgroundDrawable
(
shadowDrawable
);
if
(
abstractContact
.
isConnected
())
shadowView
.
setVisibility
(
View
.
GONE
);
else
shadowView
.
setVisibility
(
View
.
VISIBLE
);
}
}
app/src/main/res/layout/activity_chat_viewer.xml
0 → 100644
View file @
f24bde0c
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/pager"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
</android.support.v4.view.ViewPager>
\ No newline at end of file
app/src/main/res/layout/chat_viewer.xml
deleted
100644 → 0
View file @
68946a30
<?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/.
-->
<com.xabber.android.ui.widget.PageSwitcher
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:id=
"@+id/switcher"
/>
\ No newline at end of file
app/src/main/res/layout/chat_viewer_container.xml
deleted
100644 → 0
View file @
68946a30
<?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/.
-->
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/container"
android:orientation=
"vertical"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
/>
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