Minor fixes

This commit is contained in:
Grishka 2023-07-02 10:50:01 +03:00
parent fbc3081e68
commit 30a66a26c6
5 changed files with 45 additions and 12 deletions

View File

@ -52,6 +52,7 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF
private boolean isInEditMode;
private ItemTouchHelper dragHelper=new ItemTouchHelper(new ReorderCallback());
private ListImageLoaderWrapper imgLoader;
private boolean editDirty;
public void setFields(List<AccountField> fields){
this.fields=fields;
@ -83,12 +84,17 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF
fields=editableFields;
adapter.notifyDataSetChanged();
dragHelper.attachToRecyclerView(list);
editDirty=false;
}
public List<AccountField> getFields(){
return fields;
}
public boolean isEditDirty(){
return editDirty;
}
@Override
public void onApplyWindowInsets(WindowInsets insets){
if(Build.VERSION.SDK_INT>=29 && insets.getTappableElementInsets().bottom==0){
@ -209,6 +215,7 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF
private class EditableAboutViewHolder extends BaseViewHolder{
private final EditText title;
private final EditText value;
private boolean ignoreTextChange;
public EditableAboutViewHolder(){
super(R.layout.onboarding_profile_field);
@ -218,16 +225,26 @@ public class ProfileAboutFragment extends Fragment implements WindowInsetsAwareF
dragHelper.startDrag(this);
return true;
});
title.addTextChangedListener(new SimpleTextWatcher(e->item.name=e.toString()));
value.addTextChangedListener(new SimpleTextWatcher(e->item.value=e.toString()));
title.addTextChangedListener(new SimpleTextWatcher(e->{
item.name=e.toString();
if(!ignoreTextChange)
editDirty=true;
}));
value.addTextChangedListener(new SimpleTextWatcher(e->{
item.value=e.toString();
if(!ignoreTextChange)
editDirty=true;
}));
findViewById(R.id.delete).setOnClickListener(this::onRemoveRowClick);
}
@Override
public void onBind(AccountField item){
super.onBind(item);
ignoreTextChange=true;
title.setText(item.name);
value.setText(item.value);
ignoreTextChange=false;
}
private void onRemoveRowClick(View v){

View File

@ -67,6 +67,7 @@ import org.joinmastodon.android.ui.tabs.TabLayout;
import org.joinmastodon.android.ui.tabs.TabLayoutMediator;
import org.joinmastodon.android.ui.text.CustomEmojiSpan;
import org.joinmastodon.android.ui.text.HtmlParser;
import org.joinmastodon.android.ui.utils.SimpleTextWatcher;
import org.joinmastodon.android.ui.utils.UiUtils;
import org.joinmastodon.android.ui.views.CoverImageView;
import org.joinmastodon.android.ui.views.CustomDrawingOrderLinearLayout;
@ -134,7 +135,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
private boolean isOwnProfile;
private ArrayList<AccountField> fields=new ArrayList<>();
private boolean isInEditMode;
private boolean isInEditMode, editDirty;
private Uri editNewAvatar, editNewCover;
private String profileAccountID;
private boolean refreshing;
@ -304,6 +305,9 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
refreshLayout.setProgressBackgroundColorSchemeColor(UiUtils.alphaBlendColors(colorBackground, colorPrimary, 0.11f));
refreshLayout.setColorSchemeColors(colorPrimary);
nameEdit.addTextChangedListener(new SimpleTextWatcher(e->editDirty=true));
bioEdit.addTextChangedListener(new SimpleTextWatcher(e->editDirty=true));
return sizeWrapper;
}
@ -813,6 +817,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
aboutFragment.enterEditMode(account.source.fields);
refreshLayout.setEnabled(false);
editDirty=false;
}
private void exitEditMode(){
@ -896,11 +901,15 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
@Override
public boolean onBackPressed(){
if(isInEditMode){
new M3AlertDialogBuilder(getActivity())
.setTitle(R.string.discard_changes)
.setPositiveButton(R.string.discard, (dlg, btn)->exitEditMode())
.setNegativeButton(R.string.cancel, null)
.show();
if(editDirty || aboutFragment.isEditDirty()){
new M3AlertDialogBuilder(getActivity())
.setTitle(R.string.discard_changes)
.setPositiveButton(R.string.discard, (dlg, btn)->exitEditMode())
.setNegativeButton(R.string.cancel, null)
.show();
}else{
exitEditMode();
}
return true;
}
return false;
@ -961,9 +970,11 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
if(requestCode==AVATAR_RESULT){
editNewAvatar=data.getData();
ViewImageLoader.loadWithoutAnimation(avatar, null, new UrlImageLoaderRequest(editNewAvatar, V.dp(100), V.dp(100)));
editDirty=true;
}else if(requestCode==COVER_RESULT){
editNewCover=data.getData();
ViewImageLoader.loadWithoutAnimation(cover, null, new UrlImageLoaderRequest(editNewCover, V.dp(1000), V.dp(1000)));
editDirty=true;
}
}
}

View File

@ -88,6 +88,7 @@
android:paddingRight="16dp"
android:textAppearance="@style/m3_body_large"
android:gravity="center_vertical"
android:textColor="?colorM3OnSurface"
tools:text="\@mastodon.social"/>
</org.joinmastodon.android.ui.views.FloatingHintEditTextLayout>

View File

@ -84,14 +84,17 @@
android:layout_below="@id/cover"
android:layout_alignParentEnd="true"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp">
android:layout_marginHorizontal="16dp"
android:paddingStart="120dp">
<org.joinmastodon.android.ui.views.ProgressBarButton
android:id="@+id/profile_action_btn"
style="@style/Widget.Mastodon.M3.Button.Filled"
android:layout_width="156dp"
android:layout_width="wrap_content"
android:layout_height="40dp"
tools:text="Edit Profile" />
style="@style/Widget.Mastodon.M3.Button.Filled"
android:minWidth="156dp"
android:paddingHorizontal="16dp"
tools:text="@string/save_changes" />
<ProgressBar
android:id="@+id/action_progress"

View File

@ -12,6 +12,7 @@
android:textAppearance="@style/m3_body_large"
android:paddingStart="56dp"
android:paddingEnd="24dp"
android:textColor="?colorM3OnSurface"
android:text="@string/login_subtitle"/>
<org.joinmastodon.android.ui.views.FloatingHintEditTextLayout