Fix some crashes

This commit is contained in:
Thomas 2022-05-30 18:21:54 +02:00
parent c95dfda3df
commit ff0ff6cedc
2 changed files with 28 additions and 15 deletions

View File

@ -139,10 +139,11 @@ public class SpannableHelper {
apngDrawable.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
apngDrawable.setVisible(true, true);
imageSpan = new ImageSpan(apngDrawable);
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
if (endPosition <= content.length()) {
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
} catch (Exception ignored) {
}
} else if (GifParser.isGif(file.getAbsolutePath())) {
@ -151,9 +152,11 @@ public class SpannableHelper {
gifDrawable.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
gifDrawable.setVisible(true, true);
imageSpan = new ImageSpan(gifDrawable);
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
if (endPosition <= content.length()) {
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
} catch (Exception ignored) {
}
} else {
@ -162,9 +165,11 @@ public class SpannableHelper {
drawable.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
drawable.setVisible(true, true);
imageSpan = new ImageSpan(drawable);
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
if (endPosition <= content.length()) {
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
} catch (Exception ignored) {
}
}
@ -682,9 +687,11 @@ public class SpannableHelper {
drawable.setBounds(0, 0, (int) convertDpToPixel(20, context), (int) convertDpToPixel(20, context));
drawable.setVisible(true, true);
imageSpan = new ImageSpan(drawable);
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
if (endPosition <= content.length()) {
content.setSpan(
imageSpan, startPosition,
endPosition, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
} catch (Exception ignored) {
}
}

View File

@ -656,9 +656,15 @@ public class ComposeAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
int currentLength = MastodonHelper.countLength(holder);
//Copy/past
if (currentLength > instanceInfo.configuration.statusesConf.max_characters + 1) {
holder.binding.content.setText(s.delete(instanceInfo.configuration.statusesConf.max_characters - holder.binding.contentSpoiler.getText().length(), (currentLength - holder.binding.contentSpoiler.getText().length())));
int from = instanceInfo.configuration.statusesConf.max_characters - holder.binding.contentSpoiler.getText().length();
int to = (currentLength - holder.binding.contentSpoiler.getText().length());
if (to <= s.length()) {
holder.binding.content.setText(s.delete(from, to));
}
} else if (currentLength > instanceInfo.configuration.statusesConf.max_characters) {
holder.binding.content.setText(s.delete(cPosition, cPosition + 1));
if (cPosition + 1 <= s.length()) {
holder.binding.content.setText(s.delete(cPosition, cPosition + 1));
}
}
statusList.get(holder.getAdapterPosition()).text = s.toString();
if (s.toString().trim().length() < 2) {