Commit 617ba4b9 authored by Grigory Fedorov's avatar Grigory Fedorov

RecentChatFragment used as one of the page in the chat view pager.

Unstable, could hang up on chat select.
parent a5d5b4aa
......@@ -30,8 +30,7 @@ import android.util.AttributeSet;
import com.xabber.android.ui.adapter.ChatViewerAdapter;
/**
* A {@link android.support.v4.view.ViewPager} that allows pseudo-infinite paging with a wrap-around effect. Should be used with an {@link
* InfinitePagerAdapter}.
* A {@link android.support.v4.view.ViewPager} that allows pseudo-infinite paging with a wrap-around effect.
*/
public class InfiniteViewPager extends ViewPager {
......
......@@ -14,28 +14,33 @@
*/
package com.xabber.android.ui;
import java.util.Collection;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Toast;
import com.xabber.android.data.Application;
import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity;
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.roster.OnContactChangedListener;
import com.xabber.android.ui.adapter.ChatComparator;
import com.xabber.android.ui.adapter.ChatListAdapter;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
public class ChatList extends ManagedListActivity implements
OnAccountChangedListener, OnContactChangedListener,
OnChatChangedListener, OnItemClickListener {
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class ChatList extends ManagedListActivity implements OnAccountChangedListener,
OnContactChangedListener, OnChatChangedListener, OnItemClickListener {
private ChatListAdapter listAdapter;
......@@ -56,48 +61,39 @@ public class ChatList extends ManagedListActivity implements
@Override
protected void onResume() {
super.onResume();
Application.getInstance().addUIListener(OnAccountChangedListener.class,
this);
Application.getInstance().addUIListener(OnContactChangedListener.class,
this);
Application.getInstance().addUIListener(OnChatChangedListener.class,
this);
listAdapter.onChange();
Application.getInstance().addUIListener(OnAccountChangedListener.class, this);
Application.getInstance().addUIListener(OnContactChangedListener.class, this);
Application.getInstance().addUIListener(OnChatChangedListener.class, this);
updateAdapter();
}
@Override
protected void onPause() {
super.onPause();
Application.getInstance().removeUIListener(
OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(
OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(OnChatChangedListener.class,
this);
Application.getInstance().removeUIListener(OnAccountChangedListener.class, this);
Application.getInstance().removeUIListener(OnContactChangedListener.class, this);
Application.getInstance().removeUIListener(OnChatChangedListener.class, this);
}
@Override
public void onChatChanged(String account, String user, boolean incoming) {
listAdapter.onChange();
updateAdapter();
}
@Override
public void onContactsChanged(Collection<BaseEntity> addresses) {
listAdapter.onChange();
updateAdapter();
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
listAdapter.onChange();
updateAdapter();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
AbstractChat abstractChat = (AbstractChat) parent.getAdapter().getItem(
position);
startActivity(ChatViewer.createIntent(this, abstractChat.getAccount(),
abstractChat.getUser()));
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AbstractChat chat = (AbstractChat) parent.getAdapter().getItem(position);
startActivity(ChatViewer.createIntent(this, chat.getAccount(), chat.getUser()));
finish();
}
......@@ -105,4 +101,17 @@ public class ChatList extends ManagedListActivity implements
return new Intent(context, ChatList.class);
}
private void updateAdapter() {
List<AbstractChat> chats = new ArrayList<>();
chats.addAll(MessageManager.getInstance().getActiveChats());
if (chats.size() == 0) {
Toast.makeText(this, R.string.chat_list_is_empty, Toast.LENGTH_LONG).show();
finish();
}
Collections.sort(chats, ChatComparator.CHAT_COMPARATOR);
listAdapter.updateChats(chats);
}
}
......@@ -49,7 +49,7 @@ import java.util.HashSet;
*/
public class ChatViewer extends ManagedActivity implements OnChatChangedListener,
OnContactChangedListener, OnAccountChangedListener, ViewPager.OnPageChangeListener,
ChatViewerAdapter.FinishUpdateListener {
ChatViewerAdapter.FinishUpdateListener, RecentChatFragment.RecentChatFragmentInteractionListener {
/**
* Attention request.
......@@ -121,8 +121,10 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
viewPager.setAdapter(chatViewerAdapter);
viewPager.setOnPageChangeListener(this);
LogManager.i(this, "onCreate user: " + actionWithUser);
selectPage(actionWithAccount, actionWithUser);
selectPage(false);
onChatSelected();
}
@Override
......@@ -176,19 +178,25 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
LogManager.i(this, "onNewIntent account: " + account + ", user: " + user);
selectPage(account, user);
actionWithUser = user;
actionWithAccount = user;
selectPage(false);
onChatSelected();
}
private void selectPage(boolean smoothScroll ) {
}
private void selectPage(String account, String user) {
LogManager.i(this, "selectPage: account: " + account + ", user: " + user);
int position = chatViewerAdapter.getPosition(account, user);
viewPager.setCurrentItem(position);
int position = chatViewerAdapter.getPageNumber(actionWithAccount, actionWithUser);
onChatSelected(account, user);
LogManager.i(this, "selectPage user: " + actionWithUser + " position: " + position);
viewPager.setCurrentItem(position, smoothScroll);
for (ChatViewerFragment chat : registeredChats) {
chat.updateChat(false);
}
}
private static String getAccount(Intent intent) {
......@@ -253,17 +261,34 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
public void onChatChanged(final String account, final String user,
final boolean incoming) {
chatViewerAdapter.onChange();
LogManager.i(this, "onChatChanged " + user);
for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(account, user)) {
chat.updateChat(incoming);
}
}
}
@Override
public void onContactsChanged(Collection<BaseEntity> entities) {
LogManager.i(this, "onContactsChanged");
chatViewerAdapter.onChange();
for (ChatViewerFragment chat : registeredChats) {
chat.updateChat(false);
}
}
@Override
public void onAccountsChanged(Collection<String> accounts) {
LogManager.i(this, "onAccountsChanged");
chatViewerAdapter.onChange();
for (ChatViewerFragment chat : registeredChats) {
chat.updateChat(false);
}
}
void onSent() {
......@@ -289,35 +314,38 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
public void onPageSelected(int position) {
int realCount = chatViewerAdapter.getRealCount();
int virtualPosition = position % realCount;
AbstractChat chat = chatViewerAdapter.getChat(virtualPosition);
String account = chat.getAccount();
String user = chat.getUser();
AbstractChat selectedChat = chatViewerAdapter.getChatByPageNumber(position);
actionWithAccount = account;
actionWithUser = user;
if (selectedChat == null) {
setTitle(getString(R.string.chat_list));
return;
}
actionWithAccount = selectedChat.getAccount();
actionWithUser = selectedChat.getUser();
LogManager.i(this, "onPageSelected position: " + position + " user: " + actionWithUser + " position: " + position);
onChatSelected(account, user);
onChatSelected();
}
private void onChatSelected(String account, String user) {
actionWithAccount = account;
actionWithUser = user;
private void onChatSelected() {
LogManager.i(this, "onChatSelected user: " + actionWithUser);
MessageManager.getInstance().setVisibleChat(account, user);
final AbstractContact abstractContact
= RosterManager.getInstance().getBestContact(actionWithAccount, actionWithUser);
MessageArchiveManager.getInstance().requestHistory(
account, user, 0,
MessageManager.getInstance().getChat(account, user).getRequiredMessageCount());
setTitle(abstractContact.getName());
NotificationManager.getInstance().removeMessageNotification(account, user);
MessageManager.getInstance().setVisibleChat(actionWithAccount, actionWithUser);
final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
MessageArchiveManager.getInstance().requestHistory(
actionWithAccount, actionWithUser, 0,
MessageManager.getInstance().getChat(actionWithAccount, actionWithUser).getRequiredMessageCount());
setTitle(abstractContact.getName());
NotificationManager.getInstance().removeMessageNotification(actionWithAccount, actionWithUser);
}
@Override
......@@ -335,15 +363,39 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
@Override
public void onChatViewAdapterFinishUpdate() {
LogManager.i(this, "onChatViewAdapterFinishUpdate position: user: " + actionWithUser);
insertExtraText();
}
private void insertExtraText() {
if (extraText == null) {
return;
}
boolean isExtraTextInserted = false;
for (ChatViewerFragment chat : registeredChats) {
if (chat.isEqual(actionWithAccount, actionWithUser)) {
chat.setInputFocus();
if (extraText != null) {
chat.setInputText(extraText);
extraText = null;
}
chat.setInputText(extraText);
isExtraTextInserted = true;
}
}
if (isExtraTextInserted) {
extraText = null;
}
}
@Override
public void onRecentChatSelected(AbstractChat chat) {
actionWithAccount = chat.getAccount();
actionWithUser = chat.getUser();
LogManager.i(this, "onRecentChatSelected position: user: " + actionWithUser);
selectPage(true);
}
}
......@@ -53,6 +53,9 @@ import com.xabber.androiddev.R;
public class ChatViewerFragment extends Fragment {
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;
......@@ -73,30 +76,31 @@ public class ChatViewerFragment extends Fragment {
private String account;
private String user;
private int activeChatIndex;
private ActiveChatProvider activeChatProvider;
public static ChatViewerFragment newInstance(String account, String user) {
ChatViewerFragment fragment = new ChatViewerFragment();
public static ChatViewerFragment newInstance() {
return new ChatViewerFragment();
Bundle arguments = new Bundle();
arguments.putString(ARGUMENT_ACCOUNT, account);
arguments.putString(ARGUMENT_USER, user);
fragment.setArguments(arguments);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
avatarInflaterHelper = AbstractAvatarInflaterHelper.createAbstractContactInflaterHelper();
}
public void setActiveChat(ActiveChatProvider activeChatProvider, int activeChatIndex) {
this.activeChatProvider = activeChatProvider;
this.activeChatIndex = activeChatIndex;
Bundle args = getArguments();
account = args.getString(ARGUMENT_ACCOUNT, null);
user = args.getString(ARGUMENT_USER, null);
avatarInflaterHelper = AbstractAvatarInflaterHelper.createAbstractContactInflaterHelper();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
updateUserAndAccount();
shakeAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.shake);
/*
......@@ -123,6 +127,7 @@ 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);
......@@ -208,12 +213,6 @@ public class ChatViewerFragment extends Fragment {
}
private void updateUserAndAccount() {
AbstractChat activeChat = activeChatProvider.getActiveChat(activeChatIndex);
user = activeChat.getUser();
account = activeChat.getAccount();
}
@Override
public void onResume() {
super.onResume();
......@@ -269,7 +268,7 @@ public class ChatViewerFragment extends Fragment {
}
skipOnTextChanges = true;
inputView.setText("");
inputView.getText().clear();
skipOnTextChanges = false;
sendMessage(text);
......@@ -289,15 +288,8 @@ public class ChatViewerFragment extends Fragment {
updateChat(false);
}
private void updateMessages() {
chatMessageAdapter.onChange();
}
private void updateView() {
updateUserAndAccount();
chatMessageAdapter.setChat(account, user);
chatMessageAdapter.onChange();
final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
......@@ -404,7 +396,7 @@ public class ChatViewerFragment extends Fragment {
new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
inputView.setText("");
inputView.getText().clear();
return true;
}
});
......@@ -587,9 +579,7 @@ public class ChatViewerFragment extends Fragment {
if (incomingMessage) {
titleView.findViewById(R.id.name_holder).startAnimation(shakeAnimation);
}
updateUserAndAccount();
updateMessages();
updateView();
}
......@@ -605,7 +595,11 @@ public class ChatViewerFragment extends Fragment {
insertText(text);
}
public interface ActiveChatProvider {
public AbstractChat getActiveChat(int index);
public String getAccount() {
return account;
}
public String getUser() {
return user;
}
}
package com.xabber.android.ui;
import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.ui.adapter.ChatListAdapter;
import com.xabber.androiddev.R;
import java.util.List;
public class RecentChatFragment extends ListFragment {
private RecentChatFragmentInteractionListener listener;
private List<AbstractChat> initialChats = null;
public static RecentChatFragment newInstance() {
return new RecentChatFragment();
}
/**
* Mandatory empty constructor for the fragment manager to instantiate the
* fragment (e.g. upon screen orientation changes).
*/
public RecentChatFragment() {
}
public void setInitialChats(List<AbstractChat> initialChats) {
this.initialChats = initialChats;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ChatListAdapter(getActivity()));
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
listener = (RecentChatFragmentInteractionListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement RecentChatFragmentInteractionListener");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
if (initialChats != null) {
((ChatListAdapter) getListAdapter()).updateChats(initialChats);
initialChats = null;
}
return inflater.inflate(R.layout.list, container, false);
}
@Override
public void onDetach() {
super.onDetach();
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
if (null != listener) {
listener.onRecentChatSelected((AbstractChat) getListAdapter().getItem(position));
}
}
public interface RecentChatFragmentInteractionListener {
public void onRecentChatSelected(AbstractChat chat);
}
}
/**
* 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/.
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collections;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.notification.NotificationManager;
import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.ChatList;
import com.xabber.android.ui.helper.AbstractAvatarInflaterHelper;
import com.xabber.androiddev.R;
/**
* Adapter for {@link ChatList}.
*
* @author alexander.ivanov
*/
public class ChatListAdapter extends BaseAdapter implements UpdatableAdapter {
import java.util.ArrayList;
import java.util.List;
private final Activity activity;
public class ChatListAdapter extends BaseAdapter {
private final ArrayList<AbstractChat> abstractChats;
private List<AbstractChat> chats;
private final AbstractAvatarInflaterHelper avatarInflaterHelper;
public ChatListAdapter(Activity activity) {
this.activity = activity;
abstractChats = new ArrayList<AbstractChat>();
avatarInflaterHelper = AbstractAvatarInflaterHelper
.createAbstractContactInflaterHelper();
private final Context context;
public ChatListAdapter(Context context) {
this.context = context;
chats = new ArrayList<>();
avatarInflaterHelper = AbstractAvatarInflaterHelper.createAbstractContactInflaterHelper();
}
@Override
public void onChange() {
abstractChats.clear();
abstractChats.addAll(MessageManager.getInstance().getActiveChats());
Collections.sort(abstractChats, ChatComparator.CHAT_COMPARATOR);
if (abstractChats.size() == 0) {
Toast.makeText(activity, R.string.chat_list_is_empty,
Toast.LENGTH_LONG).show();
activity.finish();
return;
}
public void updateChats(List<AbstractChat> chats) {
this.chats.clear();
this.chats.addAll(chats);
notifyDataSetChanged();
}
@Override
public int getCount() {
return abstractChats.size();
return chats.size();
}
@Override
public Object getItem(int position) {
return abstractChats.get(position);
return chats.get(position);
}
@Override
......@@ -87,33 +59,32 @@ public class ChatListAdapter extends BaseAdapter implements UpdatableAdapter {
public View getView(int position, View convertView, ViewGroup parent) {
final View view;
if (convertView == null) {
view = activity.getLayoutInflater().inflate(
R.layout.chat_list_item, parent, false);
view = LayoutInflater.from(context).inflate(R.layout.chat_list_item, parent, false);
} else {
view = convertView;
}
final AbstractChat abstractChat = (AbstractChat) getItem(position);
final AbstractContact abstractContact = RosterManager.getInstance()
.getBestContact(abstractChat.getAccount(),
abstractChat.getUser());
final ImageView colorView = (ImageView) view.findViewById(R.id.color);
.getBestContact(abstractChat.getAccount(), abstractChat.getUser());
((TextView) view.findViewById(R.id.name)).setText(abstractContact.getName());
((ImageView) view.findViewById(R.id.color)).setImageLevel(abstractContact.getColorLevel());
final ImageView avatarView = (ImageView) view.findViewById(R.id.avatar);
final TextView nameView = (TextView) view.findViewById(R.id.name);
final TextView textView = (TextView) view.findViewById(R.id.text);
colorView.setImageLevel(abstractContact.getColorLevel());
avatarView.setImageDrawable(abstractContact.getAvatar());
avatarInflaterHelper.updateAvatar(avatarView, abstractContact);
nameView.setText(abstractContact.getName());
final TextView textView = (TextView) view.findViewById(R.id.text);
String statusText = MessageManager.getInstance().getLastText(
abstractContact.getAccount(), abstractContact.getUser());
textView.setText(statusText);
boolean newMessages = NotificationManager.getInstance()
.getNotificationMessageCount(abstractChat.getAccount(),
abstractChat.getUser()) > 0;
textView.setTextAppearance(activity,
newMessages ? R.style.ChatList_Notification
.getNotificationMessageCount(abstractChat.getAccount(), abstractChat.getUser()) > 0;
textView.setTextAppearance(context, newMessages ? R.style.ChatList_Notification
: R.style.ChatList_Normal);
return view;
}
}
......@@ -9,14 +9,14 @@ import android.view.ViewGroup;
import com.xabber.android.data.message.AbstractChat;
import com.xabber.android.data.message.MessageManager;
import com.xabber.android.ui.ChatViewerFragment;
import com.xabber.android.ui.RecentChatFragment;
import com.xabber.xmpp.address.Jid;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class ChatViewerAdapter extends FragmentStatePagerAdapter implements UpdatableAdapter,
ChatViewerFragment.ActiveChatProvider {
public class ChatViewerAdapter extends FragmentStatePagerAdapter implements UpdatableAdapter {
/**
* Intent sent while opening chat activity.
......@@ -27,6 +27,8 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda
private FinishUpdateListener finishUpdateListener;
private Fragment currentFragment;
public ChatViewerAdapter(FragmentManager fragmentManager, String account, String user, FinishUpdateListener finishUpdateListener) {
super(fragmentManager);
this.finishUpdateListener = finishUpdateListener;
......@@ -49,38 +51,26 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda
public int getRealCount() {
int realCount = activeChats.size();
if (realCount == 1) {
return 4;
} else if (realCount == 2 || realCount == 3) {
return realCount * 2;
} else {
return realCount;
}
}
@Override
public Fragment getItem(int i) {
int position = i % activeChats.size();
ChatViewerFragment chatViewerFragment = ChatViewerFragment.newInstance();
chatViewerFragment.setActiveChat(this, position);
return chatViewerFragment;
return realCount + 1;
}
public AbstractChat getChat(int i) {
int realCount = activeChats.size();
@Override
public Fragment getItem(int virtualPagePosition) {
int position;
int chatIndex;
int realPosition = virtualPagePosition % getRealCount();
if (realCount == 1) {
position = 0;
} else if (realCount == 2 || realCount == 3) {
position = i % realCount;
if (realPosition == 0) {
RecentChatFragment activeChatFragment = RecentChatFragment.newInstance();
activeChatFragment.setInitialChats(activeChats);
return activeChatFragment;
} else {
position = i;
chatIndex = realPosition -1;
}
return activeChats.get(position);
AbstractChat chat = activeChats.get(chatIndex);
return ChatViewerFragment.newInstance(chat.getAccount(), chat.getUser());
}
@Override
......@@ -101,25 +91,46 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda
notifyDataSetChanged();
}
public int getPosition(String account, String user) {
public int getPageNumber(String account, String user) {
for (int position = 0; position < activeChats.size(); position++) {
if (activeChats.get(position).equals(account, user)) {
return position;
return position + 1;
}
}
return -1;
}
public AbstractChat getChatByPageNumber(int virtualPosition) {
int realPosition = virtualPosition % getRealCount();
int chatIndex = realPosition - 1;
if (chatIndex < 0) {
return null;
}
return activeChats.get(chatIndex);
}
@Override
public void startUpdate(ViewGroup container) {
if (currentFragment instanceof ChatViewerFragment) {
((ChatViewerFragment)currentFragment).saveInputState();
}
super.startUpdate(container);
}
@Override
public void finishUpdate(ViewGroup container) {
super.finishUpdate(container);
finishUpdateListener.onChatViewAdapterFinishUpdate();
}
@Override
public AbstractChat getActiveChat(int index) {
return getChat(index);
if (currentFragment instanceof ChatViewerFragment) {
((ChatViewerFragment)currentFragment).updateChat(false);
((ChatViewerFragment)currentFragment).setInputFocus();
}
}
public interface FinishUpdateListener {
......@@ -127,7 +138,15 @@ public class ChatViewerAdapter extends FragmentStatePagerAdapter implements Upda
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
public void setPrimaryItem(ViewGroup container, int position, Object object) {
if (getCurrentFragment() != object) {
currentFragment = ((Fragment) object);
}
super.setPrimaryItem(container, position, object);
}
public Fragment getCurrentFragment() {
return currentFragment;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment