Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
feat(profile): add note
Browse files Browse the repository at this point in the history
  • Loading branch information
FineFindus committed Nov 2, 2023
1 parent c8122aa commit 05483db
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Relationship>{
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -1218,6 +1301,9 @@ private void updateRelationship(Relationship r){

@Override
public boolean onBackPressed(){
if(noteEdit.hasFocus())
savePrivateNote();

if(isInEditMode){
if(savingEdits)
return true;
Expand Down
7 changes: 7 additions & 0 deletions mastodon/src/main/res/drawable/bg_note_edit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:tint="@color/m3_primary_alpha11"
android:tintMode="src_over">
<solid android:color="?colorM3Surface" />
<corners android:radius="28dp" />
</shape>
42 changes: 42 additions & 0 deletions mastodon/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,48 @@

</LinearLayout>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/username"
android:id="@+id/note_edit_wrap"
android:layout_marginTop="4dp"
android:layout_marginBottom="16dp"
android:layout_marginHorizontal="16dp"
android:visibility="gone">

<EditText
android:id="@+id/note_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="16dp"
android:inputType="textMultiLine|textCapSentences"
android:singleLine="false"
android:drawablePadding="12dp"
android:drawableTint="?android:textColorSecondary"
android:background="@drawable/bg_note_edit"
android:paddingEnd="48dp"
android:paddingHorizontal="16dp"
android:elevation="0dp"
android:visibility="gone"
android:hint="@string/sk_personal_note"/>

<ImageButton
android:id="@+id/note_edit_confirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:paddingHorizontal="6dp"
android:layout_marginBottom="7dp"
android:visibility="invisible"
android:layout_gravity="right|bottom"
android:background="@drawable/bg_button_m3_text_circle"
android:tooltipText="@string/sk_personal_note_confirm"
android:contentDescription="@string/sk_personal_note_confirm"
android:src="@drawable/ic_fluent_checkmark_24_regular"
/>
</FrameLayout>

<org.joinmastodon.android.ui.views.LinkedTextView
android:id="@+id/bio"
android:layout_width="match_parent"
Expand Down
3 changes: 3 additions & 0 deletions mastodon/src/main/res/values/strings_sk.xml
Original file line number Diff line number Diff line change
Expand Up @@ -417,4 +417,7 @@
<string name="sk_settings_lock_account">Manually approve new followers</string>
<string name="sk_settings_default_visibility">Default posting visibility</string>
<string name="sk_button_mutuals">Mutuals</string>
<string name="sk_personal_note">Add a note about this profile</string>
<string name="sk_personal_note_confirm">Confirm changes to note</string>
<string name="sk_personal_note_update_failed">Failed to save note</string>
</resources>

0 comments on commit 05483db

Please sign in to comment.