Update chat colors.

This commit is contained in:
Alex Hart
2021-05-03 11:34:41 -03:00
committed by Greyson Parrelli
parent 36fe150678
commit bcc5d485ab
164 changed files with 5817 additions and 1476 deletions

View File

@@ -1,11 +1,14 @@
package org.thoughtcrime.securesms.giph.mp4;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.exoplayer2.source.MediaSource;
import org.thoughtcrime.securesms.util.Projection;
public interface GiphyMp4Playable {
/**
* Shows the area in which a video would be projected. Called when a video will not
@@ -40,8 +43,9 @@ public interface GiphyMp4Playable {
/**
* Width, height, and (x,y) of view which video player will "project" into
* @param viewGroup
*/
@NonNull GiphyMp4Projection getProjection(@NonNull RecyclerView recyclerview);
@NonNull Projection getProjection(@NonNull ViewGroup viewGroup);
/**
* Specifies whether the content can start playing.

View File

@@ -1,63 +0,0 @@
package org.thoughtcrime.securesms.giph.mp4;
import android.graphics.Rect;
import android.view.View;
import android.view.ViewParent;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import org.thoughtcrime.securesms.components.CornerMask;
/**
* Describes the position and size of the area where a video should play.
*/
public final class GiphyMp4Projection {
private final float x;
private final float y;
private final int width;
private final int height;
private final CornerMask cornerMask;
public GiphyMp4Projection(float x, float y, int width, int height, @Nullable CornerMask cornerMask) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.cornerMask = cornerMask;
}
public float getX() {
return x;
}
public float getY() {
return y;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public @Nullable CornerMask getCornerMask() {
return cornerMask;
}
public @NonNull GiphyMp4Projection translateX(float xTranslation) {
return new GiphyMp4Projection(x + xTranslation, y, width, height, cornerMask);
}
public static @NonNull GiphyMp4Projection forView(@NonNull RecyclerView recyclerView, @NonNull View view, @Nullable CornerMask cornerMask) {
Rect viewBounds = new Rect();
view.getDrawingRect(viewBounds);
recyclerView.offsetDescendantRectToMyCoords(view, viewBounds);
return new GiphyMp4Projection(viewBounds.left, viewBounds.top, view.getWidth(), view.getHeight(), cornerMask);
}
}

View File

@@ -18,6 +18,7 @@ import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import org.signal.glide.Log;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.CornerMask;
import org.thoughtcrime.securesms.util.Projection;
import java.util.ArrayList;
import java.util.List;
@@ -120,7 +121,7 @@ public final class GiphyMp4ProjectionPlayerHolder implements Player.EventListene
return holders;
}
public void setCornerMask(@Nullable CornerMask cornerMask) {
player.setCornerMask(cornerMask);
public void setCorners(@Nullable Projection.Corners corners) {
player.setCorners(corners);
}
}

View File

@@ -8,6 +8,9 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import org.thoughtcrime.securesms.conversation.ConversationItemSwipeCallback;
import org.thoughtcrime.securesms.util.Projection;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@@ -16,7 +19,7 @@ import java.util.Set;
/**
* Logic for updating content and positioning of videos as the user scrolls the list of gifs.
*/
public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackController.Callback, GiphyMp4DisplayUpdater {
public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackController.Callback {
private final List<GiphyMp4ProjectionPlayerHolder> holders;
private final SparseArray<GiphyMp4ProjectionPlayerHolder> playing;
@@ -48,7 +51,6 @@ public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackControl
}
}
@Override
public void updateDisplay(@NonNull RecyclerView recyclerView, @NonNull GiphyMp4Playable holder) {
GiphyMp4ProjectionPlayerHolder playerHolder = getCurrentHolder(holder.getAdapterPosition());
if (playerHolder != null) {
@@ -84,7 +86,7 @@ public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackControl
}
private void updateDisplay(@NonNull RecyclerView recyclerView, @NonNull GiphyMp4ProjectionPlayerHolder holder, @NonNull GiphyMp4Playable giphyMp4Playable) {
GiphyMp4Projection projection = giphyMp4Playable.getProjection(recyclerView);
Projection projection = giphyMp4Playable.getProjection(recyclerView);
holder.getContainer().setX(projection.getX());
holder.getContainer().setY(projection.getY());
@@ -96,7 +98,7 @@ public final class GiphyMp4ProjectionRecycler implements GiphyMp4PlaybackControl
holder.getContainer().setLayoutParams(params);
}
holder.setCornerMask(projection.getCornerMask());
holder.setCorners(projection.getCorners());
}
private void startPlayback(@NonNull GiphyMp4ProjectionPlayerHolder holder, @NonNull GiphyMp4Playable giphyMp4Playable) {

View File

@@ -20,6 +20,7 @@ import com.google.android.exoplayer2.ui.PlayerView;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.CornerMask;
import org.thoughtcrime.securesms.util.Projection;
/**
* Video Player class specifically created for the GiphyMp4Fragment.
@@ -72,8 +73,13 @@ public final class GiphyMp4VideoPlayer extends FrameLayout implements DefaultLif
exoPlayer.prepare(mediaSource);
}
void setCornerMask(@Nullable CornerMask cornerMask) {
this.cornerMask = new CornerMask(this, cornerMask);
void setCorners(@Nullable Projection.Corners corners) {
if (corners == null) {
this.cornerMask = null;
} else {
this.cornerMask = new CornerMask(this);
this.cornerMask.setRadii(corners.getTopLeft(), corners.getTopRight(), corners.getBottomRight(), corners.getBottomLeft());
}
invalidate();
}

View File

@@ -4,6 +4,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import androidx.annotation.NonNull;
@@ -16,10 +17,11 @@ import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.color.MaterialColor;
import org.thoughtcrime.securesms.conversation.colors.ChatColorsPalette;
import org.thoughtcrime.securesms.giph.model.ChunkedImageUrl;
import org.thoughtcrime.securesms.giph.model.GiphyImage;
import org.thoughtcrime.securesms.mms.GlideApp;
import org.thoughtcrime.securesms.util.Projection;
import org.thoughtcrime.securesms.util.Util;
/**
@@ -44,7 +46,7 @@ final class GiphyMp4ViewHolder extends RecyclerView.ViewHolder implements GiphyM
this.container = (AspectRatioFrameLayout) itemView;
this.listener = listener;
this.stillImage = itemView.findViewById(R.id.still_image);
this.placeholder = new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(itemView.getContext()));
this.placeholder = new ColorDrawable(Util.getRandomElement(ChatColorsPalette.Names.getAll()).getColor(itemView.getContext()));
this.mediaSourceFactory = mediaSourceFactory;
container.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIXED_WIDTH);
@@ -78,8 +80,8 @@ final class GiphyMp4ViewHolder extends RecyclerView.ViewHolder implements GiphyM
}
@Override
public @NonNull GiphyMp4Projection getProjection(@NonNull RecyclerView recyclerView) {
return GiphyMp4Projection.forView(recyclerView, itemView, null);
public @NonNull Projection getProjection(@NonNull ViewGroup recyclerView) {
return Projection.relativeToParent(recyclerView, itemView, null);
}
@Override