diff options
author | Alex Ning <chineseperson5@gmail.com> | 2021-06-23 12:05:46 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2021-06-23 12:05:46 +0000 |
commit | c7f9343d004f2ead3e9aaa5cc952a176f749238d (patch) | |
tree | a3658bce8168df567d1c0112a778817f90715124 /app/src | |
parent | b01c9b9e2bd965ad5de307dc81fa7e0c1dd80a94 (diff) | |
download | infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar.gz infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar.bz2 infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar.lz infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar.xz infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.tar.zst infinity-for-reddit-c7f9343d004f2ead3e9aaa5cc952a176f749238d.zip |
Fix 'android.view.ViewRootImpl: Only the original thread that created a view hierarchy can touch its views.' in SubmitPostService.
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java index 38c70df4..12b4e1a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/SubmitPostService.java @@ -196,14 +196,14 @@ public class SubmitPostService extends Service { isNSFW, kind, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { - EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null)); + handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(true, post, null))); stopService(); } @Override public void submitFailed(@Nullable String errorMessage) { - EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(false, null, errorMessage)); + handler.post(() -> EventBus.getDefault().post(new SubmitTextOrLinkPostEvent(false, null, errorMessage))); stopService(); } @@ -216,14 +216,14 @@ public class SubmitPostService extends Service { content, flair, isSpoiler, isNSFW, APIUtils.KIND_CROSSPOST, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { - EventBus.getDefault().post(new SubmitCrosspostEvent(true, post, null)); + handler.post(() -> EventBus.getDefault().post(new SubmitCrosspostEvent(true, post, null))); stopService(); } @Override public void submitFailed(@Nullable String errorMessage) { - EventBus.getDefault().post(new SubmitCrosspostEvent(false, null, errorMessage)); + handler.post(() -> EventBus.getDefault().post(new SubmitCrosspostEvent(false, null, errorMessage))); stopService(); } @@ -238,22 +238,24 @@ public class SubmitPostService extends Service { new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { - EventBus.getDefault().post(new SubmitImagePostEvent(true, null)); - Toast.makeText(SubmitPostService.this, R.string.image_is_processing, Toast.LENGTH_SHORT).show(); + handler.post(() -> { + EventBus.getDefault().post(new SubmitImagePostEvent(true, null)); + Toast.makeText(SubmitPostService.this, R.string.image_is_processing, Toast.LENGTH_SHORT).show(); + }); stopService(); } @Override public void submitFailed(@Nullable String errorMessage) { - EventBus.getDefault().post(new SubmitImagePostEvent(false, errorMessage)); + handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, errorMessage))); stopService(); } }); } catch (ExecutionException | InterruptedException e) { e.printStackTrace(); - EventBus.getDefault().post(new SubmitImagePostEvent(false, getString(R.string.error_processing_image))); + handler.post(() -> EventBus.getDefault().post(new SubmitImagePostEvent(false, getString(R.string.error_processing_image)))); stopService(); } } @@ -280,31 +282,34 @@ public class SubmitPostService extends Service { type, resource, flair, isSpoiler, isNSFW, new SubmitPost.SubmitPostListener() { @Override public void submitSuccessful(Post post) { - EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(true, false, null)); - if (type.contains("gif")) { - Toast.makeText(SubmitPostService.this, R.string.gif_is_processing, Toast.LENGTH_SHORT).show(); - } else { - Toast.makeText(SubmitPostService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show(); - } + handler.post(() -> { + EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(true, false, null)); + if (type.contains("gif")) { + Toast.makeText(SubmitPostService.this, R.string.gif_is_processing, Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(SubmitPostService.this, R.string.video_is_processing, Toast.LENGTH_SHORT).show(); + } + }); + stopService(); } @Override public void submitFailed(@Nullable String errorMessage) { - EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, false, errorMessage)); + handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, false, errorMessage))); stopService(); } }); } else { - EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null)); + handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null))); stopService(); } } catch (IOException | InterruptedException | ExecutionException e) { e.printStackTrace(); - EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null)); + handler.post(() -> EventBus.getDefault().post(new SubmitVideoOrGifPostEvent(false, true, null))); stopService(); } |