some fixes

This commit is contained in:
Thomas 2022-07-16 09:21:43 +02:00
parent dc1155d7c2
commit 96680343e0
4 changed files with 21 additions and 47 deletions

View File

@ -88,15 +88,9 @@ public class ContextActivity extends BaseActivity {
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account); MastodonHelper.loadPPMastodon(binding.profilePicture, currentAccount.mastodon_account);
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
new Thread(() -> { focusedStatus = SpannableHelper.convertStatus(getApplication().getApplicationContext(), focusedStatus);
focusedStatus = SpannableHelper.convertStatus(getApplication().getApplicationContext(), focusedStatus); bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
Handler mainHandler = new Handler(Looper.getMainLooper()); currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, null);
Runnable myRunnable = () -> {
bundle.putSerializable(Helper.ARG_STATUS, focusedStatus);
currentFragment = Helper.addFragment(getSupportFragmentManager(), R.id.nav_host_fragment_content_main, new FragmentMastodonContext(), bundle, null, null);
};
mainHandler.post(myRunnable);
}).start();
StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class); StatusesVM timelinesVM = new ViewModelProvider(ContextActivity.this).get(StatusesVM.class);
timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> { timelinesVM.getStatus(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, focusedStatus.id).observe(ContextActivity.this, status -> {
if (status != null) { if (status != null) {

View File

@ -35,8 +35,6 @@ import android.graphics.drawable.Drawable;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.CountDownTimer; import android.os.CountDownTimer;
import android.os.Handler;
import android.os.Looper;
import android.text.Html; import android.text.Html;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableString; import android.text.SpannableString;
@ -1628,12 +1626,8 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
if (translate.getTranslatedContent() != null) { if (translate.getTranslatedContent() != null) {
statusToDeal.translationShown = true; statusToDeal.translationShown = true;
statusToDeal.translationContent = translate.getTranslatedContent(); statusToDeal.translationContent = translate.getTranslatedContent();
new Thread(() -> { SpannableHelper.convertStatus(context.getApplicationContext(), statusToDeal);
SpannableHelper.convertStatus(context.getApplicationContext(), statusToDeal); adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> adapter.notifyItemChanged(getPositionAsync(notificationList, statusList, statusToDeal));
mainHandler.post(myRunnable);
}).start();
} else { } else {
Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show(); Toasty.error(context, context.getString(R.string.toast_error_translate), Toast.LENGTH_LONG).show();
} }

View File

@ -21,8 +21,6 @@ import android.content.BroadcastReceiver;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -98,26 +96,20 @@ public class FragmentMastodonContext extends Fragment {
} }
} else if (statusPosted != null && statusAdapter != null) { } else if (statusPosted != null && statusAdapter != null) {
if (requireActivity() instanceof ContextActivity) { if (requireActivity() instanceof ContextActivity) {
new Thread(() -> { Status convertStatus = SpannableHelper.convertStatus(context, statusPosted);
Status convertStatus = SpannableHelper.convertStatus(context, statusPosted); int i = 0;
Handler mainHandler = new Handler(Looper.getMainLooper()); for (Status status : statuses) {
Runnable myRunnable = () -> { if (status.id.equals(convertStatus.in_reply_to_id)) {
int i = 0; statuses.add((i + 1), convertStatus);
for (Status status : statuses) { statusAdapter.notifyItemInserted((i + 1));
if (status.id.equals(convertStatus.in_reply_to_id)) { if (requireActivity() instanceof ContextActivity) {
statuses.add((i + 1), convertStatus); //Redraw decorations
statusAdapter.notifyItemInserted((i + 1)); statusAdapter.notifyItemRangeChanged(0, statuses.size());
if (requireActivity() instanceof ContextActivity) {
//Redraw decorations
statusAdapter.notifyItemRangeChanged(0, statuses.size());
}
break;
}
i++;
} }
}; break;
mainHandler.post(myRunnable); }
}).start(); i++;
}
} }
} }
} }

View File

@ -118,15 +118,9 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
statusAdapter.notifyItemRemoved(position); statusAdapter.notifyItemRemoved(position);
} }
} else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) { } else if (statusPosted != null && statusAdapter != null && timelineType == Timeline.TimeLineEnum.HOME) {
new Thread(() -> { Status convertStatus = SpannableHelper.convertStatus(context, statusPosted);
Status convertStatus = SpannableHelper.convertStatus(context, statusPosted); statuses.add(0, convertStatus);
Handler mainHandler = new Handler(Looper.getMainLooper()); statusAdapter.notifyItemInserted(0);
Runnable myRunnable = () -> {
statuses.add(0, convertStatus);
statusAdapter.notifyItemInserted(0);
};
mainHandler.post(myRunnable);
}).start();
} }
} }
} }