modify StatusDrawable and use it for conversationList

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-02-24 12:31:58 +01:00
parent 73ce2716de
commit 1da8c3b206
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
9 changed files with 55 additions and 74 deletions

View file

@ -48,6 +48,7 @@ import com.nextcloud.talk.models.json.chat.ChatMessage;
import com.nextcloud.talk.models.json.conversations.Conversation;
import com.nextcloud.talk.models.json.status.Status;
import com.nextcloud.talk.models.json.status.StatusType;
import com.nextcloud.talk.ui.StatusDrawable;
import com.nextcloud.talk.utils.ApiUtils;
import com.nextcloud.talk.utils.DisplayUtils;
@ -70,6 +71,7 @@ import eu.davidea.viewholders.FlexibleViewHolder;
public class ConversationItem extends AbstractFlexibleItem<ConversationItem.ConversationItemViewHolder> implements ISectionable<ConversationItem.ConversationItemViewHolder, GenericTextHeaderItem>,
IFilterable<String> {
private static final float STATUS_SIZE_IN_DP = 9f;
private Conversation conversation;
private UserEntity userEntity;
@ -198,23 +200,13 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
}
if (!Conversation.ConversationType.ROOM_SYSTEM.equals(conversation.getType())) {
if (status != null && status.getStatus().equals(StatusType.DND.getString())) {
setOnlineStateIcon(holder, R.drawable.ic_user_status_dnd_with_border);
} else if (status != null && status.getIcon() != null && !status.getIcon().isEmpty()) {
holder.userStatusOnlineState.setVisibility(View.GONE);
holder.userStatusEmoji.setVisibility(View.VISIBLE);
holder.userStatusEmoji.setText(status.getIcon());
} else if (status != null && status.getStatus().equals(StatusType.AWAY.getString())) {
setOnlineStateIcon(holder, R.drawable.ic_user_status_away_with_border);
} else if (status != null && status.getStatus().equals(StatusType.ONLINE.getString())) {
setOnlineStateIcon(holder, R.drawable.online_status_with_border);
} else {
holder.userStatusEmoji.setVisibility(View.GONE);
holder.userStatusOnlineState.setVisibility(View.GONE);
}
} else {
holder.userStatusEmoji.setVisibility(View.GONE);
holder.userStatusOnlineState.setVisibility(View.GONE);
float size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, appContext);
holder.userStatusImage.setImageDrawable(new StatusDrawable(
status != null ? status.getStatus() : "",
status != null ? status.getIcon() : "",
size,
context.getResources().getColor(R.color.bg_default),
appContext));
}
if (conversation.getLastMessage() != null) {
@ -314,12 +306,6 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
}
}
private void setOnlineStateIcon(ConversationItemViewHolder holder, int icon) {
holder.userStatusEmoji.setVisibility(View.GONE);
holder.userStatusOnlineState.setVisibility(View.VISIBLE);
holder.userStatusOnlineState.setImageDrawable(ContextCompat.getDrawable(context, icon));
}
@Override
public boolean filter(String constraint) {
return conversation.getDisplayName() != null &&
@ -349,11 +335,8 @@ public class ConversationItem extends AbstractFlexibleItem<ConversationItem.Conv
Chip dialogUnreadBubble;
@BindView(R.id.favoriteConversationImageView)
ImageView pinnedConversationImageView;
@BindView(R.id.userStatusEmoji)
com.vanniktech.emoji.EmojiEditText userStatusEmoji;
@BindView(R.id.userStatusOnlineState)
ImageView userStatusOnlineState;
@BindView(R.id.user_status_image)
ImageView userStatusImage;
ConversationItemViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter);

View file

@ -43,49 +43,38 @@ public class StatusDrawable extends Drawable {
private String text;
private @DrawableRes int icon = -1;
private Paint textPaint;
private Paint backgroundPaint;
private int backgroundColor;
private final float radius;
private Context context;
private final static int whiteBackground = Color.argb(200, 255, 255, 255);
private final static int onlineStatus = Color.argb(255, 73, 179, 130);
public StatusDrawable(String status, String statusIcon, float statusSize, Context context) {
backgroundPaint = new Paint();
backgroundPaint.setStyle(Paint.Style.FILL);
backgroundPaint.setAntiAlias(true);
public StatusDrawable(String status, String statusIcon, float statusSize, int backgroundColor, Context context) {
radius = statusSize;
this.backgroundColor = backgroundColor;
if (TextUtils.isEmpty(statusIcon)) {
if ("dnd".equals(status)) {
icon = R.drawable.ic_user_status_dnd;
this.context = context;
} else if (TextUtils.isEmpty(statusIcon)) {
switch (status) {
case "dnd":
icon = R.drawable.ic_user_status_dnd;
backgroundPaint.setColor(whiteBackground);
this.context = context;
break;
case "online":
backgroundPaint.setColor(onlineStatus);
icon = R.drawable.online_status;
this.context = context;
break;
case "away":
icon = R.drawable.ic_user_status_away;
backgroundPaint.setColor(whiteBackground);
this.context = context;
break;
default:
// do not show
backgroundPaint = null;
break;
}
} else {
text = statusIcon;
backgroundPaint.setColor(whiteBackground);
textPaint = new Paint();
textPaint.setColor(Color.WHITE);
textPaint.setTextSize(statusSize);
textPaint.setAntiAlias(true);
textPaint.setTextAlign(Paint.Align.CENTER);
@ -100,16 +89,20 @@ public class StatusDrawable extends Drawable {
*/
@Override
public void draw(@NonNull Canvas canvas) {
if (backgroundPaint != null) {
canvas.drawCircle(radius, radius, radius, backgroundPaint);
}
if (text != null) {
textPaint.setTextSize(1.6f * radius);
canvas.drawText(text, radius, radius - ((textPaint.descent() + textPaint.ascent()) / 2), textPaint);
}
if (icon != -1) {
Paint backgroundPaint = new Paint();
backgroundPaint.setStyle(Paint.Style.FILL);
backgroundPaint.setAntiAlias(true);
backgroundPaint.setColor(backgroundColor);
canvas.drawCircle(radius, radius, radius, backgroundPaint);
Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), icon, null);
if (drawable != null) {

View file

@ -313,6 +313,7 @@ public class ChooseAccountDialogFragment extends DialogFragment {
status.getStatus(),
status.getIcon(),
size,
getContext().getResources().getColor(R.color.dialog_background),
getContext()));
binding.currentAccount.ticker.setVisibility(View.VISIBLE);

View file

@ -84,7 +84,7 @@ private const val LAST_SECOND_OF_MINUTE = 59
class SetStatusDialogFragment :
DialogFragment(), PredefinedStatusClickListener {
private val logTag = ChooseAccountDialogFragment::class.java.simpleName
private val logTag = SetStatusDialogFragment::class.java.simpleName
private lateinit var binding: DialogSetStatusBinding

View file

@ -17,7 +17,16 @@
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#00ff00" />
</shape>
<vector xmlns:tools="http://schemas.android.com/tools"
android:autoMirrored="true"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="24dp"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="VectorRaster">
<path
android:fillColor="#00ff00"
android:pathData="m12,2c-5.52,0 -10,4.48 -10,10s4.48,10 10,10 10,-4.48 10,-10 -4.48,-10 -10,-10z" />
</vector>

View file

@ -107,6 +107,7 @@
android:maxLines="1"
android:textColor="?android:attr/textColorSecondary"
android:visibility="gone"
tools:visibility="visible"
tools:text="☁️ My custom status" />
<TextView

View file

@ -55,24 +55,12 @@
app:tint="@color/favorite_icon_tint"
app:tintMode="src_in" />
<com.vanniktech.emoji.EmojiEditText
android:id="@+id/userStatusEmoji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:background="@color/transparent"
android:cursorVisible="false"
android:gravity="center"
android:text="@string/default_emoji"
android:textSize="16sp" />
<ImageView
android:id="@+id/userStatusOnlineState"
android:layout_width="16dp"
android:layout_height="16dp"
android:id="@+id/user_status_image"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_gravity="bottom|end"
android:contentDescription="@null"
android:src="@drawable/online_status"/>
android:contentDescription="@string/nc_account_chooser_active_user" />
</FrameLayout>
<RelativeLayout

View file

@ -68,4 +68,6 @@
<color name="list_divider_background">#222222</color>
<color name="grey_200">#818181</color>
<color name="dialog_background">#353535</color>
</resources>

View file

@ -100,4 +100,8 @@
<color name="list_divider_background">#eeeeee</color>
<color name="grey_200">#EEEEEE</color>
<!-- this is just a helper for status icon background because getting the background color of a dialog is not
possible?! don't use this to set the background of dialogs -->
<color name="dialog_background">#FFFFFF</color>
</resources>