fix paddings around dummys, text and spoilers
closes sk22#638
This commit is contained in:
parent
f5e5408d70
commit
d96c3c3c8a
|
@ -164,7 +164,6 @@ public class GlobalUserPreferences{
|
|||
.putBoolean("enablePreReleases", enablePreReleases)
|
||||
.putString("prefixReplies", prefixReplies.name())
|
||||
.putBoolean("collapseLongPosts", collapseLongPosts)
|
||||
.putBoolean("spectatorMode", spectatorMode)
|
||||
.putBoolean("autoHideFab", autoHideFab)
|
||||
.putBoolean("compactReblogReplyLine", compactReblogReplyLine)
|
||||
.putString("color", color.name())
|
||||
|
|
|
@ -68,6 +68,7 @@ public class AnnouncementsFragment extends BaseStatusListFragment<Announcement>
|
|||
instanceUser.emojis = List.of();
|
||||
Status fakeStatus = a.toStatus();
|
||||
TextStatusDisplayItem textItem = new TextStatusDisplayItem(a.id, HtmlParser.parse(a.content, a.emojis, a.mentions, a.tags, accountID), this, fakeStatus, true);
|
||||
// TODO: emoji reactions!
|
||||
textItem.textSelectable = true;
|
||||
return List.of(
|
||||
HeaderStatusDisplayItem.fromAnnouncement(a, fakeStatus, instanceUser, this, accountID, this::onMarkAsRead),
|
||||
|
|
|
@ -4,16 +4,17 @@ import android.content.Context;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.Space;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
|
||||
import me.grishka.appkit.utils.V;
|
||||
|
||||
public class DummyStatusDisplayItem extends StatusDisplayItem {
|
||||
private final boolean addMediaGridMargin;
|
||||
|
||||
public DummyStatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment, boolean addMediaGridMargin) {
|
||||
public DummyStatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment) {
|
||||
super(parentID, parentFragment);
|
||||
this.addMediaGridMargin = addMediaGridMargin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,19 +23,21 @@ public class DummyStatusDisplayItem extends StatusDisplayItem {
|
|||
}
|
||||
|
||||
public static class Holder extends StatusDisplayItem.Holder<DummyStatusDisplayItem> {
|
||||
private final RecyclerView.LayoutParams params;
|
||||
|
||||
public Holder(Context context) {
|
||||
super(new Space(context));
|
||||
}
|
||||
params=new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
||||
|
||||
@Override
|
||||
public void onBind(DummyStatusDisplayItem item) {
|
||||
// BetterItemAnimator appears not to handle InsetStatusItemDecoration's getItemOffsets
|
||||
// correctly, causing removed inset views to jump while animating. i don't quite
|
||||
// understand it, but this workaround appears to work.
|
||||
// see InsetStatusItemDecoration#getItemOffsets
|
||||
ViewGroup.MarginLayoutParams params = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
|
||||
params.setMargins(0, item.addMediaGridMargin ? V.dp(0) : 0, 0, V.dp(16));
|
||||
params.setMargins(0, 0, 0, V.dp(16));
|
||||
itemView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBind(DummyStatusDisplayItem item) {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,6 +56,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
private final Drawable placeholder;
|
||||
private final boolean hideAdd;
|
||||
private final String accountID;
|
||||
private boolean hidden;
|
||||
|
||||
public EmojiReactionsStatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment, Status status, String accountID, boolean hideAdd) {
|
||||
super(parentID, parentFragment);
|
||||
|
@ -64,6 +65,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
this.accountID=accountID;
|
||||
placeholder=parentFragment.getContext().getDrawable(R.drawable.image_placeholder).mutate();
|
||||
placeholder.setBounds(0, 0, V.sp(24), V.sp(24));
|
||||
updateHidden();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +83,15 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
return Type.EMOJI_REACTIONS;
|
||||
}
|
||||
|
||||
public static class Holder extends StatusDisplayItem.Holder<EmojiReactionsStatusDisplayItem> implements ImageLoaderViewHolder, CustomEmojiPopupKeyboard.Listener {
|
||||
public boolean isHidden(){
|
||||
return hidden;
|
||||
}
|
||||
|
||||
private void updateHidden(){
|
||||
hidden=status.reactions.isEmpty() && hideAdd;
|
||||
}
|
||||
|
||||
public static class Holder extends StatusDisplayItem.Holder<EmojiReactionsStatusDisplayItem> implements ImageLoaderViewHolder, CustomEmojiPopupKeyboard.Listener {
|
||||
private final UsableRecyclerView list;
|
||||
private final LinearLayout root, line;
|
||||
private CustomEmojiPopupKeyboard emojiKeyboard;
|
||||
|
@ -116,10 +126,10 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
|||
emojiKeyboard.setListener(this);
|
||||
space.setVisibility(View.GONE);
|
||||
root.addView(emojiKeyboard.getView());
|
||||
boolean nothingToShow=item.status.reactions.isEmpty() && item.hideAdd;
|
||||
root.setVisibility(nothingToShow ? View.GONE : View.VISIBLE);
|
||||
line.setVisibility(nothingToShow ? View.GONE : View.VISIBLE);
|
||||
line.setPadding(list.getPaddingLeft(), nothingToShow ? 0 : V.dp(8), list.getPaddingRight(), 0);
|
||||
item.updateHidden();
|
||||
root.setVisibility(item.hidden ? View.GONE : View.VISIBLE);
|
||||
line.setVisibility(item.hidden ? View.GONE : View.VISIBLE);
|
||||
line.setPadding(list.getPaddingLeft(), item.hidden ? 0 : V.dp(8), list.getPaddingRight(), 0);
|
||||
imgLoader.updateImages();
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ public class SpoilerStatusDisplayItem extends StatusDisplayItem{
|
|||
itemView.getPaddingLeft(),
|
||||
itemView.getPaddingTop(),
|
||||
itemView.getPaddingRight(),
|
||||
item.inset || GlobalUserPreferences.spectatorMode ? itemView.getPaddingTop() : 0
|
||||
item.inset ? itemView.getPaddingTop() : 0
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.joinmastodon.android.fragments.HashtagTimelineFragment;
|
|||
import org.joinmastodon.android.fragments.HomeTabFragment;
|
||||
import org.joinmastodon.android.fragments.ListTimelineFragment;
|
||||
import org.joinmastodon.android.fragments.ProfileFragment;
|
||||
import org.joinmastodon.android.fragments.ScheduledStatusListFragment;
|
||||
import org.joinmastodon.android.fragments.ThreadFragment;
|
||||
import org.joinmastodon.android.model.Account;
|
||||
import org.joinmastodon.android.model.Attachment;
|
||||
|
@ -49,7 +50,7 @@ import me.grishka.appkit.views.UsableRecyclerView;
|
|||
|
||||
public abstract class StatusDisplayItem{
|
||||
public final String parentID;
|
||||
public final BaseStatusListFragment parentFragment;
|
||||
public final BaseStatusListFragment<?> parentFragment;
|
||||
public boolean inset;
|
||||
public int index;
|
||||
public boolean
|
||||
|
@ -78,7 +79,7 @@ public abstract class StatusDisplayItem{
|
|||
this.isDirectDescendant = isDirectDescendant;
|
||||
}
|
||||
|
||||
public StatusDisplayItem(String parentID, BaseStatusListFragment parentFragment){
|
||||
public StatusDisplayItem(String parentID, BaseStatusListFragment<?> parentFragment){
|
||||
this.parentID=parentID;
|
||||
this.parentFragment=parentFragment;
|
||||
}
|
||||
|
@ -254,7 +255,7 @@ public abstract class StatusDisplayItem{
|
|||
}else if(!hasSpoiler && header!=null){
|
||||
header.needBottomPadding=true;
|
||||
}else if(hasSpoiler){
|
||||
contentItems.add(new DummyStatusDisplayItem(parentID, fragment, true));
|
||||
contentItems.add(new DummyStatusDisplayItem(parentID, fragment));
|
||||
}
|
||||
|
||||
List<Attachment> imageAttachments=statusForContent.mediaAttachments.stream().filter(att->att.type.isImage()).collect(Collectors.toList());
|
||||
|
@ -290,12 +291,14 @@ public abstract class StatusDisplayItem{
|
|||
if(contentItems!=items && statusForContent.spoilerRevealed){
|
||||
items.addAll(contentItems);
|
||||
}
|
||||
if((flags & FLAG_NO_EMOJI_REACTIONS)==0 && AccountSessionManager.get(accountID).getLocalPreferences().emojiReactionsEnabled){
|
||||
if((flags & FLAG_NO_EMOJI_REACTIONS)==0
|
||||
&& AccountSessionManager.get(accountID).getLocalPreferences().emojiReactionsEnabled){
|
||||
boolean isMainStatus=fragment instanceof ThreadFragment t && t.getMainStatus().id.equals(statusForContent.id);
|
||||
items.add(new EmojiReactionsStatusDisplayItem(parentID, fragment, statusForContent, accountID, !isMainStatus));
|
||||
}
|
||||
FooterStatusDisplayItem footer=null;
|
||||
if((flags & FLAG_NO_FOOTER)==0){
|
||||
FooterStatusDisplayItem footer=new FooterStatusDisplayItem(parentID, fragment, statusForContent, accountID);
|
||||
footer=new FooterStatusDisplayItem(parentID, fragment, statusForContent, accountID);
|
||||
footer.hideCounts=hideCounts;
|
||||
items.add(footer);
|
||||
if(status.hasGapAfter && !(fragment instanceof ThreadFragment))
|
||||
|
@ -304,10 +307,12 @@ public abstract class StatusDisplayItem{
|
|||
int i=1;
|
||||
boolean inset=(flags & FLAG_INSET)!=0;
|
||||
// add inset dummy so last content item doesn't clip out of inset bounds
|
||||
if (inset) {
|
||||
items.add(new DummyStatusDisplayItem(parentID, fragment,
|
||||
!contentItems.isEmpty() && contentItems
|
||||
.get(contentItems.size() - 1) instanceof MediaGridStatusDisplayItem));
|
||||
if(inset || footer==null){
|
||||
items.add(new DummyStatusDisplayItem(parentID, fragment));
|
||||
// in case we ever need the dummy to display a margin for the media grid again:
|
||||
// (i forgot why we apparently don't need this anymore)
|
||||
// !contentItems.isEmpty() && contentItems
|
||||
// .get(contentItems.size() - 1) instanceof MediaGridStatusDisplayItem));
|
||||
}
|
||||
for(StatusDisplayItem item:items){
|
||||
item.inset=inset;
|
||||
|
|
|
@ -32,6 +32,8 @@ import org.joinmastodon.android.ui.utils.UiUtils;
|
|||
import org.joinmastodon.android.ui.views.LinkedTextView;
|
||||
import org.joinmastodon.android.utils.StatusTextEncoder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -195,13 +197,21 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|||
readMore.setText(item.status.textExpanded ? R.string.sk_collapse : R.string.sk_expand);
|
||||
|
||||
// remove additional padding when (transparently padded) translate button is visible
|
||||
int nextPos = getAbsoluteAdapterPosition() + 1;
|
||||
int nextPos=getAbsoluteAdapterPosition() + 1;
|
||||
int bottomPadding=V.dp(12);
|
||||
if(item.parentFragment.getDisplayItems().size() > nextPos){
|
||||
if(item.parentFragment.getDisplayItems().get(nextPos) instanceof FooterStatusDisplayItem) bottomPadding=V.dp(6);
|
||||
if(item.parentFragment.getDisplayItems().get(nextPos) instanceof EmojiReactionsStatusDisplayItem){
|
||||
boolean reactionsHidden=item.status.reactions.isEmpty() && !(item.parentFragment instanceof ThreadFragment);
|
||||
bottomPadding=reactionsHidden ? V.dp(6) : 0;
|
||||
List<StatusDisplayItem> displayItems=item.parentFragment.getDisplayItems();
|
||||
if(displayItems.size() > nextPos){
|
||||
StatusDisplayItem next=displayItems.get(nextPos);
|
||||
if(next instanceof EmojiReactionsStatusDisplayItem e && e.isHidden()){
|
||||
next=displayItems.size() > ++nextPos ? displayItems.get(nextPos) : null;
|
||||
}
|
||||
|
||||
if(next instanceof FooterStatusDisplayItem){
|
||||
bottomPadding=V.dp(6);
|
||||
// why does java code always end up looking like this
|
||||
} else if((!item.inset && next instanceof DummyStatusDisplayItem) ||
|
||||
next instanceof EmojiReactionsStatusDisplayItem e && !e.isHidden()){
|
||||
bottomPadding=0;
|
||||
}
|
||||
}
|
||||
itemView.setPadding(itemView.getPaddingLeft(), itemView.getPaddingTop(), itemView.getPaddingRight(), bottomPadding);
|
||||
|
@ -239,7 +249,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
|||
|
||||
// compensate for spoiler's bottom margin
|
||||
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) itemView.getLayoutParams();
|
||||
params.setMargins(params.leftMargin, (item.inset || GlobalUserPreferences.spectatorMode) && hasSpoiler ? V.dp(-16) : 0,
|
||||
params.setMargins(params.leftMargin, item.inset && hasSpoiler ? V.dp(-16) : 0,
|
||||
params.rightMargin, params.bottomMargin);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue