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 0000000000..a1b59a4c7e --- /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 fd30387ba1..b532cd0603 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -38,6 +38,7 @@ import android.view.ViewOutlineProvider; import android.view.ViewTreeObserver; import android.view.WindowInsets; +import android.view.animation.TranslateAnimation; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.FrameLayout; @@ -56,6 +57,7 @@ import org.joinmastodon.android.api.requests.accounts.GetAccountStatuses; 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.requests.instance.GetInstance; import org.joinmastodon.android.api.session.AccountSessionManager; @@ -186,6 +188,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private ItemTouchHelper dragHelper=new ItemTouchHelper(new ReorderCallback()); private ListImageLoaderWrapper imgLoader; + // profile note + public FrameLayout noteWrap; + public EditText noteEdit; + private String note; + @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -271,6 +278,61 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu avatar.setOutlineProvider(OutlineProviders.roundedRect(24)); avatar.setClipToOutline(true); + noteEdit = content.findViewById(R.id.note_edit); + noteWrap = content.findViewById(R.id.note_edit_wrap); + ImageButton noteEditConfirm = content.findViewById(R.id.note_edit_confirm); + + noteEditConfirm.setOnClickListener((v -> { + if (!noteEdit.getText().toString().trim().equals(note)) { + savePrivateNote(); + } + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(this.getView().getRootView().getWindowToken(), 0); + noteEdit.clearFocus(); + })); + + + noteEdit.setOnFocusChangeListener((v, hasFocus) -> { + if (hasFocus) { + fab.setVisibility(View.INVISIBLE); + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + 0, + fab.getHeight() * 2); + animate.setDuration(300); + fab.startAnimation(animate); + + noteEditConfirm.setVisibility(View.VISIBLE); + noteEditConfirm.animate() + .alpha(1.0f) + .setDuration(700); + } else { + fab.setVisibility(View.VISIBLE); + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + fab.getHeight() * 2, + 0); + animate.setDuration(300); + fab.startAnimation(animate); + + noteEditConfirm.animate() + .alpha(0.0f) + .setDuration(700); + noteEditConfirm.setVisibility(View.INVISIBLE); + } + }); + + noteEditConfirm.setOnClickListener((v -> { + if (!noteEdit.getText().toString().trim().equals(note)) { + savePrivateNote(); + } + InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); + imm.hideSoftInputFromWindow(this.getView().getRootView().getWindowToken(), 0); + noteEdit.clearFocus(); + })); + FrameLayout sizeWrapper=new FrameLayout(getActivity()){ @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){ @@ -435,6 +497,25 @@ public void onError(ErrorResponse error){ return sizeWrapper; } + public void setNote(String note){ + this.note=note; + noteWrap.setVisibility(View.VISIBLE); + noteEdit.setVisibility(View.VISIBLE); + noteEdit.setText(note); + } + + private void savePrivateNote(){ + new SetPrivateNote(profileAccountID, noteEdit.getText().toString()).setCallback(new Callback<>() { + @Override + public void onSuccess(Relationship result) {} + + @Override + public void onError(ErrorResponse error) { + error.showToast(getActivity()); + } + }).exec(accountID); + } + private void onAccountLoaded(Account result) { account=result; isOwnProfile=AccountSessionManager.getInstance().isSelf(accountID, account); @@ -908,6 +989,8 @@ private void updateRelationship(){ followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); notifyButton.setSelected(relationship.notifying); notifyButton.setContentDescription(getString(relationship.notifying ? R.string.sk_user_post_notifications_on : R.string.sk_user_post_notifications_off, '@'+account.username)); + if (!isOwnProfile) + setNote(relationship.note); } public ImageButton getFab() { @@ -1218,6 +1301,9 @@ private void updateRelationship(Relationship r){ @Override public boolean onBackPressed(){ + if(noteEdit.hasFocus()) + savePrivateNote(); + if(isInEditMode){ if(savingEdits) return true; diff --git a/mastodon/src/main/res/drawable/bg_note_edit.xml b/mastodon/src/main/res/drawable/bg_note_edit.xml new file mode 100644 index 0000000000..536ee0367a --- /dev/null +++ b/mastodon/src/main/res/drawable/bg_note_edit.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index e79bdc0f2a..5f6a6f4910 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -213,6 +213,48 @@ + + + + + + + Manually approve new followers Default posting visibility Mutuals + Add a note about this profile + Confirm changes to note + Failed to save note \ No newline at end of file