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

fix: don't replace fragment on another fragment if they are the same #3835

Merged
merged 3 commits into from Mar 2, 2021

Conversation

naivekook
Copy link
Contributor

@naivekook naivekook commented Feb 16, 2021

Description

when user clicks on "Home" button twice we did a replacement of current fragment on new instance of this fragment and do extra calls to the server

Related issues

Fixes #3465

@naivekook
Copy link
Contributor Author

naivekook commented Feb 17, 2021

@VaiTon @teolemon please take a look

@VaiTon
Copy link
Member

VaiTon commented Feb 17, 2021

I don't really like this implementation using tag string. Can't we compare using is, for example? Is there a way to get the actual displayed fragment?

@naivekook
Copy link
Contributor Author

naivekook commented Feb 18, 2021

I don't really like this implementation using tag string.

Can I ask you why?

fragment manager doesn't have convenient mechanism to retrieve current fragment, by combining findFragmentByTag and fragment.isVisible we can understand this

looks like we use replace everywhere without backstack so we have only one fragment attached, in this case I can do next thing and it will work too

with((currentActivity as FragmentActivity).supportFragmentManager) {
                        val fragment = fragments.lastOrNull()
                        if (fragment == null || fragment !is HomeFragment) {
                            commit {
                                replace(R.id.fragment_container, HomeFragment.newInstance(), HomeFragment.TAG)
                                addToBackStack(null)
                            }
                        }
                    }

@VaiTon
Copy link
Member

VaiTon commented Feb 18, 2021

I don't really like this implementation using tag string.

Can I ask you why?

Just because it's a useless var if we can check the type as you showed IMHO.

About your second solution, if you could test it and see if it works it would be awesome!

@naivekook
Copy link
Contributor Author

@VaiTon hey check updated version please
I've been tested it on emulator and it works

@naivekook
Copy link
Contributor Author

ptal @VaiTon

@sonarcloud
Copy link

sonarcloud bot commented Feb 27, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@VaiTon VaiTon merged commit 97624bd into openfoodfacts:develop Mar 2, 2021
@VaiTon
Copy link
Member

VaiTon commented Mar 2, 2021

Thanks! 🎉

@naivekook naivekook deleted the fix/fragment-open-only-once branch March 3, 2021 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The app seems to duplicate queries
2 participants