Skip to content

Commit

Permalink
Basic implementation of user name in group messages (#1122)
Browse files Browse the repository at this point in the history
Working, but it needs some other things.

Signed-off-by: Daniele Ricci <[email protected]>
  • Loading branch information
daniele-athome committed Dec 17, 2017
1 parent 1f5ae64 commit e02d2c6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/org/kontalk/ui/view/AvatarMessageTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.view.View;
import android.view.ViewStub;
import android.widget.LinearLayout;
import android.widget.TextView;

import org.kontalk.R;
import org.kontalk.data.Contact;
Expand All @@ -50,8 +51,8 @@ public class AvatarMessageTheme extends BaseMessageTheme implements Contact.Cont

private Handler mHandler;

public AvatarMessageTheme(int layoutId, int drawableId, boolean messageBlocks) {
super(layoutId);
public AvatarMessageTheme(int layoutId, int drawableId, boolean messageBlocks, boolean groupChat) {
super(layoutId, groupChat);
mDrawableId = drawableId;
mMessageBlocks = messageBlocks;
}
Expand Down
22 changes: 21 additions & 1 deletion app/src/main/java/org/kontalk/ui/view/BaseMessageTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,18 @@ public abstract class BaseMessageTheme implements MessageListItemTheme {
protected Context mContext;
protected LayoutInflater mInflater;

private TextView mContactNameView;
private MessageContentLayout mContent;
private ImageView mStatusIcon;
private ImageView mWarningIcon;
private TextView mDateView;

protected BaseMessageTheme(int layoutId) {
/** If true, we will show the contact name above the message content. */
private final boolean mGroupChat;

protected BaseMessageTheme(int layoutId, boolean groupChat) {
mLayoutId = layoutId;
mGroupChat = groupChat;
}

@Override
Expand All @@ -63,6 +68,7 @@ public View inflate(ViewStub stub) {
mContext = stub.getContext();
mInflater = LayoutInflater.from(mContext);

mContactNameView = view.findViewById(R.id.contact_name);
mContent = view.findViewById(R.id.content);
mStatusIcon = view.findViewById(R.id.status_indicator);
mWarningIcon = view.findViewById(R.id.warning_icon);
Expand Down Expand Up @@ -123,6 +129,20 @@ public void setIncoming(Contact contact, boolean sameMessageBlock) {
// no status icon for incoming messages
mStatusIcon.setImageDrawable(null);
mStatusIcon.setVisibility(View.GONE);

if (mGroupChat) {
if (contact != null) {
mContactNameView.setText(contact.getDisplayName());
mContactNameView.setVisibility(View.VISIBLE);
}
else {
// FIXME awkard situation
mContactNameView.setVisibility(View.GONE);
}
}
else {
mContactNameView.setVisibility(View.GONE);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public class HangoutMessageTheme extends AvatarMessageTheme {

private final int mDirection;

public HangoutMessageTheme(int direction) {
public HangoutMessageTheme(int direction, boolean groupChat) {
super(direction == MyMessages.Messages.DIRECTION_IN ?
R.layout.balloon_avatar_in_top : R.layout.balloon_avatar_out,
direction == MyMessages.Messages.DIRECTION_IN ?
R.drawable.balloon_hangout_incoming :
R.drawable.balloon_hangout_outgoing, true);
R.drawable.balloon_hangout_outgoing, true, groupChat);
mDirection = direction;
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/kontalk/ui/view/MessageListItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void afterInflate(int direction, boolean event, boolean groupChat) {
String theme = groupChat ?
Preferences.getBalloonGroupsTheme(getContext()) :
Preferences.getBalloonTheme(getContext());
mBalloonTheme = MessageListItemThemeFactory.createTheme(theme, direction, event);
mBalloonTheme = MessageListItemThemeFactory.createTheme(theme, direction, event, groupChat);
mBalloonTheme.inflate(stub);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@
public class MessageListItemThemeFactory {

private interface FactoryCreator {
MessageListItemTheme create(int direction);
MessageListItemTheme create(int direction, boolean groupChat);
}

private static final Map<String, FactoryCreator> mThemes = new HashMap<>();

static {
mThemes.put("hangout", new FactoryCreator() {
@Override
public MessageListItemTheme create(int direction) {
return new HangoutMessageTheme(direction);
public MessageListItemTheme create(int direction, boolean groupChat) {
return new HangoutMessageTheme(direction, groupChat);
}
});
mThemes.put("silence", new FactoryCreator() {
@Override
public MessageListItemTheme create(int direction) {
public MessageListItemTheme create(int direction, boolean groupChat) {
int layoutId, drawableId;
if (direction == MyMessages.Messages.DIRECTION_IN) {
layoutId = R.layout.balloon_avatar_in_bottom;
Expand All @@ -56,36 +56,36 @@ public MessageListItemTheme create(int direction) {
layoutId = R.layout.balloon_avatar_out;
drawableId = R.drawable.balloon_silence_outgoing;
}
return new AvatarMessageTheme(layoutId, drawableId, false);
return new AvatarMessageTheme(layoutId, drawableId, false, groupChat);
}
});
mThemes.put("classic", new FactoryCreator() {
@Override
public MessageListItemTheme create(int direction) {
public MessageListItemTheme create(int direction, boolean groupChat) {
return new SimpleMessageTheme(R.drawable.balloon_classic_incoming,
R.drawable.balloon_classic_outgoing);
R.drawable.balloon_classic_outgoing, groupChat);
}
});
mThemes.put("old_classic", new FactoryCreator() {
@Override
public MessageListItemTheme create(int direction) {
public MessageListItemTheme create(int direction, boolean groupChat) {
return new SimpleMessageTheme(R.drawable.balloon_old_classic_incoming,
R.drawable.balloon_old_classic_outgoing);
R.drawable.balloon_old_classic_outgoing, groupChat);
}
});
mThemes.put("iphone", new FactoryCreator() {
@Override
public MessageListItemTheme create(int direction) {
public MessageListItemTheme create(int direction, boolean groupChat) {
return new SimpleMessageTheme(R.drawable.balloon_iphone_incoming,
R.drawable.balloon_iphone_outgoing);
R.drawable.balloon_iphone_outgoing, groupChat);
}
});
}

private MessageListItemThemeFactory() {
}

public static MessageListItemTheme createTheme(String theme, int direction, boolean event) {
public static MessageListItemTheme createTheme(String theme, int direction, boolean event, boolean groupChat) {
if (event) {
return new EventMessageTheme(R.layout.balloon_event);
}
Expand All @@ -94,7 +94,7 @@ public static MessageListItemTheme createTheme(String theme, int direction, bool
if (factory == null)
throw new IllegalArgumentException("theme not found: " + theme);

return factory.create(direction);
return factory.create(direction, groupChat);
}
}
}
8 changes: 4 additions & 4 deletions app/src/main/java/org/kontalk/ui/view/SimpleMessageTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public class SimpleMessageTheme extends BaseMessageTheme {
private LinearLayout mBalloonView;
private LinearLayout mParentView;

public SimpleMessageTheme(int incomingDrawableId, int outgoingDrawableId) {
this(R.layout.balloon_base_noavatar, incomingDrawableId, outgoingDrawableId);
public SimpleMessageTheme(int incomingDrawableId, int outgoingDrawableId, boolean groupChat) {
this(R.layout.balloon_base_noavatar, incomingDrawableId, outgoingDrawableId, groupChat);
}

protected SimpleMessageTheme(int layoutId, int incomingDrawableId, int outgoingDrawableId) {
super(layoutId);
protected SimpleMessageTheme(int layoutId, int incomingDrawableId, int outgoingDrawableId, boolean groupChat) {
super(layoutId, groupChat);
mIncomingDrawableId = incomingDrawableId;
mOutgoingDrawableId = outgoingDrawableId;
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/layout/balloon_avatar_in.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@
-->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/balloon_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="start">

<TextView android:id="@+id/contact_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:visibility="gone"
tools:text="Dev-5554"
/>

<org.kontalk.ui.view.MessageContentLayout
android:id="@+id/content"
android:orientation="vertical"
Expand Down

0 comments on commit e02d2c6

Please sign in to comment.