Commit f24bde0c authored by Grigory Fedorov's avatar Grigory Fedorov

View pager and FragmentStatePagerAdapter used to scroll active chats.

parent 68946a30
......@@ -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'
}
......@@ -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();
}
......
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
......@@ -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);
}
}
<?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
<?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
<?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"
/>
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