set fallback avatar icon

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2021-05-25 16:52:18 +02:00
parent 16dfe20c25
commit 93a1d411e0
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 56 additions and 8 deletions

View file

@ -112,26 +112,34 @@ public class AdvancedUserItem extends AbstractFlexibleItem<AdvancedUserItem.User
holder.avatarImageView.setController(null); holder.avatarImageView.setController(null);
if (adapter.hasFilter()) { if (adapter.hasFilter()) {
FlexibleUtils.highlightText(holder.contactDisplayName, participant.getDisplayName(), FlexibleUtils.highlightText(
String.valueOf(adapter.getFilter(String.class)), NextcloudTalkApplication.Companion.getSharedApplication() holder.contactDisplayName,
.getResources().getColor(R.color.colorPrimary)); participant.getDisplayName(),
String.valueOf(adapter.getFilter(String.class)),
NextcloudTalkApplication.Companion.getSharedApplication()
.getResources()
.getColor(R.color.colorPrimary));
} else { } else {
holder.contactDisplayName.setText(participant.getDisplayName()); holder.contactDisplayName.setText(participant.getDisplayName());
} }
holder.serverUrl.setText((Uri.parse(userEntity.getBaseUrl()).getHost())); holder.serverUrl.setText((Uri.parse(userEntity.getBaseUrl()).getHost()));
if (userEntity != null && userEntity.getBaseUrl() != null && userEntity.getBaseUrl().startsWith("http://") || userEntity.getBaseUrl().startsWith("https://")) { holder.avatarImageView.getHierarchy().setPlaceholderImage(R.drawable.account_circle_48dp);
holder.avatarImageView.getHierarchy().setFailureImage(R.drawable.account_circle_48dp);
if (userEntity != null && userEntity.getBaseUrl() != null &&
userEntity.getBaseUrl().startsWith("http://") ||
userEntity.getBaseUrl().startsWith("https://")) {
holder.avatarImageView.setVisibility(View.VISIBLE); holder.avatarImageView.setVisibility(View.VISIBLE);
DraweeController draweeController = Fresco.newDraweeControllerBuilder() DraweeController draweeController = Fresco.newDraweeControllerBuilder()
.setOldController(holder.avatarImageView.getController()) .setOldController(holder.avatarImageView.getController())
.setAutoPlayAnimations(true) .setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(), .setImageRequest(DisplayUtils.getImageRequestForUrl(ApiUtils.getUrlForAvatarWithName(userEntity.getBaseUrl(),
participant.getActorId(), R.dimen.avatar_size), null)) participant.getActorId(), R.dimen.small_item_height), null))
.build(); .build();
holder.avatarImageView.setController(draweeController); holder.avatarImageView.setController(draweeController);
} else { } else {
holder.avatarImageView.setVisibility(View.GONE); holder.avatarImageView.setVisibility(View.GONE);
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.linearLayout.getLayoutParams(); RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) holder.linearLayout.getLayoutParams();

View file

@ -113,7 +113,10 @@ public class ChooseAccountDialogFragment extends DialogFragment {
.setOldController(binding.currentAccount.userIcon.getController()) .setOldController(binding.currentAccount.userIcon.getController())
.setAutoPlayAnimations(true) .setAutoPlayAnimations(true)
.setImageRequest(DisplayUtils.getImageRequestForUrl( .setImageRequest(DisplayUtils.getImageRequestForUrl(
ApiUtils.getUrlForAvatarWithName(user.getBaseUrl(), user.getUserId(), R.dimen.avatar_size), ApiUtils.getUrlForAvatarWithName(
user.getBaseUrl(),
user.getUserId(),
R.dimen.small_item_height),
null)) null))
.build(); .build();
binding.currentAccount.userIcon.setController(draweeController); binding.currentAccount.userIcon.setController(draweeController);

View file

@ -0,0 +1,27 @@
<!--
@author Google LLC
Copyright (C) 2018 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:autoMirrored="true"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FF666666"
android:fillType="nonZero"
android:pathData="M12,20.64C9,20.64 6.348,19.104 4.8,16.8C4.836,14.4 9.6,13.08 12,13.08C14.4,13.08 19.164,14.4 19.2,16.8C17.652,19.104 15,20.64 12,20.64M12,3.6C13.9752,3.6 15.6,5.2248 15.6,7.2C15.6,9.1752 13.9752,10.8 12,10.8C10.0248,10.8 8.4,9.1752 8.4,7.2C8.4,5.2248 10.0248,3.6 12,3.6M12,0C5.4168,0 0,5.4168 0,12C0,18.5832 5.4168,24 12,24C18.5832,24 24,18.5832 24,12C24,5.364 18.6,0 12,0Z" />
</vector>

View file

@ -22,6 +22,7 @@
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="72dp" android:layout_height="72dp"
android:layout_margin="4dp" android:layout_margin="4dp"
@ -52,7 +53,9 @@
android:layout_marginEnd="1dp" android:layout_marginEnd="1dp"
android:layout_marginBottom="1dp" android:layout_marginBottom="1dp"
android:contentDescription="@string/avatar" android:contentDescription="@string/avatar"
android:src="@drawable/ic_user" android:src="@drawable/account_circle_48dp"
fresco:placeholderImage="@drawable/account_circle_48dp"
fresco:failureImage="@drawable/account_circle_48dp"
app:roundAsCircle="true"/> app:roundAsCircle="true"/>
<ImageView <ImageView

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve" xmlns:serif="http://www.serif.com/" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2;">
<g transform="matrix(1.2,0,0,1.2,-2.4,-2.4)">
<path d="M12,19.2C9.5,19.2 7.29,17.92 6,16C6.03,14 10,12.9 12,12.9C14,12.9 17.97,14 18,16C16.71,17.92 14.5,19.2 12,19.2M12,5C13.646,5 15,6.354 15,8C15,9.646 13.646,11 12,11C10.354,11 9,9.646 9,8C9,6.354 10.354,5 12,5M12,2C6.514,2 2,6.514 2,12C2,17.486 6.514,22 12,22C17.486,22 22,17.486 22,12C22,6.47 17.5,2 12,2Z" style="fill-rule:nonzero;"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 861 B