0
0
Fork 0
mirror of https://github.com/YTVanced/VancedManager synced 2024-12-01 15:27:26 +00:00

more refactor

This commit is contained in:
X1nto 2021-06-28 16:22:12 +04:00
parent 822778f7e9
commit bc69bd4a9d
28 changed files with 152 additions and 174 deletions

View file

@ -12,7 +12,8 @@ import com.vanced.manager.downloader.impl.VancedDownloader
import com.vanced.manager.network.util.MICROG_NAME
import com.vanced.manager.network.util.MUSIC_NAME
import com.vanced.manager.network.util.VANCED_NAME
import com.vanced.manager.ui.preferences.*
import com.vanced.manager.ui.preferences.CheckboxPreference
import com.vanced.manager.ui.preferences.RadioButtonPreference
import com.vanced.manager.ui.preferences.holder.musicVersionPref
import com.vanced.manager.ui.preferences.holder.vancedLanguagesPref
import com.vanced.manager.ui.preferences.holder.vancedThemePref

View file

@ -23,11 +23,11 @@ import com.vanced.manager.ui.components.color.managerAnimatedColor
import com.vanced.manager.ui.components.color.managerSurfaceColor
import com.vanced.manager.ui.components.color.managerTextColor
import com.vanced.manager.ui.components.menu.ManagerDropdownMenuItem
import com.vanced.manager.ui.components.text.ToolbarTitleText
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.screens.Screen
import com.vanced.manager.ui.theme.ManagerTheme
import com.vanced.manager.ui.theme.isDark
import com.vanced.manager.ui.components.text.ToolbarTitleText
class MainActivity : AppCompatActivity() {

View file

@ -11,7 +11,6 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance
import androidx.compose.ui.unit.dp
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun ManagerThemedButton(

View file

@ -1,13 +1,10 @@
package com.vanced.manager.ui.components.button
import androidx.annotation.StringRes
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.components.text.ManagerText
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun ManagerThemedTextButton(

View file

@ -10,14 +10,12 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vanced.manager.ui.components.color.ThemedItemContentColorProvider
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
private val cardModifier = Modifier.sizeIn(
minHeight = 95.dp,

View file

@ -7,21 +7,18 @@ import androidx.compose.animation.core.updateTransition
import androidx.compose.foundation.layout.requiredSize
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Done
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.vanced.manager.ui.components.card.ManagerCard
import com.vanced.manager.ui.components.color.contentColorForColor
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.components.color.managerAnimatedColor
import com.vanced.manager.ui.components.color.managerThemedCardColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@SuppressLint("UnusedTransitionTargetStateParameter")
@Composable

View file

@ -1,11 +1,8 @@
package com.vanced.manager.ui.components.color
import androidx.compose.material.LocalContentColor
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.graphics.Color
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun ThemedItemContentColorProvider(

View file

@ -2,17 +2,13 @@ package com.vanced.manager.ui.components.color
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.skydoves.colorpickerview.ColorEnvelope
import com.skydoves.orchestra.colorpicker.ColorPicker
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun ManagerColorPicker(

View file

@ -4,7 +4,6 @@ import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.tween
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.luminance
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref

View file

@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Checkbox
import androidx.compose.material.CheckboxDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
@ -16,7 +15,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.components.color.managerTextColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun CheckboxItem(

View file

@ -4,7 +4,6 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.material.RadioButton
import androidx.compose.material.RadioButtonDefaults
import androidx.compose.material.Text
@ -16,7 +15,6 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.components.color.managerTextColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
@Composable
fun <T> RadiobuttonItem(

View file

@ -1,6 +1,5 @@
package com.vanced.manager.ui.components.preference
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState

View file

@ -1,6 +1,5 @@
package com.vanced.manager.ui.components.preference
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.padding
import androidx.compose.material.LocalContentColor
import androidx.compose.material.LocalTextStyle

View file

@ -0,0 +1,22 @@
package com.vanced.manager.ui.components.progressindicator
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.runtime.Composable
import com.vanced.manager.ui.components.color.managerAccentColor
@Composable
fun ManagerProgressIndicator() {
LinearProgressIndicator(
color = managerAccentColor()
)
}
@Composable
fun ManagerProgressIndicator(
progress: Float
) {
LinearProgressIndicator(
color = managerAccentColor(),
progress = progress
)
}

View file

@ -1,6 +1,5 @@
package com.vanced.manager.ui.components.text
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable

View file

@ -21,9 +21,9 @@ import com.vanced.manager.ui.components.card.ManagerLinkCard
import com.vanced.manager.ui.components.card.ManagerThemedCard
import com.vanced.manager.ui.components.layout.ManagerScrollableColumn
import com.vanced.manager.ui.components.layout.ScrollableItemRow
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.components.list.ManagerListItem
import com.vanced.manager.ui.components.text.ManagerText
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.widgets.layout.CategoryLayout
data class Person(

View file

@ -2,16 +2,17 @@ package com.vanced.manager.ui.layouts
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.lazy.items
import androidx.compose.material.*
import androidx.compose.material.FloatingActionButton
import androidx.compose.material.Icon
import androidx.compose.material.Scaffold
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Share
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.components.color.managerSurfaceColor
import com.vanced.manager.ui.components.layout.ManagerLazyColumn
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
import com.vanced.manager.util.logs
@Composable

View file

@ -1,7 +1,6 @@
package com.vanced.manager.ui.layouts
import androidx.compose.runtime.*
import androidx.compose.ui.res.stringResource
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.dp
import com.vanced.manager.R
import com.vanced.manager.ui.components.layout.ManagerScrollableColumn

View file

@ -1,8 +1,6 @@
package com.vanced.manager.ui.theme
import androidx.compose.ui.graphics.Color
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
val primaryColor = Color(defAccentColor)
val primaryColorVariant = primaryColor.copy(alpha = 0.25f)

View file

@ -7,25 +7,24 @@ import androidx.compose.material.icons.rounded.DeleteForever
import androidx.compose.material.icons.rounded.Download
import androidx.compose.material.icons.rounded.Launch
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.vanced.manager.R
import com.vanced.manager.ui.components.button.IconButton
import com.vanced.manager.ui.components.text.AppVersionText
import com.vanced.manager.ui.components.text.ManagerText
import com.vanced.manager.ui.utils.defaultContentPaddingHorizontal
import com.vanced.manager.ui.components.text.AppVersionText
@Composable
fun AppActionCard(
appRemoteVersion: String?,
appInstalledVersion: String?,
showDownloadDialog: MutableState<Boolean>,
showAppInfo: MutableState<Boolean>,
showInstallationOptions: MutableState<Boolean>,
hasInstallationOptions: Boolean
onInfoClick: () -> Unit,
onUninstallClick: () -> Unit,
onLaunchClick: () -> Unit,
onDownloadClick: () -> Unit,
) {
Row(
modifier = Modifier.padding(
@ -65,18 +64,26 @@ fun AppActionCard(
.padding(start = 4.dp)
.wrapContentWidth(Alignment.End)
) {
IconButton(icon = Icons.Outlined.Info, contentDescription = "App Info") {
showAppInfo.value = true
}
IconButton(icon = Icons.Rounded.DeleteForever, contentDescription = "Uninstall") {}
IconButton(icon = Icons.Rounded.Launch, contentDescription = "Launch") {}
IconButton(icon = Icons.Rounded.Download, contentDescription = "Install") {
if (hasInstallationOptions) {
showInstallationOptions.value = true
} else {
showDownloadDialog.value = true
}
}
IconButton(
icon = Icons.Outlined.Info,
contentDescription = "App Info",
onClick = onInfoClick
)
IconButton(
icon = Icons.Rounded.DeleteForever,
contentDescription = "Uninstall",
onClick = onUninstallClick
)
IconButton(
icon = Icons.Rounded.Launch,
contentDescription = "Launch",
onClick = onLaunchClick
)
IconButton(
icon = Icons.Rounded.Download,
contentDescription = "Install",
onClick = onDownloadClick
)
}
}
}

View file

@ -1,14 +1,16 @@
package com.vanced.manager.ui.widgets.home.apps.card
import androidx.compose.animation.*
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.dp
import com.google.accompanist.glide.rememberGlidePainter
import com.vanced.manager.domain.model.App
@ -27,14 +29,21 @@ fun AppCard(
app: App,
fetching: Boolean
) {
val showDownloadDialog = remember { mutableStateOf(false) }
val showAppInfo = remember { mutableStateOf(false) }
val showInstallationOptions = remember { mutableStateOf(false) }
var showDownloadDialog by remember { mutableStateOf(false) }
var showAppInfoDialog by remember { mutableStateOf(false) }
var showInstallationOptions by remember { mutableStateOf(false) }
val icon = rememberGlidePainter(
request = app.iconUrl ?: "",
fadeIn = true
)
val hasInstallationOption = app.installationOptions != null
val hasInstallationOptions = app.installationOptions != null
val animationSpec = tween<IntSize>(400)
fun download() {
}
Column {
ManagerThemedCard {
@ -50,23 +59,31 @@ fun AppCard(
AppActionCard(
appInstalledVersion = app.installedVersion,
appRemoteVersion = app.remoteVersion,
showDownloadDialog = showDownloadDialog,
showAppInfo = showAppInfo,
showInstallationOptions = showInstallationOptions,
hasInstallationOptions = hasInstallationOption
onDownloadClick = {
if (hasInstallationOptions) {
showInstallationOptions = true
} else {
showDownloadDialog = true
}
},
onInfoClick = {
showAppInfoDialog = true
},
onLaunchClick = {},
onUninstallClick = {}
)
}
}
}
if (hasInstallationOption) {
if (hasInstallationOptions) {
AnimatedVisibility(
modifier = Modifier.fillMaxWidth(),
visible = showInstallationOptions.value,
visible = showInstallationOptions,
enter = expandVertically(
animationSpec = tween(400)
animationSpec = animationSpec
),
exit = shrinkVertically(
animationSpec = tween(400)
animationSpec = animationSpec
)
) {
Column(
@ -81,10 +98,10 @@ fun AppCard(
.padding(top = defaultContentPaddingVertical)
) {
ManagerDownloadButton {
showDownloadDialog.value = true
showDownloadDialog = true
}
ManagerCancelButton {
showInstallationOptions.value = false
showInstallationOptions = false
}
}
}
@ -92,19 +109,23 @@ fun AppCard(
}
}
if (app.name != null && app.downloader != null) {
if (app.name != null && app.downloader != null && showDownloadDialog) {
AppDownloadDialog(
app = app.name,
downloader = app.downloader,
showDialog = showDownloadDialog
onCancelClick = {
showDownloadDialog = false
}
)
}
if (app.name != null && app.changelog != null) {
if (app.name != null && app.changelog != null && showAppInfoDialog) {
AppChangelogDialog(
appName = app.name,
changelog = app.changelog,
showDialog = showAppInfo
onDismissRequest = {
showAppInfoDialog = false
}
)
}
}

View file

@ -3,36 +3,31 @@ package com.vanced.manager.ui.widgets.home.apps.dialog
import androidx.compose.foundation.layout.padding
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.vanced.manager.R
import com.vanced.manager.ui.components.dialog.ManagerDialog
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.components.text.ManagerText
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.widgets.button.ManagerCloseButton
@Composable
fun AppChangelogDialog(
appName: String,
changelog: String,
showDialog: MutableState<Boolean>
onDismissRequest: () -> Unit,
) {
if (showDialog.value) {
ManagerDialog(
title = managerString(R.string.app_info_title, appName),
onDismissRequest = { showDialog.value = false },
buttons = {
ManagerCloseButton {
showDialog.value = false
}
}
) {
ManagerText(
modifier = Modifier.padding(top = 4.dp),
text = changelog,
textStyle = MaterialTheme.typography.subtitle1
)
ManagerDialog(
title = managerString(R.string.app_info_title, appName),
onDismissRequest = onDismissRequest,
buttons = {
ManagerCloseButton(onClick = onDismissRequest)
}
) {
ManagerText(
modifier = Modifier.padding(top = 4.dp),
text = changelog,
textStyle = MaterialTheme.typography.subtitle1
)
}
}

View file

@ -1,53 +1,33 @@
package com.vanced.manager.ui.widgets.home.apps.dialog
import androidx.compose.runtime.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.vanced.manager.downloader.base.BaseDownloader
import com.vanced.manager.ui.components.dialog.ManagerDialog
import com.vanced.manager.ui.widgets.home.download.AppDownloadDialogButtons
import com.vanced.manager.ui.widgets.button.ManagerCancelButton
import com.vanced.manager.ui.widgets.home.download.AppDownloadDialogProgress
import kotlinx.coroutines.launch
@Composable
fun AppDownloadDialog(
app: String,
downloader: BaseDownloader,
showDialog: MutableState<Boolean>
onCancelClick: () -> Unit,
) {
val coroutineScope = rememberCoroutineScope()
val rememberProgress = remember { downloader.downloadProgress }
val rememberFile = remember { downloader.downloadFile }
val rememberInstalling = remember { downloader.installing }
val showProgress = remember { mutableStateOf(false) }
if (showDialog.value) {
ManagerDialog(
title = app,
onDismissRequest = { showDialog.value = false },
buttons = {
AppDownloadDialogButtons(
showProgress = showProgress,
onDownloadClick = {
coroutineScope.launch {
showProgress.value = true
downloader.download()
}
},
onCancelClick = {
downloader.cancelDownload()
showDialog.value = false
showProgress.value = false
}
)
}
) {
AppDownloadDialogProgress(
progress = rememberProgress,
file = rememberFile,
showProgress = showProgress.value,
installing = rememberInstalling
)
ManagerDialog(
title = app,
onDismissRequest = {},
buttons = {
ManagerCancelButton(onClick = onCancelClick)
}
) {
AppDownloadDialogProgress(
progress = rememberProgress,
file = rememberFile,
installing = rememberInstalling
)
}
}

View file

@ -1,18 +0,0 @@
package com.vanced.manager.ui.widgets.home.download
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import com.vanced.manager.ui.widgets.button.ManagerCancelButton
import com.vanced.manager.ui.widgets.button.ManagerDownloadButton
@Composable
fun AppDownloadDialogButtons(
showProgress: MutableState<Boolean>,
onDownloadClick: () -> Unit,
onCancelClick: () -> Unit,
) {
when (showProgress.value) {
true -> ManagerCancelButton(onClick = onCancelClick)
false -> ManagerDownloadButton(onClick = onDownloadClick)
}
}

View file

@ -2,43 +2,39 @@ package com.vanced.manager.ui.widgets.home.download
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.LinearProgressIndicator
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import com.vanced.manager.ui.components.color.managerAccentColor
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
import com.vanced.manager.R
import com.vanced.manager.ui.components.progressindicator.ManagerProgressIndicator
import com.vanced.manager.ui.resources.managerString
@Composable
fun AppDownloadDialogProgress(
progress: Float,
file: String,
showProgress: Boolean,
installing: Boolean
) {
if (showProgress) {
when (installing) {
true -> LinearProgressIndicator(color = managerAccentColor())
false -> LinearProgressIndicator(
progress = progress,
color = managerAccentColor()
when (installing) {
true -> ManagerProgressIndicator()
false -> ManagerProgressIndicator(progress = progress)
}
Row {
Text(
modifier = Modifier
.weight(1f)
.wrapContentWidth(Alignment.Start),
text = managerString(
stringId = R.string.app_download_dialog_downloading_file,
file
)
}
Row {
Text(
modifier = Modifier
.weight(1f)
.wrapContentWidth(Alignment.Start),
text = "Downloading $file"
)
Text(
modifier = Modifier
.weight(1f)
.wrapContentWidth(Alignment.End),
text = "$progress"
)
}
)
Text(
modifier = Modifier
.weight(1f)
.wrapContentWidth(Alignment.End),
text = "%$progress"
)
}
}

View file

@ -1,10 +1,10 @@
package com.vanced.manager.ui.widgets.home.installation
import androidx.annotation.StringRes
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.components.preference.CheckboxDialogPreference
import com.vanced.manager.ui.preferences.CheckboxPreference
import com.vanced.manager.ui.preferences.ManagerPreference
import com.vanced.manager.ui.resources.managerString
data class CheckboxInstallationOption(
@StringRes val titleId: Int,

View file

@ -4,9 +4,9 @@ import androidx.compose.foundation.layout.*
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import com.vanced.manager.ui.components.text.CategoryTitleText
import com.vanced.manager.ui.utils.defaultContentPaddingHorizontal
import com.vanced.manager.ui.utils.defaultContentPaddingVertical
import com.vanced.manager.ui.components.text.CategoryTitleText
@Composable
fun CategoryLayout(

View file

@ -5,8 +5,8 @@ import androidx.compose.ui.graphics.Color
import com.vanced.manager.R
import com.vanced.manager.ui.components.color.ManagerColorPicker
import com.vanced.manager.ui.components.preference.DialogPreference
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.preferences.holder.managerAccentColorPref
import com.vanced.manager.ui.resources.managerString
import com.vanced.manager.ui.widgets.button.ManagerSaveButton
@Composable