session-android/libsession/src/main/java/org/session/libsession/avatars/ResourceContactPhoto.java

65 lines
1.9 KiB
Java
Raw Normal View History

2021-05-18 08:03:47 +02:00
package org.session.libsession.avatars;
2021-01-08 01:10:51 +01:00
import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.widget.ImageView;
import androidx.annotation.DrawableRes;
import com.amulyakhare.textdrawable.TextDrawable;
import com.makeramen.roundedimageview.RoundedDrawable;
import org.session.libsession.R;
import org.session.libsession.utilities.ThemeUtil;
public class ResourceContactPhoto implements FallbackContactPhoto {
private final int resourceId;
public ResourceContactPhoto(@DrawableRes int resourceId) {
2021-02-03 02:44:52 +01:00
this.resourceId = resourceId;
2021-01-08 01:10:51 +01:00
}
@Override
public Drawable asDrawable(Context context, int color) {
return asDrawable(context, color, false);
}
@Override
public Drawable asDrawable(Context context, int color, boolean inverted) {
Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color);
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId));
Paged conversation recycler, update compile sdk version 31 (#1049) * Update build tools * Update appcompat version * Update dependencies * feat: add paging into conversation recycler and queries to fetch data off-thread * refactor: wip for updating paged results and bucketing messages / fetching enough to display * fix: currently works for scrolling and possibly refreshing? need scroll to message and auto scroll down on insert (at bottom) * fix: search and scrolling to X message works now * build: increase version code and name * fix: re-add refresh, remove the outdated comment * refactor: lets see if 25 size pages increases performance :eyes: * feat: add in some equals overrides for mms records to refresh if media has finished DLing * feat: add scroll to bottom for new messages if we are at the end of the chat * build: update build numbers * fix: update AGP and fix compile errors for sdk version 31 * feat: add log for loki-avatar and loki-fs on upload types and responses * feat: increase build number to match latest installed version * feat: changing props and permission checks for call service * fix: possible service exception when no call ID remote foreground service not terminated * revert: google services version * fix: re-add paging dependency * feat: adding new last seen function and figuring out the last seen for recycler adapter * build: update version names and codes for deploy * refactor: undo the new adapter and query changes to use previous cursor logic. revert this commit to enable new paged adapter * fix: use author's address in typist equality and hashcode for set inclusion * refactor: refactor the select contacts activity * refactor: refactor the select contacts activity * build: update version code * fix: hide all other bound views if deleted * refactor: change voice message tint, upgrade build number * fix: message detail showing up properly * revert: realise copy public key is actually not allowed if open group participant * fix: copy session ID, message detail activity support re-enabled * build: update build version code * build: remove version name * build: update build code * feat: google services version minimum compatible * fix: selection for re-created objects not properly highlighting * fix: foreground CENTER_INSIDE instead of just CENTER for scaletype * build: update version code * fix: don't show error if no error * build: update version code * fix: clear error messages if any on successful send Co-authored-by: charles <charles@oxen.io>
2022-12-19 01:29:05 +01:00
foreground.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
2021-01-08 01:10:51 +01:00
if (inverted) {
foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
: R.drawable.avatar_gradient_light);
return new ExpandingLayerDrawable(new Drawable[] {background, foreground, gradient});
}
private static class ExpandingLayerDrawable extends LayerDrawable {
public ExpandingLayerDrawable(Drawable[] layers) {
super(layers);
}
@Override
public int getIntrinsicWidth() {
return -1;
}
@Override
public int getIntrinsicHeight() {
return -1;
}
}
}