This commit is contained in:
Grishka 2022-02-08 13:25:17 +03:00
parent 1f4611bc4e
commit d9cd15eb2d
22 changed files with 110 additions and 22 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@
.externalNativeBuild
.cxx
local.properties
*.jks

4
mastodon/.gitignore vendored
View File

@ -1 +1,3 @@
/build
/build
/release
/debug

View File

@ -4,13 +4,14 @@ import org.joinmastodon.android.model.Status;
public class StatusCountersUpdatedEvent{
public String id;
public int favorites, reblogs;
public int favorites, reblogs, replies;
public boolean favorited, reblogged;
public StatusCountersUpdatedEvent(Status s){
id=s.id;
favorites=s.favouritesCount;
reblogs=s.reblogsCount;
replies=s.repliesCount;
favorited=s.favourited;
reblogged=s.reblogged;
}

View File

@ -12,6 +12,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
@ -42,16 +43,19 @@ import org.joinmastodon.android.api.requests.statuses.CreateStatus;
import org.joinmastodon.android.api.requests.statuses.UploadAttachment;
import org.joinmastodon.android.api.session.AccountSession;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
import org.joinmastodon.android.events.StatusCreatedEvent;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.Emoji;
import org.joinmastodon.android.model.EmojiCategory;
import org.joinmastodon.android.model.Mention;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.CustomEmojiPopupKeyboard;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.PopupKeyboard;
import org.joinmastodon.android.ui.views.SizeListenerLinearLayout;
import org.parceler.Parcels;
import java.util.ArrayList;
import java.util.List;
@ -106,12 +110,15 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
private Button publishButton;
private ImageButton mediaBtn, pollBtn, emojiBtn, spoilerBtn, visibilityBtn;
private LinearLayout attachmentsView;
private TextView replyText;
private ArrayList<DraftMediaAttachment> queuedAttachments=new ArrayList<>(), failedAttachments=new ArrayList<>(), attachments=new ArrayList<>();
private DraftMediaAttachment uploadingAttachment;
private List<EmojiCategory> customEmojis;
private CustomEmojiPopupKeyboard emojiKeyboard;
private Status replyTo;
private String initialReplyMentions;
@Override
public void onAttach(Activity activity){
@ -127,6 +134,9 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
customEmojis=AccountSessionManager.getInstance().getCustomEmojis(instanceDomain);
emojiKeyboard=new CustomEmojiPopupKeyboard(activity, customEmojis, instanceDomain);
emojiKeyboard.setListener(this::onCustomEmojiClick);
if(getArguments().containsKey("replyTo"))
replyTo=Parcels.unwrap(getArguments().getParcelable("replyTo"));
}
@Override
@ -156,6 +166,7 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
emojiBtn=view.findViewById(R.id.btn_emoji);
spoilerBtn=view.findViewById(R.id.btn_spoiler);
visibilityBtn=view.findViewById(R.id.btn_visibility);
replyText=view.findViewById(R.id.reply_text);
mediaBtn.setOnClickListener(v->openFilePicker());
emojiBtn.setOnClickListener(v->emojiKeyboard.toggleKeyboardPopup(mainEditText));
@ -207,6 +218,23 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
}
});
updateToolbar();
if(replyTo!=null){
replyText.setText(getString(R.string.in_reply_to, replyTo.account.displayName));
ArrayList<String> mentions=new ArrayList<>();
mentions.add('@'+replyTo.account.acct);
for(Mention mention : replyTo.mentions){
String m='@'+mention.acct;
if(!mentions.contains(m))
mentions.add(m);
}
initialReplyMentions=TextUtils.join(" ", mentions)+" ";
if(savedInstanceState==null){
mainEditText.setText(initialReplyMentions);
mainEditText.setSelection(mainEditText.length());
}
}else{
replyText.setVisibility(View.GONE);
}
}
@Override
@ -277,6 +305,9 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
if(!attachments.isEmpty()){
req.mediaIds=attachments.stream().map(a->a.serverAttachment.id).collect(Collectors.toList());
}
if(replyTo!=null){
req.inReplyToId=replyTo.id;
}
String uuid=UUID.randomUUID().toString();
ProgressDialog progress=new ProgressDialog(getActivity());
progress.setMessage(getString(R.string.publishing));
@ -289,6 +320,8 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
progress.dismiss();
Nav.finish(ComposeFragment.this);
E.post(new StatusCreatedEvent(result));
replyTo.repliesCount++;
E.post(new StatusCountersUpdatedEvent(replyTo));
}
@Override
@ -301,7 +334,8 @@ public class ComposeFragment extends ToolbarFragment implements OnBackPressedLis
}
private boolean hasDraft(){
return mainEditText.length()>0;
return (mainEditText.length()>0 && !mainEditText.getText().toString().equals(initialReplyMentions)) || !attachments.isEmpty()
|| uploadingAttachment!=null || !queuedAttachments.isEmpty() || !failedAttachments.isEmpty();
}
@Override

View File

@ -23,7 +23,7 @@ public class NotificationsFragment extends BaseStatusListFragment<Notification>{
@Override
protected List<StatusDisplayItem> buildDisplayItems(Notification n){
ReblogOrReplyLineStatusDisplayItem titleItem=new ReblogOrReplyLineStatusDisplayItem(n.id, switch(n.type){
ReblogOrReplyLineStatusDisplayItem titleItem=new ReblogOrReplyLineStatusDisplayItem(n.id, this, switch(n.type){
case FOLLOW -> getString(R.string.user_followed_you, n.account.displayName);
case FOLLOW_REQUEST -> getString(R.string.user_sent_follow_request, n.account.displayName);
case MENTION -> getString(R.string.user_mentioned_you, n.account.displayName);

View File

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

View File

@ -10,7 +10,9 @@ import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.joinmastodon.android.ui.utils.BlurHashDecoder;
import org.joinmastodon.android.ui.utils.BlurHashDrawable;
import org.parceler.Parcel;
@Parcel
public class Attachment extends BaseModel{
@RequiredField
public String id;
@ -88,6 +90,7 @@ public class Attachment extends BaseModel{
UNKNOWN
}
@Parcel
public static class Metadata{
public double duration;
public int width;
@ -111,6 +114,7 @@ public class Attachment extends BaseModel{
}
}
@Parcel
public static class SizeMetadata{
public int width;
public int height;

View File

@ -9,7 +9,9 @@ import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.joinmastodon.android.ui.utils.BlurHashDecoder;
import org.joinmastodon.android.ui.utils.BlurHashDrawable;
import org.parceler.Parcel;
@Parcel
public class Card extends BaseModel{
@RequiredField
public String url;

View File

@ -1,9 +1,11 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.RequiredField;
import org.parceler.Parcel;
import java.util.List;
@Parcel
public class Hashtag extends BaseModel{
@RequiredField
public String name;

View File

@ -1,8 +1,10 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.parceler.Parcel;
@AllFieldsAreRequired
@Parcel
public class History extends BaseModel{
public long day; // unixtime
public int uses;

View File

@ -1,8 +1,10 @@
package org.joinmastodon.android.model;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.parceler.Parcel;
@AllFieldsAreRequired
@Parcel
public class Mention extends BaseModel{
public String id;
public String username;

View File

@ -2,12 +2,14 @@ package org.joinmastodon.android.model;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.joinmastodon.android.api.ObjectValidationException;
import org.parceler.Parcel;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
@AllFieldsAreRequired
@Parcel
public class Poll extends BaseModel{
public String id;
public Instant expiresAt;
@ -41,6 +43,7 @@ public class Poll extends BaseModel{
'}';
}
@Parcel
public static class Option{
public String title;
public Integer votesCount;

View File

@ -3,10 +3,12 @@ package org.joinmastodon.android.model;
import org.joinmastodon.android.api.ObjectValidationException;
import org.joinmastodon.android.api.RequiredField;
import org.joinmastodon.android.events.StatusCountersUpdatedEvent;
import org.parceler.Parcel;
import java.time.Instant;
import java.util.List;
@Parcel
public class Status extends BaseModel implements DisplayItemsParent{
@RequiredField
public String id;
@ -116,6 +118,7 @@ public class Status extends BaseModel implements DisplayItemsParent{
public void update(StatusCountersUpdatedEvent ev){
favouritesCount=ev.favorites;
reblogsCount=ev.reblogs;
repliesCount=ev.replies;
favourited=ev.favorited;
reblogged=ev.reblogged;
}

View File

@ -2,8 +2,8 @@ package org.joinmastodon.android.ui.displayitems;
import android.app.Activity;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
@ -11,12 +11,16 @@ import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.fragments.ComposeFragment;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.model.StatusPrivacy;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.parceler.Parcels;
import java.text.DecimalFormat;
import me.grishka.appkit.Nav;
import me.grishka.appkit.utils.BindableViewHolder;
import me.grishka.appkit.utils.V;
@ -24,8 +28,8 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
public final Status status;
private final String accountID;
public FooterStatusDisplayItem(String parentID, Status status, String accountID){
super(parentID);
public FooterStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, Status status, String accountID){
super(parentID, parentFragment);
this.status=status;
this.accountID=accountID;
}
@ -78,7 +82,10 @@ public class FooterStatusDisplayItem extends StatusDisplayItem{
}
private void onReplyClick(View v){
Bundle args=new Bundle();
args.putString("account", item.accountID);
args.putParcelable("replyTo", Parcels.wrap(item.status));
Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args);
}
private void onBoostClick(View v){

View File

@ -13,6 +13,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.fragments.ProfileFragment;
import org.joinmastodon.android.model.Account;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -34,8 +35,8 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
private Fragment parentFragment;
private String accountID;
public HeaderStatusDisplayItem(String parentID, Account user, Instant createdAt, Fragment parentFragment, String accountID){
super(parentID);
public HeaderStatusDisplayItem(String parentID, Account user, Instant createdAt, BaseStatusListFragment parentFragment, String accountID){
super(parentID, parentFragment);
this.user=user;
this.createdAt=createdAt;
avaRequest=new UrlImageLoaderRequest(user.avatar);

View File

@ -8,6 +8,7 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.ui.photoviewer.PhotoViewerHost;
@ -23,8 +24,8 @@ public class PhotoStatusDisplayItem extends StatusDisplayItem{
private Fragment parentFragment;
private Status status;
public final int index, totalPhotos;
public PhotoStatusDisplayItem(String parentID, Status status, Attachment photo, Fragment parentFragment, int index, int totalPhotos){
super(parentID);
public PhotoStatusDisplayItem(String parentID, Status status, Attachment photo, BaseStatusListFragment parentFragment, int index, int totalPhotos){
super(parentID, parentFragment);
this.status=status;
this.attachment=photo;
request=new UrlImageLoaderRequest(photo.url, 1000, 1000);

View File

@ -6,6 +6,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.ui.utils.UiUtils;
import me.grishka.appkit.utils.BindableViewHolder;
@ -13,8 +14,8 @@ import me.grishka.appkit.utils.BindableViewHolder;
public class ReblogOrReplyLineStatusDisplayItem extends StatusDisplayItem{
private CharSequence text;
public ReblogOrReplyLineStatusDisplayItem(String parentID, CharSequence text){
super(parentID);
public ReblogOrReplyLineStatusDisplayItem(String parentID, BaseStatusListFragment parentFragment, CharSequence text){
super(parentID, parentFragment);
this.text=text;
}

View File

@ -6,6 +6,7 @@ import android.text.TextUtils;
import android.view.ViewGroup;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.model.Attachment;
import org.joinmastodon.android.model.DisplayItemsParent;
import org.joinmastodon.android.model.Status;
@ -18,9 +19,11 @@ import me.grishka.appkit.utils.BindableViewHolder;
public abstract class StatusDisplayItem{
public final String parentID;
public final BaseStatusListFragment parentFragment;
public StatusDisplayItem(String parentID){
public StatusDisplayItem(String parentID, BaseStatusListFragment parentFragment){
this.parentID=parentID;
this.parentFragment=parentFragment;
}
public abstract Type getType();
@ -44,12 +47,12 @@ public abstract class StatusDisplayItem{
};
}
public static ArrayList<StatusDisplayItem> buildItems(Fragment fragment, Status status, String accountID, DisplayItemsParent parentObject){
public static ArrayList<StatusDisplayItem> buildItems(BaseStatusListFragment fragment, Status status, String accountID, DisplayItemsParent parentObject){
String parentID=parentObject.getID();
ArrayList<StatusDisplayItem> items=new ArrayList<>();
Status statusForContent=status.getContentStatus();
if(status.reblog!=null){
items.add(new ReblogOrReplyLineStatusDisplayItem(parentID, fragment.getString(R.string.user_boosted, status.account.displayName)));
items.add(new ReblogOrReplyLineStatusDisplayItem(parentID, fragment, fragment.getString(R.string.user_boosted, status.account.displayName)));
}
items.add(new HeaderStatusDisplayItem(parentID, statusForContent.account, statusForContent.createdAt, fragment, accountID));
if(!TextUtils.isEmpty(statusForContent.content))
@ -67,7 +70,7 @@ public abstract class StatusDisplayItem{
photoIndex++;
}
}
items.add(new FooterStatusDisplayItem(parentID, statusForContent, accountID));
items.add(new FooterStatusDisplayItem(parentID, fragment, statusForContent, accountID));
return items;
}

View File

@ -9,7 +9,7 @@ import android.view.ViewGroup;
import android.widget.Toast;
import org.joinmastodon.android.R;
import org.joinmastodon.android.model.Status;
import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.ui.text.CustomEmojiSpan;
import org.joinmastodon.android.ui.text.LinkSpan;
import org.joinmastodon.android.ui.utils.UiUtils;
@ -26,8 +26,8 @@ public class TextStatusDisplayItem extends StatusDisplayItem implements LinkSpan
private CharSequence text;
private ImageLoaderRequest[] emojiRequests;
private Fragment parentFragment;
public TextStatusDisplayItem(String parentID, CharSequence text, Fragment parentFragment){
super(parentID);
public TextStatusDisplayItem(String parentID, CharSequence text, BaseStatusListFragment parentFragment){
super(parentID, parentFragment);
this.text=text;
this.parentFragment=parentFragment;
if(text instanceof Spanned){

View File

@ -0,0 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="20dp" android:height="20dp" android:viewportWidth="20" android:viewportHeight="20">
<path android:pathData="M4.31 9.5l2.963 2.963c0.293 0.293 0.293 0.768 0 1.06-0.266 0.267-0.683 0.29-0.977 0.073l-0.084-0.073L1.97 9.281C1.703 9.014 1.68 8.598 1.897 8.304L1.97 8.22l4.242-4.243c0.293-0.292 0.768-0.292 1.061 0 0.266 0.267 0.29 0.683 0.073 0.977L7.273 5.038 4.31 8H10c4.198 0 7.616 3.338 7.746 7.504l0.004 0.247c0 0.414-0.336 0.75-0.75 0.75s-0.75-0.336-0.75-0.75c0-3.376-2.675-6.126-6.02-6.246L10 9.5H4.31l2.963 2.963L4.31 9.5z" android:fillColor="@color/fluent_default_icon_tint"/>
</vector>

View File

@ -16,6 +16,20 @@
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/reply_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
android:textAppearance="@style/m3_title_small"
android:drawableStart="@drawable/ic_fluent_arrow_reply_20_filled"
android:drawableTint="@color/gray_500"
android:drawablePadding="6dp"
android:singleLine="true"
android:ellipsize="end"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View File

@ -11,7 +11,7 @@
<string name="preparing_auth">Preparing for authentication…</string>
<string name="finishing_auth">Finishing authentication…</string>
<string name="user_boosted">%s boosted</string>
<string name="replied_to">Replied to %s</string>
<string name="in_reply_to">In reply to %s</string>
<string name="notifications">Notifications</string>
<string name="user_followed_you">%s followed you</string>