mirror of
https://github.com/antebudimir/tempus.git
synced 2025-12-31 17:43:32 +00:00
Go back to first page on bottomSheet collapse
This commit is contained in:
parent
7e0081b020
commit
72a471dd6d
4 changed files with 35 additions and 18 deletions
|
|
@ -15,13 +15,10 @@ import androidx.navigation.NavController;
|
|||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.broadcast.receiver.ConnectivityStatusBroadcastReceiver;
|
||||
import com.cappielloantonio.play.databinding.ActivityMainBinding;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.service.MediaService;
|
||||
import com.cappielloantonio.play.ui.activity.base.BaseActivity;
|
||||
import com.cappielloantonio.play.ui.dialog.ConnectionAlertDialog;
|
||||
import com.cappielloantonio.play.ui.dialog.ServerUnreachableDialog;
|
||||
|
|
@ -152,19 +149,10 @@ public class MainActivity extends BaseActivity {
|
|||
break;
|
||||
case BottomSheetBehavior.STATE_COLLAPSED:
|
||||
if (playerBottomSheetFragment != null) {
|
||||
// playerBottomSheetFragment.goBackToFirstPage();
|
||||
// playerBottomSheetFragment.scrollOnTop();
|
||||
playerBottomSheetFragment.goBackToFirstPage();
|
||||
}
|
||||
case BottomSheetBehavior.STATE_SETTLING:
|
||||
if (playerBottomSheetFragment != null) {
|
||||
// playerBottomSheetFragment.scrollOnTop();
|
||||
}
|
||||
break;
|
||||
case BottomSheetBehavior.STATE_EXPANDED:
|
||||
if (playerBottomSheetFragment != null) {
|
||||
// playerBottomSheetFragment.scrollOnTop();
|
||||
// setBottomSheetDraggableState(playerBottomSheetFragment.isViewPagerInFirstPage());
|
||||
}
|
||||
case BottomSheetBehavior.STATE_DRAGGING:
|
||||
case BottomSheetBehavior.STATE_HALF_EXPANDED:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -177,4 +177,12 @@ public class PlayerBottomSheetFragment extends Fragment {
|
|||
public View getPlayerHeader() {
|
||||
return requireView().findViewById(R.id.player_header_layout);
|
||||
}
|
||||
|
||||
public void goBackToFirstPage() {
|
||||
bind.playerBodyLayout.playerBodyBottomSheetViewPager.setCurrentItem(0, false);
|
||||
|
||||
PlayerControllerVerticalPager playerControllerVerticalPager = (PlayerControllerVerticalPager) bind.playerBodyLayout.playerBodyBottomSheetViewPager.getAdapter();
|
||||
PlayerControllerFragment playerControllerFragment = (PlayerControllerFragment) playerControllerVerticalPager.getRegisteredFragment(0);
|
||||
playerControllerFragment.goBackToFirstPage();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,11 +24,11 @@ import androidx.navigation.fragment.NavHostFragment;
|
|||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.ui.fragment.pager.PlayerControllerHorizontalPager;
|
||||
import com.cappielloantonio.play.databinding.InnerFragmentPlayerControllerBinding;
|
||||
import com.cappielloantonio.play.service.MediaService;
|
||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||
import com.cappielloantonio.play.ui.dialog.RatingDialog;
|
||||
import com.cappielloantonio.play.ui.fragment.pager.PlayerControllerHorizontalPager;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.cappielloantonio.play.viewmodel.PlayerBottomSheetViewModel;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
|
@ -87,6 +87,7 @@ public class PlayerControllerFragment extends Fragment {
|
|||
bind = null;
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void init() {
|
||||
playerMoveDownBottomSheet = bind.getRoot().findViewById(R.id.player_move_down_bottom_sheet);
|
||||
|
|
@ -115,7 +116,7 @@ public class PlayerControllerFragment extends Fragment {
|
|||
try {
|
||||
MediaBrowser mediaBrowser = mediaBrowserListenableFuture.get();
|
||||
|
||||
bind.playerControlBodyLayout.setPlayer(mediaBrowser);
|
||||
bind.nowPlayingSongControllerView.setPlayer(mediaBrowser);
|
||||
|
||||
setMediaControllerListener(mediaBrowser);
|
||||
} catch (Exception e) {
|
||||
|
|
@ -200,4 +201,8 @@ public class PlayerControllerFragment extends Fragment {
|
|||
activity.collapseBottomSheet();
|
||||
}));
|
||||
}
|
||||
|
||||
public void goBackToFirstPage() {
|
||||
playerSongCoverViewPager.setCurrentItem(0, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -7,11 +7,17 @@ import androidx.viewpager2.adapter.FragmentStateAdapter;
|
|||
import com.cappielloantonio.play.ui.fragment.PlayerControllerFragment;
|
||||
import com.cappielloantonio.play.ui.fragment.PlayerQueueFragment;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PlayerControllerVerticalPager extends FragmentStateAdapter {
|
||||
private static final String TAG = "PlayerControllerVerticalPager";
|
||||
|
||||
private final HashMap<Integer, Fragment> maps;
|
||||
|
||||
public PlayerControllerVerticalPager(@NonNull Fragment fragment) {
|
||||
super(fragment);
|
||||
|
||||
this.maps = new HashMap<>();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -19,16 +25,26 @@ public class PlayerControllerVerticalPager extends FragmentStateAdapter {
|
|||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case 0:
|
||||
return new PlayerControllerFragment();
|
||||
Fragment playerControllerFragment = new PlayerControllerFragment();
|
||||
maps.put(position, playerControllerFragment);
|
||||
return playerControllerFragment;
|
||||
case 1:
|
||||
return new PlayerQueueFragment();
|
||||
Fragment playerQueueFragment = new PlayerQueueFragment();
|
||||
maps.put(position, playerQueueFragment);
|
||||
return playerQueueFragment;
|
||||
}
|
||||
|
||||
return new PlayerControllerFragment();
|
||||
Fragment playerControllerFragment = new PlayerControllerFragment();
|
||||
maps.put(position, playerControllerFragment);
|
||||
return playerControllerFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
public Fragment getRegisteredFragment(int position) {
|
||||
return maps.get(position);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue