Skip to content

Commit

Permalink
Optimized the code, added copy link to clipboard and added architectu…
Browse files Browse the repository at this point in the history
…res explanation.
  • Loading branch information
BobbyESP committed Nov 9, 2022
1 parent ad45079 commit ec172b2
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 26 deletions.
4 changes: 3 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id("kotlin-android")
id("kotlin-kapt")
id("org.jetbrains.kotlin.android")
kotlin("plugin.serialization") version "1.7.10"
kotlin("plugin.serialization") version "1.7.20"
}
apply(plugin = "dagger.hilt.android.plugin")

Expand Down Expand Up @@ -156,10 +156,12 @@ dependencies {
implementation("com.google.accompanist:accompanist-permissions:$accompanistVersion")
implementation("com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion")
implementation("io.coil-kt:coil-compose:$coilVersion")
implementation("com.holix.android:bottomsheetdialog-compose:1.0.3")

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.4.1")

implementation("androidx.hilt:hilt-navigation-compose:1.0.0")
implementation("androidx.browser:browser:1.4.0")
kapt("androidx.hilt:hilt-compiler:1.0.0")
implementation("com.google.dagger:hilt-android:$hiltVersion")
kapt("com.google.dagger:hilt-android-compiler:$hiltVersion")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.bobbyesp.spowlo.presentation.ui.components

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ExpandLess
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.bobbyesp.spowlo.R

enum class ArchExplType(
val type: String,
val archDescription: String,
val description: Int,
val archType: ArchType = ArchType.Arm64
) {
Arm64("ARM64-v8a", "64-bit ARM", R.string.arm64_desc, ArchType.Arm64),
Arm("ARMEABI-v7a", "32-bit ARM", R.string.arm32_desc, ArchType.Arm),
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ArchExplanationComponent(
type : ArchExplType,
expanded: Boolean = false
) {
var isExpanded by remember { mutableStateOf(expanded) }

ElevatedCard(
modifier = Modifier,
onClick = { isExpanded = !isExpanded },
shape = MaterialTheme.shapes.small
) {
Box {
Row(
modifier = Modifier
.fillMaxWidth()
.height(IntrinsicSize.Min)
.padding(4.dp)
) {
Column(
modifier = Modifier
.padding(vertical = 6.dp)
.padding(end = 6.dp)
.padding(start = 2.dp)
.weight(1f)
.fillMaxHeight(),
verticalArrangement = Arrangement.Top
) {
Text(
text = type.type,
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
maxLines = 2,
overflow = TextOverflow.Ellipsis
)
Text(
modifier = Modifier.padding(top = 6.dp),
text = type.archDescription,
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
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()
.size(24.dp),
onClick = { isExpanded = !isExpanded }) {
Icon(
Icons.Outlined.ExpandLess,
null,
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier.rotate(animatedDegree.value)
)
}
}
}
}
}
}
AnimatedVisibility(visible = isExpanded) {
Box(modifier = Modifier
.align(Alignment.CenterHorizontally)) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 8.dp, bottom = 4.dp, start = 4.dp, end = 4.dp),
horizontalArrangement = Arrangement.Center,
verticalAlignment = Alignment.CenterVertically
) {
ArchTag(arch = type.archType)
Text(
text = stringResource(id = type.description),
modifier = Modifier.padding(start = 6.dp),
style = MaterialTheme.typography.bodySmall,
)
}
}
}
}
}

@Preview
@Composable
fun previewArchExplanationComponent() {
ArchExplanationComponent(type = ArchExplType.Arm64)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Download
import androidx.compose.material.icons.filled.Memory
import androidx.compose.material.icons.outlined.Download
import androidx.compose.material.icons.outlined.ExpandLess
import androidx.compose.material.icons.outlined.MoreHoriz
import androidx.compose.material.icons.outlined.*
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -31,16 +29,18 @@ fun PackageItem(
type: ArchType = ArchType.Arm64,
link: String,
onClick: () -> Unit = {},
onArchClick: () -> Unit = {},
version: String = "8.7.78.373",
onLongClick: () -> Unit = {}
onLongClick: () -> Unit = {},
onCopyClick: () -> Unit = {},
) {
Surface(modifier = modifier.clickable(onClick = onClick).padding(6.dp)) {
Row(
modifier = modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
ArchTag(modifier = Modifier.height(IntrinsicSize.Max).width(IntrinsicSize.Max) ,arch = type)
ArchTag(modifier = Modifier.height(IntrinsicSize.Max).width(IntrinsicSize.Max) ,arch = type, onClick = onArchClick)
Text(
modifier = Modifier.padding(start = 8.dp).height(IntrinsicSize.Max).width(IntrinsicSize.Min),
text = version,
Expand All @@ -60,7 +60,7 @@ fun PackageItem(
.padding(end = 12.dp)
.align(Alignment.Bottom)
.size(24.dp),
onClick = {}
onClick = onClick
) {
Icon(
Icons.Filled.Download,
Expand All @@ -75,13 +75,14 @@ fun PackageItem(
.padding()
.align(Alignment.Bottom)
.size(24.dp),
onClick = {}
onClick = onCopyClick
) {
Icon(
Icons.Outlined.MoreHoriz,
Icons.Outlined.ContentCopy,
//Icons.Outlined.MoreHoriz,
contentDescription = null,
tint = MaterialTheme.colorScheme.onPrimaryContainer,
modifier = Modifier
modifier = Modifier.size(18.dp)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.bobbyesp.spowlo.presentation.ui.components
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ExpandLess
import androidx.compose.material3.*
Expand All @@ -11,7 +12,10 @@ import androidx.compose.ui.Alignment
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.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
Expand All @@ -20,6 +24,8 @@ import com.bobbyesp.spowlo.domain.spotify.model.PackagesObject
import com.bobbyesp.spowlo.presentation.MainActivity
import com.bobbyesp.spowlo.presentation.ui.pages.home.HomeViewModel
import com.bobbyesp.spowlo.util.DownloadUtil
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialog
import com.holix.android.bottomsheetdialog.compose.BottomSheetDialogProperties

enum class PackagesListItemType(
val type: Int,
Expand Down Expand Up @@ -53,8 +59,9 @@ fun PackagesListItem(
onClick: () -> Unit = {},
) {
var isExpanded by remember { mutableStateOf(expanded) }


var show by remember {
mutableStateOf(false)
}
ElevatedCard(
modifier = modifier,
onClick = { isExpanded = !isExpanded },
Expand Down Expand Up @@ -124,20 +131,24 @@ fun PackagesListItem(
.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 = packages[packages.indexOf(version)].Title.contains("ARM64-V8A")
val containsArch: Boolean = packages[packages.indexOf(version)].Title.contains("(ARM64-V8A)") || packages[packages.indexOf(version)].Title.contains("ARMEABI-V7A")
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) packages[packages.indexOf(version)].Title.substringBefore("(").trim() else packages[packages.indexOf(version)].Title
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 = packages[packages.indexOf(version)].Link,
link = link,
//on click open the link in browser
onClick = { DownloadUtil.openLinkInBrowser(packages[packages.indexOf(version)].Link) }
onClick = { DownloadUtil.openLinkInBrowser(link) },
onArchClick = {show = !show},
onCopyClick = {DownloadUtil.copyLinkToClipboard(link)}
)

if (packages.indexOf(version) != packages.lastIndex) {
Expand All @@ -152,6 +163,62 @@ fun PackagesListItem(
}
}
}
if (show) {
BottomSheetDialog(
onDismissRequest = {
show = false
},
properties = BottomSheetDialogProperties(

),
) {
// content
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),
modifier = Modifier,
style = MaterialTheme.typography.bodySmall)

Divider(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 6.dp)
.width(1f.dp)
)
Text(
text = stringResource(id = R.string.archs_provided),
modifier = Modifier,
style = MaterialTheme.typography.bodySmall,
)
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stringResource(id = R.string.different_archs),
modifier = Modifier,
style = MaterialTheme.typography.bodySmall,
)
Spacer(modifier = Modifier.height(6.dp))
ArchExplanationComponent(type = ArchExplType.Arm64)
Spacer(modifier = Modifier.height(8.dp))
ArchExplanationComponent(type = ArchExplType.Arm)
Spacer(modifier = Modifier.height(6.dp))
Text(
text = stringResource(id = R.string.check_arch),
modifier = Modifier,
style = MaterialTheme.typography.bodySmall,
)

}
}
}
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ fun HomePage(navController: NavController, homeViewModel: HomeViewModel = hiltVi
style = MaterialTheme.typography.displaySmall
)
}
PackagesListItem( type = PackagesListItemType.Regular, expanded = false, onClick = {}, packages = regularVersions.sortedByDescending { it.Title })
PackagesListItem( type = PackagesListItemType.RegularCloned, expanded = false, onClick = {}, packages = regularClonedVersions.sortedByDescending { it.Title })
PackagesListItem( type = PackagesListItemType.Amoled, expanded = false, onClick = {}, packages = amoledVersions.sortedByDescending { it.Title })
PackagesListItem( type = PackagesListItemType.AmoledCloned, expanded = false, onClick = {}, packages = amoledClonedVersions.sortedByDescending { it.Title })
PackagesListItem( type = PackagesListItemType.Regular, expanded = false, onClick = {}, packages = regularVersions)
PackagesListItem( type = PackagesListItemType.RegularCloned, expanded = false, onClick = {}, packages = regularClonedVersions)
PackagesListItem( type = PackagesListItemType.Amoled, expanded = false, onClick = {}, packages = amoledVersions)
PackagesListItem( type = PackagesListItemType.AmoledCloned, expanded = false, onClick = {}, packages = amoledClonedVersions)
Divider(modifier = Modifier.padding(top = 16.dp, bottom = 14.dp))
AnimatedVisibility(visible = loaded) {
when(loaded){
Expand Down
Loading

0 comments on commit ec172b2

Please sign in to comment.