mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 08:08:43 +00:00
committed by
Moxie Marlinspike
parent
4314a4b42b
commit
61386e9ca9
@@ -3,13 +3,8 @@ package org.thoughtcrime.securesms.components;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.util.Pair;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
@@ -21,13 +16,10 @@ import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper.UserCapabilities.Capability;
|
||||
|
||||
public class AvatarImageView extends ImageView {
|
||||
|
||||
private boolean inverted;
|
||||
private boolean showBadge;
|
||||
|
||||
public AvatarImageView(Context context) {
|
||||
super(context);
|
||||
@@ -41,7 +33,6 @@ public class AvatarImageView extends ImageView {
|
||||
if (attrs != null) {
|
||||
TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.AvatarImageView, 0, 0);
|
||||
inverted = typedArray.getBoolean(0, false);
|
||||
showBadge = typedArray.getBoolean(1, false);
|
||||
typedArray.recycle();
|
||||
}
|
||||
}
|
||||
@@ -51,12 +42,9 @@ public class AvatarImageView extends ImageView {
|
||||
MaterialColor backgroundColor = recipients.getColor();
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(getContext()), inverted));
|
||||
setAvatarClickHandler(recipients, quickContactEnabled);
|
||||
setTag(recipients);
|
||||
if (showBadge) new BadgeResolutionTask(getContext()).execute(recipients);
|
||||
} else {
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
|
||||
setOnClickListener(null);
|
||||
setTag(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,30 +73,4 @@ public class AvatarImageView extends ImageView {
|
||||
setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
private class BadgeResolutionTask extends AsyncTask<Recipients,Void,Pair<Recipients, Boolean>> {
|
||||
private final Context context;
|
||||
|
||||
public BadgeResolutionTask(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Recipients, Boolean> doInBackground(Recipients... recipients) {
|
||||
Capability textCapability = DirectoryHelper.getUserCapabilities(context, recipients[0]).getTextCapability();
|
||||
return new Pair<>(recipients[0], textCapability == Capability.SUPPORTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Pair<Recipients, Boolean> result) {
|
||||
if (getTag() == result.first && result.second) {
|
||||
final Drawable badged = new LayerDrawable(new Drawable[] {
|
||||
getDrawable(),
|
||||
ContextCompat.getDrawable(context, R.drawable.badge_drawable)
|
||||
});
|
||||
|
||||
setImageDrawable(badged);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build.VERSION;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
@@ -57,8 +56,8 @@ public class RecyclerViewFastScroller extends LinearLayout {
|
||||
return;
|
||||
final int verticalScrollOffset = recyclerView.computeVerticalScrollOffset();
|
||||
final int verticalScrollRange = recyclerView.computeVerticalScrollRange();
|
||||
float proportion = (float)verticalScrollOffset / ((float)verticalScrollRange - height);
|
||||
setBubbleAndHandlePosition(height * proportion);
|
||||
final float proportion = (float)verticalScrollOffset / verticalScrollRange;
|
||||
setBubbleAndHandlePosition(proportion);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -106,7 +105,7 @@ public class RecyclerViewFastScroller extends LinearLayout {
|
||||
handle.setSelected(true);
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final float y = event.getY();
|
||||
setBubbleAndHandlePosition(y);
|
||||
setBubbleAndHandlePosition(y / height);
|
||||
setRecyclerViewPosition(y);
|
||||
return true;
|
||||
case MotionEvent.ACTION_UP:
|
||||
@@ -147,12 +146,14 @@ public class RecyclerViewFastScroller extends LinearLayout {
|
||||
if (recyclerView != null) {
|
||||
final int itemCount = recyclerView.getAdapter().getItemCount();
|
||||
float proportion;
|
||||
if (ViewUtil.getY(handle) == 0)
|
||||
if (ViewUtil.getY(handle) == 0) {
|
||||
proportion = 0f;
|
||||
else if (ViewUtil.getY(handle) + handle.getHeight() >= height - TRACK_SNAP_RANGE)
|
||||
} else if (ViewUtil.getY(handle) + handle.getHeight() >= height - TRACK_SNAP_RANGE) {
|
||||
proportion = 1f;
|
||||
else
|
||||
proportion = y / (float) height;
|
||||
} else {
|
||||
proportion = y / (float)height;
|
||||
}
|
||||
|
||||
final int targetPos = Util.clamp((int)(proportion * (float)itemCount), 0, itemCount - 1);
|
||||
((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(targetPos, 0);
|
||||
final CharSequence bubbleText = ((FastScrollAdapter) recyclerView.getAdapter()).getBubbleText(targetPos);
|
||||
@@ -164,8 +165,11 @@ public class RecyclerViewFastScroller extends LinearLayout {
|
||||
private void setBubbleAndHandlePosition(float y) {
|
||||
final int handleHeight = handle.getHeight();
|
||||
final int bubbleHeight = bubble.getHeight();
|
||||
ViewUtil.setY(handle, Util.clamp((int)(y - handleHeight / 2), 0, height - handleHeight));
|
||||
ViewUtil.setY(bubble, Util.clamp((int)(y - bubbleHeight), 0, height - bubbleHeight - handleHeight / 2));
|
||||
final int handleY = Util.clamp((int)((height - handleHeight) * y), 0, height - handleHeight);
|
||||
ViewUtil.setY(handle, handleY);
|
||||
ViewUtil.setY(bubble, Util.clamp(handleY - bubbleHeight - bubble.getPaddingBottom() + handleHeight,
|
||||
0,
|
||||
height - bubbleHeight));
|
||||
}
|
||||
|
||||
@TargetApi(11)
|
||||
|
||||
Reference in New Issue
Block a user