-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[Refactor] Convert playback buttons to segmented button #13669
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
Open
Isira-Seneviratne
wants to merge
7
commits into
TeamNewPipe:refactor
Choose a base branch
from
Isira-Seneviratne:Improve-playback-buttons
base: refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4de9986
[Refactor] Convert playback buttons to segmented button
Isira-Seneviratne 14f76f3
Fixed some issues, reused existing enum
Isira-Seneviratne 5dc6e53
Add system overlay permission check
Isira-Seneviratne e8d7b6c
Corrected main player icon, option order
Isira-Seneviratne 1077dea
Address review comments
Isira-Seneviratne 153c6b4
Updated strings
Isira-Seneviratne 6d9e481
Fix crash at runtime
Isira-Seneviratne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
app/src/main/java/org/schabi/newpipe/ui/components/common/PlaybackControlButtons.kt
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
app/src/main/java/org/schabi/newpipe/ui/components/common/PlayerOptions.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| package org.schabi.newpipe.ui.components.common | ||
|
|
||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.material3.ExperimentalMaterial3Api | ||
| import androidx.compose.material3.Icon | ||
| import androidx.compose.material3.RichTooltip | ||
| import androidx.compose.material3.SegmentedButton | ||
| import androidx.compose.material3.SegmentedButtonDefaults | ||
| import androidx.compose.material3.SingleChoiceSegmentedButtonRow | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TooltipAnchorPosition | ||
| import androidx.compose.material3.TooltipBox | ||
| import androidx.compose.material3.TooltipDefaults.rememberTooltipPositionProvider | ||
| import androidx.compose.material3.rememberTooltipState | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.saveable.rememberSaveable | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.platform.LocalContext | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.compose.ui.tooling.preview.PreviewLightDark | ||
| import androidx.compose.ui.tooling.preview.PreviewWrapper | ||
| import androidx.compose.ui.unit.dp | ||
| import net.newpipe.app.preview.ThemePreviewProvider | ||
| import org.schabi.newpipe.R | ||
| import org.schabi.newpipe.ktx.findFragmentActivity | ||
| import org.schabi.newpipe.player.PlayerType | ||
| import org.schabi.newpipe.player.playqueue.PlayQueue | ||
| import org.schabi.newpipe.util.NavigationHelper.playOnBackgroundPlayer | ||
| import org.schabi.newpipe.util.NavigationHelper.playOnMainPlayer | ||
| import org.schabi.newpipe.util.NavigationHelper.playOnPopupPlayer | ||
| import org.schabi.newpipe.util.PermissionHelper | ||
|
|
||
| @Composable | ||
| fun PlayerOptions(queue: PlayQueue) { | ||
| val context = LocalContext.current | ||
| var selectedOption by rememberSaveable { mutableStateOf<PlayerType?>(null) } | ||
|
|
||
| LaunchedEffect(selectedOption) { | ||
| when (selectedOption) { | ||
| PlayerType.MAIN -> playOnMainPlayer(context.findFragmentActivity(), queue) | ||
| PlayerType.BACKGROUND -> playOnBackgroundPlayer(context, queue, true) | ||
| PlayerType.POPUP -> playOnPopupPlayer(context, queue, false) | ||
| else -> {} | ||
| } | ||
| } | ||
|
|
||
| PlayerOptions( | ||
| selectedOption = selectedOption, | ||
| onSelectOption = { | ||
| if (it != PlayerType.POPUP || PermissionHelper.checkSystemAlertWindowPermission(context)) { | ||
| selectedOption = it | ||
| } | ||
| } | ||
| ) | ||
| } | ||
|
|
||
| @OptIn(ExperimentalMaterial3Api::class) | ||
| @Composable | ||
| fun PlayerOptions( | ||
| selectedOption: PlayerType?, | ||
| onSelectOption: (PlayerType) -> Unit | ||
| ) { | ||
| Row( | ||
| horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text(text = stringResource(R.string.player_options_label)) | ||
|
|
||
| SingleChoiceSegmentedButtonRow { | ||
| PlayerType.entries.forEachIndexed { index, key -> | ||
| val tooltipState = rememberTooltipState() | ||
|
|
||
| TooltipBox( | ||
| positionProvider = rememberTooltipPositionProvider(positioning = TooltipAnchorPosition.Above), | ||
| tooltip = { | ||
| RichTooltip { | ||
| Text(text = stringResource(key.title)) | ||
| } | ||
| }, | ||
| state = tooltipState | ||
| ) { | ||
| SegmentedButton( | ||
| selected = key == selectedOption, | ||
| onClick = { onSelectOption(key) }, | ||
| shape = SegmentedButtonDefaults | ||
| .itemShape(index = index, count = PlayerType.entries.size) | ||
| ) { | ||
| Icon( | ||
| imageVector = key.icon, | ||
| contentDescription = stringResource(key.title) | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @PreviewWrapper(ThemePreviewProvider::class) | ||
| @PreviewLightDark | ||
| @Composable | ||
| private fun PlayerOptionsPreview() { | ||
| PlayerOptions( | ||
| selectedOption = PlayerType.MAIN, | ||
| onSelectOption = {} | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion you shouldn't add Compose code in the non-UI player one. The player has already a lot of dependencies breaking separation concerns.