mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-01 12:11:59 +00:00
Progress with setting chip avatars
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
1938c3fbb4
commit
ad3b440e88
@ -151,6 +151,7 @@ public class MagicIncomingTextMessageViewHolder
|
||||
messageString,
|
||||
individualHashMap.get("id"),
|
||||
individualHashMap.get("name"),
|
||||
userUtils.getUserById(message.getActiveUserId()),
|
||||
R.xml.chip_simple_background);
|
||||
} else {
|
||||
messageString =
|
||||
@ -158,6 +159,7 @@ public class MagicIncomingTextMessageViewHolder
|
||||
messageString,
|
||||
individualHashMap.get("id"),
|
||||
individualHashMap.get("name"),
|
||||
userUtils.getUserById(message.getActiveUserId()),
|
||||
R.xml.chip_accent_background);
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
||||
messageString,
|
||||
individualHashMap.get("id"),
|
||||
individualHashMap.get("name"),
|
||||
userUtils.getUserById(message.getActiveUserId()),
|
||||
R.xml.chip_simple_background);
|
||||
} else {
|
||||
messageString =
|
||||
@ -105,6 +106,7 @@ public class MagicOutcomingTextMessageViewHolder extends MessageHolders.Outcomin
|
||||
messageString,
|
||||
individualHashMap.get("id"),
|
||||
individualHashMap.get("name"),
|
||||
userUtils.getUserById(message.getActiveUserId()),
|
||||
R.xml.chip_outgoing_own_mention);
|
||||
}
|
||||
} else if (individualHashMap.get("type").equals("file")) {
|
||||
|
@ -25,6 +25,7 @@ import android.text.Editable;
|
||||
import android.text.Spanned;
|
||||
import android.text.style.DynamicDrawableSpan;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.models.json.mention.Mention;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import com.nextcloud.talk.utils.MagicCharPolicy;
|
||||
@ -33,9 +34,11 @@ import com.otaliastudios.autocomplete.AutocompleteCallback;
|
||||
|
||||
public class MentionAutocompleteCallback implements AutocompleteCallback<Mention> {
|
||||
private Context context;
|
||||
private UserEntity conversationUser;
|
||||
|
||||
public MentionAutocompleteCallback(Context context) {
|
||||
public MentionAutocompleteCallback(Context context, UserEntity conversationUser) {
|
||||
this.context = context;
|
||||
this.conversationUser = conversationUser;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -48,7 +51,9 @@ public class MentionAutocompleteCallback implements AutocompleteCallback<Mention
|
||||
editable.replace(start, end, replacement + " ");
|
||||
Spans.MentionChipSpan mentionChipSpan =
|
||||
new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||
item.getLabel(), R.xml.chip_accent_background), DynamicDrawableSpan.ALIGN_BASELINE,
|
||||
item.getId(), item.getLabel(), conversationUser,
|
||||
R.xml.chip_accent_background),
|
||||
DynamicDrawableSpan.ALIGN_BASELINE,
|
||||
item.getId(), item.getLabel());
|
||||
editable.setSpan(mentionChipSpan, start, start + item.getLabel().length() ,
|
||||
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
|
@ -485,7 +485,8 @@ public class ChatController extends BaseController implements MessagesListAdapte
|
||||
float elevation = 6f;
|
||||
Drawable backgroundDrawable = new ColorDrawable(Color.WHITE);
|
||||
AutocompletePresenter<Mention> presenter = new MentionAutocompletePresenter(getApplicationContext(), roomToken);
|
||||
AutocompleteCallback<Mention> callback = new MentionAutocompleteCallback(getActivity());
|
||||
AutocompleteCallback<Mention> callback = new MentionAutocompleteCallback(getActivity(),
|
||||
conversationUser);
|
||||
|
||||
if (mentionAutocomplete == null && messageInput != null) {
|
||||
mentionAutocomplete = Autocomplete.<Mention>on(messageInput)
|
||||
|
@ -29,10 +29,7 @@ import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Animatable;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.VectorDrawable;
|
||||
import android.graphics.drawable.*;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.*;
|
||||
@ -47,9 +44,17 @@ import androidx.annotation.*;
|
||||
import androidx.appcompat.widget.AppCompatDrawableManager;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.graphics.drawable.DrawableCompat;
|
||||
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.drawee.controller.ControllerListener;
|
||||
import com.facebook.drawee.drawable.RoundedColorDrawable;
|
||||
import com.facebook.drawee.view.SimpleDraweeView;
|
||||
import com.facebook.imagepipeline.common.RotationOptions;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.image.ImageInfo;
|
||||
import com.facebook.imagepipeline.postprocessors.RoundAsCirclePostprocessor;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
@ -57,6 +62,7 @@ import com.facebook.imagepipeline.request.ImageRequestBuilder;
|
||||
import com.google.android.material.chip.ChipDrawable;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
||||
import com.nextcloud.talk.models.database.UserEntity;
|
||||
import com.nextcloud.talk.utils.text.Spans;
|
||||
import com.vanniktech.emoji.EmojiTextView;
|
||||
|
||||
@ -208,15 +214,52 @@ public class DisplayUtils {
|
||||
}
|
||||
|
||||
|
||||
public static Drawable getDrawableForMentionChipSpan(Context context, String label, @XmlRes int chipResource) {
|
||||
public static Drawable getDrawableForMentionChipSpan(Context context, String id, String label,
|
||||
UserEntity conversationUser,
|
||||
@XmlRes int chipResource) {
|
||||
ChipDrawable chip = ChipDrawable.createFromResource(context, chipResource);
|
||||
chip.setText(label);
|
||||
int drawable;
|
||||
|
||||
if (chipResource == R.xml.chip_accent_background) {
|
||||
drawable = R.drawable.white_circle;
|
||||
} else {
|
||||
drawable = R.drawable.accent_circle;
|
||||
}
|
||||
|
||||
chip.setChipIcon(context.getDrawable(drawable));
|
||||
|
||||
chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
|
||||
|
||||
ImageRequest imageRequest =
|
||||
getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(conversationUser.getBaseUrl(), id, R.dimen.avatar_size_big));
|
||||
ImagePipeline imagePipeline = Fresco.getImagePipeline();
|
||||
DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
|
||||
|
||||
dataSource.subscribe(
|
||||
new BaseBitmapDataSubscriber() {
|
||||
|
||||
@Override
|
||||
protected void onNewResultImpl(Bitmap bitmap) {
|
||||
if (bitmap != null) {
|
||||
chip.setChipIcon(getRoundedDrawable(new BitmapDrawable(bitmap)));
|
||||
chip.invalidateSelf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
|
||||
}
|
||||
},
|
||||
UiThreadImmediateExecutorService.getInstance());
|
||||
|
||||
return chip;
|
||||
}
|
||||
|
||||
|
||||
public static Spannable searchAndReplaceWithMentionSpan(Context context, Spannable text,
|
||||
String id, String label,
|
||||
UserEntity conversationUser,
|
||||
@XmlRes int chipXmlRes) {
|
||||
|
||||
Spannable spannableString = new SpannableString(text);
|
||||
@ -233,13 +276,16 @@ public class DisplayUtils {
|
||||
int end = start + m.group().length();
|
||||
lastStartIndex = end;
|
||||
mentionChipSpan = new Spans.MentionChipSpan(DisplayUtils.getDrawableForMentionChipSpan(context,
|
||||
label, chipXmlRes), DynamicDrawableSpan.ALIGN_BASELINE, id, label);
|
||||
id, label, conversationUser, chipXmlRes),
|
||||
DynamicDrawableSpan.ALIGN_BASELINE, id,
|
||||
label);
|
||||
spannableString.setSpan(mentionChipSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
}
|
||||
|
||||
return spannableString;
|
||||
|
||||
}
|
||||
|
||||
public static Spannable searchAndColor(Spannable text, String searchText, @ColorInt int color) {
|
||||
|
||||
Spannable spannableString = new SpannableString(text);
|
||||
|
@ -105,6 +105,13 @@ public class UserUtils {
|
||||
|
||||
}
|
||||
|
||||
public UserEntity getUserById(String id) {
|
||||
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.USER_ID.eq(id))
|
||||
.limit(1).get();
|
||||
|
||||
return (UserEntity) findUserQueryResult.firstOrNull();
|
||||
}
|
||||
|
||||
public UserEntity getUserWithId(long id) {
|
||||
Result findUserQueryResult = dataStore.select(User.class).where(UserEntity.ID.eq(id))
|
||||
.limit(1).get();
|
||||
|
@ -20,10 +20,24 @@
|
||||
|
||||
package com.nextcloud.talk.utils.text;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.common.executors.UiThreadImmediateExecutorService;
|
||||
import com.facebook.common.references.CloseableReference;
|
||||
import com.facebook.datasource.DataSource;
|
||||
import com.facebook.drawee.backends.pipeline.Fresco;
|
||||
import com.facebook.imagepipeline.core.ImagePipeline;
|
||||
import com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber;
|
||||
import com.facebook.imagepipeline.image.CloseableImage;
|
||||
import com.facebook.imagepipeline.request.ImageRequest;
|
||||
import com.nextcloud.talk.R;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.DisplayUtils;
|
||||
import lombok.Data;
|
||||
|
||||
import static com.nextcloud.talk.utils.DisplayUtils.getImageRequestForUrl;
|
||||
|
||||
public class Spans {
|
||||
|
||||
@Data
|
||||
|
26
app/src/main/res/drawable/accent_circle.xml
Normal file
26
app/src/main/res/drawable/accent_circle.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Nextcloud Talk application
|
||||
~
|
||||
~ @author Mario Danic
|
||||
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU 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="@color/colorAccent"/>
|
||||
</shape>
|
26
app/src/main/res/drawable/white_circle.xml
Normal file
26
app/src/main/res/drawable/white_circle.xml
Normal file
@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Nextcloud Talk application
|
||||
~
|
||||
~ @author Mario Danic
|
||||
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
|
||||
~
|
||||
~ This program is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ at your option) any later version.
|
||||
~
|
||||
~ This program is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU 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="@color/white"/>
|
||||
</shape>
|
Loading…
Reference in New Issue
Block a user