Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reader] Fix IllegalStateException in ReaderPostListFragment #20507

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import androidx.appcompat.widget.SearchView;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -2320,10 +2321,15 @@ private void updateCurrentTagIfTime() {
new Thread() {
@Override
public void run() {
// Check the fragment is attached to the activity when this Thread starts.
FragmentActivity activity = getActivity();
if (activity == null) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 I think doing the check here still has a great chance of not solving the crash, since the function that probably takes the most time to run is shouldAutoUpdateTag. This means that even with this check here, when the code reaches line 2330 or 2332 the fragment might already be dettached anyway, which will likely yield other issues.

Because of that, I think it would be better if the check is done in each of the if clause's blocks (before line 2330 and line 2332) below.

I know the code will look a bit repetitive, but since we're working with Java here, there's not much way around it. 😞

return;
}
if (ReaderTagTable.shouldAutoUpdateTag(getCurrentTag()) && isAdded()) {
requireActivity().runOnUiThread(() -> updateCurrentTag());
activity.runOnUiThread(() -> updateCurrentTag());
} else {
requireActivity().runOnUiThread(() -> {
activity.runOnUiThread(() -> {
if (isBookmarksList() && isPostAdapterEmpty() && isAdded()) {
setEmptyTitleAndDescriptionForBookmarksList();
mActionableEmptyView.image.setImageResource(
Expand Down
Loading