Skip to content
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

refactor(ui): Use AutoMirrored icons and migrated deprecated components #1631

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/src/main/java/com/junkfood/seal/ui/component/Buttons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.defaultMinSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.OpenInNew
import androidx.compose.material.icons.outlined.OpenInNew
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonColors
Expand Down Expand Up @@ -172,7 +173,7 @@ fun DismissButton(text: String = stringResource(R.string.dismiss), onClick: () -
fun LinkButton(
modifier: Modifier = Modifier,
text: String = stringResource(R.string.yt_dlp_docs),
icon: ImageVector = Icons.Outlined.OpenInNew,
icon: ImageVector = Icons.AutoMirrored.Outlined.OpenInNew,
link: String = ytdlpReference
) {
val uriHandler = LocalUriHandler.current
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/junkfood/seal/ui/component/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.outlined.HelpOutline
import androidx.compose.material.icons.outlined.SignalCellularConnectedNoInternet4Bar
import androidx.compose.material3.AlertDialog
Expand Down Expand Up @@ -59,7 +60,7 @@ fun HelpDialog(
AlertDialog(
onDismissRequest = onDismissRequest,
title = { Text(text = stringResource(id = R.string.how_does_it_work)) },
icon = { Icon(Icons.Outlined.HelpOutline, null) },
icon = { Icon(Icons.AutoMirrored.Outlined.HelpOutline, null) },
text = { Text(text = text) },
confirmButton = confirmButton,
dismissButton = dismissButton,
Expand Down Expand Up @@ -272,7 +273,7 @@ fun SealDialogVariant(
tonalElevation: Dp = AlertDialogDefaults.TonalElevation,
properties: DialogProperties = DialogProperties()
) {
AlertDialog(
BasicAlertDialog(
onDismissRequest = onDismissRequest,
modifier = modifier,
properties = properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,13 @@ fun CustomCommandTaskItem(
)
else
CircularProgressIndicator(
progress = { animatedProgress },
modifier = Modifier
.padding(8.dp)
.size(24.dp),
color = accentColor,
strokeWidth = 5.dp,
progress = animatedProgress,
color = accentColor
trackColor = ProgressIndicatorDefaults.circularDeterminateTrackColor,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.material3.AssistChipDefaults
import androidx.compose.material3.Divider
import androidx.compose.material3.ElevatedAssistChip
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -84,7 +85,7 @@ fun TaskLogPage(onNavigateBack: () -> Unit, taskHashCode: Int) {
.navigationBarsPadding(),
verticalArrangement = Arrangement.Center
) {
Divider(modifier = Modifier.fillMaxWidth())
HorizontalDivider(modifier = Modifier.fillMaxWidth())
Row(
Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.PlaylistAdd
import androidx.compose.material.icons.outlined.PlaylistAdd
import androidx.compose.material3.*
import androidx.compose.runtime.*
Expand Down Expand Up @@ -53,7 +54,7 @@ fun PlaylistSelectionDialog(
}
}
AlertDialog(onDismissRequest = { onDismissRequest() },
icon = { Icon(Icons.Outlined.PlaylistAdd, null) },
icon = { Icon(Icons.AutoMirrored.Outlined.PlaylistAdd, null) },
title = { Text(stringResource(R.string.download_range_selection)) },
text = {
Column {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.selection.selectable
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.PlaylistAdd
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.PlaylistAdd
import androidx.compose.material3.Checkbox
import androidx.compose.material3.Divider
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -116,7 +116,7 @@ fun PlaylistSelectionPage(onNavigateBack: () -> Unit = {}) {
.navigationBarsPadding(),
verticalArrangement = Arrangement.Center
) {
Divider(modifier = Modifier.fillMaxWidth())
HorizontalDivider(modifier = Modifier.fillMaxWidth())
Row(verticalAlignment = Alignment.CenterVertically) {
Row(
modifier = Modifier.selectable(selected = selectedItems.size == playlistCount && selectedItems.size != 0,
Expand Down Expand Up @@ -145,7 +145,7 @@ fun PlaylistSelectionPage(onNavigateBack: () -> Unit = {}) {
IconButton(modifier = Modifier.padding(end = 4.dp),
onClick = { showDialog = true }) {
Icon(
imageVector = Icons.Outlined.PlaylistAdd,
imageVector = Icons.AutoMirrored.Outlined.PlaylistAdd,
contentDescription = stringResource(
R.string.download_range_selection
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ fun InputUrl(
.clip(MaterialTheme.shapes.large),
)
else LinearProgressIndicator(
progress = progressAnimationValue,
progress = { progressAnimationValue },
modifier = Modifier
.weight(0.75f)
.clip(MaterialTheme.shapes.large),
Expand Down Expand Up @@ -599,8 +599,8 @@ fun VideoCardV2(
modifier = Modifier.fillMaxWidth(),
)
else LinearProgressIndicator(
progress = { progressAnimationValue / 100f },
modifier = Modifier.fillMaxWidth(),
progress = progressAnimationValue / 100f,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.junkfood.seal.ui.page.downloadv2

import android.content.Intent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.Spring
import androidx.compose.animation.core.VisibilityThreshold
import androidx.compose.animation.core.spring
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi
Expand Down Expand Up @@ -35,7 +37,6 @@ import androidx.compose.material.icons.outlined.Delete
import androidx.compose.material.icons.outlined.Edit
import androidx.compose.material.icons.outlined.FileDownload
import androidx.compose.material.icons.outlined.Subtitles
import androidx.compose.material.icons.rounded.Download
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
Expand Down Expand Up @@ -73,6 +74,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.junkfood.seal.Downloader
Expand Down Expand Up @@ -108,9 +110,9 @@ import com.junkfood.seal.util.VIDEO_CLIP
import com.junkfood.seal.util.VideoClip
import com.junkfood.seal.util.VideoInfo
import com.junkfood.seal.util.toHttpsUrl
import kotlinx.coroutines.delay
import kotlin.math.min
import kotlin.math.roundToInt
import kotlinx.coroutines.delay

private const val TAG = "FormatPage"

Expand Down Expand Up @@ -882,7 +884,13 @@ private fun SubtitleSelectionDialog(
for ((code, formats) in suggestedSubtitlesFiltered) {
item(key = code) {
DialogCheckBoxItem(
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(
fadeInSpec = null, fadeOutSpec = null,
placementSpec = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset.VisibilityThreshold
)
),
checked = selectedSubtitles.contains(code),
onClick = {
if (selectedSubtitles.contains(code)) {
Expand All @@ -906,7 +914,14 @@ private fun SubtitleSelectionDialog(
for ((code, formats) in autoCaptionsFiltered) {
item(key = code) {
DialogCheckBoxItem(
modifier = Modifier.animateItemPlacement(),
modifier = Modifier.animateItem(
fadeInSpec = null,
fadeOutSpec = null,
placementSpec = spring(
stiffness = Spring.StiffnessMediumLow,
visibilityThreshold = IntOffset.VisibilityThreshold
)
),
checked = selectedSubtitles.contains(code),
onClick = {
if (selectedSubtitles.contains(code)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.junkfood.seal.ui.page.settings.about

import android.util.Log
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.text.ClickableText
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.ContactSupport
import androidx.compose.material.icons.outlined.AutoAwesome
import androidx.compose.material.icons.outlined.ContactSupport
import androidx.compose.material.icons.outlined.Description
import androidx.compose.material.icons.outlined.Info
import androidx.compose.material.icons.outlined.NewReleases
Expand Down Expand Up @@ -38,11 +38,13 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.ExperimentalTextApi
import androidx.compose.ui.text.LinkAnnotation
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.UrlAnnotation
import androidx.compose.ui.text.TextLinkStyles
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.text.withLink
import androidx.compose.ui.tooling.preview.Preview
import com.junkfood.seal.App
import com.junkfood.seal.App.Companion.packageInfo
Expand Down Expand Up @@ -131,7 +133,7 @@ fun AboutPage(
PreferenceItem(
title = stringResource(R.string.github_issue),
description = stringResource(R.string.github_issue_desc),
icon = Icons.Outlined.ContactSupport,
icon = Icons.AutoMirrored.Outlined.ContactSupport,
) { openUrl(githubIssueUrl) }
}
item {
Expand Down Expand Up @@ -199,7 +201,6 @@ fun AboutPage(
})
}

@OptIn(ExperimentalTextApi::class)
@Composable
@Preview
fun AutoUpdateUnavailableDialog(onDismissRequest: () -> Unit = {}) {
Expand All @@ -212,22 +213,27 @@ fun AutoUpdateUnavailableDialog(onDismissRequest: () -> Unit = {}) {
)

val annotatedString = buildAnnotatedString {
append(text)
append(text.substring(0, text.indexOf(hyperLinkText)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if the hyperLinkText is not at the end of the text?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the hyperLinkText is being a parameter for another string there is no other way than doing a substring for putting the style and click listening in the new implementation.

In this case I believe that the current implementation is well done. Modifying the string resource is not viable. Any ideas are welcome.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only thing I think that might be okay, but tell me some other options If you are not comfortable with the changes and I'll do them. Thanks!

    val annotatedString = buildAnnotatedString {
        append(text.substring(0, text.indexOf(hyperLinkText)))

        withLink(
            LinkAnnotation.Clickable(
                tag = "Link to the latest app release in GitHub",
                styles = TextLinkStyles(
                    SpanStyle(
                        color = MaterialTheme.colorScheme.tertiary,
                        textDecoration = TextDecoration.Underline,
                    )
                ),
                linkInteractionListener = { _ ->
                    uriHandler.openUri("https://github.com/JunkFood02/Seal/releases/latest")
                    hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
                }
            )
        ) {
            append(hyperLinkText)
        }
    }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really understand what you meant on this:

  1. There's an addLink() which is a drop-in replacement of the addUrlAnnotation here
  2. If you'd go with withLink(), you should append the rest of the text which is after the hyperLinkText (if exist)
        append(text.substring(0, startIndex))
        //...
        append(hyperLinkText)
        //...
        append(text.substring(endIndex, text.length))

val startIndex = text.indexOf(hyperLinkText)
val endIndex = startIndex + hyperLinkText.length
addUrlAnnotation(
UrlAnnotation("https://github.com/JunkFood02/Seal/releases/latest"),
start = startIndex,
end = endIndex
)
addStyle(
SpanStyle(
color = MaterialTheme.colorScheme.tertiary,
textDecoration = TextDecoration.Underline,
), start = startIndex,
end = endIndex
)

withLink(
LinkAnnotation.Clickable(
tag = "Link to the latest app release in GitHub",
styles = TextLinkStyles(
SpanStyle(
color = MaterialTheme.colorScheme.tertiary,
textDecoration = TextDecoration.Underline,
)
),
linkInteractionListener = { _ ->
uriHandler.openUri("https://github.com/JunkFood02/Seal/releases/latest")
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
)
) {
append(text.substring(startIndex, endIndex))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

}
}
AlertDialog(
onDismissRequest = onDismissRequest,
Expand All @@ -244,16 +250,11 @@ fun AutoUpdateUnavailableDialog(onDismissRequest: () -> Unit = {}) {
)
},
text = {
ClickableText(
Text(
text = annotatedString,
onClick = { index ->
annotatedString.getUrlAnnotations(index, index).firstOrNull()?.let {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
uriHandler.openUri(it.item.url)
}
},
style = MaterialTheme.typography.bodyMedium.copy(MaterialTheme.colorScheme.onSurfaceVariant)
)
})
}
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ fun AppearancePreferences(
}
}

HorizontalPagerIndicator(pagerState = pagerState,
HorizontalPagerIndicator(
pagerState = pagerState,
pageCount = pageCount,
modifier = Modifier
.clearAndSetSemantics { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.AssignmentReturn
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
import androidx.compose.material.icons.outlined.Add
import androidx.compose.material.icons.outlined.AssignmentReturn
import androidx.compose.material.icons.outlined.BookmarkAdd
Expand Down Expand Up @@ -157,7 +159,7 @@ fun TemplateListPage(onNavigateBack: () -> Unit, onNavigateToEditPage: (Int) ->
showHelpDialog = true
}) {
Icon(
imageVector = Icons.Outlined.HelpOutline,
imageVector = Icons.AutoMirrored.Outlined.HelpOutline,
contentDescription = stringResource(
id = R.string.how_does_it_work
)
Expand Down Expand Up @@ -200,7 +202,7 @@ fun TemplateListPage(onNavigateBack: () -> Unit, onNavigateToEditPage: (Int) ->
})
DropdownMenuItem(leadingIcon = {
Icon(
Icons.Outlined.AssignmentReturn, null
Icons.AutoMirrored.Outlined.AssignmentReturn, null
)
}, text = {
Text(stringResource(R.string.import_from_clipboard))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.outlined.Sort
import androidx.compose.material.icons.outlined.ArtTrack
import androidx.compose.material.icons.outlined.AudioFile
import androidx.compose.material.icons.outlined.ContentCut
Expand Down Expand Up @@ -273,7 +274,7 @@ fun DownloadFormatPreferences(onNavigateBack: () -> Unit, navigateToSubtitlePage
}
item {
PreferenceSwitchWithDivider(title = stringResource(id = R.string.format_sorting),
icon = Icons.Outlined.Sort,
icon = Icons.AutoMirrored.Outlined.Sort,
description = stringResource(id = R.string.format_sorting_desc),
enabled = !isCustomCommandEnabled,
isChecked = isFormatSortingEnabled,
Expand Down
Loading
Loading