From 8fc4ba093ab5967288cbf2d34489ef37857c962e Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Mon, 25 Nov 2024 14:34:56 -0300 Subject: [PATCH] feat: add private notes This is still missing the icon on the top bar, which we will add when we come back to adding the profile menus --- .../api/requests/accounts/SetPrivateNote.java | 19 +++++++ .../android/fragments/ProfileFragment.java | 53 +++++++++++++++++++ .../src/main/res/layout/fragment_profile.xml | 27 ++++++++++ 3 files changed, 99 insertions(+) create mode 100644 mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetPrivateNote.java diff --git a/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetPrivateNote.java b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetPrivateNote.java new file mode 100644 index 000000000..a1b59a4c7 --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/api/requests/accounts/SetPrivateNote.java @@ -0,0 +1,19 @@ +package org.joinmastodon.android.api.requests.accounts; + +import org.joinmastodon.android.api.MastodonAPIRequest; +import org.joinmastodon.android.model.Relationship; + +public class SetPrivateNote extends MastodonAPIRequest{ + public SetPrivateNote(String id, String comment){ + super(MastodonAPIRequest.HttpMethod.POST, "/accounts/"+id+"/note", Relationship.class); + Request req = new Request(comment); + setRequestBody(req); + } + + private static class Request{ + public String comment; + public Request(String comment){ + this.comment=comment; + } + } +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 3229eae98..18c86b2a0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -20,6 +20,7 @@ import android.graphics.drawable.LayerDrawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.text.InputType; import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.TextUtils; @@ -56,6 +57,7 @@ import org.joinmastodon.android.api.requests.accounts.GetAccountFamiliarFollower import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.accounts.GetOwnAccount; import org.joinmastodon.android.api.requests.accounts.SetAccountFollowed; +import org.joinmastodon.android.api.requests.accounts.SetPrivateNote; import org.joinmastodon.android.api.requests.accounts.UpdateAccountCredentials; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.account_list.FamiliarFollowerListFragment; @@ -177,6 +179,10 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, private Runnable editModeBackCallback=this::onEditModeBackCallback; private HashSet> relationshipRequests=new HashSet<>(); + // MOSHIDON: profile note + private FrameLayout noteWrap; + private EditText noteEdit; + @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -259,6 +265,19 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, avatar.setOutlineProvider(OutlineProviders.roundedRect(24)); avatar.setClipToOutline(true); + noteEdit=content.findViewById(R.id.note_edit); + noteWrap=content.findViewById(R.id.note_edit_wrap); + + noteEdit.setOnFocusChangeListener((v, hasFocus)->{ + if(hasFocus){ +// hideFab(); + noteEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); + }else{ +// showFab(); + savePrivateNote(noteEdit.getText().toString()); + } + }); + FrameLayout sizeWrapper=new FrameLayout(getActivity()){ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ @@ -431,6 +450,36 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, doLoadData(); } + private void showPrivateNote(){ + noteWrap.setVisibility(View.VISIBLE); + noteEdit.setText(relationship.note); + } + + private void hidePrivateNote(){ + noteWrap.setVisibility(View.GONE); + noteEdit.setText(null); + } + + private void savePrivateNote(String note){ + if(note!=null && note.equals(relationship.note)){ + updateRelationship(); + invalidateOptionsMenu(); + return; + } + new SetPrivateNote(profileAccountID, note).setCallback(new Callback<>() { + @Override + public void onSuccess(Relationship result) { + updateRelationship(result); + invalidateOptionsMenu(); + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + } + }).exec(accountID); + } + @Override public void dataLoaded(){ if(getActivity()==null) @@ -864,6 +913,10 @@ public class ProfileFragment extends LoaderFragment implements ScrollableToTop, UiUtils.setRelationshipToActionButtonM3(relationship, actionButton); actionProgress.setIndeterminateTintList(actionButton.getTextColors()); followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); + + // MOSHIDON: private note stuff! + showPrivateNote(); + UiUtils.beginLayoutTransition(scrollableContent); } private void updateFamiliarFollowers(){ diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 1c31c5f68..7e247ad07 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -142,6 +142,33 @@ android:layout_marginTop="16dp" android:visibility="gone"/> + + + + + + +