Better editing

This commit is contained in:
Grishka 2022-09-02 11:21:28 +03:00
parent ff52c37868
commit f531a90b41
4 changed files with 70 additions and 6 deletions

View File

@ -9,7 +9,7 @@ android {
applicationId "org.joinmastodon.android" applicationId "org.joinmastodon.android"
minSdk 23 minSdk 23
targetSdk 31 targetSdk 31
versionCode 39 versionCode 40
versionName "1.1.3" versionName "1.1.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
} }
@ -47,6 +47,10 @@ android {
setRoot "src/appcenter" setRoot "src/appcenter"
} }
} }
lintOptions{
checkReleaseBuilds false
abortOnError false
}
} }
dependencies { dependencies {

View File

@ -0,0 +1,18 @@
package org.joinmastodon.android.api.requests.statuses;
import org.joinmastodon.android.api.AllFieldsAreRequired;
import org.joinmastodon.android.api.MastodonAPIRequest;
import org.joinmastodon.android.model.BaseModel;
public class GetStatusSourceText extends MastodonAPIRequest<GetStatusSourceText.Response>{
public GetStatusSourceText(String id){
super(HttpMethod.GET, "/statuses/"+id+"/source", Response.class);
}
@AllFieldsAreRequired
public static class Response extends BaseModel{
public String id;
public String text;
public String spoilerText;
}
}

View File

@ -178,6 +178,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private boolean attachmentsErrorShowing; private boolean attachmentsErrorShowing;
private Status editingStatus; private Status editingStatus;
private boolean pollChanged;
private boolean creatingView;
@Override @Override
public void onCreate(Bundle savedInstanceState){ public void onCreate(Bundle savedInstanceState){
@ -233,6 +235,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
@Override @Override
public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ public View onCreateContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
creatingView=true;
emojiKeyboard=new CustomEmojiPopupKeyboard(getActivity(), customEmojis, instanceDomain); emojiKeyboard=new CustomEmojiPopupKeyboard(getActivity(), customEmojis, instanceDomain);
emojiKeyboard.setListener(this::onCustomEmojiClick); emojiKeyboard.setListener(this::onCustomEmojiClick);
@ -328,7 +331,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
spoilerBtn.setSelected(true); spoilerBtn.setSelected(true);
}else if(editingStatus!=null && !TextUtils.isEmpty(editingStatus.spoilerText)){ }else if(editingStatus!=null && !TextUtils.isEmpty(editingStatus.spoilerText)){
spoilerEdit.setVisibility(View.VISIBLE); spoilerEdit.setVisibility(View.VISIBLE);
spoilerEdit.setText(editingStatus.spoilerText); spoilerEdit.setText(getArguments().getString("sourceSpoiler", editingStatus.spoilerText));
spoilerBtn.setSelected(true); spoilerBtn.setSelected(true);
} }
@ -354,6 +357,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
autocompleteView.setVisibility(View.GONE); autocompleteView.setVisibility(View.GONE);
mainEditTextWrap.addView(autocompleteView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(178), Gravity.TOP)); mainEditTextWrap.addView(autocompleteView, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, V.dp(178), Gravity.TOP));
creatingView=false;
return view; return view;
} }
@ -488,7 +493,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
} }
if(savedInstanceState==null){ if(savedInstanceState==null){
if(editingStatus!=null){ if(editingStatus!=null){
mainEditText.setText(initialText=HtmlParser.strip(editingStatus.content)); initialText=getArguments().getString("sourceText", "");
mainEditText.setText(initialText);
mainEditText.setSelection(mainEditText.length()); mainEditText.setSelection(mainEditText.length());
if(!editingStatus.mediaAttachments.isEmpty()){ if(!editingStatus.mediaAttachments.isEmpty()){
attachmentsView.setVisibility(View.VISIBLE); attachmentsView.setVisibility(View.VISIBLE);
@ -596,6 +602,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
if(opt.edit.length()>0) if(opt.edit.length()>0)
nonEmptyPollOptionsCount++; nonEmptyPollOptionsCount++;
} }
if(publishButton==null)
return;
publishButton.setEnabled((trimmedCharCount>0 || !attachments.isEmpty()) && charCount<=charLimit && uploadingAttachment==null && failedAttachments.isEmpty() && queuedAttachments.isEmpty() publishButton.setEnabled((trimmedCharCount>0 || !attachments.isEmpty()) && charCount<=charLimit && uploadingAttachment==null && failedAttachments.isEmpty() && queuedAttachments.isEmpty()
&& (pollOptions.isEmpty() || nonEmptyPollOptionsCount>1)); && (pollOptions.isEmpty() || nonEmptyPollOptionsCount>1));
} }
@ -693,6 +701,14 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
} }
private boolean hasDraft(){ private boolean hasDraft(){
if(editingStatus!=null){
if(!mainEditText.getText().toString().equals(initialText))
return true;
List<String> existingMediaIDs=editingStatus.mediaAttachments.stream().map(a->a.id).collect(Collectors.toList());
if(!existingMediaIDs.equals(attachments.stream().map(a->a.serverAttachment.id).collect(Collectors.toList())))
return true;
return pollChanged;
}
boolean pollFieldsHaveContent=false; boolean pollFieldsHaveContent=false;
for(DraftPollOption opt:pollOptions) for(DraftPollOption opt:pollOptions)
pollFieldsHaveContent|=opt.edit.length()>0; pollFieldsHaveContent|=opt.edit.length()>0;
@ -1021,7 +1037,11 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
pollOptionsView.startDragging(option.view); pollOptionsView.startDragging(option.view);
return true; return true;
}); });
option.edit.addTextChangedListener(new SimpleTextWatcher(e->updatePublishButtonState())); option.edit.addTextChangedListener(new SimpleTextWatcher(e->{
if(!creatingView)
pollChanged=true;
updatePublishButtonState();
}));
option.edit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(instance.configuration!=null && instance.configuration.polls!=null && instance.configuration.polls.maxCharactersPerOption>0 ? instance.configuration.polls.maxCharactersPerOption : 50)}); option.edit.setFilters(new InputFilter[]{new InputFilter.LengthFilter(instance.configuration!=null && instance.configuration.polls!=null && instance.configuration.polls.maxCharactersPerOption>0 ? instance.configuration.polls.maxCharactersPerOption : 50)});
pollOptionsView.addView(option.view); pollOptionsView.addView(option.view);
@ -1041,6 +1061,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
private void onSwapPollOptions(int oldIndex, int newIndex){ private void onSwapPollOptions(int oldIndex, int newIndex){
pollOptions.add(newIndex, pollOptions.remove(oldIndex)); pollOptions.add(newIndex, pollOptions.remove(oldIndex));
updatePollOptionHints(); updatePollOptionHints();
pollChanged=true;
} }
private void showPollDurationMenu(){ private void showPollDurationMenu(){
@ -1064,6 +1085,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
default -> throw new IllegalStateException("Unexpected value: "+item.getItemId()); default -> throw new IllegalStateException("Unexpected value: "+item.getItemId());
}; };
pollDurationView.setText(getString(R.string.compose_poll_duration, pollDurationStr=item.getTitle().toString())); pollDurationView.setText(getString(R.string.compose_poll_duration, pollDurationStr=item.getTitle().toString()));
pollChanged=true;
return true; return true;
}); });
menu.show(); menu.show();

View File

@ -21,6 +21,7 @@ import android.widget.Toast;
import org.joinmastodon.android.GlobalUserPreferences; import org.joinmastodon.android.GlobalUserPreferences;
import org.joinmastodon.android.R; import org.joinmastodon.android.R;
import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships; import org.joinmastodon.android.api.requests.accounts.GetAccountRelationships;
import org.joinmastodon.android.api.requests.statuses.GetStatusSourceText;
import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.fragments.BaseStatusListFragment; import org.joinmastodon.android.fragments.BaseStatusListFragment;
import org.joinmastodon.android.fragments.ComposeFragment; import org.joinmastodon.android.fragments.ComposeFragment;
@ -137,10 +138,29 @@ public class HeaderStatusDisplayItem extends StatusDisplayItem{
Account account=item.user; Account account=item.user;
int id=menuItem.getItemId(); int id=menuItem.getItemId();
if(id==R.id.edit){ if(id==R.id.edit){
Bundle args=new Bundle(); final Bundle args=new Bundle();
args.putString("account", item.parentFragment.getAccountID()); args.putString("account", item.parentFragment.getAccountID());
args.putParcelable("editStatus", Parcels.wrap(item.status)); args.putParcelable("editStatus", Parcels.wrap(item.status));
Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args); if(TextUtils.isEmpty(item.status.content) && TextUtils.isEmpty(item.status.spoilerText)){
Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args);
}else{
new GetStatusSourceText(item.status.id)
.setCallback(new Callback<>(){
@Override
public void onSuccess(GetStatusSourceText.Response result){
args.putString("sourceText", result.text);
args.putString("sourceSpoiler", result.spoilerText);
Nav.go(item.parentFragment.getActivity(), ComposeFragment.class, args);
}
@Override
public void onError(ErrorResponse error){
error.showToast(item.parentFragment.getActivity());
}
})
.wrapProgress(item.parentFragment.getActivity(), R.string.loading, true)
.exec(item.parentFragment.getAccountID());
}
}else if(id==R.id.delete){ }else if(id==R.id.delete){
UiUtils.confirmDeletePost(item.parentFragment.getActivity(), item.parentFragment.getAccountID(), item.status, s->{}); UiUtils.confirmDeletePost(item.parentFragment.getActivity(), item.parentFragment.getAccountID(), item.status, s->{});
}else if(id==R.id.mute){ }else if(id==R.id.mute){