Compare commits
10 Commits
2.3.0+fork
...
merge-upst
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26df5762f | ||
|
|
2021c335ac | ||
|
|
d121f14d30 | ||
|
|
d1a2a70cdc | ||
|
|
89ef482e2e | ||
|
|
9918649d7c | ||
|
|
09185faf9a | ||
|
|
b7e0596014 | ||
|
|
dbef984908 | ||
|
|
55259f103d |
@@ -9,6 +9,7 @@ import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Pair;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
@@ -709,26 +710,17 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||
}
|
||||
|
||||
public void updateStatusWithQuote(DisplayItemsParent parent) {
|
||||
int startIndex=-1;
|
||||
int endIndex=-1;
|
||||
for(int i=0; i<displayItems.size(); i++){
|
||||
StatusDisplayItem item = displayItems.get(i);
|
||||
if(item.parentID.equals(parent.getID())) {
|
||||
startIndex= startIndex==-1 ? i : startIndex;
|
||||
endIndex=i;
|
||||
}
|
||||
}
|
||||
|
||||
if (startIndex==-1 || endIndex==-1)
|
||||
Pair<Integer, Integer> items=findAllItemsOfParent(parent);
|
||||
if (items==null)
|
||||
return;
|
||||
|
||||
// Only StatusListFragments/NotificationsListFragments can display status with quotes
|
||||
assert (this instanceof StatusListFragment) || (this instanceof NotificationsListFragment);
|
||||
List<StatusDisplayItem> oldItems = displayItems.subList(startIndex, endIndex+1);
|
||||
List<StatusDisplayItem> oldItems = displayItems.subList(items.first, items.second+1);
|
||||
List<StatusDisplayItem> newItems=this.buildDisplayItems((T) parent);
|
||||
int prevSize=oldItems.size();
|
||||
oldItems.clear();
|
||||
displayItems.addAll(startIndex, newItems);
|
||||
displayItems.addAll(items.first, newItems);
|
||||
|
||||
// Update the cache
|
||||
final CacheController cache=AccountSessionManager.get(accountID).getCacheController();
|
||||
@@ -738,8 +730,19 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||
cache.updateNotification((Notification) parent);
|
||||
}
|
||||
|
||||
adapter.notifyItemRangeRemoved(startIndex, prevSize);
|
||||
adapter.notifyItemRangeInserted(startIndex, newItems.size());
|
||||
adapter.notifyItemRangeRemoved(items.first, prevSize);
|
||||
adapter.notifyItemRangeInserted(items.first, newItems.size());
|
||||
}
|
||||
|
||||
public void removeStatus(DisplayItemsParent parent) {
|
||||
Pair<Integer, Integer> items=findAllItemsOfParent(parent);
|
||||
if (items==null)
|
||||
return;
|
||||
|
||||
List<StatusDisplayItem> statusDisplayItems = displayItems.subList(items.first, items.second+1);
|
||||
int prevSize=statusDisplayItems.size();
|
||||
statusDisplayItems.clear();
|
||||
adapter.notifyItemRangeRemoved(items.first, prevSize);
|
||||
}
|
||||
|
||||
public void onVisibilityIconClick(HeaderStatusDisplayItem.Holder holder) {
|
||||
@@ -945,6 +948,23 @@ public abstract class BaseStatusListFragment<T extends DisplayItemsParent> exten
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected Pair<Integer, Integer> findAllItemsOfParent(DisplayItemsParent parent){
|
||||
int startIndex=-1;
|
||||
int endIndex=-1;
|
||||
for(int i=0; i<displayItems.size(); i++){
|
||||
StatusDisplayItem item = displayItems.get(i);
|
||||
if(item.parentID.equals(parent.getID())) {
|
||||
startIndex= startIndex==-1 ? i : startIndex;
|
||||
endIndex=i;
|
||||
}
|
||||
}
|
||||
|
||||
if(startIndex==-1 || endIndex==-1)
|
||||
return null;
|
||||
return Pair.create(startIndex, endIndex);
|
||||
}
|
||||
|
||||
protected <I extends StatusDisplayItem, H extends StatusDisplayItem.Holder<I>> List<H> findAllHoldersOfType(String id, Class<H> type){
|
||||
ArrayList<H> holders=new ArrayList<>();
|
||||
for(int i=0;i<list.getChildCount();i++){
|
||||
|
||||
@@ -297,8 +297,8 @@ public class FollowRequestsListFragment extends MastodonRecyclerFragment<FollowR
|
||||
cover.setImageDrawable(image);
|
||||
}else{
|
||||
item.emojiHelper.setImageDrawable(index-2, image);
|
||||
name.invalidate();
|
||||
bio.invalidate();
|
||||
name.setText(name.getText());
|
||||
bio.setText(bio.getText());
|
||||
}
|
||||
if(image instanceof Animatable a && !a.isRunning())
|
||||
a.start();
|
||||
|
||||
@@ -1587,8 +1587,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
|
||||
public void setImage(int index, Drawable image){
|
||||
CustomEmojiSpan span=index>=item.nameEmojis.length ? item.valueEmojis[index-item.nameEmojis.length] : item.nameEmojis[index];
|
||||
span.setDrawable(image);
|
||||
title.invalidate();
|
||||
value.invalidate();
|
||||
title.setText(title.getText());
|
||||
value.setText(value.getText());
|
||||
toolbarTitleView.setText(toolbarTitleView.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -279,8 +279,8 @@ public class DiscoverAccountsFragment extends MastodonRecyclerFragment<DiscoverA
|
||||
cover.setImageDrawable(image);
|
||||
}else{
|
||||
item.emojiHelper.setImageDrawable(index-2, image);
|
||||
name.invalidate();
|
||||
bio.invalidate();
|
||||
name.setText(name.getText());
|
||||
bio.setText(bio.getText());
|
||||
}
|
||||
if(image instanceof Animatable a && !a.isRunning())
|
||||
a.start();
|
||||
|
||||
@@ -131,8 +131,7 @@ public class DiscoverTrendingLinkTimelineFragment extends StatusListFragment{
|
||||
|
||||
@Override
|
||||
public Uri getWebUri(Uri.Builder base) {
|
||||
//TODO: add URL link once web version implements a UI
|
||||
return base.path("/explore/links").build();
|
||||
return base.path("/links").appendPath(trendingLink.url).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -38,7 +38,7 @@ public class EmojiReaction {
|
||||
reaction.staticUrl=info.staticUrl;
|
||||
reaction.accounts=new ArrayList<>(Collections.singleton(me));
|
||||
reaction.accountIds=new ArrayList<>(Collections.singleton(me.id));
|
||||
reaction.request=new UrlImageLoaderRequest(info.url, V.sp(24), V.sp(24));
|
||||
reaction.request=new UrlImageLoaderRequest(info.url, 0, V.sp(24));
|
||||
return reaction;
|
||||
}
|
||||
|
||||
|
||||
@@ -225,8 +225,8 @@ public class AccountCardStatusDisplayItem extends StatusDisplayItem{
|
||||
cover.setImageDrawable(image);
|
||||
}else{
|
||||
item.emojiHelper.setImageDrawable(index-2, image);
|
||||
name.invalidate();
|
||||
bio.invalidate();
|
||||
name.setText(name.getText());
|
||||
bio.setText(bio.getText());
|
||||
}
|
||||
if(image instanceof Animatable && !((Animatable) image).isRunning())
|
||||
((Animatable) image).start();
|
||||
|
||||
@@ -172,7 +172,7 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||
addButton.setSelected(false);
|
||||
AccountSession session=item.parentFragment.getSession();
|
||||
item.status.reactions.forEach(r->r.request=r.getUrl(item.playGifs)!=null
|
||||
? new UrlImageLoaderRequest(r.getUrl(item.playGifs), V.sp(24), V.sp(24))
|
||||
? new UrlImageLoaderRequest(r.getUrl(item.playGifs), 0, V.sp(24))
|
||||
: null);
|
||||
emojiKeyboard=new CustomEmojiPopupKeyboard(
|
||||
(Activity) item.parentFragment.getContext(),
|
||||
@@ -342,7 +342,9 @@ public class EmojiReactionsStatusDisplayItem extends StatusDisplayItem {
|
||||
|
||||
@Override
|
||||
public void setImage(int index, Drawable drawable){
|
||||
drawable.setBounds(0, 0, V.sp(24), V.sp(24));
|
||||
int height=V.sp(24);
|
||||
int width=drawable.getIntrinsicWidth()*height/drawable.getIntrinsicHeight();
|
||||
drawable.setBounds(0, 0, width, height);
|
||||
btn.setCompoundDrawablesRelative(drawable, null, null, null);
|
||||
if(drawable instanceof Animatable) ((Animatable) drawable).start();
|
||||
}
|
||||
|
||||
@@ -422,7 +422,7 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
|
||||
public void setImage(int index, Drawable drawable){
|
||||
if(index>0){
|
||||
item.emojiHelper.setImageDrawable(index-1, drawable);
|
||||
name.invalidate();
|
||||
name.setText(name.getText());
|
||||
}else{
|
||||
avatar.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class NotificationHeaderStatusDisplayItem extends StatusDisplayItem{
|
||||
avatar.setImageDrawable(image);
|
||||
}else{
|
||||
item.emojiHelper.setImageDrawable(index-1, image);
|
||||
text.invalidate();
|
||||
text.setText(text.getText());
|
||||
}
|
||||
if(image instanceof Animatable)
|
||||
((Animatable) image).start();
|
||||
|
||||
@@ -136,7 +136,7 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void setImage(int index, Drawable image){
|
||||
item.emojiHelper.setImageDrawable(index, image);
|
||||
text.invalidate();
|
||||
text.setText(text.getText());
|
||||
if(image instanceof Animatable){
|
||||
((Animatable) image).start();
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public class PollOptionStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void clearImage(int index){
|
||||
item.emojiHelper.setImageDrawable(index, null);
|
||||
text.invalidate();
|
||||
text.setText(text.getText());
|
||||
}
|
||||
|
||||
private void onButtonClick(View v){
|
||||
|
||||
@@ -152,8 +152,8 @@ public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
|
||||
int firstHelperCount=item.emojiHelper.getImageCount();
|
||||
CustomEmojiHelper helper=index<firstHelperCount ? item.emojiHelper : item.extra.emojiHelper;
|
||||
helper.setImageDrawable(firstHelperCount>0 ? index%firstHelperCount : index, image);
|
||||
text.invalidate();
|
||||
extraText.invalidate();
|
||||
text.setText(text.getText());
|
||||
extraText.setText(extraText.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -114,7 +114,7 @@ public class SpoilerStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void setImage(int index, Drawable image){
|
||||
item.emojiHelper.setImageDrawable(index, image);
|
||||
title.invalidate();
|
||||
title.setText(title.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,8 +17,10 @@ import android.view.ViewGroup;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships;
|
||||
import org.joinmastodon.android.api.requests.search.GetSearchResults;
|
||||
import org.joinmastodon.android.api.session.AccountLocalPreferences;
|
||||
import org.joinmastodon.android.api.session.AccountSession;
|
||||
import org.joinmastodon.android.api.session.AccountSessionManager;
|
||||
import org.joinmastodon.android.fragments.BaseStatusListFragment;
|
||||
import org.joinmastodon.android.fragments.HashtagTimelineFragment;
|
||||
@@ -35,6 +37,7 @@ import org.joinmastodon.android.model.FilterResult;
|
||||
import org.joinmastodon.android.model.LegacyFilter;
|
||||
import org.joinmastodon.android.model.Notification;
|
||||
import org.joinmastodon.android.model.Poll;
|
||||
import org.joinmastodon.android.model.Relationship;
|
||||
import org.joinmastodon.android.model.ScheduledStatus;
|
||||
import org.joinmastodon.android.model.SearchResults;
|
||||
import org.joinmastodon.android.model.Status;
|
||||
@@ -339,7 +342,7 @@ public abstract class StatusDisplayItem{
|
||||
contentItems.add(new DummyStatusDisplayItem(parentID, fragment));
|
||||
contentItems.addAll(buildItems(fragment, statusForContent.quote, accountID, parentObject, knownAccounts, filterContext, FLAG_NO_FOOTER|FLAG_INSET|FLAG_NO_EMOJI_REACTIONS|FLAG_IS_FOR_QUOTE));
|
||||
} else if((flags & FLAG_INSET)==0 && statusForContent.mediaAttachments.isEmpty()){
|
||||
tryAddNonOfficialQuote(statusForContent, fragment, accountID);
|
||||
tryAddNonOfficialQuote(statusForContent, fragment, accountID, filterContext);
|
||||
}
|
||||
if(contentItems!=items && statusForContent.spoilerRevealed){
|
||||
items.addAll(contentItems);
|
||||
@@ -421,29 +424,54 @@ public abstract class StatusDisplayItem{
|
||||
* Tries to adds a non-official quote to a status.
|
||||
* A non-official quote is a quote on an instance that does not support quotes officially.
|
||||
*/
|
||||
private static void tryAddNonOfficialQuote(Status status, BaseStatusListFragment fragment, String accountID) {
|
||||
private static void tryAddNonOfficialQuote(Status status, BaseStatusListFragment fragment, String accountID, FilterContext filterContext) {
|
||||
Matcher matcher=QUOTE_PATTERN.matcher(status.getStrippedText());
|
||||
|
||||
if(!matcher.find())
|
||||
return;
|
||||
String quoteURL=matcher.group();
|
||||
|
||||
if (UiUtils.looksLikeFediverseUrl(quoteURL)) {
|
||||
new GetSearchResults(quoteURL, GetSearchResults.Type.STATUSES, true, null, 0, 0).setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(SearchResults results){
|
||||
if (results.statuses != null && !results.statuses.isEmpty()){
|
||||
status.quote=results.statuses.get(0);
|
||||
fragment.updateStatusWithQuote(status);
|
||||
}
|
||||
}
|
||||
if (!UiUtils.looksLikeFediverseUrl(quoteURL))
|
||||
return;
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
Log.w("StatusDisplayItem", "onError: failed to find quote status with URL: " + quoteURL + " " + error);
|
||||
}
|
||||
}).exec(accountID);
|
||||
}
|
||||
new GetSearchResults(quoteURL, GetSearchResults.Type.STATUSES, true, null, 0, 0).setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(SearchResults results){
|
||||
AccountSessionManager.get(accountID).filterStatuses(results.statuses, filterContext);
|
||||
if (results.statuses == null || results.statuses.isEmpty())
|
||||
return;
|
||||
|
||||
Status quote=results.statuses.get(0);
|
||||
new GetAccountRelationships(Collections.singletonList(quote.account.id))
|
||||
.setCallback(new Callback<>(){
|
||||
@Override
|
||||
public void onSuccess(List<Relationship> relationships){
|
||||
if(relationships.isEmpty())
|
||||
return;
|
||||
|
||||
Relationship relationship=relationships.get(0);
|
||||
String selfId=AccountSessionManager.get(accountID).self.id;
|
||||
if(!status.account.id.equals(selfId) && (relationship.domainBlocking || relationship.muting || relationship.blocking)) {
|
||||
// do not show posts that are quoting a muted/blocked user
|
||||
fragment.removeStatus(status);
|
||||
return;
|
||||
}
|
||||
|
||||
status.quote=results.statuses.get(0);
|
||||
fragment.updateStatusWithQuote(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){}
|
||||
})
|
||||
.exec(accountID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error){
|
||||
Log.w("StatusDisplayItem", "onError: failed to find quote status with URL: " + quoteURL + " " + error);
|
||||
}
|
||||
}).exec(accountID);
|
||||
}
|
||||
|
||||
public enum Type{
|
||||
|
||||
@@ -173,7 +173,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void setImage(int index, Drawable image){
|
||||
getEmojiHelper().setImageDrawable(index, image);
|
||||
text.invalidate();
|
||||
text.setText(text.getText());
|
||||
if(image instanceof Animatable){
|
||||
((Animatable) image).start();
|
||||
if(image instanceof MovieDrawable)
|
||||
@@ -184,7 +184,7 @@ public class TextStatusDisplayItem extends StatusDisplayItem{
|
||||
@Override
|
||||
public void clearImage(int index){
|
||||
getEmojiHelper().setImageDrawable(index, null);
|
||||
text.invalidate();
|
||||
text.setText(text.getText());
|
||||
}
|
||||
|
||||
private CustomEmojiHelper getEmojiHelper(){
|
||||
|
||||
@@ -24,7 +24,8 @@ public class CustomEmojiSpan extends ReplacementSpan{
|
||||
|
||||
@Override
|
||||
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, @Nullable Paint.FontMetricsInt fm){
|
||||
return Math.round(paint.descent()-paint.ascent());
|
||||
int size = Math.round(paint.descent()-paint.ascent());
|
||||
return drawable!=null ? (int) (drawable.getIntrinsicWidth()*(size/(float) drawable.getIntrinsicHeight())) : size;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,7 +46,8 @@ public class CustomEmojiSpan extends ReplacementSpan{
|
||||
}
|
||||
canvas.save();
|
||||
canvas.translate(x, top);
|
||||
canvas.scale(size/(float)dw, size/(float)dh, 0f, 0f);
|
||||
float scale = size/(float)dh;
|
||||
canvas.scale(scale, scale, 0f, 0f);
|
||||
drawable.draw(canvas);
|
||||
canvas.restore();
|
||||
}
|
||||
@@ -56,7 +58,6 @@ public class CustomEmojiSpan extends ReplacementSpan{
|
||||
}
|
||||
|
||||
public UrlImageLoaderRequest createImageLoaderRequest(){
|
||||
int size=V.dp(20);
|
||||
return new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? emoji.url : emoji.staticUrl, size, size);
|
||||
return new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? emoji.url : emoji.staticUrl, 0, V.dp(20));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -417,7 +417,6 @@ public class UiUtils {
|
||||
CustomEmojiSpan[] spans = text.getSpans(0, text.length(), CustomEmojiSpan.class);
|
||||
if (spans.length == 0)
|
||||
return;
|
||||
int emojiSize = V.dp(20);
|
||||
Map<Emoji, List<CustomEmojiSpan>> spansByEmoji = Arrays.stream(spans).collect(Collectors.groupingBy(s -> s.emoji));
|
||||
for (Map.Entry<Emoji, List<CustomEmojiSpan>> emoji : spansByEmoji.entrySet()) {
|
||||
ViewImageLoader.load(new ViewImageLoader.Target() {
|
||||
@@ -428,14 +427,14 @@ public class UiUtils {
|
||||
for (CustomEmojiSpan span : emoji.getValue()) {
|
||||
span.setDrawable(d);
|
||||
}
|
||||
view.invalidate();
|
||||
view.setText(view.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
}, null, new UrlImageLoaderRequest(emoji.getKey().url, emojiSize, emojiSize), null, false, true);
|
||||
}, null, new UrlImageLoaderRequest(emoji.getKey().url, 0, V.dp(20)), null, false, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -185,8 +185,8 @@ public class AccountViewHolder extends BindableViewHolder<AccountViewModel> impl
|
||||
avatar.setImageDrawable(image);
|
||||
}else{
|
||||
item.emojiHelper.setImageDrawable(index-1, image);
|
||||
name.invalidate();
|
||||
bio.invalidate();
|
||||
name.setText(name.getText());
|
||||
bio.setText(bio.getText());
|
||||
}
|
||||
|
||||
if(image instanceof Animatable a && !a.isRunning())
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:pathData="M17.75,2.007a2.25,2.25 0,0 1,2.245 2.096l0.005,0.154v15.498A2.25,2.25 0,0 1,17.904 22l-0.154,0.005H6.25a2.25,2.25 0,0 1,-2.245 -2.096L4,19.755V4.257a2.25,2.25 0,0 1,2.096 -2.245l0.154,-0.005h11.5ZM7.75,7a0.75,0.75 0,1 0,0 1.5h8.5a0.75,0.75 0,0 0,0 -1.5h-8.5ZM7,11.75c0,0.414 0.336,0.75 0.75,0.75h8.5a0.75,0.75 0,0 0,0 -1.5h-8.5a0.75,0.75 0,0 0,-0.75 0.75ZM7.75,15a0.75,0.75 0,1 0,0 1.5h8.5a0.75,0.75 0,0 0,0 -1.5h-8.5Z"
|
||||
android:fillColor="#212121"/>
|
||||
</vector>
|
||||
@@ -2,7 +2,7 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/open_link"
|
||||
android:icon="@drawable/ic_fluent_document_one_page_24_filled"
|
||||
android:icon="@drawable/ic_fluent_open_24_regular"
|
||||
android:showAsAction="always"
|
||||
android:title="@string/mo_trending_link_read"/>
|
||||
</menu>
|
||||
Reference in New Issue
Block a user