Merge remote-tracking branch 'megalodon_main/main' into m3-merger

# Conflicts:
#	README.md
#	build.gradle
#	mastodon/build.gradle
#	mastodon/src/main/AndroidManifest.xml
#	mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java
#	mastodon/src/main/java/org/joinmastodon/android/MainActivity.java
#	mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java
#	mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetAccountMuted.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/EditTimelinesFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/NotificationsFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/PinnableStatusListFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/SettingsFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/StatusListFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/account_list/BaseAccountListFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/CustomWelcomeFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/InstanceRulesFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/onboarding/OnboardingFollowSuggestionsFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/fragments/settings/SettingsMainFragment.java
#	mastodon/src/main/java/org/joinmastodon/android/model/Attachment.java
#	mastodon/src/main/java/org/joinmastodon/android/model/Status.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/CustomEmojiPopupKeyboard.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/M3AlertDialogBuilder.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/AudioStatusDisplayItem.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/FooterStatusDisplayItem.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/HeaderStatusDisplayItem.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/PollOptionStatusDisplayItem.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/displayitems/StatusDisplayItem.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/utils/InsetStatusItemDecoration.java
#	mastodon/src/main/java/org/joinmastodon/android/ui/utils/UiUtils.java
#	mastodon/src/main/res/color/button_bg_secondary_dark_on_light.xml
#	mastodon/src/main/res/color/button_text_primary_light_on_dark.xml
#	mastodon/src/main/res/drawable/bg_image_alt_text_overlay.xml
#	mastodon/src/main/res/drawable/bg_rect_4dp_ripple.xml
#	mastodon/src/main/res/drawable/bg_search_field.xml
#	mastodon/src/main/res/drawable/ic_fluent_save_24_regular.xml
#	mastodon/src/main/res/layout/compose_action.xml
#	mastodon/src/main/res/layout/compose_media_thumb.xml
#	mastodon/src/main/res/layout/compose_poll_option.xml
#	mastodon/src/main/res/layout/display_item_footer.xml
#	mastodon/src/main/res/layout/display_item_header.xml
#	mastodon/src/main/res/layout/display_item_text.xml
#	mastodon/src/main/res/layout/fragment_compose.xml
#	mastodon/src/main/res/layout/fragment_profile.xml
#	mastodon/src/main/res/layout/item_instance_category.xml
#	mastodon/src/main/res/layout/item_report_choice.xml
#	mastodon/src/main/res/layout/item_settings_footer.xml
#	mastodon/src/main/res/layout/item_settings_switch.xml
#	mastodon/src/main/res/layout/item_settings_theme.xml
#	mastodon/src/main/res/layout/item_settings_theme_subitem.xml
#	mastodon/src/main/res/layout/item_settings_update.xml
#	mastodon/src/main/res/layout/tab_bar.xml
#	mastodon/src/main/res/menu/mute_duration.xml
#	mastodon/src/main/res/values-de-rDE/strings_sk.xml
#	mastodon/src/main/res/values-es-rES/strings_sk.xml
#	mastodon/src/main/res/values-fa/strings_sk.xml
#	mastodon/src/main/res/values-night/colors.xml
#	mastodon/src/main/res/values-nl-rNL/strings_sk.xml
#	mastodon/src/main/res/values-uk-rUA/strings_sk.xml
#	mastodon/src/main/res/values-zh-rCN/strings_sk.xml
#	mastodon/src/main/res/values/attrs.xml
#	mastodon/src/main/res/values/ids.xml
#	mastodon/src/main/res/values/styles.xml
#	metadata/es/changelogs/83.txt
This commit is contained in:
LucasGGamerM
2023-08-20 11:36:16 -03:00
parent 8f4363a2d8
commit 93818903c8
753 changed files with 28298 additions and 14085 deletions

View File

@@ -3,6 +3,7 @@ package org.joinmastodon.android.model;
import android.graphics.Bitmap;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.media.MediaMetadataRetriever;
import com.google.gson.annotations.SerializedName;
@@ -14,10 +15,6 @@ import org.parceler.Parcel;
import org.parceler.ParcelConstructor;
import org.parceler.ParcelProperty;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@Parcel
public class Attachment extends BaseModel{
// @RequiredField
@@ -46,39 +43,29 @@ public class Attachment extends BaseModel{
blurhashPlaceholder=new BlurHashDrawable(placeholder, getWidth(), getHeight());
}
}
public static List<Attachment> createFakeAttachments(String url, Drawable drawable){
Attachment att=new Attachment();
att.type=Attachment.Type.IMAGE;
att.url=url;
att.meta=new Attachment.Metadata();
att.meta.width=drawable.getIntrinsicWidth();
att.meta.height=drawable.getIntrinsicHeight();
return Collections.singletonList(att);
}
public int getWidth(){
if(meta==null)
return 1920;
return 0;
if(meta.width>0)
return meta.width;
if(meta.original!=null && meta.original.width>0)
return meta.original.width;
if(meta.small!=null && meta.small.width>0)
return meta.small.width;
return 1920;
return 0;
}
public int getHeight(){
if(meta==null)
return 1080;
return 0;
if(meta.height>0)
return meta.height;
if(meta.original!=null && meta.original.height>0)
return meta.original.height;
if(meta.small!=null && meta.small.height>0)
return meta.small.height;
return 1080;
return 0;
}
public double getDuration(){
@@ -91,6 +78,13 @@ public class Attachment extends BaseModel{
return 0;
}
public boolean hasSound() {
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(url);
String hasAudioStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_HAS_AUDIO);
return "yes".equals(hasAudioStr);
}
@Override
public void postprocess() throws ObjectValidationException{
super.postprocess();
@@ -147,6 +141,7 @@ public class Attachment extends BaseModel{
public PointF focus;
public SizeMetadata original;
public SizeMetadata small;
public ColorsMetadata colors;
@Override
public String toString(){
@@ -158,6 +153,7 @@ public class Attachment extends BaseModel{
", focus="+focus+
", original="+original+
", small="+small+
", colors="+colors+
'}';
}
}
@@ -181,4 +177,20 @@ public class Attachment extends BaseModel{
'}';
}
}
@Parcel
public static class ColorsMetadata{
public String background;
public String foreground;
public String accent;
@Override
public String toString(){
return "ColorsMetadata{"+
"background='"+background+'\''+
", foreground='"+foreground+'\''+
", accent='"+accent+'\''+
'}';
}
}
}

View File

@@ -18,23 +18,22 @@ public enum ContentType {
@SerializedName("text/bbcode")
BBCODE, // akkoma
@SerializedName("text/x.misskeymarkdown")
MISSKEY_MARKDOWN; // akkoma/*key
MISSKEY_MARKDOWN, // akkoma/*key
@SerializedName("")
UNSPECIFIED;
public static int getContentTypeRes(@Nullable ContentType contentType) {
return contentType == null ? R.id.content_type_null : switch(contentType) {
case PLAIN -> R.id.content_type_plain;
case HTML -> R.id.content_type_html;
case MARKDOWN -> R.id.content_type_markdown;
case BBCODE -> R.id.content_type_bbcode;
case MISSKEY_MARKDOWN -> R.id.content_type_misskey_markdown;
public int getName() {
return switch(this) {
case PLAIN -> R.string.sk_content_type_plain;
case HTML -> R.string.sk_content_type_html;
case MARKDOWN -> R.string.sk_content_type_markdown;
case BBCODE -> R.string.sk_content_type_bbcode;
case MISSKEY_MARKDOWN -> R.string.sk_content_type_mfm;
case UNSPECIFIED -> R.string.sk_content_type_unspecified;
};
}
public static void adaptMenuToInstance(Menu m, Instance i) {
if (i.pleroma == null) {
// memo: change this if glitch or another mastodon fork supports bbcode or mfm
m.findItem(R.id.content_type_bbcode).setVisible(false);
m.findItem(R.id.content_type_misskey_markdown).setVisible(false);
}
public boolean supportedByInstance(Instance i) {
return i.isAkkoma() || (this!=BBCODE && this!=MISSKEY_MARKDOWN);
}
}

View File

@@ -33,6 +33,14 @@ public class Emoji extends BaseModel{
*/
public String category;
public Emoji() {}
public Emoji(String shortcode, String url, String staticUrl) {
this.shortcode = shortcode.replaceAll(":", "");
this.url = url;
this.staticUrl = staticUrl;
}
@Override
public String toString(){
return "Emoji{"+

View File

@@ -0,0 +1,16 @@
package org.joinmastodon.android.model;
import org.parceler.Parcel;
import java.util.List;
@Parcel
public class EmojiReaction {
public List<Account> accounts;
public List<String> accountIds;
public int count;
public boolean me;
public String name;
public String url;
public String staticUrl;
}

View File

@@ -1,62 +1,43 @@
package org.joinmastodon.android.model;
import android.text.TextUtils;
import androidx.annotation.Nullable;
import com.google.gson.annotations.SerializedName;
import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
import java.time.Instant;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
@Parcel
public class Filter extends BaseModel{
@RequiredField
public String id;
public String phrase;
@RequiredField
public String title;
public transient EnumSet<FilterContext> context=EnumSet.noneOf(FilterContext.class);
@RequiredField
public EnumSet<FilterContext> context;
public Instant expiresAt;
public boolean irreversible;
public boolean wholeWord;
public FilterAction filterAction;
@SerializedName("context")
protected List<FilterContext> _context;
public List<FilterKeyword> keywords=new ArrayList<>();
private transient Pattern pattern;
public List<FilterStatus> statuses=new ArrayList<>();
@Override
public void postprocess() throws ObjectValidationException{
super.postprocess();
if(_context==null)
throw new ObjectValidationException();
for(FilterContext c:_context){
if(c!=null)
context.add(c);
}
for(FilterKeyword keyword:keywords)
keyword.postprocess();
for(FilterStatus status:statuses)
status.postprocess();
}
public boolean matches(CharSequence text){
if(TextUtils.isEmpty(text))
return false;
if(pattern==null){
if(wholeWord)
pattern=Pattern.compile("\\b"+Pattern.quote(phrase)+"\\b", Pattern.CASE_INSENSITIVE);
else
pattern=Pattern.compile(Pattern.quote(phrase), Pattern.CASE_INSENSITIVE);
}
if (title == null) title = phrase;
return pattern.matcher(text).find();
}
public boolean matches(Status status){
return matches(status.getContentStatus().getStrippedText());
public boolean isActive(){
return expiresAt==null || expiresAt.isAfter(Instant.now());
}
@Override
@@ -64,31 +45,11 @@ public class Filter extends BaseModel{
return "Filter{"+
"id='"+id+'\''+
", title='"+title+'\''+
", phrase='"+phrase+'\''+
", context="+context+
", expiresAt="+expiresAt+
", irreversible="+irreversible+
", wholeWord="+wholeWord+
", filterAction="+filterAction+
", keywords="+keywords+
", statuses="+statuses+
'}';
}
public enum FilterContext{
@SerializedName("home")
HOME,
@SerializedName("notifications")
NOTIFICATIONS,
@SerializedName("public")
PUBLIC,
@SerializedName("thread")
THREAD,
@SerializedName("account")
ACCOUNT
}
public enum FilterAction{
@SerializedName("hide")
HIDE,
@SerializedName("warn")
WARN
}
}

View File

@@ -0,0 +1,10 @@
package org.joinmastodon.android.model;
import com.google.gson.annotations.SerializedName;
public enum FilterAction{
@SerializedName("warn")
WARN,
@SerializedName("hide")
HIDE
}

View File

@@ -0,0 +1,31 @@
package org.joinmastodon.android.model;
import com.google.gson.annotations.SerializedName;
import org.joinmastodon.android.R;
import androidx.annotation.StringRes;
public enum FilterContext{
@SerializedName("home")
HOME,
@SerializedName("notifications")
NOTIFICATIONS,
@SerializedName("public")
PUBLIC,
@SerializedName("thread")
THREAD,
@SerializedName("account")
ACCOUNT;
@StringRes
public int getDisplayNameRes(){
return switch(this){
case HOME -> R.string.filter_context_home_lists;
case NOTIFICATIONS -> R.string.filter_context_notifications;
case PUBLIC -> R.string.filter_context_public_timelines;
case THREAD -> R.string.filter_context_threads_replies;
case ACCOUNT -> R.string.filter_context_profiles;
};
}
}

View File

@@ -0,0 +1,21 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.parceler.Parcel;
@AllFieldsAreRequired
@Parcel
public class FilterKeyword extends BaseModel{
public String id;
public String keyword;
public boolean wholeWord;
@Override
public String toString(){
return "FilterKeyword{"+
"id='"+id+'\''+
", keyword='"+keyword+'\''+
", wholeWord="+wholeWord+
'}';
}
}

View File

@@ -3,9 +3,13 @@ package org.joinmastodon.android.model;
import org.joinmastodon.android.api.ObjectValidationException;
import org.parceler.Parcel;
import java.util.List;
@Parcel
public class FilterResult extends BaseModel {
public Filter filter;
public LegacyFilter filter;
public List<String> keywordMatches;
@Override
public void postprocess() throws ObjectValidationException {

View File

@@ -0,0 +1,11 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.parceler.Parcel;
@AllFieldsAreRequired
@Parcel
public class FilterStatus extends BaseModel{
public String id;
public String statusId;
}

View File

@@ -6,13 +6,14 @@ import org.parceler.Parcel;
import java.util.List;
@Parcel
public class Hashtag extends BaseModel{
public class Hashtag extends BaseModel implements DisplayItemsParent{
@RequiredField
public String name;
@RequiredField
public String url;
public boolean following;
public List<History> history;
public int statusesCount;
@Override
public String toString(){
@@ -21,6 +22,12 @@ public class Hashtag extends BaseModel{
", url='"+url+'\''+
", following="+following+
", history="+history+
", statusesCount="+statusesCount+
'}';
}
@Override
public String getID(){
return name;
}
}

View File

@@ -131,7 +131,7 @@ public class Instance extends BaseModel{
ci.domain=uri;
ci.normalizedDomain=IDN.toUnicode(uri);
ci.description=Html.fromHtml(shortDescription).toString().trim();
if(languages!=null && languages.size() > 0){
if(languages!=null&&languages.size()>0){
ci.language=languages.get(0);
ci.languages=languages;
}else{

View File

@@ -0,0 +1,89 @@
package org.joinmastodon.android.model;
import android.text.TextUtils;
import com.google.gson.annotations.SerializedName;
import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
import java.time.Instant;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.regex.Pattern;
@Parcel
public class LegacyFilter extends BaseModel{
public String id;
public String phrase;
public String title;
public transient EnumSet<FilterContext> context=EnumSet.noneOf(FilterContext.class);
public Instant expiresAt;
public boolean irreversible;
public boolean wholeWord;
@SerializedName("context")
protected List<FilterContext> _context;
public FilterAction filterAction;
public List<FilterKeyword> keywords=new ArrayList<>();
public List<FilterStatus> statuses=new ArrayList<>();
private transient Pattern pattern;
@Override
public void postprocess() throws ObjectValidationException{
super.postprocess();
if(_context==null)
throw new ObjectValidationException();
for(FilterContext c:_context){
if(c!=null)
context.add(c);
}
for(FilterKeyword keyword:keywords)
keyword.postprocess();
for(FilterStatus status:statuses)
status.postprocess();
}
public boolean matches(CharSequence text){
if(TextUtils.isEmpty(text))
return false;
if(pattern==null){
if(wholeWord)
pattern=Pattern.compile("\\b"+Pattern.quote(phrase)+"\\b", Pattern.CASE_INSENSITIVE);
else
pattern=Pattern.compile(Pattern.quote(phrase), Pattern.CASE_INSENSITIVE);
}
if (title == null) title = phrase;
return pattern.matcher(text).find();
}
public boolean matches(Status status){
return matches(status.getContentStatus().getStrippedText());
}
public boolean isActive(){
return expiresAt==null || expiresAt.isAfter(Instant.now());
}
@Override
public String toString(){
return "Filter{"+
"id='"+id+'\''+
", title='"+title+'\''+
", phrase='"+phrase+'\''+
", context="+context+
", expiresAt="+expiresAt+
", irreversible="+irreversible+
", wholeWord="+wholeWord+
", filterAction="+filterAction+
", keywords="+keywords+
", statuses="+statuses+
'}';
}
}

View File

@@ -1,33 +0,0 @@
package org.joinmastodon.android.model;
import android.text.SpannableStringBuilder;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
import java.util.Collections;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class ParsedAccount{
public Account account;
public CharSequence parsedName, parsedBio;
public CustomEmojiHelper emojiHelper;
public ImageLoaderRequest avatarRequest;
public ParsedAccount(Account account, String accountID){
this.account=account;
parsedName=HtmlParser.parseCustomEmoji(account.displayName, account.emojis);
parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
emojiHelper=new CustomEmojiHelper();
SpannableStringBuilder ssb=new SpannableStringBuilder(parsedName);
ssb.append(parsedBio);
emojiHelper.setText(ssb);
avatarRequest=new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? account.avatar : account.avatarStatic, V.dp(40), V.dp(40));
}
}

View File

@@ -13,7 +13,7 @@ public class Poll extends BaseModel{
@RequiredField
public String id;
public Instant expiresAt;
protected boolean expired;
public boolean expired;
public boolean multiple;
public int votersCount;
public int votesCount;

View File

@@ -1,9 +1,12 @@
package org.joinmastodon.android.model;
import android.content.Context;
import com.google.gson.annotations.SerializedName;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.RequiredField;
import org.joinmastodon.android.ui.utils.UiUtils;
import androidx.annotation.StringRes;
@@ -20,6 +23,40 @@ public class PushNotification extends BaseModel{
@RequiredField
public String body;
public static PushNotification fromNotification(Context context, Notification notification){
PushNotification pushNotification = new PushNotification();
pushNotification.notificationType = switch(notification.type) {
case FOLLOW -> PushNotification.Type.FOLLOW;
case MENTION -> PushNotification.Type.MENTION;
case REBLOG -> PushNotification.Type.REBLOG;
case FAVORITE -> PushNotification.Type.FAVORITE;
case POLL -> PushNotification.Type.POLL;
case STATUS -> PushNotification.Type.STATUS;
case UPDATE -> PushNotification.Type.UPDATE;
case SIGN_UP -> PushNotification.Type.SIGN_UP;
case REPORT -> PushNotification.Type.REPORT;
//Follow request, and reactions are not supported by the API
default -> throw new IllegalStateException("Unexpected value: "+notification.type);
};
String notificationTitle = context.getString(switch(notification.type){
case FOLLOW -> R.string.user_followed_you;
case MENTION -> R.string.sk_notification_mention;
case REBLOG -> R.string.notification_boosted;
case FAVORITE -> R.string.user_favorited;
case POLL -> R.string.poll_ended;
case UPDATE -> R.string.sk_post_edited;
case SIGN_UP -> R.string.sk_signed_up;
case REPORT -> R.string.sk_reported;
default -> throw new IllegalStateException("Unexpected value: "+notification.type);
});
pushNotification.title = UiUtils.generateFormattedString(notificationTitle, notification.account.displayName).toString();
pushNotification.icon = notification.status.account.avatarStatic;
pushNotification.body = notification.status.getStrippedText();
return pushNotification;
}
@Override
public String toString(){
return "PushNotification{"+

View File

@@ -1,7 +1,9 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
@Parcel
public class Relationship extends BaseModel{
@RequiredField
public String id;

View File

@@ -2,6 +2,7 @@ package org.joinmastodon.android.model;
import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.joinmastodon.android.model.viewmodel.AccountViewModel;
public class SearchResult extends BaseModel implements DisplayItemsParent{
public Account account;
@@ -11,6 +12,7 @@ public class SearchResult extends BaseModel implements DisplayItemsParent{
public Type type;
public transient String id;
public transient boolean firstInSection;
public SearchResult(){}

View File

@@ -5,6 +5,10 @@ import static org.joinmastodon.android.api.MastodonAPIController.gsonWithoutDese
import androidx.annotation.Nullable;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@@ -21,6 +25,7 @@ import org.parceler.Parcel;
import java.lang.reflect.Type;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
@@ -54,8 +59,6 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
public long favouritesCount;
public long repliesCount;
public Instant editedAt;
// might not be provided (by older mastodon servers),
// so megalodon will use the locally cached filters if filtered == null
public List<FilterResult> filtered;
public String url;
@@ -78,19 +81,22 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
public Status quote; // can be boolean in calckey
public List<EmojiReaction> reactions;
protected List<EmojiReaction> emojiReactions; // akkoma
public transient boolean filterRevealed;
public transient boolean spoilerRevealed;
public transient boolean sensitiveRevealed;
public transient boolean textExpanded, textExpandable;
public transient boolean hasGapAfter;
public transient TranslatedStatus translation;
public transient boolean translationShown;
private transient String strippedText;
public Status(){}
@Override
public void postprocess() throws ObjectValidationException{
if(spoilerText!=null && !spoilerText.isEmpty() && !sensitive)
sensitive=true;
super.postprocess();
if(application!=null)
application.postprocess();
@@ -111,11 +117,15 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
if(reblog!=null)
reblog.postprocess();
if(filtered!=null)
for(FilterResult fr : filtered)
for(FilterResult fr:filtered)
fr.postprocess();
spoilerRevealed=GlobalUserPreferences.alwaysExpandContentWarnings || !sensitive;
if (visibility.equals(StatusPrivacy.LOCAL)) localOnly = true;
if(!TextUtils.isEmpty(spoilerText)) sensitive=true;
spoilerRevealed=TextUtils.isEmpty(spoilerText);
sensitiveRevealed=!sensitive;
if(visibility.equals(StatusPrivacy.LOCAL)) localOnly=true;
if(emojiReactions!=null) reactions=emojiReactions;
if(reactions==null) reactions=new ArrayList<>();
}
@Override
@@ -137,6 +147,7 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
", reblogsCount="+reblogsCount+
", favouritesCount="+favouritesCount+
", repliesCount="+repliesCount+
", editedAt="+editedAt+
", url='"+url+'\''+
", inReplyToId='"+inReplyToId+'\''+
", inReplyToAccountId='"+inReplyToAccountId+'\''+
@@ -145,11 +156,15 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
", card="+card+
", language='"+language+'\''+
", text='"+text+'\''+
", filtered="+filtered+
", favourited="+favourited+
", reblogged="+reblogged+
", muted="+muted+
", bookmarked="+bookmarked+
", pinned="+pinned+
", spoilerRevealed="+spoilerRevealed+
", hasGapAfter="+hasGapAfter+
", strippedText='"+strippedText+'\''+
'}';
}
@@ -166,6 +181,8 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
reblogged=ev.reblogged;
bookmarked=ev.bookmarked;
pinned=ev.pinned;
reactions.clear();
reactions.addAll(ev.reactions);
}
public Status getContentStatus(){
@@ -178,6 +195,12 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
return strippedText;
}
@NonNull
@Override
public Status clone(){
return (Status) super.clone();
}
public boolean isReblogPermitted(String accountID){
return visibility.isReblogPermitted(account.id.equals(
AccountSessionManager.getInstance().getAccount(accountID).self.id
@@ -195,6 +218,7 @@ public class Status extends BaseModel implements DisplayItemsParent, Searchable{
s.mentions = List.of();
s.tags = List.of();
s.emojis = List.of();
s.filtered = List.of();
return s;
}

View File

@@ -354,20 +354,20 @@ public class TimelineDefinition {
}
};
public static List<TimelineDefinition> getDefaultTimelines(String accountId) {
public static ArrayList<TimelineDefinition> getDefaultTimelines(String accountId) {
AccountSession session = AccountSessionManager.getInstance().getAccount(accountId);
return DEFAULT_TIMELINES.stream()
.filter(tl -> tl.isCompatible(session) && tl.wantsDefault(session))
.map(TimelineDefinition::copy)
.collect(Collectors.toList());
.collect(Collectors.toCollection(ArrayList::new));
}
public static List<TimelineDefinition> getAllTimelines(String accountId) {
public static ArrayList<TimelineDefinition> getAllTimelines(String accountId) {
AccountSession session = AccountSessionManager.getInstance().getAccount(accountId);
return ALL_TIMELINES.stream()
.filter(tl -> tl.isCompatible(session))
.map(TimelineDefinition::copy)
.collect(Collectors.toList());
.collect(Collectors.toCollection(ArrayList::new));
}
private static final List<TimelineDefinition> DEFAULT_TIMELINES = List.of(

View File

@@ -0,0 +1,13 @@
package org.joinmastodon.android.model;
public class TimelineMarkers{
public Marker home, notifications;
@Override
public String toString(){
return "TimelineMarkers{"+
"home="+home+
", notifications="+notifications+
'}';
}
}

View File

@@ -0,0 +1,10 @@
package org.joinmastodon.android.model.catalog;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.joinmastodon.android.model.BaseModel;
@AllFieldsAreRequired
public class CatalogDefaultInstance extends BaseModel{
public String domain;
public float weight;
}

View File

@@ -0,0 +1,46 @@
package org.joinmastodon.android.model.viewmodel;
import android.text.SpannableStringBuilder;
import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.AccountField;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.CustomEmojiHelper;
import java.util.Collections;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class AccountViewModel{
public final Account account;
public final ImageLoaderRequest avaRequest;
public final CustomEmojiHelper emojiHelper;
public final CharSequence parsedName, parsedBio;
public final String verifiedLink;
public AccountViewModel(Account account, String accountID){
this.account=account;
avaRequest=new UrlImageLoaderRequest(GlobalUserPreferences.playGifs ? account.avatar : account.avatarStatic, V.dp(50), V.dp(50));
emojiHelper=new CustomEmojiHelper();
if(AccountSessionManager.get(accountID).getLocalPreferences().customEmojiInNames)
parsedName=HtmlParser.parseCustomEmoji(account.displayName, account.emojis);
else
parsedName=account.displayName;
parsedBio=HtmlParser.parse(account.note, account.emojis, Collections.emptyList(), Collections.emptyList(), accountID);
SpannableStringBuilder ssb=new SpannableStringBuilder(parsedName);
ssb.append(parsedBio);
emojiHelper.setText(ssb);
String verifiedLink=null;
for(AccountField fld:account.fields){
if(fld.verifiedAt!=null){
verifiedLink=HtmlParser.stripAndRemoveInvisibleSpans(fld.value);
break;
}
}
this.verifiedLink=verifiedLink;
}
}

View File

@@ -0,0 +1,19 @@
package org.joinmastodon.android.model.viewmodel;
import android.text.TextUtils;
import org.joinmastodon.android.model.Card;
import me.grishka.appkit.imageloader.requests.ImageLoaderRequest;
import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest;
import me.grishka.appkit.utils.V;
public class CardViewModel{
public final Card card;
public final ImageLoaderRequest imageRequest;
public CardViewModel(Card card, int width, int height){
this.card=card;
this.imageRequest=TextUtils.isEmpty(card.image) ? null : new UrlImageLoaderRequest(card.image, V.dp(width), V.dp(height));
}
}

View File

@@ -0,0 +1,74 @@
package org.joinmastodon.android.model.viewmodel;
import org.joinmastodon.android.R;
import java.util.function.Consumer;
public class CheckableListItem<T> extends ListItem<T>{
public Style style;
public boolean checked;
public Consumer<Boolean> checkedChangeListener;
public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick, T parentObject, boolean dividerAfter){
super(title, subtitle, iconRes, onClick, parentObject, 0, dividerAfter);
this.style=style;
this.checked=checked;
}
public CheckableListItem(String title, String subtitle, Style style, boolean checked, Runnable onClick){
this(title, subtitle, style, checked, 0, onClick, null, false);
}
public CheckableListItem(String title, String subtitle, Style style, boolean checked, Runnable onClick, T parentObject){
this(title, subtitle, style, checked, 0, onClick, parentObject, false);
}
public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick){
this(title, subtitle, style, checked, iconRes, onClick, null, false);
}
public CheckableListItem(String title, String subtitle, Style style, boolean checked, int iconRes, Runnable onClick, T parentObject){
this(title, subtitle, style, checked, iconRes, onClick, parentObject, false);
}
public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Runnable onClick){
this(titleRes, subtitleRes, style, checked, 0, onClick, false);
}
public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, Runnable onClick, boolean dividerAfter){
this(titleRes, subtitleRes, style, checked, 0, onClick, dividerAfter);
}
public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Runnable onClick){
this(titleRes, subtitleRes, style, checked, iconRes, onClick, false);
}
public CheckableListItem(int titleRes, int subtitleRes, Style style, boolean checked, int iconRes, Runnable onClick, boolean dividerAfter){
super(titleRes, subtitleRes, iconRes, onClick, 0, dividerAfter);
this.style=style;
this.checked=checked;
}
@Override
public int getItemViewType(){
return switch(style){
case CHECKBOX -> R.id.list_item_checkbox;
case RADIO -> R.id.list_item_radio;
case SWITCH -> R.id.list_item_switch;
};
}
public void setChecked(boolean checked){
this.checked=checked;
}
public void toggle(){
checked=!checked;
}
public enum Style{
CHECKBOX,
RADIO,
SWITCH
}
}

View File

@@ -0,0 +1,82 @@
package org.joinmastodon.android.model.viewmodel;
import org.joinmastodon.android.R;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
public class ListItem<T>{
public String title;
public String subtitle;
@StringRes
public int titleRes;
@StringRes
public int subtitleRes;
@DrawableRes
public int iconRes;
public int colorOverrideAttr;
public boolean dividerAfter;
public Runnable onClick;
public boolean isEnabled=true;
public T parentObject;
public ListItem(String title, String subtitle, int iconRes, Runnable onClick, T parentObject, int colorOverrideAttr, boolean dividerAfter){
this.title=title;
this.subtitle=subtitle;
this.iconRes=iconRes;
this.colorOverrideAttr=colorOverrideAttr;
this.dividerAfter=dividerAfter;
this.onClick=onClick;
this.parentObject=parentObject;
if(onClick==null)
isEnabled=false;
}
public ListItem(String title, String subtitle, Runnable onClick){
this(title, subtitle, 0, onClick, null, 0, false);
}
public ListItem(String title, String subtitle, Runnable onClick, T parentObject){
this(title, subtitle, 0, onClick, parentObject, 0, false);
}
public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick){
this(title, subtitle, iconRes, onClick, null, 0, false);
}
public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick, boolean dividerAfter){
this(title, subtitle, iconRes, onClick, null, 0, dividerAfter);
}
public ListItem(String title, String subtitle, @DrawableRes int iconRes, Runnable onClick, T parentObject){
this(title, subtitle, iconRes, onClick, parentObject, 0, false);
}
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Runnable onClick){
this(null, null, 0, onClick, null, 0, false);
this.titleRes=titleRes;
this.subtitleRes=subtitleRes;
}
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, Runnable onClick, int colorOverrideAttr, boolean dividerAfter){
this(null, null, 0, onClick, null, colorOverrideAttr, dividerAfter);
this.titleRes=titleRes;
this.subtitleRes=subtitleRes;
}
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Runnable onClick){
this(null, null, iconRes, onClick, null, 0, false);
this.titleRes=titleRes;
this.subtitleRes=subtitleRes;
}
public ListItem(@StringRes int titleRes, @StringRes int subtitleRes, @DrawableRes int iconRes, Runnable onClick, int colorOverrideAttr, boolean dividerAfter){
this(null, null, iconRes, onClick, null, colorOverrideAttr, dividerAfter);
this.titleRes=titleRes;
this.subtitleRes=subtitleRes;
}
public int getItemViewType(){
return colorOverrideAttr==0 ? R.id.list_item_simple : R.id.list_item_simple_tinted;
}
}

View File

@@ -0,0 +1,24 @@
package org.joinmastodon.android.model.viewmodel;
import android.content.Context;
import org.joinmastodon.android.R;
import org.joinmastodon.android.model.Hashtag;
import org.joinmastodon.android.model.SearchResult;
public class SearchResultViewModel{
public SearchResult result;
public AccountViewModel account;
public ListItem<Hashtag> hashtagItem;
public SearchResultViewModel(SearchResult result, String accountID, boolean isRecents){
this.result=result;
switch(result.type){
case ACCOUNT -> account=new AccountViewModel(result.account, accountID);
case HASHTAG -> {
hashtagItem=new ListItem<>((isRecents ? "#" : "")+result.hashtag.name, null, isRecents ? R.drawable.ic_fluent_history_24_regular : R.drawable.ic_fluent_number_symbol_24_regular, null, result.hashtag);
hashtagItem.isEnabled=true;
}
}
}
}