mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
Add fragment manager destroyed checks. Fixes https://github.com/austinhuang0131/barinsta/issues/1068
This commit is contained in:
parent
ea2956f3ca
commit
af3670e3ec
@ -12,9 +12,6 @@ import awais.instagrabber.interfaces.FetchListener;
|
|||||||
import awais.instagrabber.repositories.responses.Media;
|
import awais.instagrabber.repositories.responses.Media;
|
||||||
import awais.instagrabber.utils.NetworkUtils;
|
import awais.instagrabber.utils.NetworkUtils;
|
||||||
import awais.instagrabber.utils.ResponseBodyUtils;
|
import awais.instagrabber.utils.ResponseBodyUtils;
|
||||||
//import awaisomereport.LogCollector;
|
|
||||||
|
|
||||||
//import static awais.instagrabber.utils.Utils.logCollector;
|
|
||||||
|
|
||||||
public final class PostFetcher extends AsyncTask<Void, Void, Media> {
|
public final class PostFetcher extends AsyncTask<Void, Void, Media> {
|
||||||
private static final String TAG = "PostFetcher";
|
private static final String TAG = "PostFetcher";
|
||||||
@ -136,9 +133,9 @@ public final class PostFetcher extends AsyncTask<Void, Void, Media> {
|
|||||||
return ResponseBodyUtils.parseGraphQLItem(media, null);
|
return ResponseBodyUtils.parseGraphQLItem(media, null);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// if (logCollector != null) {
|
// if (logCollector != null) {
|
||||||
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground");
|
// logCollector.appendException(e, LogCollector.LogFile.ASYNC_POST_FETCHER, "doInBackground");
|
||||||
// }
|
// }
|
||||||
Log.e(TAG, "Error fetching post", e);
|
Log.e(TAG, "Error fetching post", e);
|
||||||
} finally {
|
} finally {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
|
@ -26,6 +26,7 @@ import androidx.appcompat.app.ActionBar;
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.content.PermissionChecker;
|
import androidx.core.content.PermissionChecker;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
@ -60,6 +61,7 @@ import awais.instagrabber.repositories.requests.StoryViewerOptions;
|
|||||||
import awais.instagrabber.repositories.responses.Hashtag;
|
import awais.instagrabber.repositories.responses.Hashtag;
|
||||||
import awais.instagrabber.repositories.responses.Location;
|
import awais.instagrabber.repositories.responses.Location;
|
||||||
import awais.instagrabber.repositories.responses.Media;
|
import awais.instagrabber.repositories.responses.Media;
|
||||||
|
import awais.instagrabber.repositories.responses.User;
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.DownloadUtils;
|
import awais.instagrabber.utils.DownloadUtils;
|
||||||
@ -213,7 +215,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
final View mainPostImage,
|
final View mainPostImage,
|
||||||
final int position) {
|
final int position) {
|
||||||
if (opening) return;
|
if (opening) return;
|
||||||
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) {
|
final User user = feedModel.getUser();
|
||||||
|
if (user == null) return;
|
||||||
|
if (TextUtils.isEmpty(user.getUsername())) {
|
||||||
opening = true;
|
opening = true;
|
||||||
new PostFetcher(feedModel.getCode(), newFeedModel -> {
|
new PostFetcher(feedModel.getCode(), newFeedModel -> {
|
||||||
opening = false;
|
opening = false;
|
||||||
@ -231,7 +235,9 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
builder.setSharedProfilePicElement(profilePicView)
|
builder.setSharedProfilePicElement(profilePicView)
|
||||||
.setSharedMainPostElement(mainPostImage);
|
.setSharedMainPostElement(mainPostImage);
|
||||||
}
|
}
|
||||||
builder.build().show(getChildFragmentManager(), "post_view");
|
final FragmentManager fragmentManager = getChildFragmentManager();
|
||||||
|
if (fragmentManager.isDestroyed()) return;
|
||||||
|
builder.build().show(fragmentManager, "post_view");
|
||||||
opening = false;
|
opening = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -403,8 +409,7 @@ public class HashTagFragment extends Fragment implements SwipeRefreshLayout.OnRe
|
|||||||
try {
|
try {
|
||||||
Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), R.string.error_loading_hashtag, Toast.LENGTH_SHORT).show();
|
||||||
binding.swipeRefreshLayout.setEnabled(false);
|
binding.swipeRefreshLayout.setEnabled(false);
|
||||||
}
|
} catch (Exception ignored) {}
|
||||||
catch (Exception ignored) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTitle();
|
setTitle();
|
||||||
|
@ -24,6 +24,7 @@ import androidx.appcompat.app.ActionBar;
|
|||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
||||||
import androidx.core.content.PermissionChecker;
|
import androidx.core.content.PermissionChecker;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.navigation.NavController;
|
import androidx.navigation.NavController;
|
||||||
import androidx.navigation.NavDirections;
|
import androidx.navigation.NavDirections;
|
||||||
import androidx.navigation.fragment.NavHostFragment;
|
import androidx.navigation.fragment.NavHostFragment;
|
||||||
@ -56,6 +57,7 @@ import awais.instagrabber.models.enums.FavoriteType;
|
|||||||
import awais.instagrabber.repositories.requests.StoryViewerOptions;
|
import awais.instagrabber.repositories.requests.StoryViewerOptions;
|
||||||
import awais.instagrabber.repositories.responses.Location;
|
import awais.instagrabber.repositories.responses.Location;
|
||||||
import awais.instagrabber.repositories.responses.Media;
|
import awais.instagrabber.repositories.responses.Media;
|
||||||
|
import awais.instagrabber.repositories.responses.User;
|
||||||
import awais.instagrabber.utils.Constants;
|
import awais.instagrabber.utils.Constants;
|
||||||
import awais.instagrabber.utils.CookieUtils;
|
import awais.instagrabber.utils.CookieUtils;
|
||||||
import awais.instagrabber.utils.DownloadUtils;
|
import awais.instagrabber.utils.DownloadUtils;
|
||||||
@ -204,7 +206,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
final View mainPostImage,
|
final View mainPostImage,
|
||||||
final int position) {
|
final int position) {
|
||||||
if (opening) return;
|
if (opening) return;
|
||||||
if (TextUtils.isEmpty(feedModel.getUser().getUsername())) {
|
final User user = feedModel.getUser();
|
||||||
|
if (user == null) return;
|
||||||
|
if (TextUtils.isEmpty(user.getUsername())) {
|
||||||
opening = true;
|
opening = true;
|
||||||
new PostFetcher(feedModel.getCode(), newFeedModel -> {
|
new PostFetcher(feedModel.getCode(), newFeedModel -> {
|
||||||
opening = false;
|
opening = false;
|
||||||
@ -223,7 +227,9 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
builder.setSharedProfilePicElement(profilePicView)
|
builder.setSharedProfilePicElement(profilePicView)
|
||||||
.setSharedMainPostElement(mainPostImage);
|
.setSharedMainPostElement(mainPostImage);
|
||||||
}
|
}
|
||||||
builder.build().show(getChildFragmentManager(), "post_view");
|
final FragmentManager fragmentManager = getChildFragmentManager();
|
||||||
|
if (fragmentManager.isDestroyed()) return;
|
||||||
|
builder.build().show(fragmentManager, "post_view");
|
||||||
opening = false;
|
opening = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -399,8 +405,7 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
try {
|
try {
|
||||||
Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show();
|
Toast.makeText(getContext(), R.string.error_loading_location, Toast.LENGTH_SHORT).show();
|
||||||
binding.swipeRefreshLayout.setEnabled(false);
|
binding.swipeRefreshLayout.setEnabled(false);
|
||||||
}
|
} catch (Exception ignored) {}
|
||||||
catch (Exception ignored) {}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTitle();
|
setTitle();
|
||||||
@ -409,16 +414,16 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
final long locationId = locationModel.getPk();
|
final long locationId = locationModel.getPk();
|
||||||
// binding.swipeRefreshLayout.setRefreshing(true);
|
// binding.swipeRefreshLayout.setRefreshing(true);
|
||||||
locationDetailsBinding.mainLocationImage.setImageURI("res:/" + R.drawable.ic_location);
|
locationDetailsBinding.mainLocationImage.setImageURI("res:/" + R.drawable.ic_location);
|
||||||
// final String postCount = String.valueOf(locationModel.getCount());
|
// final String postCount = String.valueOf(locationModel.getCount());
|
||||||
// final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
|
// final SpannableStringBuilder span = new SpannableStringBuilder(getResources().getQuantityString(R.plurals.main_posts_count_inline,
|
||||||
// locationModel.getPostCount() > 2000000000L
|
// locationModel.getPostCount() > 2000000000L
|
||||||
// ? 2000000000
|
// ? 2000000000
|
||||||
// : locationModel.getPostCount().intValue(),
|
// : locationModel.getPostCount().intValue(),
|
||||||
// postCount));
|
// postCount));
|
||||||
// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
|
// span.setSpan(new RelativeSizeSpan(1.2f), 0, postCount.length(), 0);
|
||||||
// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
|
// span.setSpan(new StyleSpan(Typeface.BOLD), 0, postCount.length(), 0);
|
||||||
// locationDetailsBinding.mainLocPostCount.setText(span);
|
// locationDetailsBinding.mainLocPostCount.setText(span);
|
||||||
// locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE);
|
// locationDetailsBinding.mainLocPostCount.setVisibility(View.VISIBLE);
|
||||||
locationDetailsBinding.locationFullName.setText(locationModel.getName());
|
locationDetailsBinding.locationFullName.setText(locationModel.getName());
|
||||||
CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity();
|
CharSequence biography = locationModel.getAddress() + "\n" + locationModel.getCity();
|
||||||
// binding.locationBiography.setCaptionIsExpandable(true);
|
// binding.locationBiography.setCaptionIsExpandable(true);
|
||||||
@ -431,22 +436,22 @@ public class LocationFragment extends Fragment implements SwipeRefreshLayout.OnR
|
|||||||
} else {
|
} else {
|
||||||
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
|
locationDetailsBinding.locationBiography.setVisibility(View.VISIBLE);
|
||||||
locationDetailsBinding.locationBiography.setText(biography);
|
locationDetailsBinding.locationBiography.setText(biography);
|
||||||
// locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> {
|
// locationDetailsBinding.locationBiography.addOnHashtagListener(autoLinkItem -> {
|
||||||
// final NavController navController = NavHostFragment.findNavController(this);
|
// final NavController navController = NavHostFragment.findNavController(this);
|
||||||
// final Bundle bundle = new Bundle();
|
// final Bundle bundle = new Bundle();
|
||||||
// final String originalText = autoLinkItem.getOriginalText().trim();
|
// final String originalText = autoLinkItem.getOriginalText().trim();
|
||||||
// bundle.putString(ARG_HASHTAG, originalText);
|
// bundle.putString(ARG_HASHTAG, originalText);
|
||||||
// navController.navigate(R.id.action_global_hashTagFragment, bundle);
|
// navController.navigate(R.id.action_global_hashTagFragment, bundle);
|
||||||
// });
|
// });
|
||||||
// locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> {
|
// locationDetailsBinding.locationBiography.addOnMentionClickListener(autoLinkItem -> {
|
||||||
// final String originalText = autoLinkItem.getOriginalText().trim();
|
// final String originalText = autoLinkItem.getOriginalText().trim();
|
||||||
// navigateToProfile(originalText);
|
// navigateToProfile(originalText);
|
||||||
// });
|
// });
|
||||||
// locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context,
|
// locationDetailsBinding.locationBiography.addOnEmailClickListener(autoLinkItem -> Utils.openEmailAddress(context,
|
||||||
// autoLinkItem.getOriginalText()
|
// autoLinkItem.getOriginalText()
|
||||||
// .trim()));
|
// .trim()));
|
||||||
// locationDetailsBinding.locationBiography
|
// locationDetailsBinding.locationBiography
|
||||||
// .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim()));
|
// .addOnURLClickListener(autoLinkItem -> Utils.openURL(context, autoLinkItem.getOriginalText().trim()));
|
||||||
locationDetailsBinding.locationBiography.setOnLongClickListener(v -> {
|
locationDetailsBinding.locationBiography.setOnLongClickListener(v -> {
|
||||||
Utils.copyText(context, biography);
|
Utils.copyText(context, biography);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user