Commit 4ace1632 authored by Grigory Fedorov's avatar Grigory Fedorov

ChatViewer now also uses ContactTitleActionBarInflater....

ChatViewer now also uses ContactTitleActionBarInflater. ContactTitleActionBarInflater better encapsulates inner views.
parent 673647ed
...@@ -16,26 +16,17 @@ package com.xabber.android.ui; ...@@ -16,26 +16,17 @@ package com.xabber.android.ui;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView; import android.widget.ImageView;
import com.xabber.android.data.ActivityManager; import com.xabber.android.data.ActivityManager;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.OnAccountChangedListener; import com.xabber.android.data.account.OnAccountChangedListener;
import com.xabber.android.data.entity.BaseEntity; import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.archive.MessageArchiveManager; import com.xabber.android.data.extension.archive.MessageArchiveManager;
...@@ -56,7 +47,7 @@ import com.xabber.android.data.roster.OnContactChangedListener; ...@@ -56,7 +47,7 @@ import com.xabber.android.data.roster.OnContactChangedListener;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.ui.adapter.ChatViewerAdapter; import com.xabber.android.ui.adapter.ChatViewerAdapter;
import com.xabber.android.ui.dialog.ChatExportDialogFragment; import com.xabber.android.ui.dialog.ChatExportDialogFragment;
import com.xabber.android.ui.helper.ContactTitleInflater; import com.xabber.android.ui.helper.ContactTitleActionBarInflater;
import com.xabber.android.ui.helper.ManagedActivity; import com.xabber.android.ui.helper.ManagedActivity;
import com.xabber.android.ui.preferences.ChatEditor; import com.xabber.android.ui.preferences.ChatEditor;
import com.xabber.androiddev.R; import com.xabber.androiddev.R;
...@@ -92,19 +83,14 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -92,19 +83,14 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
ChatViewerAdapter chatViewerAdapter; ChatViewerAdapter chatViewerAdapter;
ViewPager viewPager; ViewPager viewPager;
private View actionBarView;
Collection<ChatViewerFragment> registeredChats = new HashSet<>(); Collection<ChatViewerFragment> registeredChats = new HashSet<>();
Collection<RecentChatFragment> recentChatFragments = new HashSet<>(); Collection<RecentChatFragment> recentChatFragments = new HashSet<>();
private String actionWithAccount = null; private String actionWithAccount = null;
private String actionWithUser = null; private String actionWithUser = null;
private int[] accountActionBarColors;
private int[] accountStatusBarColors;
private Window window;
private int defaultStatusBarColor;
private Animation shakeAnimation; private ContactTitleActionBarInflater contactTitleActionBarInflater;
private boolean isChatSelected; private boolean isChatSelected;
private Menu menu = null; private Menu menu = null;
...@@ -133,38 +119,16 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -133,38 +119,16 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND); exitOnSend = savedInstanceState.getBoolean(SAVED_EXIT_ON_SEND);
} }
shakeAnimation = AnimationUtils.loadAnimation(this, R.anim.shake); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setUpActionBarView();
window = getWindow(); contactTitleActionBarInflater.setOnClickListener(new View.OnClickListener() {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
defaultStatusBarColor = window.getStatusBarColor();
}
accountActionBarColors = getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = getResources().getIntArray(R.array.account_status_bar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBarView = LayoutInflater.from(this).inflate(R.layout.contact_title, null);
actionBarView.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
scrollChat(); scrollChat();
} }
}); });
actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
setContentView(R.layout.activity_chat_viewer); setContentView(R.layout.activity_chat_viewer);
if (account != null && user != null) { if (account != null && user != null) {
...@@ -584,11 +548,9 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -584,11 +548,9 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
&& actionWithUser != null && actionWithUser.equals(user)) { && actionWithUser != null && actionWithUser.equals(user)) {
updateActionBar(account, user); updateActionBar(account, user);
if (incoming) { if (incoming) {
actionBarView.findViewById(R.id.name_holder).startAnimation(shakeAnimation); contactTitleActionBarInflater.playIncomingAnimation();
} }
} }
} }
@Override @Override
...@@ -649,13 +611,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -649,13 +611,7 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
createOptionsMenu(); createOptionsMenu();
if (!isChatSelected) { if (!isChatSelected) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { contactTitleActionBarInflater.restoreDefaultTitleView(getString(R.string.chat_list));
window.setStatusBarColor(defaultStatusBarColor);
}
getSupportActionBar().setBackgroundDrawable(null);
getSupportActionBar().setDisplayShowTitleEnabled(true);
actionBarView.setVisibility(View.GONE);
setTitle(getString(R.string.chat_list));
MessageManager.getInstance().removeVisibleChat(); MessageManager.getInstance().removeVisibleChat();
return; return;
} }
...@@ -672,20 +628,14 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener ...@@ -672,20 +628,14 @@ public class ChatViewer extends ManagedActivity implements OnChatChangedListener
} }
private void updateActionBar(String account, String user) { private void updateActionBar(String account, String user) {
actionBarView.setVisibility(View.VISIBLE);
getSupportActionBar().setDisplayShowTitleEnabled(false);
final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user); final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
ContactTitleInflater.updateTitle(actionBarView, this, abstractContact);
int colorLevel = AccountManager.getInstance().getColorLevel(abstractContact.getAccount()); contactTitleActionBarInflater.update(abstractContact);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(accountStatusBarColors[colorLevel]);
}
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user); SecurityLevel securityLevel = OTRManager.getInstance().getSecurityLevel(account, user);
SettingsManager.SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode(); SettingsManager.SecurityOtrMode securityOtrMode = SettingsManager.securityOtrMode();
ImageView securityView = (ImageView) actionBarView.findViewById(R.id.security);
ImageView securityView = contactTitleActionBarInflater.getSecurityView();
if (securityLevel == SecurityLevel.plain if (securityLevel == SecurityLevel.plain
&& (securityOtrMode == SettingsManager.SecurityOtrMode.disabled && (securityOtrMode == SettingsManager.SecurityOtrMode.disabled
......
...@@ -17,10 +17,8 @@ package com.xabber.android.ui; ...@@ -17,10 +17,8 @@ package com.xabber.android.ui;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.NetworkException; import com.xabber.android.data.NetworkException;
...@@ -51,7 +49,7 @@ public class ContactEditor extends GroupListActivity implements ...@@ -51,7 +49,7 @@ public class ContactEditor extends GroupListActivity implements
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
} }
@Override @Override
...@@ -103,12 +101,8 @@ public class ContactEditor extends GroupListActivity implements ...@@ -103,12 +101,8 @@ public class ContactEditor extends GroupListActivity implements
private void update() { private void update() {
AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user); AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleActionBarInflater.update(abstractContact); contactTitleActionBarInflater.update(abstractContact);
contactTitleActionBarInflater.setName(getString(R.string.contact_editor_title, abstractContact.getName()));
View actionBarView = contactTitleActionBarInflater.getActionBarView(); contactTitleActionBarInflater.setStatusText(user);
((TextView) actionBarView.findViewById(R.id.name))
.setText(getString(R.string.contact_editor_title, abstractContact.getName()));
((TextView) actionBarView.findViewById(R.id.status_text)).setText(user);
} }
@Override @Override
......
...@@ -119,7 +119,7 @@ public class FingerprintViewer extends ManagedActivity implements ...@@ -119,7 +119,7 @@ public class FingerprintViewer extends ManagedActivity implements
isUpdating = false; isUpdating = false;
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
} }
@Override @Override
......
...@@ -102,7 +102,7 @@ public class QuestionViewer extends ManagedActivity implements ...@@ -102,7 +102,7 @@ public class QuestionViewer extends ManagedActivity implements
findViewById(R.id.send).setOnClickListener(this); findViewById(R.id.send).setOnClickListener(this);
contactTitleActionBarInflater = new ContactTitleActionBarInflater(this); contactTitleActionBarInflater = new ContactTitleActionBarInflater(this);
contactTitleActionBarInflater.setActionBarView(); contactTitleActionBarInflater.setUpActionBarView();
} }
@Override @Override
......
...@@ -89,12 +89,12 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -89,12 +89,12 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
hint = null; hint = null;
appearanceStyle = SettingsManager.chatsAppearanceStyle(); appearanceStyle = SettingsManager.chatsAppearanceStyle();
ChatsDivide chatsDivide = SettingsManager.chatsDivide(); ChatsDivide chatsDivide = SettingsManager.chatsDivide();
if (chatsDivide == ChatsDivide.always if (chatsDivide == ChatsDivide.always || (chatsDivide == ChatsDivide.portial
|| (chatsDivide == ChatsDivide.portial && !activity && !activity.getResources().getBoolean(R.bool.landscape))) {
.getResources().getBoolean(R.bool.landscape)))
divider = "\n"; divider = "\n";
else } else {
divider = " "; divider = " ";
}
} }
@Override @Override
...@@ -104,10 +104,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -104,10 +104,11 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override @Override
public Object getItem(int position) { public Object getItem(int position) {
if (position < messages.size()) if (position < messages.size()) {
return messages.get(position); return messages.get(position);
else } else {
return null; return null;
}
} }
@Override @Override
...@@ -122,18 +123,17 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -122,18 +123,17 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (position < messages.size()) if (position < messages.size()) {
return TYPE_MESSAGE; return TYPE_MESSAGE;
else } else {
return hint == null ? TYPE_EMPTY : TYPE_HINT; return hint == null ? TYPE_EMPTY : TYPE_HINT;
}
} }
private void append(SpannableStringBuilder builder, CharSequence text, private void append(SpannableStringBuilder builder, CharSequence text, CharacterStyle span) {
CharacterStyle span) {
int start = builder.length(); int start = builder.length();
builder.append(text); builder.append(text);
builder.setSpan(span, start, start + text.length(), builder.setSpan(span, start, start + text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
} }
@Override @Override
...@@ -142,24 +142,32 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -142,24 +142,32 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
final View view; final View view;
if (convertView == null) { if (convertView == null) {
final int resource; final int resource;
if (type == TYPE_MESSAGE) switch (type) {
resource = R.layout.chat_viewer_message; case TYPE_MESSAGE:
else if (type == TYPE_HINT) resource = R.layout.chat_viewer_message;
resource = R.layout.chat_viewer_info; break;
else if (type == TYPE_EMPTY) case TYPE_HINT:
resource = R.layout.chat_viewer_empty; resource = R.layout.chat_viewer_info;
else break;
throw new IllegalStateException(); case TYPE_EMPTY:
view = activity.getLayoutInflater() resource = R.layout.chat_viewer_empty;
.inflate(resource, parent, false); break;
if (type == TYPE_MESSAGE) default:
((TextView) view.findViewById(R.id.text)).setTextAppearance( throw new IllegalStateException();
activity, appearanceStyle); }
} else
view = activity.getLayoutInflater().inflate(resource, parent, false);
if (type == TYPE_MESSAGE) {
((TextView) view.findViewById(R.id.text)).setTextAppearance(activity, appearanceStyle);
}
} else {
view = convertView; view = convertView;
}
if (type == TYPE_EMPTY) if (type == TYPE_EMPTY) {
return view; return view;
}
if (type == TYPE_HINT) { if (type == TYPE_HINT) {
TextView textView = ((TextView) view.findViewById(R.id.info)); TextView textView = ((TextView) view.findViewById(R.id.info));
...@@ -177,111 +185,94 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -177,111 +185,94 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
if (isMUC) { if (isMUC) {
name = resource; name = resource;
} else { } else {
if (incoming) if (incoming) {
name = RosterManager.getInstance().getName(account, user); name = RosterManager.getInstance().getName(account, user);
else } else {
name = AccountManager.getInstance().getNickName(account); name = AccountManager.getInstance().getNickName(account);
}
} }
if (incoming) { if (incoming) {
if (view.getBackground() == null) if (view.getBackground() == null) {
view.setBackgroundResource(R.drawable.chat_bg); view.setBackgroundResource(R.drawable.chat_bg);
view.getBackground().setLevel( }
AccountManager.getInstance().getColorLevel(account)); view.getBackground().setLevel(AccountManager.getInstance().getColorLevel(account));
} else { } else {
view.setBackgroundDrawable(null); view.setBackgroundDrawable(null);
} }
Spannable text = messageItem.getSpannable(); Spannable text = messageItem.getSpannable();
TextView textView = (TextView) view.findViewById(R.id.text); TextView textView = (TextView) view.findViewById(R.id.text);
ImageView avatarView = (ImageView) view.findViewById(R.id.avatar); ImageView avatarView = (ImageView) view.findViewById(R.id.avatar);
ChatAction action = messageItem.getAction(); ChatAction action = messageItem.getAction();
String time = StringUtils.getSmartTimeText(messageItem.getTimestamp()); String time = StringUtils.getSmartTimeText(messageItem.getTimestamp());
SpannableStringBuilder builder = new SpannableStringBuilder(); SpannableStringBuilder builder = new SpannableStringBuilder();
if (action == null) { if (action == null) {
int messageResource = R.drawable.ic_message_delivered; int messageResource = R.drawable.ic_message_delivered;
if (!incoming) { if (!incoming) {
if (messageItem.isError()) if (messageItem.isError()) {
messageResource = R.drawable.ic_message_has_error; messageResource = R.drawable.ic_message_has_error;
else if (!messageItem.isSent()) } else if (!messageItem.isSent()) {
messageResource = R.drawable.ic_message_not_sent; messageResource = R.drawable.ic_message_not_sent;
else if (!messageItem.isDelivered()) } else if (!messageItem.isDelivered()) {
messageResource = R.drawable.ic_message_not_delivered; messageResource = R.drawable.ic_message_not_delivered;
}
} }
append(builder, " ", new ImageSpan(activity, messageResource)); append(builder, " ", new ImageSpan(activity, messageResource));
append(builder, " ", new TextAppearanceSpan(activity, append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
R.style.ChatHeader)); append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
append(builder, time, new TextAppearanceSpan(activity, append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
R.style.ChatHeader_Time)); append(builder, name, new TextAppearanceSpan(activity, R.style.ChatHeader_Name));
append(builder, " ", new TextAppearanceSpan(activity, append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
R.style.ChatHeader));
append(builder, name, new TextAppearanceSpan(activity,
R.style.ChatHeader_Name));
append(builder, divider, new TextAppearanceSpan(activity,
R.style.ChatHeader));
Date timeStamp = messageItem.getDelayTimestamp(); Date timeStamp = messageItem.getDelayTimestamp();
if (timeStamp != null) { if (timeStamp != null) {
String delay = activity.getString( String delay = activity.getString(incoming ? R.string.chat_delay : R.string.chat_typed,
incoming ? R.string.chat_delay : R.string.chat_typed,
StringUtils.getSmartTimeText(timeStamp)); StringUtils.getSmartTimeText(timeStamp));
append(builder, delay, new TextAppearanceSpan(activity, append(builder, delay, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
R.style.ChatHeader_Delay)); append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
append(builder, divider, new TextAppearanceSpan(activity,
R.style.ChatHeader));
} }
if (messageItem.isUnencypted()) { if (messageItem.isUnencypted()) {
append(builder, append(builder, activity.getString(R.string.otr_unencrypted_message),
activity.getString(R.string.otr_unencrypted_message), new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
new TextAppearanceSpan(activity, append(builder, divider, new TextAppearanceSpan(activity, R.style.ChatHeader));
R.style.ChatHeader_Delay));
append(builder, divider, new TextAppearanceSpan(activity,
R.style.ChatHeader));
} }
Emoticons.getSmiledText(activity.getApplication(), text); Emoticons.getSmiledText(activity.getApplication(), text);
if (messageItem.getTag() == null) if (messageItem.getTag() == null) {
builder.append(text); builder.append(text);
else } else {
append(builder, text, new TextAppearanceSpan(activity, append(builder, text, new TextAppearanceSpan(activity, R.style.ChatRead));
R.style.ChatRead)); }
} else { } else {
append(builder, time, new TextAppearanceSpan(activity, append(builder, time, new TextAppearanceSpan(activity, R.style.ChatHeader_Time));
R.style.ChatHeader_Time)); append(builder, " ", new TextAppearanceSpan(activity, R.style.ChatHeader));
append(builder, " ", new TextAppearanceSpan(activity, text = Emoticons.newSpannable(action.getText(activity, name, text.toString()));
R.style.ChatHeader));
text = Emoticons.newSpannable(action.getText(activity, name,
text.toString()));
Emoticons.getSmiledText(activity.getApplication(), text); Emoticons.getSmiledText(activity.getApplication(), text);
append(builder, text, new TextAppearanceSpan(activity, append(builder, text, new TextAppearanceSpan(activity, R.style.ChatHeader_Delay));
R.style.ChatHeader_Delay));
} }
textView.setText(builder); textView.setText(builder);
textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setMovementMethod(LinkMovementMethod.getInstance());
if (SettingsManager.chatsShowAvatars()) { if (SettingsManager.chatsShowAvatars()) {
avatarView.setVisibility(View.VISIBLE); avatarView.setVisibility(View.VISIBLE);
if (!incoming if (!incoming || (isMUC && MUCManager.getInstance().getNickname(account, user).equalsIgnoreCase(resource))) {
|| (isMUC && MUCManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance().getAccountAvatar(account));
.getNickname(account, user)
.equalsIgnoreCase(resource))) {
avatarView.setImageDrawable(AvatarManager.getInstance()
.getAccountAvatar(account));
} else { } else {
if (isMUC) { if (isMUC) {
if ("".equals(resource)) { if ("".equals(resource)) {
avatarView.setImageDrawable(AvatarManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance().getRoomAvatar(user));
.getRoomAvatar(user));
} else { } else {
avatarView.setImageDrawable(AvatarManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance().getOccupantAvatar(user + "/" + resource));
.getOccupantAvatar(user + "/" + resource));
} }
} else { } else {
avatarView.setImageDrawable(AvatarManager.getInstance() avatarView.setImageDrawable(AvatarManager.getInstance().getUserAvatar(user));
.getUserAvatar(user));
} }
} }
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule( ((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, R.id.avatar);
RelativeLayout.RIGHT_OF, R.id.avatar);
} else { } else {
avatarView.setVisibility(View.GONE); avatarView.setVisibility(View.GONE);
((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule( ((RelativeLayout.LayoutParams) textView.getLayoutParams()).addRule(RelativeLayout.RIGHT_OF, 0);
RelativeLayout.RIGHT_OF, 0);
} }
return view; return view;
} }
...@@ -318,26 +309,21 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -318,26 +309,21 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
* @return New hint. * @return New hint.
*/ */
private String getHint() { private String getHint() {
AccountItem accountItem = AccountManager.getInstance().getAccount( AccountItem accountItem = AccountManager.getInstance().getAccount(account);
account); boolean online = accountItem != null && accountItem.getState().isConnected();
boolean online; final AbstractContact abstractContact = RosterManager.getInstance().getBestContact(account, user);
if (accountItem == null)
online = false;
else
online = accountItem.getState().isConnected();
final AbstractContact abstractContact = RosterManager.getInstance()
.getBestContact(account, user);
if (!online) { if (!online) {
if (abstractContact instanceof RoomContact) if (abstractContact instanceof RoomContact) {
return activity.getString(R.string.muc_is_unavailable); return activity.getString(R.string.muc_is_unavailable);
else } else {
return activity.getString(R.string.account_is_offline); return activity.getString(R.string.account_is_offline);
}
} else if (!abstractContact.getStatusMode().isOnline()) { } else if (!abstractContact.getStatusMode().isOnline()) {
if (abstractContact instanceof RoomContact) if (abstractContact instanceof RoomContact) {
return activity.getString(R.string.muc_is_unavailable); return activity.getString(R.string.muc_is_unavailable);
else } else {
return activity.getString(R.string.contact_is_offline, return activity.getString(R.string.contact_is_offline, abstractContact.getName());
abstractContact.getName()); }
} }
return null; return null;
} }
...@@ -348,8 +334,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter ...@@ -348,8 +334,9 @@ public class ChatMessageAdapter extends BaseAdapter implements UpdatableAdapter
*/ */
public void updateInfo() { public void updateInfo() {
String info = getHint(); String info = getHint();
if (this.hint == info || (this.hint != null && this.hint.equals(info))) if (this.hint.equals(info) || (this.hint != null && this.hint.equals(info))) {
return; return;
}
this.hint = info; this.hint = info;
notifyDataSetChanged(); notifyDataSetChanged();
} }
......
...@@ -8,6 +8,10 @@ import android.view.LayoutInflater; ...@@ -8,6 +8,10 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;
import com.xabber.android.data.account.AccountManager; import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.roster.AbstractContact; import com.xabber.android.data.roster.AbstractContact;
...@@ -20,17 +24,17 @@ public class ContactTitleActionBarInflater { ...@@ -20,17 +24,17 @@ public class ContactTitleActionBarInflater {
private int[] accountActionBarColors; private int[] accountActionBarColors;
private int[] accountStatusBarColors; private int[] accountStatusBarColors;
private Window window; private Window window;
private int defaultStatusBarColor;
private Animation shakeAnimation = null;
public ContactTitleActionBarInflater(ActionBarActivity activity) { public ContactTitleActionBarInflater(ActionBarActivity activity) {
this.activity = activity; this.activity = activity;
} }
public void setActionBarView() { public void setUpActionBarView() {
window = this.activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar); accountActionBarColors = activity.getResources().getIntArray(R.array.account_action_bar);
accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar); accountStatusBarColors = activity.getResources().getIntArray(R.array.account_status_bar);
...@@ -44,9 +48,19 @@ public class ContactTitleActionBarInflater { ...@@ -44,9 +48,19 @@ public class ContactTitleActionBarInflater {
actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams( actionBar.setCustomView(actionBarView, new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT)); ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window = this.activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
defaultStatusBarColor = window.getStatusBarColor();
}
} }
public void update(AbstractContact abstractContact) { public void update(AbstractContact abstractContact) {
activity.getSupportActionBar().setDisplayShowTitleEnabled(false);
actionBarView.setVisibility(View.VISIBLE);
ContactTitleInflater.updateTitle(actionBarView, activity, abstractContact); ContactTitleInflater.updateTitle(actionBarView, activity, abstractContact);
int colorLevel = AccountManager.getInstance().getColorLevel(abstractContact.getAccount()); int colorLevel = AccountManager.getInstance().getColorLevel(abstractContact.getAccount());
...@@ -56,7 +70,37 @@ public class ContactTitleActionBarInflater { ...@@ -56,7 +70,37 @@ public class ContactTitleActionBarInflater {
activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel])); activity.getSupportActionBar().setBackgroundDrawable(new ColorDrawable(accountActionBarColors[colorLevel]));
} }
public View getActionBarView() { public void restoreDefaultTitleView(String title) {
return actionBarView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(defaultStatusBarColor);
}
activity.getSupportActionBar().setBackgroundDrawable(null);
activity.getSupportActionBar().setDisplayShowTitleEnabled(true);
actionBarView.setVisibility(View.GONE);
activity.setTitle(title);
}
public ImageView getSecurityView() {
return (ImageView)actionBarView.findViewById(R.id.security);
}
public void playIncomingAnimation() {
if (shakeAnimation == null) {
shakeAnimation = AnimationUtils.loadAnimation(activity, R.anim.shake);
}
actionBarView.findViewById(R.id.name_holder).startAnimation(shakeAnimation);
}
public void setOnClickListener(View.OnClickListener onClickListener) {
actionBarView.setOnClickListener(onClickListener);
}
public void setName(String name) {
((TextView) actionBarView.findViewById(R.id.name)).setText(name);
}
public void setStatusText(String user) {
((TextView) actionBarView.findViewById(R.id.status_text)).setText(user);
} }
} }
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