Added comments and improved the code

This commit is contained in:
Avently 2020-09-30 00:49:34 +03:00
parent c1d5a5cd98
commit 6665d630ec
3 changed files with 17 additions and 3 deletions

View file

@ -460,8 +460,10 @@ public class MainActivity extends AppCompatActivity {
if (!isChangingConfigurations()) { if (!isChangingConfigurations()) {
StateSaver.clearStateFiles(); StateSaver.clearStateFiles();
} }
if (broadcastReceiver != null) {
unregisterReceiver(broadcastReceiver); unregisterReceiver(broadcastReceiver);
} }
}
@Override @Override
protected void onResume() { protected void onResume() {
@ -811,8 +813,20 @@ public class MainActivity extends AppCompatActivity {
final Fragment fragmentPlayer = getSupportFragmentManager() final Fragment fragmentPlayer = getSupportFragmentManager()
.findFragmentById(R.id.fragment_player_holder); .findFragmentById(R.id.fragment_player_holder);
if (fragmentPlayer == null) { if (fragmentPlayer == null) {
/*
* We still don't have a fragment attached to the activity.
* It can happen when a user started popup or background players
* without opening a stream inside the fragment.
* Adding it in a collapsed state (only mini player will be visible)
* */
NavigationHelper.showMiniPlayer(getSupportFragmentManager()); NavigationHelper.showMiniPlayer(getSupportFragmentManager());
} }
/*
* At this point the player is added 100%, we can unregister.
* Other actions are useless since the fragment will not be removed after that
* */
unregisterReceiver(broadcastReceiver);
broadcastReceiver = null;
} }
} }
}; };

View file

@ -304,7 +304,7 @@ public class VideoDetailFragment
return instance; return instance;
} }
public static VideoDetailFragment getInstanceCollapsed() { public static VideoDetailFragment getInstanceInCollapsedState() {
final VideoDetailFragment instance = new VideoDetailFragment(); final VideoDetailFragment instance = new VideoDetailFragment();
instance.bottomSheetState = BottomSheetBehavior.STATE_COLLAPSED; instance.bottomSheetState = BottomSheetBehavior.STATE_COLLAPSED;
return instance; return instance;

View file

@ -392,7 +392,7 @@ public final class NavigationHelper {
} }
public static void showMiniPlayer(final FragmentManager fragmentManager) { public static void showMiniPlayer(final FragmentManager fragmentManager) {
final VideoDetailFragment instance = VideoDetailFragment.getInstanceCollapsed(); final VideoDetailFragment instance = VideoDetailFragment.getInstanceInCollapsedState();
defaultTransaction(fragmentManager) defaultTransaction(fragmentManager)
.replace(R.id.fragment_player_holder, instance) .replace(R.id.fragment_player_holder, instance)
.runOnCommit(() -> sendPlayerStartedEvent(instance.requireActivity())) .runOnCommit(() -> sendPlayerStartedEvent(instance.requireActivity()))