diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-12-25 13:50:40 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2023-12-25 13:50:40 +0000 |
commit | 9af6c4077a4b97cd84cf1f8832d59076b7026387 (patch) | |
tree | 6963e8a7e48129456bae939efb25d1a46e5f8296 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | e2af6dc9091b000d358e76474729a32d19136bf4 (diff) | |
download | infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar.gz infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar.bz2 infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar.lz infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar.xz infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.tar.zst infinity-for-reddit-9af6c4077a4b97cd84cf1f8832d59076b7026387.zip |
Fix app crashes when suggesting title in PostLinkActivity.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostLinkActivity.java | 14 |
1 files changed, 13 insertions, 1 deletions
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<String> call, @NonNull Response<String> response) { if (response.isSuccessful()) { - titleEditText.setText(response.body().substring(response.body().indexOf("<title>") + 7, response.body().indexOf("</title>"))); + String body = response.body(); + if (body != null) { + int start = body.indexOf("<title>"); + if (start >= 0) { + int end = body.indexOf("</title>"); + 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(); } |