From 160d556ac5e23d417ac2b8bd9f577b5239174d8b Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Wed, 17 Mar 2021 00:55:34 +0900 Subject: [PATCH] Null check context object. Should fix https://github.com/austinhuang0131/barinsta/issues/427 --- .../awais/instagrabber/fragments/LocationFragment.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java index ee2852c8..d21e750e 100644 --- a/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/LocationFragment.java @@ -416,6 +416,8 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR // binding.locationBiography.setCaptionIsExpandable(true); // binding.locationBiography.setCaptionIsExpanded(true); + final Context context = getContext(); + if (context == null) return; if (TextUtils.isEmpty(biography)) { locationDetailsBinding.locationBiography.setVisibility(View.GONE); } else { @@ -432,13 +434,13 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR final String originalText = autoLinkItem.getOriginalText().trim(); navigateToProfile(originalText); }); - locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(getContext(), + locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context, autoLinkItem.getOriginalText() .trim())); locationDetailsBinding.locationBiography - .addOnURLClickListener(autoLinkItem -> Utils.openURL(getContext(), autoLinkItem.getOriginalText().trim())); + .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim())); locationDetailsBinding.locationBiography.setOnLongClickListener(v -> { - Utils.copyText(getContext(), biography); + Utils.copyText(context, biography); return true; }); } @@ -465,7 +467,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR locationDetailsBinding.locationUrl.setVisibility(View.VISIBLE); locationDetailsBinding.locationUrl.setText(TextUtils.getSpannableUrl(url)); } - final FavoriteDataSource dataSource = FavoriteDataSource.getInstance(getContext()); + final FavoriteDataSource dataSource = FavoriteDataSource.getInstance(context); final FavoriteRepository favoriteRepository = FavoriteRepository.getInstance(dataSource); locationDetailsBinding.favChip.setVisibility(View.VISIBLE); favoriteRepository.getFavorite(String.valueOf(locationId), FavoriteType.LOCATION, new RepositoryCallback() {