Skip to content

Commit

Permalink
app: Bump version to 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Aug 3, 2024
1 parent a94979b commit bf97271
Show file tree
Hide file tree
Showing 10 changed files with 238 additions and 33 deletions.
Binary file modified Picture/Screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
minSdk = 26
targetSdk = 35
versionCode = getVersionCode()
versionName = "1.2.0"
versionName = "1.2.1"

vectorDrawables.useSupportLibrary = true
}
Expand Down Expand Up @@ -53,7 +53,7 @@ android {
isMinifyEnabled = true
isShrinkResources = true
vcsInfo.include = false
proguardFiles("proguard-rules.pro")
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
signingConfig = signingConfigs.getByName(if (keystorePath != null) "github" else "release")
}
debug {
Expand Down
65 changes: 45 additions & 20 deletions app/src/main/kotlin/top/yukonga/hq_icon/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.compose.animation.core.animateDpAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -44,6 +46,7 @@ import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.collectAsState
Expand Down Expand Up @@ -72,7 +75,8 @@ import top.yukonga.hq_icon.ui.components.AboutDialog
import top.yukonga.hq_icon.ui.components.MainCardView
import top.yukonga.hq_icon.ui.components.ResultsView
import top.yukonga.hq_icon.ui.components.SecondCardView
import top.yukonga.hq_icon.ui.theme.HqIconTheme
import top.yukonga.hq_icon.ui.components.TuneDialog
import top.yukonga.hq_icon.ui.theme.AppTheme
import top.yukonga.hq_icon.utils.AppContext
import top.yukonga.hq_icon.utils.Preferences
import top.yukonga.hq_icon.utils.Search
Expand All @@ -86,20 +90,35 @@ class MainActivity : ComponentActivity() {

AppContext.init(this)

enableEdgeToEdge()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) window.isNavigationBarContrastEnforced = false

val resultsViewModel: ResultsViewModel by viewModels()

setContent {
App(resultsViewModel)
val colorMode = remember { mutableIntStateOf(Preferences().perfGet("colorMode")?.toInt() ?: 0) }
val darkMode = colorMode.intValue == 2 || (isSystemInDarkTheme() && colorMode.intValue == 0)

DisposableEffect(darkMode) {
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(android.graphics.Color.TRANSPARENT, android.graphics.Color.TRANSPARENT) { darkMode },
navigationBarStyle = SystemBarStyle.auto(android.graphics.Color.TRANSPARENT, android.graphics.Color.TRANSPARENT) { darkMode },
)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
window.isNavigationBarContrastEnforced = false // Xiaomi moment, this code must be here
}

onDispose {}
}
App(resultsViewModel, colorMode)
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun App(resultsViewModel: ResultsViewModel) {
fun App(
resultsViewModel: ResultsViewModel,
colorMode: MutableState<Int> = remember { mutableIntStateOf(Preferences().perfGet("colorMode")?.toInt() ?: 0) }
) {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(rememberTopAppBarState())

val listState = rememberLazyListState()
Expand Down Expand Up @@ -149,7 +168,7 @@ fun App(resultsViewModel: ResultsViewModel) {
resultsViewModel.updateResolution(resolutionCode.value)
}

HqIconTheme {
AppTheme(colorMode = colorMode.value) {
Surface(
color = MaterialTheme.colorScheme.background
) {
Expand All @@ -160,7 +179,7 @@ fun App(resultsViewModel: ResultsViewModel) {
.imePadding()
.nestedScroll(scrollBehavior.nestedScrollConnection),
topBar = {
TopAppBar(scrollBehavior)
TopAppBar(scrollBehavior, colorMode)
}
) { padding ->
Box(
Expand Down Expand Up @@ -218,7 +237,7 @@ fun App(resultsViewModel: ResultsViewModel) {

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun TopAppBar(scrollBehavior: TopAppBarScrollBehavior) {
private fun TopAppBar(scrollBehavior: TopAppBarScrollBehavior, colorMode: MutableState<Int>) {
CenterAlignedTopAppBar(
title = {
Text(
Expand All @@ -234,7 +253,8 @@ private fun TopAppBar(scrollBehavior: TopAppBarScrollBehavior) {
titleContentColor = MaterialTheme.colorScheme.onBackground,
scrolledContainerColor = MaterialTheme.colorScheme.background,
),
actions = { AboutDialog() },
navigationIcon = { AboutDialog() },
actions = { TuneDialog(colorMode) },
scrollBehavior = scrollBehavior
)
}
Expand All @@ -252,22 +272,27 @@ private fun FloatActionButton(
val coroutineScope = rememberCoroutineScope()
val hapticFeedback = LocalHapticFeedback.current
val searching = stringResource(R.string.searching)
val appNameEmpty = stringResource(R.string.appNameEmpty)

ExtendedFloatingActionButton(
modifier = Modifier.offset(y = fabOffsetHeight),
onClick = {
Toast.makeText(AppContext.context, searching, Toast.LENGTH_SHORT).show()
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
coroutineScope.launch {
if (term.value != "") {
val results = Search().search(term.value, country.value, platform.value, limit.value)
val response = Utils().json.decodeFromString<Response.Root>(results)
resultsViewModel.updateResults(response.results)
if (term.value == "") {
Toast.makeText(AppContext.context, appNameEmpty, Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(AppContext.context, searching, Toast.LENGTH_SHORT).show()
coroutineScope.launch {
if (term.value != "") {
val results = Search().search(term.value, country.value, platform.value, limit.value)
val response = Utils().json.decodeFromString<Response.Root>(results)
resultsViewModel.updateResults(response.results)

Preferences().perfSet("appName", term.value)
Preferences().perfSet("country", country.value)
Preferences().perfSet("platform", platform.value)
Preferences().perfSet("corner", cornerState.value)
Preferences().perfSet("appName", term.value)
Preferences().perfSet("country", country.value)
Preferences().perfSet("platform", platform.value)
Preferences().perfSet("corner", cornerState.value)
}
}
}
},
Expand Down
157 changes: 157 additions & 0 deletions app/src/main/kotlin/top/yukonga/hq_icon/ui/components/TuneDialog.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package top.yukonga.hq_icon.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
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.widthIn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Tune
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.MenuAnchorType.Companion.PrimaryNotEditable
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
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.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import top.yukonga.hq_icon.R
import top.yukonga.hq_icon.utils.Preferences

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TuneDialog(
colorMode: MutableState<Int>
) {
var showDialog by remember { mutableStateOf(false) }

val hapticFeedback = LocalHapticFeedback.current
val extensionSettings = stringResource(R.string.extension_settings)

IconButton(
modifier = Modifier.widthIn(max = 48.dp),
onClick = {
showDialog = true
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
) {
Icon(
imageVector = Icons.Default.Tune,
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface
)
}

if (showDialog) {
BasicAlertDialog(
onDismissRequest = { showDialog = false }) {
Column(
modifier = Modifier
.widthIn(min = 350.dp, max = 380.dp)
.clip(RoundedCornerShape(30.dp))
.background(MaterialTheme.colorScheme.primaryContainer),
) {
Text(
modifier = Modifier
.padding(horizontal = 24.dp)
.padding(top = 24.dp, bottom = 12.dp),
text = extensionSettings,
fontWeight = FontWeight.SemiBold,
fontSize = MaterialTheme.typography.titleLarge.fontSize
)
Column(
modifier = Modifier.padding(horizontal = 24.dp)
) {
UiColorMode(colorMode)
Spacer(modifier = Modifier.height(12.dp))
}
}
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun UiColorMode(colorMode: MutableState<Int>) {
var isDropdownExpanded by remember { mutableStateOf(false) }
val darkTheme = stringResource(R.string.dark_theme)
val systemDefault = stringResource(R.string.system_default)
val lightMode = stringResource(R.string.light_mode)
val darkMode = stringResource(R.string.dark_mode)
val options = listOf(systemDefault, lightMode, darkMode)
val selectedOption = remember { mutableStateOf(options[colorMode.value]) }

Row(
modifier = Modifier
.padding(bottom = 12.dp)
.fillMaxWidth()
.clickable { if (!isDropdownExpanded) isDropdownExpanded = true },
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = darkTheme,
fontWeight = FontWeight.SemiBold,
fontSize = MaterialTheme.typography.bodyMedium.fontSize
)
ExposedDropdownMenuBox(
expanded = isDropdownExpanded,
onExpandedChange = { isDropdownExpanded = it }
) {
Text(
modifier = Modifier
.menuAnchor(PrimaryNotEditable)
.widthIn(min = 100.dp),
text = selectedOption.value,
fontSize = MaterialTheme.typography.bodyMedium.fontSize,
textAlign = TextAlign.End
)
ExposedDropdownMenu(
shape = RoundedCornerShape(10.dp),
expanded = isDropdownExpanded,
onDismissRequest = { isDropdownExpanded = false },
containerColor = MaterialTheme.colorScheme.primaryContainer
) {
options.forEachIndexed { index, option ->
DropdownMenuItem(
text = {
Text(
modifier = Modifier.fillMaxWidth(),
text = option,
textAlign = TextAlign.Center
)
},
onClick = {
selectedOption.value = option
colorMode.value = index
Preferences().perfSet("colorMode", index.toString())
isDropdownExpanded = false
},
)
}
}
}
}
}
17 changes: 8 additions & 9 deletions app/src/main/kotlin/top/yukonga/hq_icon/ui/theme/Theme.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ private val DarkColorScheme = darkColorScheme(
)

@Composable
fun HqIconTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
fun AppTheme(
colorMode: Int = 0,
content: @Composable () -> Unit
) {
val colorScheme = when {
darkTheme -> DarkColorScheme
else -> LightColorScheme
}

MaterialTheme(
colorScheme = colorScheme,
content = content
colorScheme = when (colorMode) {
1 -> LightColorScheme
2 -> DarkColorScheme
else -> if (isSystemInDarkTheme()) DarkColorScheme else LightColorScheme
},
content = content,
)
}
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<string name="download_successful">下载成功</string>
<string name="download_failed">下载失败</string>
<string name="searching">开始搜索…</string>
<string name="appNameEmpty">应用名称为空</string>
<string name="extension_settings">扩展设置</string>
<string name="dark_theme">显示模式</string>
<string name="system_default">跟随系统</string>
<string name="light_mode">浅色模式</string>
<string name="dark_mode">深色模式</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rHK/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<string name="download_successful">下載成功</string>
<string name="download_failed">下載失敗</string>
<string name="searching">開始搜索…</string>
<string name="appNameEmpty">應用名稱為空</string>
<string name="extension_settings">擴展設定</string>
<string name="dark_theme">顯示模式</string>
<string name="system_default">跟隨系統</string>
<string name="light_mode">淺色模式</string>
<string name="dark_mode">深色模式</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<string name="download_successful">下載成功</string>
<string name="download_failed">下載失敗</string>
<string name="searching">開始搜索…</string>
<string name="appNameEmpty">應用名稱為空</string>
<string name="extension_settings">擴展設定</string>
<string name="dark_theme">顯示模式</string>
<string name="system_default">跟隨系統</string>
<string name="light_mode">淺色模式</string>
<string name="dark_mode">深色模式</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@
<string name="download_successful">Download successful</string>
<string name="download_failed">Download failed</string>
<string name="searching">Searching…</string>
<string name="appNameEmpty">App name is empty</string>
<string name="extension_settings">Extension settings</string>
<string name="dark_theme">Display mode</string>
<string name="system_default">System default</string>
<string name="light_mode">Light mode</string>
<string name="dark_mode">Dark mode</string>
</resources>
Loading

0 comments on commit bf97271

Please sign in to comment.