Fix some crashes

This commit is contained in:
Thomas 2022-11-27 16:30:51 +01:00
parent ab9b367a38
commit c7420a8760
4 changed files with 20 additions and 7 deletions

View File

@ -586,7 +586,10 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
} }
Handler mainHandler = new Handler(Looper.getMainLooper()); Handler mainHandler = new Handler(Looper.getMainLooper());
Runnable myRunnable = () -> { Runnable myRunnable = () -> {
if (currentAccount == null || currentAccount.mastodon_account == null) { if (currentToken == null) {
currentToken = sharedpreferences.getString(Helper.PREF_USER_TOKEN, null);
}
if (currentAccount == null) {
//It is not, the user is redirected to the login page //It is not, the user is redirected to the login page
Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class); Intent myIntent = new Intent(BaseMainActivity.this, LoginActivity.class);
startActivity(myIntent); startActivity(myIntent);

View File

@ -78,13 +78,18 @@ public class AccountFollowRequestAdapter extends RecyclerView.Adapter<RecyclerVi
AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class); AccountsVM accountsVM = new ViewModelProvider((ViewModelStoreOwner) context).get(AccountsVM.class);
holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id) holderFollow.binding.acceptButton.setOnClickListener(v -> accountsVM.acceptFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
.observe((LifecycleOwner) context, relationShip -> { .observe((LifecycleOwner) context, relationShip -> {
accountList.remove(position); if (accountList.size() > position) {
notifyItemRemoved(position); accountList.remove(position);
notifyItemRemoved(position);
}
})); }));
holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id) holderFollow.binding.rejectButton.setOnClickListener(v -> accountsVM.rejectFollow(BaseMainActivity.currentInstance, BaseMainActivity.currentToken, account.id)
.observe((LifecycleOwner) context, relationShip -> { .observe((LifecycleOwner) context, relationShip -> {
accountList.remove(position); if (accountList.size() > position) {
notifyItemRemoved(position); accountList.remove(position);
notifyItemRemoved(position);
}
})); }));
holderFollow.binding.avatar.setOnClickListener(v -> { holderFollow.binding.avatar.setOnClickListener(v -> {
Intent intent = new Intent(context, ProfileActivity.class); Intent intent = new Intent(context, ProfileActivity.class);

View File

@ -941,6 +941,11 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
composeAttachmentItemBinding.buttonOrderDown.setVisibility(View.INVISIBLE); composeAttachmentItemBinding.buttonOrderDown.setVisibility(View.INVISIBLE);
} }
int finalMediaPosition = mediaPosition; int finalMediaPosition = mediaPosition;
if (attachment.local_path.endsWith("png") || attachment.local_path.endsWith("jpg") || attachment.local_path.endsWith("jpeg")) {
composeAttachmentItemBinding.editPreview.setVisibility(View.VISIBLE);
} else {
composeAttachmentItemBinding.editPreview.setVisibility(View.GONE);
}
composeAttachmentItemBinding.editPreview.setOnClickListener(v -> { composeAttachmentItemBinding.editPreview.setOnClickListener(v -> {
Intent intent = new Intent(context, EditImageActivity.class); Intent intent = new Intent(context, EditImageActivity.class);
Bundle b = new Bundle(); Bundle b = new Bundle();

View File

@ -2341,7 +2341,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
holder.bindingArt.artMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this); holder.bindingArt.artMedia.getViewTreeObserver().removeOnGlobalLayoutListener(this);
if (status.art_attachment.meta != null) { if (status.art_attachment.meta != null && status.art_attachment.meta.small != null) {
float viewWidth = holder.bindingArt.artMedia.getWidth(); float viewWidth = holder.bindingArt.artMedia.getWidth();
ConstraintLayout.LayoutParams lp; ConstraintLayout.LayoutParams lp;
float mediaH = status.art_attachment.meta.small.height; float mediaH = status.art_attachment.meta.small.height;
@ -2357,7 +2357,7 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
} }
}); });
if (status.art_attachment.meta != null) { if (status.art_attachment.meta != null && status.art_attachment.meta.small != null) {
float viewWidth = holder.bindingArt.artMedia.getWidth(); float viewWidth = holder.bindingArt.artMedia.getWidth();
ConstraintLayout.LayoutParams lp; ConstraintLayout.LayoutParams lp;
float mediaH = status.art_attachment.meta.small.height; float mediaH = status.art_attachment.meta.small.height;