feat: sorta reworked the dashboard screen

This commit is contained in:
baiorett 2022-08-23 23:11:14 +03:00
parent 27f3d315cc
commit 4daacf0e91
No known key found for this signature in database
GPG Key ID: 4CADF41C3EA7DE4A
8 changed files with 233 additions and 51 deletions

View File

@ -22,11 +22,12 @@ fun ApplicationItem(
ExpandableCard(
content = { arrowButton ->
Row(
modifier = Modifier.fillMaxWidth(),
modifier = Modifier.fillMaxSize(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {
Row(
modifier = Modifier.height(68.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
) {

View File

@ -4,20 +4,21 @@ import androidx.compose.animation.animateContentSize
import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.rotate
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.revanced.manager.R
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun ExpandableCard(
content: @Composable (arrowButton: @Composable () -> Unit) -> Unit,
@ -29,6 +30,7 @@ fun ExpandableCard(
Card(
modifier = Modifier
.fillMaxWidth()
.defaultMinSize(minHeight = 68.dp)
.animateContentSize(
animationSpec = tween(
durationMillis = 300,
@ -56,9 +58,10 @@ fun ExpandableCard(
contentDescription = stringResource(R.string.expand)
)
}
AssistChip(onClick = { /*TODO*/ }, label = {Text("Update")}, shape = CircleShape)
}
if (expandedState) {
Box(modifier = Modifier.padding(bottom = 8.dp)) {
Box(modifier = Modifier.padding(bottom = 16.dp)) {
expandedContent()
}
}

View File

@ -23,6 +23,5 @@ enum class DashboardDestination(
@StringRes val label: Int
) : Destination {
DASHBOARD(Icons.Default.Dashboard, R.string.dashboard),
PATCHER(Icons.Default.Build, R.string.patcher),
SETTINGS(Icons.Default.Settings, R.string.settings),
PATCHER(Icons.Default.Build, R.string.patcher)
}

View File

@ -8,10 +8,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.Dashboard
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
@ -26,6 +23,7 @@ import app.revanced.manager.ui.component.HeadlineWithCard
import app.revanced.manager.ui.viewmodel.DashboardViewModel
import org.koin.androidx.compose.getViewModel
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DashboardScreen(viewModel: DashboardViewModel = getViewModel()) {
val context = LocalContext.current
@ -38,7 +36,7 @@ fun DashboardScreen(viewModel: DashboardViewModel = getViewModel()) {
.padding(horizontal = 18.dp)
.verticalScroll(state = rememberScrollState()),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(8.dp)
verticalArrangement = Arrangement.spacedBy(18.dp)
) {
HeadlineWithCard(R.string.updates) {
Row(
@ -65,51 +63,36 @@ fun DashboardScreen(viewModel: DashboardViewModel = getViewModel()) {
Toast.makeText(context, "Already up-to-date!", Toast.LENGTH_SHORT)
.show()
},
) { Text(stringResource(R.string.update_manager)) }
) { Text(stringResource(R.string.update_patch_bundle)) }
}
}
}
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Text(
text = "No updates available",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontSize = 10.sp,
text = "Patched Applications",
style = MaterialTheme.typography.headlineSmall
)
}
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
FilterChip(selected = true, onClick = { /*TODO*/ }, label = {
Text("Updates Available")
})
FilterChip(selected = false, onClick = { /*TODO*/ }, label = {
Text("Installed")
})
}
HeadlineWithCard(R.string.patched_apps) {
Row(
modifier = Modifier
.padding(horizontal = padHoriz, vertical = padVert)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column {
val amount = 2 // TODO
Text(
text = "${stringResource(R.string.updates_available)}: $amount",
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
fontSize = 18.sp
)
}
Button(
enabled = true, // needs update
onClick = {
Toast.makeText(context, "Already up-to-date!", Toast.LENGTH_SHORT).show()
}
) { Text(stringResource(R.string.update_all)) }
}
Column(
modifier = Modifier
.padding(horizontal = padHoriz)
.padding(bottom = padVert)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp)
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
ApplicationItem(
name = "ReVanced",
released = "Released 2 days ago",
released = "com.google.android.youtube",
icon = { Icon(Icons.Default.Dashboard, "ReVanced") }
) {
ChangelogText(

View File

@ -31,7 +31,7 @@ fun MainRootScreen(navigator: BackstackNavigator<AppDestination>) {
.fillMaxSize()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
SmallTopAppBar(
LargeTopAppBar(
title = {
Text(
text = stringResource(mainRootNavigator.currentDestination.label),
@ -64,11 +64,9 @@ fun MainRootScreen(navigator: BackstackNavigator<AppDestination>) {
) { destination ->
when (destination) {
DashboardDestination.DASHBOARD -> DashboardScreen()
DashboardDestination.PATCHER -> DashboardScreen()
DashboardDestination.SETTINGS -> SettingsScreen()
DashboardDestination.PATCHER -> PatcherScreen()
}
}
}
}
}

View File

@ -0,0 +1,158 @@
package app.revanced.manager.ui.screen
import android.widget.Toast
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.material.icons.filled.Dashboard
import androidx.compose.material3.Button
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.revanced.manager.R
import app.revanced.manager.ui.component.ApplicationItem
import app.revanced.manager.ui.component.HeadlineWithCard
import app.revanced.manager.ui.viewmodel.DashboardViewModel
import app.revanced.manager.ui.viewmodel.PatcherViewModel
import org.koin.androidx.compose.getViewModel
@Composable
fun PatcherScreen(viewModel: DashboardViewModel = getViewModel()) {
val context = LocalContext.current
val padHoriz = 16.dp
val padVert = 10.dp
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 18.dp)
.verticalScroll(state = rememberScrollState()),
horizontalAlignment = Alignment.Start,
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
HeadlineWithCard(R.string.updates) {
Row(
modifier = Modifier
.padding(horizontal = padHoriz, vertical = padVert)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column {
CommitDate(
label = R.string.patcher,
date = viewModel.patcherCommitDate
)
CommitDate(
label = R.string.manager,
date = viewModel.managerCommitDate
)
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Button(
enabled = false, // needs update
onClick = {
Toast.makeText(context, "Already up-to-date!", Toast.LENGTH_SHORT)
.show()
},
) { Text(stringResource(R.string.update_patch_bundle)) }
Text(
text = "No updates available",
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
fontSize = 10.sp,
)
}
}
}
HeadlineWithCard(R.string.patched_apps) {
Row(
modifier = Modifier
.padding(horizontal = padHoriz, vertical = padVert)
.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
) {
Column {
val amount = 2 // TODO
Text(
text = "${stringResource(R.string.updates_available)}: $amount",
style = MaterialTheme.typography.bodyLarge,
fontWeight = FontWeight.Bold,
fontSize = 18.sp
)
}
Button(
enabled = true, // needs update
onClick = {
Toast.makeText(context, "Already up-to-date!", Toast.LENGTH_SHORT).show()
}
) { Text(stringResource(R.string.update_all)) }
}
Column(
modifier = Modifier
.padding(horizontal = padHoriz)
.padding(bottom = padVert)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(8.dp)
) {
ApplicationItem(
name = "ReVanced",
released = "Released 2 days ago",
icon = { Icon(Icons.Default.Dashboard, "ReVanced") }
) {
ChangelogText(
"""
fix: aaaaaa
fix: aaaaaa
fix: aaaaaa
fix: aaaaaa
fix: aaaaaa
""".trimIndent()
)
}
ApplicationItem(
name = "ReReddit",
released = "Released 1 month ago",
icon = { Icon(Icons.Default.Build, "ReReddit") }
) {
ChangelogText(
"""
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
fix: bbbbbb
""".trimIndent()
)
}
}
}
}
}

View File

@ -0,0 +1,40 @@
package app.revanced.manager.ui.viewmodel
import android.text.format.DateUtils
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import app.revanced.manager.repository.GitHubRepository
import app.revanced.manager.util.ghManager
import app.revanced.manager.util.ghPatcher
import kotlinx.coroutines.runBlocking
import java.text.SimpleDateFormat
import java.util.*
class PatcherViewModel(private val repository: GitHubRepository) : ViewModel() {
var patcherCommitDate by mutableStateOf("")
private set
var managerCommitDate by mutableStateOf("")
private set
init {
runBlocking {
patcherCommitDate = commitDateOf(ghPatcher)
managerCommitDate = commitDateOf(ghManager)
}
}
private suspend fun commitDateOf(repo: String, ref: String = "HEAD"): String {
val commit = repository.getLatestCommit(repo, ref).commit
return DateUtils.getRelativeTimeSpanString(
formatter.parse(commit.committer.date)!!.time,
Calendar.getInstance().timeInMillis,
DateUtils.MINUTE_IN_MILLIS
).toString()
}
private companion object {
val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault())
}
}

View File

@ -7,7 +7,7 @@
<string name="settings">Settings</string>
<string name="updates">Updates</string>
<string name="manager">Manager</string>
<string name="update_manager">Update Manager</string>
<string name="update_patch_bundle">Update Patches</string>
<string name="patched_apps">Installed</string>
<string name="update_all">Update All</string>
<string name="updates_available">Available updates</string>