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
......
...@@ -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