Skip to content

Commit

Permalink
refactor(profile-note): remove save button, automatically save on foc…
Browse files Browse the repository at this point in the history
…us change/exit
  • Loading branch information
LucasGGamerM committed Dec 21, 2023
1 parent 0364d95 commit 18e3fad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private SwipeRefreshLayout refreshLayout;
private View followersBtn, followingBtn;
private EditText nameEdit, bioEdit;
private ProgressBar actionProgress, notifyProgress, noteSaveProgress;
private ProgressBar actionProgress, notifyProgress;
private FrameLayout[] tabViews;
private TabLayoutMediator tabLayoutMediator;
private TextView followsYouView;
Expand Down Expand Up @@ -197,7 +197,6 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList

// profile note
private FrameLayout noteWrap;
private ImageButton noteSaveBtn;
private EditText noteEdit;

@Override
Expand Down Expand Up @@ -271,7 +270,6 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu
bioEditWrap=content.findViewById(R.id.bio_edit_wrap);
actionProgress=content.findViewById(R.id.action_progress);
notifyProgress=content.findViewById(R.id.notify_progress);
noteSaveProgress=content.findViewById(R.id.note_save_progress);
fab=content.findViewById(R.id.fab);
followsYouView=content.findViewById(R.id.follows_you);
countersLayout=content.findViewById(R.id.profile_counters);
Expand All @@ -288,47 +286,15 @@ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bu

noteEdit=content.findViewById(R.id.note_edit);
noteWrap=content.findViewById(R.id.note_edit_wrap);
noteSaveBtn=content.findViewById(R.id.note_save_btn);

noteSaveBtn.setOnClickListener((v->{
savePrivateNote(noteEdit.getText().toString());
InputMethodManager imm=(InputMethodManager) getContext().getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getView().getRootView().getWindowToken(), 0);
noteEdit.clearFocus();
noteSaveBtn.clearFocus();
}));


noteEdit.setOnFocusChangeListener((v, hasFocus)->{
if(hasFocus){
hideFab();
V.setVisibilityAnimated(noteSaveBtn, View.VISIBLE);
noteEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
}else if(!noteSaveBtn.hasFocus()){
showFab();
hideNoteSaveBtnIfNotDirty();
}
});

noteEdit.addTextChangedListener(new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
if(relationship!=null && noteSaveBtn.getVisibility()!=View.VISIBLE && !s.toString().equals(relationship.note))
V.setVisibilityAnimated(noteSaveBtn, View.VISIBLE);
}

@Override
public void afterTextChanged(Editable s){}
});

noteSaveBtn.setOnFocusChangeListener((v, hasFocus)->{
if(!hasFocus && !noteEdit.hasFocus()){
}else{
showFab();
hideNoteSaveBtnIfNotDirty();
}
savePrivateNote(noteEdit.getText().toString());
});

FrameLayout sizeWrapper=new FrameLayout(getActivity()){
Expand Down Expand Up @@ -495,12 +461,6 @@ public void onError(ErrorResponse error){
return sizeWrapper;
}

private void hideNoteSaveBtnIfNotDirty(){
if(noteEdit.getText().toString().equals(relationship.note)){
V.setVisibilityAnimated(noteSaveBtn, View.INVISIBLE);
}
}

private void showPrivateNote(){
noteWrap.setVisibility(View.VISIBLE);
noteEdit.setText(relationship.note);
Expand All @@ -517,8 +477,6 @@ private void savePrivateNote(String note){
invalidateOptionsMenu();
return;
}
V.setVisibilityAnimated(noteSaveProgress, View.VISIBLE);
V.setVisibilityAnimated(noteSaveBtn, View.INVISIBLE);
new SetPrivateNote(profileAccountID, note).setCallback(new Callback<>() {
@Override
public void onSuccess(Relationship result) {
Expand All @@ -529,8 +487,6 @@ public void onSuccess(Relationship result) {
@Override
public void onError(ErrorResponse error) {
error.showToast(getContext());
V.setVisibilityAnimated(noteSaveProgress, View.GONE);
V.setVisibilityAnimated(noteSaveBtn, View.VISIBLE);
}
}).exec(accountID);
}
Expand Down Expand Up @@ -693,6 +649,13 @@ public void onSaveInstanceState(Bundle outState){
getChildFragmentManager().putFragment(outState, "pinnedPosts", pinnedPostsFragment);
}

@Override
public void onHidden(){
if (relationship != null && !noteEdit.getText().toString().equals(relationship.note)){
savePrivateNote(noteEdit.getText().toString());
}
}

@Override
public void onConfigurationChanged(Configuration newConfig){
super.onConfigurationChanged(newConfig);
Expand Down Expand Up @@ -1015,13 +978,10 @@ private void updateRelationship(){
UiUtils.setRelationshipToActionButtonM3(relationship, actionButton);
actionProgress.setIndeterminateTintList(actionButton.getTextColors());
notifyProgress.setIndeterminateTintList(notifyButton.getTextColors());
noteSaveProgress.setIndeterminateTintList(noteEdit.getTextColors());
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));
noteEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
V.setVisibilityAnimated(noteSaveProgress, View.GONE);
V.setVisibilityAnimated(noteSaveBtn, View.INVISIBLE);
UiUtils.beginLayoutTransition(scrollableContent);
}

Expand Down
27 changes: 0 additions & 27 deletions mastodon/src/main/res/layout/fragment_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,33 +239,6 @@
android:maxHeight="200dp"
android:hint="@string/mo_personal_note"
tools:ignore="RtlSymmetry" />

<FrameLayout
android:layout_width="52dp"
android:layout_height="52dp"
android:paddingTop="8dp"
android:layout_gravity="end">

<ImageButton
android:id="@+id/note_save_btn"
android:layout_width="52dp"
android:layout_height="52dp"
android:visibility="invisible"
android:background="@drawable/bg_button_m3_text_circle"
android:tooltipText="@string/sk_confirm_changes"
android:contentDescription="@string/sk_confirm_changes"
android:src="@drawable/ic_fluent_checkmark_24_regular"/>

<ProgressBar
android:id="@+id/note_save_progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
style="?android:progressBarStyleSmall"
android:indeterminate="true"
android:visibility="gone" />

</FrameLayout>
</org.joinmastodon.android.ui.views.FloatingHintEditTextLayout>

<org.joinmastodon.android.ui.views.LinkedTextView
Expand Down

0 comments on commit 18e3fad

Please sign in to comment.