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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<APIRequest<?>> 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(){
|
||||
|
||||
@@ -142,6 +142,33 @@
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
<!-- MOSHIDON: profile notes-->
|
||||
<org.joinmastodon.android.ui.views.FloatingHintEditTextLayout
|
||||
android:id="@+id/note_edit_wrap"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:layout_marginHorizontal="16dp"
|
||||
app:labelTextColor="@color/m3_outlined_text_field_label"
|
||||
android:foreground="@drawable/bg_m3_outlined_text_field"
|
||||
android:visibility="gone">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/note_edit"
|
||||
android:layout_width="match_parent"
|
||||
android:minHeight="52dp"
|
||||
android:maxHeight="200dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="8dp"
|
||||
android:padding="16dp"
|
||||
android:background="@null"
|
||||
android:inputType="text|textMultiLine|textCapSentences"
|
||||
android:hint="@string/mo_personal_note"
|
||||
tools:ignore="RtlSymmetry" />
|
||||
</org.joinmastodon.android.ui.views.FloatingHintEditTextLayout>
|
||||
|
||||
|
||||
<org.joinmastodon.android.ui.views.LinkedTextView
|
||||
android:id="@+id/bio"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user