Skip to content

Commit

Permalink
Merge pull request VinylMusicPlayer#765 from Osiris-Team/always_ask_f…
Browse files Browse the repository at this point in the history
…or_actions_works_on_landscape

"Always ask for actions" menu now works in landscape mode
  • Loading branch information
soncaokim authored and XMA2l committed Dec 21, 2023
1 parent ff1db08 commit 635f307
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.FrameLayout;

Expand All @@ -11,11 +12,22 @@
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.poupa.vinylmusicplayer.util.ImageTheme.ThemeStyleUtil;
import com.poupa.vinylmusicplayer.util.Util;

import java.util.concurrent.CopyOnWriteArrayList;


public abstract class BottomSheetDialog extends BottomSheetDialogFragment {
public static BottomSheetDialog newInstance() { return null; }

/**
* Not null after {@link #onCreateDialog(Bundle)} was called. <br>
* You can add a listener to {@link #onBottomSheetCreated}.
*/
public FrameLayout bottomSheet = null;

public CopyOnWriteArrayList<Runnable> onBottomSheetCreated = new CopyOnWriteArrayList<>();

@NonNull @Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

Expand All @@ -27,27 +39,39 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
public void onShow(DialogInterface dialog) {
com.google.android.material.bottomsheet.BottomSheetDialog
d = (com.google.android.material.bottomsheet.BottomSheetDialog) dialog;
FrameLayout bottomSheet = d.findViewById(com.google.android.material.R.id.design_bottom_sheet);
bottomSheet = d.findViewById(com.google.android.material.R.id.design_bottom_sheet);

BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
behaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
behaviour.setDraggable(false);
behaviour.addBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
behaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {

}
});

for (Runnable code : onBottomSheetCreated) {
code.run();
}
}
});

return dialog;
}

public void expand(){
Runnable code = () -> {
BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
if(behaviour.getState() == BottomSheetBehavior.STATE_EXPANDED) return;
behaviour.setState(BottomSheetBehavior.STATE_EXPANDED);
};
if(bottomSheet != null) code.run();
else onBottomSheetCreated.add(code);
}

public void collapse(){
Runnable code = () -> {
BottomSheetBehavior behaviour = BottomSheetBehavior.from(bottomSheet);
if(behaviour.getState() == BottomSheetBehavior.STATE_COLLAPSED) return;
behaviour.setState(BottomSheetBehavior.STATE_COLLAPSED);
};
if(bottomSheet != null) code.run();
else onBottomSheetCreated.add(code);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public BottomSheetDialogWithButtons setDefaultButtonIndex(int defaultIndex) {
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bottom_sheet_button_list, container, false);
Context context = getContext();
expand();

if (buttonList == null || context == null) { dismiss(); return view; }

Expand Down

0 comments on commit 635f307

Please sign in to comment.