From 9af6c4077a4b97cd84cf1f8832d59076b7026387 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Mon, 25 Dec 2023 08:50:40 -0500 Subject: Fix app crashes when suggesting title in PostLinkActivity. --- .../infinityforreddit/activities/PostLinkActivity.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'app') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java index 3bfb4573..34dff394 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java @@ -362,7 +362,19 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @Override public void onResponse(@NonNull Call call, @NonNull Response response) { if (response.isSuccessful()) { - titleEditText.setText(response.body().substring(response.body().indexOf("") + 7, response.body().indexOf(""))); + String body = response.body(); + if (body != null) { + int start = body.indexOf(""); + if (start >= 0) { + int end = body.indexOf(""); + if (end > start) { + titleEditText.setText(body.substring(start + 7, end)); + return; + } + } + } + + Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show(); } else { Toast.makeText(PostLinkActivity.this, R.string.suggest_title_failed, Toast.LENGTH_SHORT).show(); } -- cgit v1.2.3