Skip to content

Commit

Permalink
beaut: Improved the pager of the downloader bottom sheet and added a …
Browse files Browse the repository at this point in the history
…popup menu in the track page
  • Loading branch information
BobbyESP committed Mar 26, 2023
1 parent 9794182 commit 39b7da7
Show file tree
Hide file tree
Showing 8 changed files with 417 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
Expand All @@ -28,7 +27,6 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -102,7 +100,7 @@ fun SongCard(
)
Spacer(modifier = Modifier.width(6.dp))
LyricsIcon(
visible = isLyrics
visible = false //isLyrics
)
}
Spacer(Modifier.height(8.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,38 @@ import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ContentCopy
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.Divider
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilledTonalIconButton
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.PopupProperties
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.ui.components.MarqueeText
import com.bobbyesp.spowlo.ui.components.songs.ExplicitIcon
import com.bobbyesp.spowlo.ui.components.songs.LyricsIcon
import com.bobbyesp.spowlo.ui.pages.settings.about.LocalAsset
import com.bobbyesp.spowlo.utils.ChromeCustomTabsUtil


Expand All @@ -36,9 +52,11 @@ fun TrackComponent(
artists: String,
spotifyUrl: String,
hasLyrics: Boolean = false,
isExplicit : Boolean = false,
onClick: () -> Unit = { ChromeCustomTabsUtil.openUrl(spotifyUrl)}
isExplicit: Boolean = false,
onClick: () -> Unit = { ChromeCustomTabsUtil.openUrl(spotifyUrl) }
) {
val clipboardManager = LocalClipboardManager.current
val showDropdown = remember { mutableStateOf(false) }
Column(
modifier
.fillMaxWidth()
Expand Down Expand Up @@ -81,7 +99,7 @@ fun TrackComponent(
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
){
) {
MarqueeText(
text = artists,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.4f),
Expand All @@ -99,7 +117,73 @@ fun TrackComponent(
}
}
}
Icon(imageVector = Icons.Filled.Download, contentDescription = "Download icon", modifier = Modifier.weight(0.1f).padding(6.dp))
Column {
FilledTonalIconButton(onClick = {
showDropdown.value = !showDropdown.value
},
modifier = Modifier.size(32.dp),
) {
Icon(
imageVector = Icons.Filled.MoreVert,
contentDescription = "More options button",
modifier = Modifier
.weight(0.1f)
.padding(6.dp)
)
}

DropdownMenu(
expanded = showDropdown.value,
onDismissRequest = { showDropdown.value = false },
properties = PopupProperties(
dismissOnClickOutside = true,
dismissOnBackPress = true,
focusable = true,
),
) {
DropdownMenuItem(
onClick = onClick,
text = {
Text(text = stringResource(id = R.string.download))
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.Download,
contentDescription = "Download icon",
)
}
)
Divider()
DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.open_in_spotify))
}, onClick = {
ChromeCustomTabsUtil.openUrl(spotifyUrl)
},
leadingIcon = {
Icon(
imageVector = LocalAsset(id = R.drawable.spotify_logo),
contentDescription = "Spotify logo",
)
}
)

DropdownMenuItem(
onClick = {
clipboardManager.setText(AnnotatedString(spotifyUrl))
},
text = {
Text(text = stringResource(id = R.string.copy_link))
},
leadingIcon = {
Icon(
imageVector = Icons.Filled.ContentCopy,
contentDescription = "Copy link icon",
)
}
)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import android.os.Build
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Cancel
import androidx.compose.material.icons.outlined.Dataset
import androidx.compose.material.icons.outlined.DownloadDone
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Tab
import androidx.compose.material3.TabRow
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
Expand All @@ -29,9 +33,13 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
Expand Down Expand Up @@ -72,8 +80,7 @@ fun DownloaderBottomSheet(
}

val checkPermissionOrDownload = {
if (Build.VERSION.SDK_INT > 29 || storagePermission.status == PermissionStatus.Granted)
downloaderViewModel.startDownloadSong()
if (Build.VERSION.SDK_INT > 29 || storagePermission.status == PermissionStatus.Granted) downloaderViewModel.startDownloadSong()
else {
storagePermission.launchPermissionRequest()
}
Expand All @@ -95,10 +102,55 @@ fun DownloaderBottomSheet(
.background(MaterialTheme.colorScheme.background)
.navigationBarsPadding()
.clip(roundedTopShape)
.padding(8.dp)

) {
//I want to create a pager here with tabs at the top for each page
TabRow(selectedTabIndex = pagerState.currentPage) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Start,
verticalAlignment = Alignment.CenterVertically
) {
Icon(
imageVector = Icons.Outlined.DownloadDone,
contentDescription = null,
modifier = Modifier.padding(end = 8.dp, start = 8.dp),
tint = MaterialTheme.colorScheme.onSurface
)
Text(
text = stringResource(R.string.settings_before_download),
style = MaterialTheme.typography.headlineSmall,
modifier = Modifier
.padding(vertical = 12.dp),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
color = MaterialTheme.colorScheme.onSurface,
textAlign = TextAlign.Center,
fontWeight = FontWeight.Bold
)
}
Text(
text = stringResource(R.string.settings_before_download_text),
style = MaterialTheme.typography.bodySmall,
fontWeight = FontWeight.Bold,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center,
modifier = Modifier.align(Alignment.Start).padding(start = 8.dp)
)
IndicatorBehindScrollableTabRow(
selectedTabIndex = pagerState.currentPage,
indicator = { tabPositions ->
Box(
Modifier
.padding(vertical = 12.dp)
.tabIndicatorOffset(tabPositions[pagerState.currentPage])
.fillMaxHeight()
.clip(CircleShape)
.background(MaterialTheme.colorScheme.secondaryContainer)
)
},
edgePadding = 16.dp,
tabAlignment = Alignment.CenterStart,
) {
pages.forEachIndexed { index, page ->
Tab(
text = { Text(text = page) },
Expand All @@ -107,20 +159,22 @@ fun DownloaderBottomSheet(
scope.launch {
pagerState.animateScrollToPage(index)
}
}
},
)
}
}
HorizontalPager(pageCount = pages.size, state = pagerState) {
when (pages[it]) {
BottomSheetPages.MAIN -> {
Text(text = "Main page")
Text(text = "Main page", color = MaterialTheme.colorScheme.onSurface)
}

BottomSheetPages.SECONDARY -> {
Text(text = "Secondary page")
Text(text = "Secondary page", color = MaterialTheme.colorScheme.onSurface)
}

BottomSheetPages.TERTIARY -> {
Text(text = "Tertiary page")
Text(text = "Tertiary page", color = MaterialTheme.colorScheme.onSurface)
}
}
}
Expand Down
Loading

0 comments on commit 39b7da7

Please sign in to comment.