Display photo attachments as a grid
This commit is contained in:
parent
c885a5fc28
commit
102fbeee1a
5 changed files with 38 additions and 44 deletions
|
@ -24,6 +24,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import me.grishka.appkit.fragments.BaseRecyclerFragment;
|
||||
import me.grishka.appkit.imageloader.ImageLoaderRecyclerAdapter;
|
||||
|
@ -231,6 +232,29 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager onCreateLayoutManager(){
|
||||
GridLayoutManager lm=new GridLayoutManager(getActivity(), 2);
|
||||
lm.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup(){
|
||||
@Override
|
||||
public int getSpanSize(int position){
|
||||
position-=getMainAdapterOffset();
|
||||
if(position>=0 && position<displayItems.size()){
|
||||
StatusDisplayItem item=displayItems.get(position);
|
||||
if(item instanceof PhotoStatusDisplayItem){
|
||||
int total=((PhotoStatusDisplayItem) item).totalPhotos;
|
||||
if(total>1){
|
||||
int index=((PhotoStatusDisplayItem) item).index;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
});
|
||||
return lm;
|
||||
}
|
||||
|
||||
protected int getMainAdapterOffset(){
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,15 @@ public class PhotoStatusDisplayItem extends StatusDisplayItem{
|
|||
private ImageLoaderRequest request;
|
||||
private Fragment parentFragment;
|
||||
private Status status;
|
||||
public PhotoStatusDisplayItem(String parentID, Status status, Attachment photo, Fragment parentFragment){
|
||||
public final int index, totalPhotos;
|
||||
public PhotoStatusDisplayItem(String parentID, Status status, Attachment photo, Fragment parentFragment, int index, int totalPhotos){
|
||||
super(parentID);
|
||||
this.status=status;
|
||||
this.attachment=photo;
|
||||
request=new UrlImageLoaderRequest(photo.url, 1000, 1000);
|
||||
this.parentFragment=parentFragment;
|
||||
this.index=index;
|
||||
this.totalPhotos=totalPhotos;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -54,9 +54,17 @@ public abstract class StatusDisplayItem{
|
|||
items.add(new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID));
|
||||
if(!TextUtils.isEmpty(statusForContent.content))
|
||||
items.add(new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis), fragment));
|
||||
int photoIndex=0;
|
||||
int totalPhotos=0;
|
||||
for(Attachment attachment:statusForContent.mediaAttachments){
|
||||
if(attachment.type==Attachment.Type.IMAGE){
|
||||
items.add(new PhotoStatusDisplayItem(parentID, status, attachment, fragment));
|
||||
totalPhotos++;
|
||||
}
|
||||
}
|
||||
for(Attachment attachment:statusForContent.mediaAttachments){
|
||||
if(attachment.type==Attachment.Type.IMAGE){
|
||||
items.add(new PhotoStatusDisplayItem(parentID, status, attachment, fragment, photoIndex, totalPhotos));
|
||||
photoIndex++;
|
||||
}
|
||||
}
|
||||
items.add(new FooterStatusDisplayItem(parentID, status, accountID));
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package org.joinmastodon.android.utils;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* from https://github.com/Richienb/char-regex/blob/master/index.js
|
||||
*/
|
||||
public class CharRegex{
|
||||
// Used to compose unicode character classes.
|
||||
private static final String astralRange = "\\ud800-\\udfff";
|
||||
private static final String comboMarksRange = "\\u0300-\\u036f";
|
||||
private static final String comboHalfMarksRange = "\\ufe20-\\ufe2f";
|
||||
private static final String comboSymbolsRange = "\\u20d0-\\u20ff";
|
||||
private static final String comboMarksExtendedRange = "\\u1ab0-\\u1aff";
|
||||
private static final String comboMarksSupplementRange = "\\u1dc0-\\u1dff";
|
||||
private static final String comboRange = comboMarksRange + comboHalfMarksRange + comboSymbolsRange + comboMarksExtendedRange + comboMarksSupplementRange;
|
||||
private static final String varRange = "\\ufe0e\\ufe0f";
|
||||
|
||||
|
||||
// Used to compose unicode capture groups.
|
||||
private static final String astral = "["+astralRange+"]";
|
||||
private static final String combo = "["+comboRange+"]";
|
||||
private static final String fitz = "\\ud83c[\\udffb-\\udfff]";
|
||||
private static final String modifier = "(?:"+combo+"|"+fitz+")";
|
||||
private static final String nonAstral = "[^"+astralRange+"]";
|
||||
private static final String regional = "(?:\\ud83c[\\udde6-\\uddff]){2}";
|
||||
private static final String surrogatePair = "[\\ud800-\\udbff][\\udc00-\\udfff]";
|
||||
private static final String zeroWidthJoiner = "\\u200d";
|
||||
private static final String blackFlag = "(?:\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40(?:\\udc65|\\udc73|\\udc77)\\udb40(?:\\udc6e|\\udc63|\\udc6c)\\udb40(?:\\udc67|\\udc74|\\udc73)\\udb40\\udc7f)";
|
||||
|
||||
// Used to compose unicode regexes.
|
||||
private static final String optModifier = modifier+"?";
|
||||
private static final String optVar = "["+varRange+"]?";
|
||||
private static final String optJoin = "(?:"+zeroWidthJoiner+"(?:"+nonAstral+"|"+regional+"|"+surrogatePair+")"+optVar + optModifier+")*";
|
||||
private static final String seq = optVar + optModifier + optJoin;
|
||||
private static final String nonAstralCombo = nonAstral+combo+"?";
|
||||
private static final String symbol = "(?:"+blackFlag+"|"+nonAstralCombo+"|"+combo+"|"+regional+"|"+surrogatePair+"|"+astral+")";
|
||||
|
||||
public static final Pattern REGEX=Pattern.compile(fitz+"(?="+fitz+")|"+symbol + seq);
|
||||
// public static final Pattern REGEX=Pattern.compile("\\ud83c[\\udffb-\\udfff](?=\\ud83c[\\udffb-\\udfff])|(?:(?:\\ud83c\\udff4\\udb40\\udc67\\udb40\\udc62\\udb40(?:\\udc65|\\udc73|\\udc77)\\udb40(?:\\udc6e|\\udc63|\\udc6c)\\udb40(?:\\udc67|\\udc74|\\udc73)\\udb40\\udc7f)|[^\\ud800-\\udfff][\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\u1ab0-\\u1aff\\u1dc0-\\u1dff]?|[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\u1ab0-\\u1aff\\u1dc0-\\u1dff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff]|[\\ud800-\\udfff])[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\u1ab0-\\u1aff\\u1dc0-\\u1dff]|\\ud83c[\\udffb-\\udfff])?(?:\\u200d(?:[^\\ud800-\\udfff]|(?:\\ud83c[\\udde6-\\uddff]){2}|[\\ud800-\\udbff][\\udc00-\\udfff])[\\ufe0e\\ufe0f]?(?:[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\u1ab0-\\u1aff\\u1dc0-\\u1dff]|\\ud83c[\\udffb-\\udfff])?)*");
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<ImageView
|
||||
android:id="@+id/photo"
|
||||
android:layout_width="250dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="250dp"
|
||||
android:layout_gravity="center"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue