Fix issue #1014 - Wrong profiles when enabling remote conversations

Media3
Thomas 10 months ago
parent dd119449f3
commit 4204f658d7

@ -28,6 +28,7 @@ import java.lang.ref.WeakReference;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import app.fedilab.android.mastodon.helper.Helper;
import app.fedilab.android.mastodon.helper.SpannableHelper; import app.fedilab.android.mastodon.helper.SpannableHelper;
import de.timfreiheit.mathjax.android.MathJaxView; import de.timfreiheit.mathjax.android.MathJaxView;
@ -152,9 +153,9 @@ public class Status implements Serializable, Cloneable {
return same; return same;
} }
public synchronized Spannable getSpanContent(Context context, WeakReference<View> viewWeakReference, Callback callback) { public synchronized Spannable getSpanContent(Context context, boolean checkRemotely, WeakReference<View> viewWeakReference, Callback callback) {
if (contentSpan == null) { if (contentSpan == null) {
contentSpan = SpannableHelper.convert(context, content, this, null, null, viewWeakReference, callback, true, true); contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, viewWeakReference, callback, true, true);
} }
return contentSpan; return contentSpan;
} }

@ -111,6 +111,12 @@ public class SpannableHelper {
public static Spannable convert(Context context, String text, public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, Status status, Account account, Announcement announcement,
WeakReference<View> viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) { WeakReference<View> viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) {
return convert(context, text, status, account, announcement, false, viewWeakReference, callback, convertHtml, convertMarkdown);
}
public static Spannable convert(Context context, String text,
Status status, Account account, Announcement announcement, boolean checkRemotely,
WeakReference<View> viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) {
if (text == null) { if (text == null) {
return null; return null;
} }
@ -296,14 +302,23 @@ public class SpannableHelper {
intent = new Intent(context, ProfileActivity.class); intent = new Intent(context, ProfileActivity.class);
args = new Bundle(); args = new Bundle();
Mention targetedMention = null; Mention targetedMention = null;
String acct = null;
for (Mention mention : mentions) { for (Mention mention : mentions) {
if (word.compareToIgnoreCase("@" + mention.username) == 0) { if (word.compareToIgnoreCase("@" + mention.username) == 0) {
targetedMention = mention; if(!checkRemotely) {
targetedMention = mention;
} else {
acct = mention.acct;
}
break; break;
} }
} }
if (targetedMention != null) { if (targetedMention != null) {
args.putString(Helper.ARG_USER_ID, targetedMention.id); args.putString(Helper.ARG_USER_ID, targetedMention.id);
} else if( acct != null){
args.putString(Helper.ARG_MENTION, acct);
} else { } else {
args.putString(Helper.ARG_MENTION, word); args.putString(Helper.ARG_MENTION, word);
} }

@ -1395,7 +1395,7 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
holder.binding.simpleMediaContainer.setVisibility(View.GONE); holder.binding.simpleMediaContainer.setVisibility(View.GONE);
} }
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
status.getSpanContent(context, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(position))), new WeakReference<>(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(position))),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance()); holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance());

@ -209,7 +209,7 @@ public class ConversationAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
} }
//--- MAIN CONTENT --- //--- MAIN CONTENT ---
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
conversation.last_status.getSpanContent(context, conversation.last_status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))), new WeakReference<>(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
//--- DATE --- //--- DATE ---

@ -514,7 +514,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
}); });
holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary)); holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary));
holder.binding.quotedMessage.statusContent.setText( holder.binding.quotedMessage.statusContent.setText(
statusToDeal.quote.getSpanContent(context, statusToDeal.quote.getSpanContent(context, remote,
new WeakReference<>(holder.binding.quotedMessage.statusContent), null), new WeakReference<>(holder.binding.quotedMessage.statusContent), null),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account); MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account);
@ -1413,10 +1413,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
case "direct" -> holder.binding.actionButtonBoost.setVisibility(View.GONE); case "direct" -> holder.binding.actionButtonBoost.setVisibility(View.GONE);
} }
//--- MAIN CONTENT --- //--- MAIN CONTENT ---
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
statusToDeal.getSpanContent(context, statusToDeal.getSpanContent(context, remote,
new WeakReference<>(holder.binding.statusContent), () -> { new WeakReference<>(holder.binding.statusContent), () -> {
recyclerView.post(() -> adapter.notifyItemChanged(holder.getBindingAdapterPosition())); recyclerView.post(() -> adapter.notifyItemChanged(holder.getBindingAdapterPosition()));
}), }),

@ -241,7 +241,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter<RecyclerVie
SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences sharedpreferences = PreferenceManager.getDefaultSharedPreferences(context);
status.underlined = true; status.underlined = true;
holder.binding.messageContent.setText( holder.binding.messageContent.setText(
status.getSpanContent(context, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.messageContent), new WeakReference<>(holder.binding.messageContent),
() -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);

@ -55,7 +55,7 @@ public class StatusHistoryAdapter extends RecyclerView.Adapter<RecyclerView.View
StatusHistoryViewHolder holder = (StatusHistoryViewHolder) viewHolder; StatusHistoryViewHolder holder = (StatusHistoryViewHolder) viewHolder;
Status status = statuses.get(position); Status status = statuses.get(position);
holder.binding.statusContent.setText( holder.binding.statusContent.setText(
status.getSpanContent(context, status.getSpanContent(context, false,
new WeakReference<>(holder.binding.statusContent), null), new WeakReference<>(holder.binding.statusContent), null),
TextView.BufferType.SPANNABLE); TextView.BufferType.SPANNABLE);
if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) { if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) {

@ -28,7 +28,6 @@ import android.database.sqlite.SQLiteDatabase;
import android.net.Uri; import android.net.Uri;
import android.os.Handler; import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.util.Log;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import android.webkit.URLUtil; import android.webkit.URLUtil;

Loading…
Cancel
Save