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..e9c9fe764 --- /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/ProfileAboutFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java index 15b11215c..ba2cb9d95 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileAboutFragment.java @@ -1,5 +1,6 @@ package org.joinmastodon.android.fragments; +import android.app.Activity; import android.app.Fragment; import android.graphics.Canvas; import android.graphics.Paint; @@ -12,11 +13,23 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.WindowInsets; +import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.TextView; +import android.widget.Toast; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; import org.joinmastodon.android.R; +import org.joinmastodon.android.api.requests.accounts.SetPrivateNote; import org.joinmastodon.android.model.AccountField; +import org.joinmastodon.android.model.Relationship; import org.joinmastodon.android.ui.BetterItemAnimator; import org.joinmastodon.android.ui.text.CustomEmojiSpan; import org.joinmastodon.android.ui.utils.SimpleTextWatcher; @@ -26,11 +39,8 @@ import org.joinmastodon.android.ui.views.LinkedTextView; import java.util.Collections; import java.util.List; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.recyclerview.widget.ItemTouchHelper; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; +import me.grishka.appkit.api.Callback; +import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.fragments.WindowInsetsAwareFragment; import me.grishka.appkit.imageloader.ImageLoaderRecyclerAdapter; import me.grishka.appkit.imageloader.ImageLoaderViewHolder; @@ -46,6 +56,11 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF private static final int MAX_FIELDS=4; public UsableRecyclerView list; + public FrameLayout noteWrap; + public EditText noteEdit; + private String accountID; + private String profileAccountID; + private String note; private List fields=Collections.emptyList(); private AboutAdapter adapter; private Paint dividerPaint=new Paint(); @@ -64,11 +79,49 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF adapter.notifyDataSetChanged(); } + public void setNote(String note, String accountID, String profileAccountID){ + this.note=note; + this.accountID=accountID; + this.profileAccountID=profileAccountID; + noteWrap.setVisibility(View.VISIBLE); + noteEdit.setVisibility(View.VISIBLE); + noteEdit.setText(note); + } + @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState){ - list=new UsableRecyclerView(getActivity()); - list.setId(R.id.list); + View view = inflater.inflate(R.layout.fragment_profile_about, null); + + noteEdit = view.findViewById(R.id.note_edit); + noteWrap = view.findViewById(R.id.note_edit_wrap); + ImageButton noteEditConfirm = view.findViewById(R.id.note_edit_confirm); + + + noteEdit.setOnFocusChangeListener((v, hasFocus) -> { + if (hasFocus) { + noteEditConfirm.setVisibility(View.VISIBLE); + noteEditConfirm.animate() + .alpha(1.0f) + .setDuration(700); + } else { + 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(); + })); + + list = view.findViewById(R.id.list); list.setItemAnimator(new BetterItemAnimator()); list.setDrawSelectorOnTop(true); list.setLayoutManager(new LinearLayoutManager(getActivity())); @@ -95,8 +148,20 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF } } }); - return list; + return view; } + private void savePrivateNote(){ + new SetPrivateNote(profileAccountID, noteEdit.getText().toString()).setCallback(new Callback<>() { + @Override + public void onSuccess(Relationship result) {} + + @Override + public void onError(ErrorResponse result) { + Toast.makeText(getActivity(), getString(R.string.sk_personal_note_update_failed), Toast.LENGTH_LONG).show(); + } + }).exec(accountID); + } + public void enterEditMode(List editableFields){ isInEditMode=true; 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 cddb620d3..2991f1803 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -449,6 +449,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList boolean isSelf=AccountSessionManager.getInstance().isSelf(accountID, account); + if(account.locked){ ssb=new SpannableStringBuilder("@"); ssb.append(account.acct); @@ -473,6 +474,8 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList bio.setVisibility(View.VISIBLE); bio.setText(parsedBio); } + + followersCount.setText(UiUtils.abbreviateNumber(account.followersCount)); followingCount.setText(UiUtils.abbreviateNumber(account.followingCount)); postsCount.setText(UiUtils.abbreviateNumber(account.statusesCount)); @@ -685,6 +688,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList notifyProgress.setIndeterminateTintList(notifyButton.getTextColors()); followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); notifyButton.setSelected(relationship.notifying); + if (!isOwnProfile) { + aboutFragment.setNote(relationship.note, accountID, profileAccountID); + } if (getActivity() != null) notifyButton.setContentDescription(getString(relationship.notifying ? R.string.sk_user_post_notifications_on : R.string.sk_user_post_notifications_off, '@'+account.username)); } diff --git a/mastodon/src/main/res/drawable/ic_fluent_notepad_20_regular.xml b/mastodon/src/main/res/drawable/ic_fluent_notepad_20_regular.xml new file mode 100644 index 000000000..67619d7cf --- /dev/null +++ b/mastodon/src/main/res/drawable/ic_fluent_notepad_20_regular.xml @@ -0,0 +1,9 @@ + + + diff --git a/mastodon/src/main/res/layout/fragment_profile_about.xml b/mastodon/src/main/res/layout/fragment_profile_about.xml new file mode 100644 index 000000000..2bfed9121 --- /dev/null +++ b/mastodon/src/main/res/layout/fragment_profile_about.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/values/strings_sk.xml b/mastodon/src/main/res/values/strings_sk.xml index 1d7b7c32f..80e31703a 100644 --- a/mastodon/src/main/res/values/strings_sk.xml +++ b/mastodon/src/main/res/values/strings_sk.xml @@ -68,6 +68,9 @@ \@moshidon Disable swiping between tabs Set up profile + Add a note about this profile + Confirm changes to note + Failed to save note Posting preferences Configure filters Security settings