Skip to content

Commit 52cfb57

Browse files
alex-signalcody-signal
authored andcommitted
Fix color offset on devices with notches.
1 parent a385cb0 commit 52cfb57

File tree

9 files changed

+18
-29
lines changed

9 files changed

+18
-29
lines changed

app/src/main/java/org/thoughtcrime/securesms/components/ConversationItemFooter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import android.graphics.Rect;
1111
import android.util.AttributeSet;
1212
import android.view.View;
13+
import android.view.ViewGroup;
1314
import android.widget.ImageView;
1415
import android.widget.TextView;
1516

@@ -207,9 +208,9 @@ public void disableBubbleBackground() {
207208
setBackground(null);
208209
}
209210

210-
public @Nullable Projection getProjection() {
211+
public @Nullable Projection getProjection(@NonNull ViewGroup coordinateRoot) {
211212
if (getVisibility() == VISIBLE) {
212-
return Projection.relativeToViewRoot(this, new Projection.Corners(ViewUtil.dpToPx(11)));
213+
return Projection.relativeToParent(coordinateRoot, this, new Projection.Corners(ViewUtil.dpToPx(11)));
213214
} else {
214215
return null;
215216
}

app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,8 @@ public boolean canPlayContent() {
691691
}
692692

693693
@Override
694-
public @NonNull List<Projection> getColorizerProjections() {
695-
return getBindable().getColorizerProjections();
694+
public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
695+
return getBindable().getColorizerProjections(coordinateRoot);
696696
}
697697
}
698698

app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationItem.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,18 +1715,18 @@ public boolean canPlayContent() {
17151715
}
17161716

17171717
@Override
1718-
public @NonNull List<Projection> getColorizerProjections() {
1718+
public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
17191719
List<Projection> projections = new LinkedList<>();
17201720

17211721
if (messageRecord.isOutgoing() &&
17221722
!hasNoBubble(messageRecord) &&
17231723
!messageRecord.isRemoteDelete() &&
17241724
bodyBubbleCorners != null)
17251725
{
1726-
Projection bodyBubbleToRoot = Projection.relativeToViewRoot(bodyBubble, bodyBubbleCorners).translateX(bodyBubble.getTranslationX());
1726+
Projection bodyBubbleToRoot = Projection.relativeToParent(coordinateRoot, bodyBubble, bodyBubbleCorners).translateX(bodyBubble.getTranslationX());
17271727
Projection videoToBubble = bodyBubble.getVideoPlayerProjection();
17281728
if (videoToBubble != null) {
1729-
Projection videoToRoot = Projection.translateFromDescendantToParentCoords(videoToBubble, bodyBubble, (ViewGroup) getRootView());
1729+
Projection videoToRoot = Projection.translateFromDescendantToParentCoords(videoToBubble, bodyBubble, coordinateRoot);
17301730
projections.addAll(Projection.getCapAndTail(bodyBubbleToRoot, videoToRoot));
17311731
} else {
17321732
projections.add(bodyBubbleToRoot);
@@ -1737,7 +1737,7 @@ public boolean canPlayContent() {
17371737
hasNoBubble(messageRecord) &&
17381738
hasWallpaper)
17391739
{
1740-
Projection footerProjection = getActiveFooter(messageRecord).getProjection();
1740+
Projection footerProjection = getActiveFooter(messageRecord).getProjection(coordinateRoot);
17411741
if (footerProjection != null) {
17421742
projections.add(footerProjection.translateX(bodyBubble.getTranslationX()));
17431743
}
@@ -1748,7 +1748,7 @@ public boolean canPlayContent() {
17481748
quoteView != null)
17491749
{
17501750
bodyBubble.setQuoteViewProjection(quoteView.getProjection(bodyBubble));
1751-
projections.add(quoteView.getProjection((ViewGroup) getRootView()).translateX(bodyBubble.getTranslationX() + this.getTranslationX()));
1751+
projections.add(quoteView.getProjection(coordinateRoot).translateX(bodyBubble.getTranslationX() + this.getTranslationX()));
17521752
}
17531753

17541754
return projections;

app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationUpdateItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public boolean canPlayContent() {
221221
}
222222

223223
@Override
224-
public @NonNull List<Projection> getColorizerProjections() {
224+
public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
225225
return Collections.emptyList();
226226
}
227227

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package org.thoughtcrime.securesms.conversation.colors
22

3+
import android.view.ViewGroup
34
import org.thoughtcrime.securesms.util.Projection
45

56
/**
67
* Denotes that a class can be colorized. The class is responsible for
78
* generating its own projection.
89
*/
910
interface Colorizable {
10-
val colorizerProjections: List<Projection>
11+
fun getColorizerProjections(coordinateRoot: ViewGroup): List<Projection>
1112
}

app/src/main/java/org/thoughtcrime/securesms/conversation/colors/RecyclerViewColorizer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class RecyclerViewColorizer(private val recyclerView: RecyclerView) {
9898
if (child != null) {
9999
val holder = parent.getChildViewHolder(child)
100100
if (holder is Colorizable) {
101-
holder.colorizerProjections.forEach {
101+
holder.getColorizerProjections(parent).forEach {
102102
c.drawPath(it.path, holePunchPaint)
103103
}
104104
}

app/src/main/java/org/thoughtcrime/securesms/conversation/mutiselect/MultiselectItemDecoration.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class MultiselectItemDecoration(
127127

128128
val parts: MultiselectCollection = child.conversationMessage.multiselectCollection
129129

130-
val projections: List<Projection> = child.colorizerProjections + if (child.canPlayContent()) listOf(child.getGiphyMp4PlayableProjection(child.rootView as ViewGroup)) else emptyList()
130+
val projections: List<Projection> = child.getColorizerProjections(parent) + if (child.canPlayContent()) listOf(child.getGiphyMp4PlayableProjection(parent)) else emptyList()
131131
path.reset()
132132
projections.forEach { it.applyToPath(path) }
133133

@@ -307,7 +307,7 @@ class MultiselectItemDecoration(
307307
parent.forEach { child ->
308308
if (child is Multiselectable && child.conversationMessage == inFocus.conversationMessage) {
309309
path.addRect(child.left.toFloat(), child.top.toFloat(), child.right.toFloat(), child.bottom.toFloat(), Path.Direction.CW)
310-
child.colorizerProjections.forEach {
310+
child.getColorizerProjections(parent).forEach {
311311
path.op(it.path, Path.Op.DIFFERENCE)
312312
}
313313

app/src/main/java/org/thoughtcrime/securesms/messagedetails/MessageHeaderViewHolder.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,8 @@ public boolean canPlayContent() {
250250
}
251251

252252
@Override
253-
public @NonNull List<Projection> getColorizerProjections() {
254-
return conversationItem.getColorizerProjections()
255-
.stream()
256-
.map(p -> Projection.translateFromRootToDescendantCoords(p, (ViewGroup) itemView.getParent()))
257-
.collect(Collectors.toList());
253+
public @NonNull List<Projection> getColorizerProjections(@NonNull ViewGroup coordinateRoot) {
254+
return conversationItem.getColorizerProjections(coordinateRoot);
258255
}
259256

260257
private class ExpiresUpdater implements Runnable {

app/src/main/java/org/thoughtcrime/securesms/util/Projection.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,6 @@ public void applyToPath(@NonNull Path path) {
142142
return new Projection(viewBounds.left, viewBounds.top, toProject.getWidth(), toProject.getHeight(), corners);
143143
}
144144

145-
public static @NonNull Projection translateFromRootToDescendantCoords(@NonNull Projection rootProjection, @NonNull View descendant) {
146-
Rect viewBounds = new Rect();
147-
148-
viewBounds.set((int) rootProjection.x, (int) rootProjection.y, (int) rootProjection.x + rootProjection.width, (int) rootProjection.y + rootProjection.height);
149-
150-
((ViewGroup) descendant.getRootView()).offsetRectIntoDescendantCoords(descendant, viewBounds);
151-
152-
return new Projection(viewBounds.left, viewBounds.top, rootProjection.width, rootProjection.height, rootProjection.corners);
153-
}
154-
155145
public static @NonNull Projection translateFromDescendantToParentCoords(@NonNull Projection descendantProjection, @NonNull View descendant, @NonNull ViewGroup parent) {
156146
Rect viewBounds = new Rect();
157147

0 commit comments

Comments
 (0)