HabitRPG / habitica-android

Native Android app for Habitica
GNU General Public License v3.0
1.42k stars 507 forks source link

Fix Party Chat #1970

Closed Hafizzle closed 1 year ago

Hafizzle commented 1 year ago

I believe when creating a new fragment instance using FragmentStateAdapter, the parentFragment is not PartyFragment due to how FragmentStateAdapter manages it's fragments internally.

In instances where ChatFragment is created from FragmentStateAdapter, use a passed viewmodel reference.Else, use the Parent fragment as the ownerProducer.

phillipthelen commented 1 year ago

I accidentally also fixed this before I saw your PR. The issue I see is that with this solution we run into the same issue that we already had before. Where sometimes the app crashes because the viewModel property of the chat fragment is not initialised.

The root of the issue is that if the ChatFragment is inside the PartyFragment, there is no provider for GroupViewModel. Because the PartyFragment uses the subclass of that PartyViewModel. I fixed this by making the viewModel property open and making a PartyChatFragment subclass.

Hafizzle commented 1 year ago

I accidentally also fixed this before I saw your PR. The issue I see is that with this solution we run into the same issue that we already had before. Where sometimes the app crashes because the viewModel property of the chat fragment is not initialised.

The root of the issue is that if the ChatFragment is inside the PartyFragment, there is no provider for GroupViewModel. Because the PartyFragment uses the subclass of that PartyViewModel. I fixed this by making the viewModel property open and making a PartyChatFragment subclass.

@phillipthelen Ahh! That makes sense, thank you!!