From 8829f4a66e6ff9bd6633a4ca550bd9b7e69da44d Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 2 Dec 2020 20:01:40 +0900 Subject: [PATCH] Prevent DM button double click and check current fragment still attached before navigating. Fixes a crash reported in telegram group. --- .../fragments/main/ProfileFragment.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java index 022e056e..5743bdf7 100644 --- a/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/main/ProfileFragment.java @@ -800,10 +800,17 @@ public class ProfileFragment extends Fragment implements SwipeRefreshLayout.OnRe PostItemType.TAGGED); NavHostFragment.findNavController(this).navigate(action); }); - profileDetailsBinding.btnDM.setOnClickListener(v -> new CreateThreadAction(cookie, profileModel.getId(), threadId -> { - final NavDirections action = ProfileFragmentDirections.actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername()); - NavHostFragment.findNavController(this).navigate(action); - }).execute()); + profileDetailsBinding.btnDM.setOnClickListener(v -> { + profileDetailsBinding.btnDM.setEnabled(false); + new CreateThreadAction(cookie, profileModel.getId(), threadId -> { + if (isAdded()) { + final NavDirections action = ProfileFragmentDirections + .actionProfileFragmentToDMThreadFragment(threadId, profileModel.getUsername()); + NavHostFragment.findNavController(this).navigate(action); + } + profileDetailsBinding.btnDM.setEnabled(true); + }).execute(); + }); profileDetailsBinding.mainProfileImage.setOnClickListener(v -> { if (!hasStories) { // show profile pic