From 8594e34bb581c0d5e7a4b580cb68fc077385d9b6 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Sat, 14 Jan 2023 12:46:40 +0100 Subject: [PATCH] refactor(profile/note): move note in about tab --- .../fragments/ProfileAboutFragment.java | 83 +++++++++++++++++-- .../android/fragments/ProfileFragment.java | 57 ++----------- .../src/main/res/layout/fragment_profile.xml | 44 +--------- .../res/layout/fragment_profile_about.xml | 49 +++++++++++ 4 files changed, 130 insertions(+), 103 deletions(-) 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..82d858009 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,51 @@ 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.setVisibility(View.INVISIBLE); + noteEditConfirm.animate() + .alpha(0.0f) + .setDuration(700); + + } + }); + + 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 +150,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 fb23bf2b9..23c1c8574 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -27,16 +27,13 @@ import android.view.ViewGroup; import android.view.ViewOutlineProvider; import android.view.ViewTreeObserver; import android.view.WindowInsets; -import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.FrameLayout; -import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; -import android.widget.Toast; import android.widget.Toolbar; import androidx.annotation.NonNull; @@ -51,7 +48,6 @@ import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; 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.session.AccountSessionManager; import org.joinmastodon.android.fragments.account_list.FollowerListFragment; @@ -112,9 +108,8 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private SwipeRefreshLayout refreshLayout; private CoverOverlayGradientDrawable coverGradient=new CoverOverlayGradientDrawable(); private float titleTransY; - private View postsBtn, followersBtn, followingBtn, noteEditWrapper; - private EditText nameEdit, bioEdit, noteEdit; - private ImageButton noteEditConfirm; + private View postsBtn, followersBtn, followingBtn; + private EditText nameEdit, bioEdit; private ProgressBar actionProgress, notifyProgress; private FrameLayout[] tabViews; private TabLayoutMediator tabLayoutMediator; @@ -177,9 +172,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList name=content.findViewById(R.id.name); username=content.findViewById(R.id.username); bio=content.findViewById(R.id.bio); - noteEdit=content.findViewById(R.id.note_edit); - noteEditConfirm=content.findViewById(R.id.note_edit_confirm); - noteEditWrapper=content.findViewById(R.id.note_edit_wrap); followersCount=content.findViewById(R.id.followers_count); followersLabel=content.findViewById(R.id.followers_label); followersBtn=content.findViewById(R.id.followers_btn); @@ -472,34 +464,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList bio.setText(parsedBio); } - if(isOwnProfile){ - noteEditWrapper.setVisibility(View.GONE); - } - - noteEdit.setOnFocusChangeListener((v, hasFocus) -> { - if (hasFocus) { - noteEditConfirm.setVisibility(View.VISIBLE); - noteEditConfirm.animate() - .alpha(1.0f) - .setDuration(700); - - } else { - noteEditConfirm.setVisibility(View.INVISIBLE); - noteEditConfirm.animate() - .alpha(0.0f) - .setDuration(700); - - } - }); - - noteEditConfirm.setOnClickListener((v -> { - if (!noteEdit.getText().toString().trim().equals(account.note)) { - savePrivateNote(); - } - InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE); - imm.hideSoftInputFromWindow(this.getView().getRootView().getWindowToken(), 0); - noteEdit.clearFocus(); - })); followersCount.setText(UiUtils.abbreviateNumber(account.followersCount)); followingCount.setText(UiUtils.abbreviateNumber(account.followingCount)); @@ -697,7 +661,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList notifyProgress.setIndeterminateTintList(notifyButton.getTextColors()); followsYouView.setVisibility(relationship.followedBy ? View.VISIBLE : View.GONE); notifyButton.setSelected(relationship.notifying); - noteEdit.setText(relationship.note); + 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)); } @@ -1003,19 +969,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList scrollView.smoothScrollTo(0, 0); } - private void savePrivateNote(){ - currentRequest = 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); - } - private void onFollowersOrFollowingClick(View v){ Bundle args=new Bundle(); args.putString("account", accountID); diff --git a/mastodon/src/main/res/layout/fragment_profile.xml b/mastodon/src/main/res/layout/fragment_profile.xml index 11bd27315..3d50ad9b7 100644 --- a/mastodon/src/main/res/layout/fragment_profile.xml +++ b/mastodon/src/main/res/layout/fragment_profile.xml @@ -258,53 +258,11 @@ android:textColor="?android:textColorSecondary" tools:text="\@Gargron" /> - - - - - - - - - + + + + + + + + + + \ No newline at end of file