aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java')
-rw-r--r--src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java96
1 files changed, 45 insertions, 51 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
index 7138f8e3..71db3e3a 100644
--- a/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
+++ b/src/main/java/de/thedevstack/conversationsplus/ui/ConversationActivity.java
@@ -28,7 +28,6 @@ import android.view.MenuItem;
import android.view.Surface;
import android.view.View;
import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
@@ -36,6 +35,7 @@ import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.PopupMenu.OnMenuItemClickListener;
+import android.widget.TextView;
import android.widget.Toast;
import net.java.otr4j.session.SessionStatus;
@@ -51,6 +51,7 @@ import de.thedevstack.android.logcat.Logging;
import de.thedevstack.conversationsplus.ConversationsPlusPreferences;
import de.thedevstack.conversationsplus.services.AvatarService;
import de.thedevstack.conversationsplus.ui.dialogs.UserDecisionDialog;
+import de.thedevstack.conversationsplus.ui.listeners.AvatarLogoPositioningListener;
import de.thedevstack.conversationsplus.ui.listeners.ResizePictureUserDecisionListener;
import de.thedevstack.conversationsplus.utils.ConversationUtil;
import de.timroes.android.listview.EnhancedListView;
@@ -118,6 +119,7 @@ public class ConversationActivity extends XmppActivity
private View mContentView;
private View avatarLogoView;
+ private View titleView;
private List<Conversation> conversationList = new ArrayList<>();
private Conversation swipedConversation = null;
@@ -131,7 +133,7 @@ public class ConversationActivity extends XmppActivity
private AtomicBoolean mRedirected = new AtomicBoolean(false);
private Pair<Integer, Intent> mPostponedActivityResult;
- public Conversation getSelectedConversation() {
+ public Conversation getSelectedConversation() {
return this.mSelectedConversation;
}
@@ -354,81 +356,73 @@ public class ConversationActivity extends XmppActivity
private void updateActionBarTitle(boolean titleShouldBeName) {
final ActionBar ab = getActionBar();
- final Conversation conversation = getSelectedConversation();
if (ab != null) {
+ if (null == this.titleView || null == this.avatarLogoView) {
+ this.initializeCustomActionBarViews(ab);
+ }
+ TextView title = (TextView) this.titleView.findViewById(R.id.conversationsTitle);
+ final Conversation conversation = getSelectedConversation();
if (titleShouldBeName && conversation != null) {
- this.updateLogoAvatar(true);
+ this.toggleShowCustomActionBarView(ab, true);
+ this.showLogoAvatar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setHomeButtonEnabled(true);
+
if (conversation.getMode() == Conversation.MODE_SINGLE || ConversationsPlusPreferences.useSubject()) {
- ab.setTitle(conversation.getName());
+ title.setText(conversation.getName());
} else {
- ab.setTitle(conversation.getJid().toBareJid().toString());
+ title.setText(conversation.getJid().toBareJid().toString());
}
} else {
+ this.toggleShowCustomActionBarView(ab, false);
ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false);
- ab.setTitle(R.string.app_name);
- this.updateLogoAvatar(false);
+ title.setText(R.string.app_name);
+ this.hideLogoAvatar();
}
}
}
- private void updateLogoAvatar(boolean show) {
+ private void toggleShowCustomActionBarView(ActionBar ab, boolean show) {
+ if (show) {
+ ab.setDisplayShowTitleEnabled(false);
+ ab.setDisplayShowCustomEnabled(true);
+ } else {
+ ab.setDisplayShowTitleEnabled(true);
+ ab.setDisplayShowCustomEnabled(false);
+ }
+ }
+
+ private void initializeCustomActionBarViews(ActionBar ab) {
+ if (null == this.titleView) {
+ this.titleView = LayoutInflater.from(this).inflate(R.layout.title, null);
+ ab.setCustomView(this.titleView);
+ }
if (null == this.avatarLogoView) {
this.avatarLogoView = LayoutInflater.from(this).inflate(R.layout.logo_view, null, false);
ViewGroup decorViewGroup = (ViewGroup) getWindow().getDecorView();
decorViewGroup.addView(avatarLogoView);
int resId = getResources().getIdentifier("action_bar_container", "id", "android");
final View actionBarView = decorViewGroup.findViewById(resId);
- final View iconPlaceholderView = decorViewGroup.findViewById(R.id.icon_placeholder);
if (actionBarView != null) {
- actionBarView.getViewTreeObserver().addOnGlobalLayoutListener(
- new ViewTreeObserver.OnGlobalLayoutListener() {
- public void onGlobalLayout() {
- // Remove the listener
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- actionBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
- } else {
- actionBarView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
- }
-
- // Measure views
- int[] location = new int[2];
- actionBarView.getLocationOnScreen(location);
-
- int[] logoLocation = new int[2];
- avatarLogoView.getLocationOnScreen(logoLocation);
-
- int[] iconPlaceHolderLocation = new int[2];
- if (null != iconPlaceholderView) {
- iconPlaceholderView.getLocationOnScreen(iconPlaceHolderLocation);
- }else {
- iconPlaceHolderLocation[0] = 0;
- }
-
- // Add top padding if necessary
- if (location[1] > logoLocation[1]) {
- avatarLogoView.setPadding(iconPlaceHolderLocation[0], actionBarView.getMeasuredHeight() / 4 + location[1] - logoLocation[1], 0, 0);
- }
- /*if (iconPlaceHolderLocation[0] > logoLocation[0]) {
- avatarLogoView.setPadding
- }*/
- }
- }
- );
+ actionBarView.getViewTreeObserver().addOnGlobalLayoutListener(new AvatarLogoPositioningListener(actionBarView, avatarLogoView));
}
}
- if (show) {
- ImageView avatarView = (ImageView) this.avatarLogoView.findViewById(R.id.logoViewAvatar);
- avatarView.setImageBitmap(AvatarService.getInstance().get(getSelectedConversation(), getPixel(56)));
- //avatarView.setAlpha(0.5f);
- avatarLogoView.setVisibility(View.VISIBLE);
- } else {
- avatarLogoView.setVisibility(View.GONE);
+ }
+
+ private void hideLogoAvatar() {
+ if (null != this.avatarLogoView) {
+ this.avatarLogoView.setVisibility(View.GONE);
}
}
+ private void showLogoAvatar() {
+ ImageView avatarView = (ImageView) this.avatarLogoView.findViewById(R.id.logoViewAvatar);
+ avatarView.setImageBitmap(AvatarService.getInstance().getCircled(getSelectedConversation(), getPixel(56)));
+ //avatarView.setAlpha(0.5f);
+ avatarLogoView.setVisibility(View.VISIBLE);
+ }
+
private void openConversation() {
this.updateActionBarTitle();
this.invalidateOptionsMenu();