From 7b4c005513911b993940e560ce97f3a7ab234e2a Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Sat, 29 Aug 2020 15:55:40 -0400 Subject: [PATCH] fix #75, fix #94 (added error handling for suspicious situations) --- .../activities/CommentsViewer.java | 32 +++++++++++-------- .../instagrabber/asyncs/PostsFetcher.java | 2 +- .../DirectMessageThreadFragment.java | 9 ++++-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java index 0a98cc01..73352b6b 100755 --- a/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java +++ b/app/src/main/java/awais/instagrabber/activities/CommentsViewer.java @@ -119,21 +119,25 @@ public final class CommentsViewer extends BaseLanguageActivity implements SwipeR } else if (which == 3) { Utils.copyText(this, commentModel.getText().toString()); } else if (which == 4) { - focus = commentsBinding.rvComments.findViewWithTag(commentModel); - focus.setBackgroundColor(0x80888888); - commentsBinding.commentCancelParent.setVisibility(View.VISIBLE); - String mention = "@"+profileModel.getUsername()+" "; - commentsBinding.commentText.setText(mention); - commentsBinding.commentText.requestFocus(); - commentsBinding.commentText.setSelection(mention.length()); - commentsBinding.commentText.postDelayed(new Runnable(){ - @Override - public void run(){ - imm = (InputMethodManager) getSystemService(getApplicationContext().INPUT_METHOD_SERVICE); - imm.showSoftInput(commentsBinding.commentText, 0); - } + if (commentModel == null) { + Toast.makeText(getApplicationContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); + } + else { + focus = commentsBinding.rvComments.findViewWithTag(commentModel); + focus.setBackgroundColor(0x80888888); + commentsBinding.commentCancelParent.setVisibility(View.VISIBLE); + String mention = "@" + profileModel.getUsername() + " "; + commentsBinding.commentText.setText(mention); + commentsBinding.commentText.requestFocus(); + commentsBinding.commentText.setSelection(mention.length()); + commentsBinding.commentText.postDelayed(new Runnable() { + @Override + public void run() { + imm = (InputMethodManager) getSystemService(getApplicationContext().INPUT_METHOD_SERVICE); + imm.showSoftInput(commentsBinding.commentText, 0); + } + }, 200); } - ,200); } else if (which == 5) { new CommentAction().execute((commentModel.getLiked() ? "unlike/" : "like/")+commentModel.getId()); } else if (which == 6) { diff --git a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java index 3e972871..204323d6 100755 --- a/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java +++ b/app/src/main/java/awais/instagrabber/asyncs/PostsFetcher.java @@ -131,7 +131,7 @@ public final class PostsFetcher extends AsyncTask { Utils.checkExistence(downloadDir, customDir, isSlider, models[i]); } - if (models[models.length - 1] != null) + if (models.length > 0 && models[models.length - 1] != null) models[models.length - 1].setPageCursor(hasNextPage, endCursor); result = models; diff --git a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java index a077b082..2d19a507 100644 --- a/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java @@ -67,6 +67,7 @@ import awais.instagrabber.models.direct_messages.DirectItemModel; import awais.instagrabber.models.direct_messages.InboxThreadModel; import awais.instagrabber.models.enums.DirectItemType; import awais.instagrabber.models.enums.DownloadMethod; +import awais.instagrabber.models.enums.MediaItemType; import awais.instagrabber.models.enums.UserInboxDirection; import awais.instagrabber.utils.Constants; import awais.instagrabber.utils.Utils; @@ -220,8 +221,12 @@ public class DirectMessageThreadFragment extends Fragment { case RAVEN_MEDIA: case MEDIA: final ProfileModel user = getUser(directItemModel.getUserId()); - Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, Collections.singletonList(itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia())); - Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); + String url = selectedItem.getMediaType() == MediaItemType.MEDIA_TYPE_VIDEO ? selectedItem.getVideoUrl() : selectedItem.getThumbUrl(); + if (url != null) { + Utils.dmDownload(requireContext(), user.getUsername(), DownloadMethod.DOWNLOAD_DIRECT, Collections.singletonList(itemType == DirectItemType.MEDIA ? directItemModel.getMediaModel() : directItemModel.getRavenMediaModel().getMedia())); + Toast.makeText(requireContext(), R.string.downloader_downloading_media, Toast.LENGTH_SHORT).show(); + } + else Toast.makeText(requireContext(), R.string.downloader_unknown_error, Toast.LENGTH_SHORT).show(); break; case STORY_SHARE: if (directItemModel.getReelShare() != null) {