-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make language item display the current language and make language men…
…u accessible in audio player
- Loading branch information
Showing
4 changed files
with
114 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
83 changes: 83 additions & 0 deletions
83
new-player/src/main/java/net/newpipe/newplayer/ui/common/LanguageMenu.kt
This file contains 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,83 @@ | ||
/* NewPlayer | ||
* | ||
* @author Christian Schabesberger | ||
* | ||
* Copyright (C) NewPipe e.V. 2024 <code(at)newpipe-ev.de> | ||
* | ||
* NewPlayer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* NewPlayer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with NewPlayer. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package net.newpipe.newplayer.ui.common | ||
|
||
import androidx.annotation.OptIn | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Translate | ||
import androidx.compose.material3.DropdownMenu | ||
import androidx.compose.material3.DropdownMenuItem | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.media3.common.util.UnstableApi | ||
import net.newpipe.newplayer.R | ||
import net.newpipe.newplayer.logic.TrackUtils | ||
import net.newpipe.newplayer.uiModel.InternalNewPlayerViewModel | ||
import net.newpipe.newplayer.uiModel.NewPlayerUIState | ||
import net.newpipe.newplayer.uiModel.UIModeState | ||
import java.util.Locale | ||
|
||
@OptIn(UnstableApi::class) | ||
@Composable | ||
internal fun LanguageMenu(uiState: NewPlayerUIState, viewModel: InternalNewPlayerViewModel, isVisible: Boolean, makeInvisible: () -> Unit) { | ||
val availableLanguages = TrackUtils.getAvailableLanguages(uiState.currentlyAvailableTracks) | ||
|
||
DropdownMenu(expanded = isVisible, onDismissRequest = { | ||
makeInvisible() | ||
viewModel.dialogVisible(false) | ||
}) { | ||
for (language in availableLanguages) { | ||
val locale = Locale(language) | ||
|
||
DropdownMenuItem( | ||
text = { | ||
Text(locale.displayLanguage) | ||
}, | ||
onClick = { /*TODO*/ makeInvisible() | ||
viewModel.dialogVisible(false) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
|
||
@OptIn(UnstableApi::class) | ||
@Composable | ||
internal fun LanguageMenuItem(uiState: NewPlayerUIState, onClick: () -> Unit) { | ||
val availableLanguages = TrackUtils.getAvailableLanguages(uiState.currentlyAvailableTracks) | ||
|
||
if (2 <= availableLanguages.size) { | ||
val language = TrackUtils.getAvailableLanguages(uiState.currentlyAvailableTracks)[0] | ||
val locale = Locale(language) | ||
DropdownMenuItem(text = { Text(locale.displayLanguage) }, | ||
leadingIcon = { | ||
Icon( | ||
imageVector = Icons.Filled.Translate, | ||
contentDescription = String.format( | ||
stringResource(R.string.menu_selected_language_item), | ||
locale.displayLanguage | ||
) | ||
) | ||
}, onClick = onClick) | ||
} | ||
} |
This file contains 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 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