set avatar on message on top again and a UI fixes

This commit is contained in:
Arne 2023-08-25 09:12:34 +02:00
parent d1ce34f304
commit 501c579086
10 changed files with 32 additions and 142 deletions

View file

@ -1808,72 +1808,4 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
return ++resendCount;
}
/**
* Checks whether message should show an avatar next to it. Mainly used to hide the avatar
* when succeeding messages have the same author. Thus it defaults to true.
*
* @return boolean
*/
public boolean isAvatarable() {
if (this.next() == null) {
return true;
}
Message next = this.next();
// same status (particularly sent vs received)
if (this.getStatus() == next.getStatus()) {
// same user
if (this.getAvatarName().equals(next.getAvatarName())) {
// same encryption
if (this.getEncryption() != next.getEncryption()) {
return true;
}
// same day
if (!UIHelper.sameDay(this.getTimeSent(), next.getTimeSent())){
return true;
}
// if merged, ask merged
if (next.wasMergedIntoPrevious()) {
return next.isAvatarable();
}
return false;
}
}
return true;
}
/**
* Checks whether message should show a username next to it. Mainly used to hide the username
* when succeeding messages have the same author. Thus it defaults to true.
*
* @return boolean
*/
public boolean showUsername() {
if (this.prev() == null) {
return true;
}
Message prev = this.prev();
// same status (particularly sent vs received)
if (this.getStatus() == prev.getStatus()) {
// same user
if (this.getAvatarName().equals(prev.getAvatarName())) {
// same encryption
if (this.getEncryption() != prev.getEncryption()) {
return true;
}
// same day
if (!UIHelper.sameDay(this.getTimeSent(), prev.getTimeSent())){
return true;
}
// if merged, ask merged
if (prev.wasMergedIntoPrevious()) {
return prev.isAvatarable();
}
return false;
}
}
return true;
}
}

View file

@ -369,7 +369,12 @@ public class MessageAdapter extends ArrayAdapter<Message> {
default:
if (mForceNames || multiReceived || (message.getTrueCounterpart() != null && message.getContact() != null)) {
final int shadowSize = 10;
showUsername(viewHolder, message, darkBackground);
viewHolder.username.setVisibility(View.VISIBLE);
viewHolder.username.setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message));
if (activity.xmppConnectionService.colored_muc_names() && ThemeHelper.showColoredUsernameBackGround(activity, darkBackground)) {
viewHolder.username.setPadding(4, 2, 4, 2);
viewHolder.username.setBackground(ContextCompat.getDrawable(activity, R.drawable.duration_background));
}
} else if (singleReceived) {
viewHolder.username.setVisibility(View.GONE);
}
@ -463,24 +468,6 @@ public class MessageAdapter extends ArrayAdapter<Message> {
}
}
}
private void showUsername(ViewHolder viewHolder, Message message, boolean darkBackground) {
if (message == null || viewHolder == null) {
return;
}
viewHolder.username.setText(UIHelper.getColoredUsername(activity.xmppConnectionService, message));
if (message.showUsername() || mForceNames) {
viewHolder.username.setVisibility(View.VISIBLE);
} else {
viewHolder.username.setVisibility(View.GONE);
}
if (activity.xmppConnectionService.colored_muc_names() && ThemeHelper.showColoredUsernameBackGround(activity, darkBackground)) {
viewHolder.username.setPadding(4, 2, 4, 2);
viewHolder.username.setBackground(ContextCompat.getDrawable(activity, R.drawable.duration_background));
} else {
viewHolder.username.setPadding(4, 2, 4, 2);
viewHolder.username.setBackground(null);
}
}
private void displayInfoMessage(ViewHolder viewHolder, CharSequence text, boolean darkBackground, Message message) {
viewHolder.download_button.setVisibility(View.GONE);
@ -1742,26 +1729,8 @@ public class MessageAdapter extends ArrayAdapter<Message> {
setBubbleBackgroundColor(viewHolder.message_box, type, message.isPrivateMessage(), isInValidSession);
}
displayStatus(viewHolder, message, type, darkBackground);
showAvatar(viewHolder, message, view);
return view;
}
private void showAvatar(ViewHolder viewHolder, Message message, View view) {
if (message.isAvatarable()) {
viewHolder.contact_picture.setVisibility(View.VISIBLE);
int left = ThemeHelper.dp2Px(getContext(), 8);
int top = ThemeHelper.dp2Px(getContext(), 0);
int right = ThemeHelper.dp2Px(getContext(), 8);
int bottom = ThemeHelper.dp2Px(getContext(), 16);
view.setPadding(left, top, right, bottom);
} else {
viewHolder.contact_picture.setVisibility(View.INVISIBLE);
int left = ThemeHelper.dp2Px(getContext(), 8);
int top = ThemeHelper.dp2Px(getContext(), 0);
int right = ThemeHelper.dp2Px(getContext(), 8);
int bottom = ThemeHelper.dp2Px(getContext(), 1);
view.setPadding(left, top, right, bottom);
}
}
private static class markFileExistingFinisher implements Runnable {
private final Message message;

View file

@ -697,15 +697,4 @@ public class ThemeHelper {
}
}
/**
* Calculate pixels relative to density.
*
* @param context from which to calculate the density
* @param dp density pixels
* @return pixels (dp)
*/
public static int dp2Px(Context context, int dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) (dp * scale + 0.5f);
}
}

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="0dp"
android:topRightRadius="15dp"
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="2dp"
android:left="6dp"

View file

@ -2,10 +2,10 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="2dp" android:color="@color/accent"/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="0dp"
android:topRightRadius="15dp"
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="2dp"
android:left="6dp"

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="0dp"
android:topRightRadius="15dp"
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="4dp"
android:left="6dp"

View file

@ -2,10 +2,10 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="2dp" android:color="@color/accent"/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="0dp"
android:topRightRadius="15dp"
android:bottomRightRadius="15dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="4dp"
android:left="6dp"

View file

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="4dp"
android:left="6dp"

View file

@ -2,10 +2,10 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<stroke android:width="2dp" android:color="@color/accent"/>
<corners
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp" />
android:topLeftRadius="15dp"
android:topRightRadius="15dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="15dp" />
<padding
android:bottom="4dp"
android:left="6dp"

View file

@ -18,7 +18,7 @@
android:layout_height="48dp"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
app:strokeColor="@color/custom_theme_accent"
app:riv_corner_radius="30dp" />
@ -51,7 +51,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:text="@string/user"
android:text="@string/sending"
android:textSize="15dp"
android:textAppearance="@style/TextAppearance.Conversations.Caption" />