Skip to content

Commit

Permalink
Added Spotify Lite, latest version below the mod description and gene…
Browse files Browse the repository at this point in the history
…ral optimization
  • Loading branch information
BobbyESP committed Nov 26, 2022
1 parent 52a74a6 commit c81d719
Show file tree
Hide file tree
Showing 9 changed files with 300 additions and 126 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ apply(plugin = "dagger.hilt.android.plugin")

val versionMajor = 0
val versionMinor = 2
val versionPatch = 0
val versionPatch = 1
val versionBuild = 0
val isStable = true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ data class APICallState(
Amoled_Latest = "",
RC_Latest = "",
ABC_Latest = "",
Lite_Latest = "",
Regular = emptyList(),
Amoled = emptyList(),
Regular_Cloned = emptyList(),
Amoled_Cloned = emptyList()
Amoled_Cloned = emptyList(),
Lite = emptyList()
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ data class APIResponse(
val RC_Latest: String,
@SerializedName("ABC_Latest")
val ABC_Latest: String,
@SerializedName("Lite_Latest")
val Lite_Latest: String,
@SerializedName("Regular")
val Regular: List<PackagesObject>,
@SerializedName("Amoled")
val Amoled: List<PackagesObject>,
@SerializedName("Regular_Cloned")
val Regular_Cloned: List<PackagesObject>,
@SerializedName("Amoled_Cloned")
val Amoled_Cloned: List<PackagesObject>
val Amoled_Cloned: List<PackagesObject>,
@SerializedName("Lite")
val Lite: List<PackagesObject>
) {
var status: Status = Status.SUCCESS
var message: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@ class MainActivity : ComponentActivity() {
icon = Icons.Filled.Home,
route = Route.HOME
),
/*NavBarItem(
name = stringResource(id = R.string.settings),
icon = Icons.Filled.Settings,
route = Route.SETTINGS,
),*/
NavBarItem(
name = stringResource(id = R.string.searcher),
icon = Icons.Filled.Search,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package com.bobbyesp.spowlo.presentation.ui.components

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ExpandLess
Expand All @@ -13,12 +17,15 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times
import com.bobbyesp.spowlo.R
import com.bobbyesp.spowlo.domain.spotify.model.PackagesObject
import com.bobbyesp.spowlo.presentation.MainActivity
Expand Down Expand Up @@ -46,6 +53,10 @@ enum class PackagesListItemType(
AmoledCloned(
R.string.amoled_cloned,
R.string.amoled_cloned_description
),
Lite(
R.string.lite,
R.string.lite_description
)
}

Expand All @@ -56,6 +67,7 @@ fun PackagesListItem(
type: PackagesListItemType = PackagesListItemType.Regular,
expanded: Boolean = false,
packages: List<PackagesObject>,
latestVersion: String = "Unknown",
onClick: () -> Unit = {},
) {
var isExpanded by remember { mutableStateOf(expanded) }
Expand All @@ -65,8 +77,9 @@ fun PackagesListItem(
ElevatedCard(
modifier = modifier,
onClick = { isExpanded = !isExpanded },
shape = MaterialTheme.shapes.small) {
Box{
shape = MaterialTheme.shapes.small
) {
Box {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -96,17 +109,53 @@ fun PackagesListItem(
color = MaterialTheme.colorScheme.onSurfaceVariant,
overflow = TextOverflow.Ellipsis
)
Divider(modifier = Modifier.padding(top = 6.dp, bottom = 6.dp))

Row(
modifier = Modifier.weight(1f),
modifier = Modifier
.fillMaxWidth()
.padding(bottom = 4.dp),
verticalAlignment = Alignment.CenterVertically
){
Spacer(modifier = Modifier
.weight(1f, true))
) {
Text(
text = stringResource(id = R.string.latest_version),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontStyle = FontStyle.Italic,
fontWeight = FontWeight.Bold
)

val animatedDegree = animateFloatAsState(targetValue = if (isExpanded) 0f else -180f)
Box(modifier = Modifier
.padding(2.dp)
.align(Alignment.Bottom)){
.fillMaxWidth()
.wrapContentSize(Alignment.CenterEnd)){
Text(
modifier = Modifier,
text = latestVersion,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontStyle = FontStyle.Italic,
fontWeight = FontWeight.Bold,
overflow = TextOverflow.Ellipsis
)
}
}

Row(
modifier = Modifier.weight(1f),
verticalAlignment = Alignment.CenterVertically
) {
Spacer(
modifier = Modifier
.weight(1f, true)
)
val animatedDegree =
animateFloatAsState(targetValue = if (isExpanded) 0f else -180f)

Box(
modifier = Modifier
.padding(2.dp)
.align(Alignment.Bottom)
) {
FilledTonalIconButton(
modifier = Modifier
.padding()
Expand All @@ -125,38 +174,57 @@ fun PackagesListItem(
}
}
AnimatedVisibility(visible = isExpanded) {
Box{
Column(modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 6.dp)
) {
packages.forEach { version ->
val title = packages[packages.indexOf(version)].Title
val link = packages[packages.indexOf(version)].Link
//if the package title has ARM64-V8A, the type is Arm64
val isArm64: Boolean = title.contains("ARM64-V8A")
val containsArch: Boolean = title.contains("(ARM64-V8A)") || title.contains("ARMEABI-V7A")
//get just the version name without the architecture
val versionName = if (containsArch) title.substringBefore("(").trim() else title
PackageItem(
modifier = Modifier
.fillMaxWidth(),
//if its Arm64, ArchType is Arm64, else ArchType is Arm
type = if (isArm64) ArchType.Arm64 else ArchType.Arm,
version = versionName,
link = link,
//on click open the link in browser
onClick = { DownloadUtil.openLinkInBrowser(link) },
onArchClick = {show = !show},
onCopyClick = {DownloadUtil.copyLinkToClipboard(link)}
Box {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 6.dp)
//adjust the size of the column to the quantity of items
.height(
when {
packages.size <= 2 -> 84.dp
else -> packages.size * 18.dp
}
)
) {
LazyColumn {
items(
items = packages,
) { packageObject ->
val title = packageObject.Title
val link = packageObject.Link

//if the package title has ARM64-V8A, the type is Arm64
val isArm64: Boolean = title.contains("ARM64-V8A")

val containsArch: Boolean =
title.contains("(ARM64-V8A)") || title.contains("ARMEABI-V7A")

//Get just the version name without the architecture
val versionName =
if (containsArch) title.substringBefore("(").trim() else title

if (packages.indexOf(version) != packages.lastIndex) {
Divider(
PackageItem(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp)
.fillMaxWidth(),
//if its Arm64, ArchType is Arm64, else ArchType is Arm
type = if (isArm64) ArchType.Arm64 else ArchType.Arm,
version = versionName,
link = link,
//on click open the link in browser
onClick = { DownloadUtil.openLinkInBrowser(link) },
onArchClick = { show = !show },
onCopyClick = { DownloadUtil.copyLinkToClipboard(link) }
)

//the last item of the lazy column will not have divider
if (packageObject != packages.last()) {
Divider(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp)
)
}
}
}
}
Expand All @@ -173,19 +241,26 @@ fun PackagesListItem(
),
) {
// content
Surface(modifier = Modifier, shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)) {
Column(modifier = Modifier
.fillMaxWidth()
.padding(16.dp)) {
Surface(
modifier = Modifier,
shape = RoundedCornerShape(topStart = 16.dp, topEnd = 16.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(16.dp)
) {
Text(
text = stringResource(id = R.string.architectures),
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.titleMedium,
fontWeight = FontWeight.Bold,
)
Text(text = stringResource(id = R.string.archs_desc),
Text(
text = stringResource(id = R.string.archs_desc),
modifier = Modifier,
style = MaterialTheme.typography.bodySmall)
style = MaterialTheme.typography.bodySmall
)

Divider(
modifier = Modifier
Expand Down Expand Up @@ -223,10 +298,39 @@ fun PackagesListItem(

@Composable
@Preview
fun CardPreview(){
fun CardPreview() {
Column() {
// PackagesListItem( type = PackagesListItemType.RegularCloned, expanded = true, versions = listOf("1.0.0", "1.0.1", "1.0.2").random(), archs = listOf(ArchType.Arm64, ArchType.Arm).random())
// PackagesListItem( type = PackagesListItemType.RegularCloned, expanded = true, versions = listOf("1.0.0", "1.0.1", "1.0.2").random(), archs = listOf(ArchType.Arm64, ArchType.Arm).random())
//PackagesListItem(type = PackagesListItemType.Amoled, expanded = true, versions = listOf("1.0.0", "1.0.1", "1.0.2").random(), archs = listOf(ArchType.Arm64, ArchType.Arm).random())
}
}

//create a scrollbar for the lazy column
@Composable
fun Scrollbar(
modifier: Modifier = Modifier,
scrollState: ScrollState,
itemCount: Int,
averageItemSize: Dp
) {
val thumbHeight = with(LocalDensity.current) {
(scrollState.maxValue / itemCount * averageItemSize.toPx()).toDp()
}
val thumbOffset = with(LocalDensity.current) {
(scrollState.value / itemCount * averageItemSize.toPx()).toDp()
}
Box(
modifier = modifier
.fillMaxHeight()
.width(8.dp)
.padding(horizontal = 4.dp)
) {
Box(
Modifier
.fillMaxWidth()
.height(thumbHeight)
.offset(y = thumbOffset)
.background(MaterialTheme.colorScheme.onPrimaryContainer)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.runtime.*
import androidx.compose.runtime.saveable.rememberSaveable
Expand Down Expand Up @@ -86,15 +87,15 @@ fun InitialEntry(homeViewModel: HomeViewModel,
}
}

val homeviewState = homeViewModel.stateFlow.collectAsState()
val homeViewState = homeViewModel.stateFlow.collectAsState()
val searcherViewState = searcherViewModel.stateFlow.collectAsState()


Box(modifier = modifier){
Box(
modifier = Modifier
.fillMaxSize()
.background(androidx.compose.material3.MaterialTheme.colorScheme.background)
.background(MaterialTheme.colorScheme.background)
){
AnimatedNavHost(
modifier = Modifier
Expand All @@ -111,7 +112,7 @@ fun InitialEntry(homeViewModel: HomeViewModel,

animatedComposable(Route.HOME){
HomePage(navController = navController, homeViewModel = homeViewModel)
if (!homeviewState.value.loaded){
if (!homeViewState.value.loaded){
homeViewModel.setup()
}
}
Expand Down
Loading

0 comments on commit c81d719

Please sign in to comment.