fix wrong margins for media posts with cw / without text
This commit is contained in:
parent
14dcc769f2
commit
ee0048a406
|
@ -3,16 +3,15 @@ package org.joinmastodon.android.ui.displayitems;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Space;
|
import android.widget.Space;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||||
|
|
||||||
import me.grishka.appkit.utils.V;
|
import me.grishka.appkit.utils.V;
|
||||||
|
|
||||||
public class InsetDummyStatusDisplayItem extends StatusDisplayItem {
|
public class DummyStatusDisplayItem extends StatusDisplayItem {
|
||||||
private final boolean addMediaGridMargin;
|
private final boolean addMediaGridMargin;
|
||||||
|
|
||||||
public InsetDummyStatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment, boolean addMediaGridMargin) {
|
public DummyStatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment, boolean addMediaGridMargin) {
|
||||||
super(parentID, parentFragment);
|
super(parentID, parentFragment);
|
||||||
this.addMediaGridMargin = addMediaGridMargin;
|
this.addMediaGridMargin = addMediaGridMargin;
|
||||||
}
|
}
|
||||||
|
@ -22,19 +21,19 @@ public class InsetDummyStatusDisplayItem extends StatusDisplayItem {
|
||||||
return Type.DUMMY;
|
return Type.DUMMY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Holder extends StatusDisplayItem.Holder<InsetDummyStatusDisplayItem> {
|
public static class Holder extends StatusDisplayItem.Holder<DummyStatusDisplayItem> {
|
||||||
public Holder(Context context) {
|
public Holder(Context context) {
|
||||||
super(new Space(context));
|
super(new Space(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBind(InsetDummyStatusDisplayItem item) {
|
public void onBind(DummyStatusDisplayItem item) {
|
||||||
// BetterItemAnimator appears not to handle InsetStatusItemDecoration's getItemOffsets
|
// BetterItemAnimator appears not to handle InsetStatusItemDecoration's getItemOffsets
|
||||||
// correctly, causing removed inset views to jump while animating. i don't quite
|
// correctly, causing removed inset views to jump while animating. i don't quite
|
||||||
// understand it, but this workaround appears to work.
|
// understand it, but this workaround appears to work.
|
||||||
// see InsetStatusItemDecoration#getItemOffsets
|
// see InsetStatusItemDecoration#getItemOffsets
|
||||||
ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
||||||
params.setMargins(0, item.addMediaGridMargin ? V.dp(4) : 0, 0, V.dp(16));
|
params.setMargins(0, item.addMediaGridMargin ? V.dp(0) : 0, 0, V.dp(16));
|
||||||
itemView.setLayoutParams(params);
|
itemView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,7 +25,6 @@ import org.joinmastodon.android.model.LegacyFilter;
|
||||||
import org.joinmastodon.android.model.FilterAction;
|
import org.joinmastodon.android.model.FilterAction;
|
||||||
import org.joinmastodon.android.model.FilterContext;
|
import org.joinmastodon.android.model.FilterContext;
|
||||||
import org.joinmastodon.android.model.FilterResult;
|
import org.joinmastodon.android.model.FilterResult;
|
||||||
import org.joinmastodon.android.model.Notification;
|
|
||||||
import org.joinmastodon.android.model.Poll;
|
import org.joinmastodon.android.model.Poll;
|
||||||
import org.joinmastodon.android.model.ScheduledStatus;
|
import org.joinmastodon.android.model.ScheduledStatus;
|
||||||
import org.joinmastodon.android.model.Status;
|
import org.joinmastodon.android.model.Status;
|
||||||
|
@ -113,7 +112,7 @@ public abstract class StatusDisplayItem{
|
||||||
case SPOILER, FILTER_SPOILER -> new SpoilerStatusDisplayItem.Holder(activity, parent, type);
|
case SPOILER, FILTER_SPOILER -> new SpoilerStatusDisplayItem.Holder(activity, parent, type);
|
||||||
case SECTION_HEADER -> null; // new SectionHeaderStatusDisplayItem.Holder(activity, parent);
|
case SECTION_HEADER -> null; // new SectionHeaderStatusDisplayItem.Holder(activity, parent);
|
||||||
case NOTIFICATION_HEADER -> new NotificationHeaderStatusDisplayItem.Holder(activity, parent);
|
case NOTIFICATION_HEADER -> new NotificationHeaderStatusDisplayItem.Holder(activity, parent);
|
||||||
case DUMMY -> new InsetDummyStatusDisplayItem.Holder(activity);
|
case DUMMY -> new DummyStatusDisplayItem.Holder(activity);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,13 +239,16 @@ public abstract class StatusDisplayItem{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasSpoiler=!TextUtils.isEmpty(statusForContent.spoilerText);
|
||||||
if(!TextUtils.isEmpty(statusForContent.content)){
|
if(!TextUtils.isEmpty(statusForContent.content)){
|
||||||
SpannableStringBuilder parsedText=HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID);
|
SpannableStringBuilder parsedText=HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID);
|
||||||
HtmlParser.applyFilterHighlights(fragment.getActivity(), parsedText, status.filtered);
|
HtmlParser.applyFilterHighlights(fragment.getActivity(), parsedText, status.filtered);
|
||||||
TextStatusDisplayItem text=new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent, (flags & FLAG_NO_TRANSLATE) != 0);
|
TextStatusDisplayItem text=new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent, (flags & FLAG_NO_TRANSLATE) != 0);
|
||||||
contentItems.add(text);
|
contentItems.add(text);
|
||||||
} else if (header!=null){
|
}else if(!hasSpoiler && header!=null){
|
||||||
header.needBottomPadding=true;
|
header.needBottomPadding=true;
|
||||||
|
}else if(hasSpoiler){
|
||||||
|
contentItems.add(new DummyStatusDisplayItem(parentID, fragment, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Attachment> imageAttachments=statusForContent.mediaAttachments.stream().filter(att->att.type.isImage()).collect(Collectors.toList());
|
List<Attachment> imageAttachments=statusForContent.mediaAttachments.stream().filter(att->att.type.isImage()).collect(Collectors.toList());
|
||||||
|
@ -287,7 +289,7 @@ public abstract class StatusDisplayItem{
|
||||||
boolean inset=(flags & FLAG_INSET)!=0;
|
boolean inset=(flags & FLAG_INSET)!=0;
|
||||||
// add inset dummy so last content item doesn't clip out of inset bounds
|
// add inset dummy so last content item doesn't clip out of inset bounds
|
||||||
if (inset) {
|
if (inset) {
|
||||||
items.add(new InsetDummyStatusDisplayItem(parentID, fragment,
|
items.add(new DummyStatusDisplayItem(parentID, fragment,
|
||||||
!contentItems.isEmpty() && contentItems
|
!contentItems.isEmpty() && contentItems
|
||||||
.get(contentItems.size() - 1) instanceof MediaGridStatusDisplayItem));
|
.get(contentItems.size() - 1) instanceof MediaGridStatusDisplayItem));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue