Commit 68946a30 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewer and ChatViewerFragment rewritten. ChatViewerAdapter removed. No scroll chat for now.

Dialogs do not use support libraries.
parent bcbb1c98
......@@ -171,8 +171,8 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
text);
return;
}
AccountChooseDialogFragment.newInstance(bareAddress, text).show(
getSupportFragmentManager(), "OPEN_WITH_ACCOUNT");
AccountChooseDialogFragment.newInstance(bareAddress, text)
.show(getFragmentManager(), "OPEN_WITH_ACCOUNT");
}
/**
......@@ -240,15 +240,14 @@ public class ContactList extends ManagedActivity implements OnChoosedListener, O
if (SettingsManager.bootCount() > 2
&& !SettingsManager.connectionStartAtBoot()
&& !SettingsManager.startAtBootSuggested())
StartAtBootDialogFragment.newInstance().show(
getSupportFragmentManager(), "START_AT_BOOT");
StartAtBootDialogFragment.newInstance().show(getFragmentManager(), "START_AT_BOOT");
if (!SettingsManager.contactIntegrationSuggested()
&& Application.getInstance().isContactsSupported()) {
if (AccountManager.getInstance().getAllAccounts().isEmpty())
SettingsManager.setContactIntegrationSuggested();
else
ContactIntegrationDialogFragment.newInstance().show(
getSupportFragmentManager(), "CONTACT_INTEGRATION");
getFragmentManager(), "CONTACT_INTEGRATION");
}
}
}
......
......@@ -14,10 +14,6 @@
*/
package com.xabber.android.ui;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
......@@ -34,6 +30,10 @@ import com.xabber.android.ui.dialog.GroupAddDialogFragment.OnGroupAddConfirmed;
import com.xabber.android.ui.helper.ManagedListActivity;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
/**
* Manage list of selected groups.
*
......@@ -146,8 +146,7 @@ public abstract class GroupListActivity extends ManagedListActivity implements
}
private void showGroupAddDialog() {
GroupAddDialogFragment.newInstance(getGroups()).show(
getSupportFragmentManager(), "GROUP-ADD");
GroupAddDialogFragment.newInstance(getGroups()).show(getFragmentManager(), "GROUP-ADD");
}
@Override
......
......@@ -14,11 +14,6 @@
*/
package com.xabber.android.ui.adapter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import android.app.Activity;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
......@@ -49,6 +44,11 @@ import com.xabber.android.utils.Emoticons;
import com.xabber.android.utils.StringUtils;
import com.xabber.androiddev.R;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
* Adapter for the list of messages in the chat.
*
......@@ -309,7 +309,7 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override
public void onChange() {
messages = new ArrayList<MessageItem>(MessageManager.getInstance()
messages = new ArrayList<>(MessageManager.getInstance()
.getMessages(account, user));
hint = getHint();
notifyDataSetChanged();
......
/**
* 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.Collection;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
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.ui.ChatViewerFragment;
import com.xabber.xmpp.address.Jid;
/**
* Adapter for the list of chat pages.
*
* @author alexander.ivanov
*/
public class ChatViewerAdapter extends BaseAdapter implements SaveStateAdapter,
UpdatableAdapter {
private final FragmentActivity activity;
/**
* Intent sent while opening chat activity.
*/
private final AbstractChat intent;
/**
* Position to insert intent.
*/
private final int intentPosition;
private ArrayList<AbstractChat> activeChats;
public ChatViewerAdapter(FragmentActivity activity, String account,
String user) {
this.activity = activity;
activeChats = new ArrayList<AbstractChat>();
intent = MessageManager.getInstance().getOrCreateChat(account,
Jid.getBareAddress(user));
Collection<? extends BaseEntity> activeChats = MessageManager
.getInstance().getActiveChats();
if (activeChats.contains(intent))
intentPosition = -1;
else
intentPosition = activeChats.size();
onChange();
}
@Override
public int getCount() {
return activeChats.size();
}
@Override
public Object getItem(int position) {
return activeChats.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view;
final AbstractChat chat = (AbstractChat) getItem(position);
ChatViewerFragment fragment;
if (convertView == null) {
fragment = new ChatViewerFragment(activity);
view = fragment.getView();
view.setTag(fragment);
} else {
view = convertView;
fragment = (ChatViewerFragment) view.getTag();
}
fragment.setChat(chat);
return view;
}
@Override
public void saveState(View view) {
((ChatViewerFragment) view.getTag()).saveState();
}
@Override
public void hidePages(View view) {
((ChatViewerFragment) view.getTag()).hidePages();
}
@Override
public void showPages(View view) {
((ChatViewerFragment) view.getTag()).showPages();
}
/**
* Must be called on changes in chat (message sent, received, etc.).
*/
public void onChatChange(View view, boolean incomingMessage) {
((ChatViewerFragment) view.getTag()).onChatChange(incomingMessage);
}
/**
* Must be called on changes in chat (message sent, received, etc.).
*/
public void onPrepareOptionsMenu(View view, Menu menu) {
((ChatViewerFragment) view.getTag()).onPrepareOptionsMenu(menu);
}
public void insertText(View view, String text) {
((ChatViewerFragment) view.getTag()).insertText(text);
}
@Override
public void onChange() {
activeChats = new ArrayList<AbstractChat>(MessageManager.getInstance()
.getActiveChats());
if (intentPosition != -1) {
int index = activeChats.indexOf(intent);
AbstractChat chat;
if (index == -1)
chat = intent;
else
chat = activeChats.remove(index);
activeChats.add(Math.min(intentPosition, activeChats.size()), chat);
}
notifyDataSetChanged();
}
public int getPosition(String account, String user) {
for (int position = 0; position < activeChats.size(); position++)
if (activeChats.get(position).equals(account, user))
return position;
return -1;
}
}
......@@ -14,13 +14,13 @@
*/
package com.xabber.android.ui.dialog;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import java.util.ArrayList;
/**
* Base dialog fragment.
......
package com.xabber.android.ui.dialog;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.view.ViewGroup;
......@@ -14,6 +12,8 @@ import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.AccountChooseAdapter;
import java.util.ArrayList;
public class AccountChooseDialogFragment extends AbstractDialogFragment {
private static final String USER = "USER";
......
......@@ -14,14 +14,12 @@
*/
package com.xabber.android.ui.dialog;
import java.io.File;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.DialogFragment;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v4.app.DialogFragment;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
......@@ -34,6 +32,8 @@ import com.xabber.android.data.message.MessageManager;
import com.xabber.android.data.roster.RosterManager;
import com.xabber.androiddev.R;
import java.io.File;
public class ChatExportDialogFragment extends ConfirmDialogFragment {
private static final String ACCOUNT = "ACCOUNT";
......@@ -45,8 +45,7 @@ public class ChatExportDialogFragment extends ConfirmDialogFragment {
* @return
*/
public static DialogFragment newInstance(String account, String user) {
return new ChatExportDialogFragment().putAgrument(ACCOUNT, account)
.putAgrument(USER, user);
return new ChatExportDialogFragment().putAgrument(ACCOUNT, account).putAgrument(USER, user);
}
private String account;
......
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
......
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
......
......@@ -14,17 +14,17 @@
*/
package com.xabber.android.ui.dialog;
import java.util.ArrayList;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.xabber.androiddev.R;
import java.util.ArrayList;
public class GroupAddDialogFragment extends ConfirmDialogFragment {
private static final String GROUPS = "GROUPS";
......
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException;
......
......@@ -16,7 +16,7 @@ package com.xabber.android.ui.dialog;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
......
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.extension.muc.MUCManager;
......
package com.xabber.android.ui.dialog;
import android.app.AlertDialog.Builder;
import android.support.v4.app.DialogFragment;
import android.app.DialogFragment;
import com.xabber.android.data.SettingsManager;
import com.xabber.androiddev.R;
......
......@@ -14,8 +14,6 @@
*/
package com.xabber.android.ui.helper;
import org.jivesoftware.smackx.ChatState;
import android.app.Activity;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
......@@ -24,7 +22,6 @@ import android.graphics.Shader.TileMode;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
......@@ -34,6 +31,8 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.utils.Emoticons;
import com.xabber.androiddev.R;
import org.jivesoftware.smackx.ChatState;
/**
* Helper class to update <code>contact_title.xml</code>.
*
......@@ -61,8 +60,7 @@ public class ContactTitleInflater {
.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 TextView statusTextView = (TextView) titleView.findViewById(R.id.status_text);
final View shadowView = titleView.findViewById(R.id.shadow);
titleView.setBackgroundDrawable(titleAccountBackground);
nameView.setText(abstractContact.getName());
......
......@@ -33,11 +33,9 @@ import com.xabber.android.data.roster.AbstractContact;
import com.xabber.android.data.roster.GroupManager;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.ShowOfflineMode;
import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.ChatViewer;
import com.xabber.android.ui.ContactAdd;
import com.xabber.android.ui.ContactEditor;
import com.xabber.android.ui.preferences.ContactViewer;
import com.xabber.android.ui.MUCEditor;
import com.xabber.android.ui.StatusEditor;
import com.xabber.android.ui.adapter.UpdatableAdapter;
......@@ -45,6 +43,8 @@ import com.xabber.android.ui.dialog.ContactDeleteDialogFragment;
import com.xabber.android.ui.dialog.GroupDeleteDialogFragment;
import com.xabber.android.ui.dialog.GroupRenameDialogFragment;
import com.xabber.android.ui.dialog.MUCDeleteDialogFragment;
import com.xabber.android.ui.preferences.AccountEditor;
import com.xabber.android.ui.preferences.ContactViewer;
import com.xabber.androiddev.R;
/**
......@@ -84,7 +84,7 @@ public class ContextMenuHelper {
@Override
public boolean onMenuItemClick(MenuItem item) {
MUCDeleteDialogFragment.newInstance(account, user)
.show(activity.getSupportFragmentManager(),
.show(activity.getFragmentManager(),
"MUC_DELETE");
return true;
}
......@@ -131,8 +131,7 @@ public class ContextMenuHelper {
@Override
public boolean onMenuItemClick(MenuItem item) {
ContactDeleteDialogFragment.newInstance(account,
user).show(
activity.getSupportFragmentManager(),
user).show(activity.getFragmentManager(),
"CONTACT_DELETE");
return true;
}
......@@ -225,8 +224,7 @@ public class ContextMenuHelper {
account == GroupManager.NO_ACCOUNT ? null
: account,
group == GroupManager.NO_GROUP ? null
: group).show(
activity.getSupportFragmentManager(),
: group).show(activity.getFragmentManager(),
"GROUP_RENAME");
return true;
}
......@@ -241,9 +239,7 @@ public class ContextMenuHelper {
.newInstance(
account == GroupManager.NO_ACCOUNT ? null
: account, group)
.show(activity
.getSupportFragmentManager(),
"GROUP_DELETE");
.show(activity.getFragmentManager(), "GROUP_DELETE");
return true;
}
});
......
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