Fix issue #136 - Mentions are lost when replying to a own message

This commit is contained in:
Thomas 2022-06-06 15:46:45 +02:00
parent 0c19da62c0
commit 4e52fa0c70
4 changed files with 25 additions and 38 deletions

View File

@ -62,8 +62,7 @@
android:configChanges="keyboardHidden|orientation|screenSize" />
<activity
android:name=".activities.ComposeActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:windowSoftInputMode="adjustPan|adjustResize"
android:configChanges="orientation|screenSize"
android:label="@string/compose" />
<activity
android:name=".activities.StatusInfoActivity"

View File

@ -247,29 +247,27 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
statusList.add(statusReply);
int statusCount = statusList.size();
statusDraftList.get(0).in_reply_to_id = statusReply.id;
statusDraftList.get(0).mentions = statusReply.mentions;
if (statusReply.spoiler_text != null) {
statusDraftList.get(0).spoiler_text = statusReply.spoiler_text;
//We change order for mentions
//At first place the account that has been mentioned if it's not our
statusDraftList.get(0).mentions = new ArrayList<>();
if (!statusReply.account.acct.equalsIgnoreCase(MainActivity.accountWeakReference.get().mastodon_account.acct)) {
Mention mention = new Mention();
mention.acct = "@" + statusReply.account.acct;
mention.url = statusReply.account.url;
mention.username = statusReply.account.username;
statusDraftList.get(0).mentions.add(mention);
}
if (statusDraftList.get(0).mentions == null) {
statusDraftList.get(0).mentions = new ArrayList<>();
}
//We will add the mentioned account in mention if not the current user nor if it is already mentioned
if (statusReply.account != null && statusReply.account.acct != null && !statusReply.account.id.equals(BaseMainActivity.currentUserID)) {
boolean canBeAdded = true;
for (Mention mention : statusDraftList.get(0).mentions) {
if (mention.acct.compareToIgnoreCase(statusReply.account.acct) == 0) {
mention.id = null;
canBeAdded = false;
//There are other mentions to
if (statusReply.mentions != null && statusReply.mentions.size() > 0) {
for (Mention mentionTmp : statusReply.mentions) {
if (!mentionTmp.acct.equalsIgnoreCase(statusReply.account.acct) && !mentionTmp.acct.equalsIgnoreCase(MainActivity.accountWeakReference.get().mastodon_account.acct)) {
statusDraftList.get(0).mentions.add(mentionTmp);
}
}
if (canBeAdded) {
Mention mention = new Mention();
mention.acct = "@" + statusReply.account.acct;
mention.url = statusReply.account.url;
mention.username = statusReply.account.username;
statusDraftList.get(0).mentions.add(mention);
}
}
if (statusReply.spoiler_text != null) {
statusDraftList.get(0).spoiler_text = statusReply.spoiler_text;
}
//StatusDraftList at this point should only have one element
statusList.addAll(statusDraftList);

View File

@ -9,7 +9,6 @@ import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AnticipateOvershootInterpolator;
@ -413,7 +412,6 @@ public class EditImageActivity extends BaseActivity implements OnPhotoEditorList
mPropertiesBSFragment.show(getSupportFragmentManager(), mPropertiesBSFragment.getTag());
break;
case CROP:
Log.v(Helper.TAG, "crop! " + uri);
CropImage.activity(uri)
.start(this);
break;

View File

@ -187,13 +187,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
//Retrieves mentioned accounts + OP and adds them at the beginin of the toot
final SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
Mention inReplyToUser = null;
for (Mention mention : statusDraft.mentions) {
//Mentioned account has a null id
if (mention.id == null) {
inReplyToUser = mention;
break;
}
}
inReplyToUser = statusDraft.mentions.get(0);
if (statusDraft.text == null) {
statusDraft.text = "";
}
@ -201,20 +195,18 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
boolean capitalize = sharedpreferences.getBoolean(context.getString(R.string.SET_CAPITALIZE), true);
if (inReplyToUser != null) {
if (capitalize) {
statusDraft.text = inReplyToUser.acct + "\n";
statusDraft.text = inReplyToUser.acct.startsWith("@") ? inReplyToUser.acct + "\n" : "@" + inReplyToUser.acct + "\n";
} else {
statusDraft.text = inReplyToUser.acct + " ";
statusDraft.text = inReplyToUser.acct.startsWith("@") ? inReplyToUser.acct + " " : "@" + inReplyToUser.acct + " ";
}
}
holder.binding.content.setText(statusDraft.text);
statusDraft.cursorPosition = statusDraft.text.length();
if (statusDraft.mentions.size() > 1) {
statusDraft.text += "\n";
for (Mention mention : statusDraft.mentions) {
if (mention.id != null && mention.acct != null && !mention.id.equals(BaseMainActivity.currentUserID)) {
String tootTemp = String.format("@%s ", mention.acct);
statusDraft.text = String.format("%s ", (statusDraft.text + tootTemp.trim()));
}
for (int i = 1; i < statusDraft.mentions.size(); i++) {
String tootTemp = String.format("@%s ", statusDraft.mentions.get(i).acct);
statusDraft.text = String.format("%s ", (statusDraft.text + tootTemp.trim()));
}
}
holder.binding.content.setText(statusDraft.text);