Skip to content

Commit

Permalink
app: Add haptic feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Jun 18, 2024
1 parent cb69d9a commit 876c116
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 17 deletions.
6 changes: 5 additions & 1 deletion app/src/main/kotlin/top/yukonga/hq_icon/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -154,9 +156,12 @@ private fun FloatActionButton(
cornerState: MutableState<String>
) {
val coroutineScope = rememberCoroutineScope()
val hapticFeedback = LocalHapticFeedback.current

ExtendedFloatingActionButton(
modifier = Modifier.offset(y = fabOffsetHeight),
onClick = {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
coroutineScope.launch {
if (term.value != "") {
val results = Search().search(term.value, country.value, platform.value, limit.value)
Expand All @@ -177,7 +182,6 @@ private fun FloatActionButton(
modifier = Modifier.height(20.dp),
imageVector = Icons.Filled.Check,
contentDescription = null

)
Spacer(
modifier = Modifier.width(8.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType.Companion.LongPress
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
Expand All @@ -40,14 +42,18 @@ import androidx.compose.ui.unit.dp
import top.yukonga.hq_icon.BuildConfig
import top.yukonga.hq_icon.R


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutDialog() {
var showDialog by remember { mutableStateOf(false) }
val uriHandler = LocalUriHandler.current
val hapticFeedback = LocalHapticFeedback.current

IconButton(
onClick = { showDialog = true }) {
onClick = {
showDialog = true
hapticFeedback.performHapticFeedback(LongPress)
}) {
Icon(
imageVector = Icons.Outlined.ImageSearch,
contentDescription = null,
Expand Down Expand Up @@ -111,7 +117,10 @@ fun AboutDialog() {
text = "GitHub",
spanStyle = SpanStyle(textDecoration = TextDecoration.Underline)
),
onClick = { uriHandler.openUri("https://github.com/YuKongA/HQ-ICON_Compose") },
onClick = {
uriHandler.openUri("https://github.com/YuKongA/HQ-ICON_Compose")
hapticFeedback.performHapticFeedback(LongPress)
},
style = MaterialTheme.typography.bodyMedium + SpanStyle(color = MaterialTheme.colorScheme.primary)
)
}
Expand All @@ -125,7 +134,10 @@ fun AboutDialog() {
text = "Telegram",
spanStyle = SpanStyle(textDecoration = TextDecoration.Underline)
),
onClick = { uriHandler.openUri("https://t.me/YuKongA13579") },
onClick = {
uriHandler.openUri("https://t.me/YuKongA13579")
hapticFeedback.performHapticFeedback(LongPress)
},
style = MaterialTheme.typography.bodyMedium + SpanStyle(color = MaterialTheme.colorScheme.primary)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
Expand All @@ -53,6 +55,10 @@ fun ResultsView(results: List<Response.Result>, corner: String, resolution: Stri
@Composable
fun ResultItemView(result: Response.Result, corner: String, resolution: String) {
val isVisible = remember { mutableStateOf(false) }
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
val hapticFeedback = LocalHapticFeedback.current

AnimatedVisibility(
visible = isVisible.value,
enter = fadeIn() + expandVertically(),
Expand Down Expand Up @@ -93,12 +99,11 @@ fun ResultItemView(result: Response.Result, corner: String, resolution: String)
style = MaterialTheme.typography.labelSmall
)
}
val coroutineScope = rememberCoroutineScope()
val context = LocalContext.current
Text(
modifier = Modifier
.padding(start = 16.dp)
.clickable {
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
coroutineScope.launch {
Download().downloadImage(
context,
Expand Down Expand Up @@ -127,6 +132,7 @@ fun ResultItemView(result: Response.Result, corner: String, resolution: String)
@Composable
fun MessageText(text: String, style: TextStyle) {
val scrollState = rememberScrollState()

Text(
text = text,
style = style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.hapticfeedback.HapticFeedbackType.Companion.LongPress
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -81,6 +83,7 @@ fun PlatformView(
platformCode: MutableState<String>
) {
val platform = Data().platformNames
val hapticFeedback = LocalHapticFeedback.current

Column(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 14.dp),
Expand All @@ -101,6 +104,7 @@ fun PlatformView(
selected = (text == selectedOption),
onClick = {
onOptionSelected(text)
hapticFeedback.performHapticFeedback(LongPress)
platformCode.value = Data().platformCode(text)
},
role = Role.RadioButton
Expand All @@ -126,6 +130,7 @@ fun CornerView(
cornerStateCode: MutableState<String>
) {
val cornerState = Data().cornerStateNames
val hapticFeedback = LocalHapticFeedback.current

Column(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 14.dp),
Expand All @@ -147,6 +152,7 @@ fun CornerView(
selected = (text == selectedOption),
onClick = {
onOptionSelected(text)
hapticFeedback.performHapticFeedback(LongPress)
cornerStateCode.value = Data().cornerStateCode(text)
},
role = Role.RadioButton
Expand All @@ -172,6 +178,7 @@ fun ResolutionView(
resolutionCode: MutableState<String>
) {
val resolution = Data().resolutionNames
val hapticFeedback = LocalHapticFeedback.current

Column(
modifier = Modifier.padding(horizontal = 16.dp, vertical = 14.dp),
Expand All @@ -193,6 +200,7 @@ fun ResolutionView(
selected = (text == selectedOption),
onClick = {
onOptionSelected(text)
hapticFeedback.performHapticFeedback(LongPress)
resolutionCode.value = Data().resolutionCode(text)
Preferences().perfSet("resolution", resolutionCode.value)
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package top.yukonga.hq_icon.ui.components

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.shape.RoundedCornerShape
Expand All @@ -18,10 +19,12 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.unit.dp


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun TextFieldWithDropdown(
Expand All @@ -30,42 +33,43 @@ fun TextFieldWithDropdown(
label: String,
leadingIcon: ImageVector
) {
val hapticFeedback = LocalHapticFeedback.current
var isDropdownExpanded by remember { mutableStateOf(false) }

ExposedDropdownMenuBox(
expanded = isDropdownExpanded,
onExpandedChange = { isDropdownExpanded = it },
onExpandedChange = {
isDropdownExpanded = it
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
},
) {
OutlinedTextField(
value = text.value,
onValueChange = {},
label = { Text(label) },
readOnly = true,
singleLine = true,
modifier = Modifier
.fillMaxWidth()
.menuAnchor(),
modifier = Modifier.menuAnchor().fillMaxWidth(),
shape = RoundedCornerShape(10.dp),
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(isDropdownExpanded) },
leadingIcon = { Icon(imageVector = leadingIcon, null) },
)
DropdownMenu(
modifier = Modifier
.exposedDropdownSize()
.heightIn(max = 250.dp),
modifier = Modifier.exposedDropdownSize().heightIn(max = 250.dp),
expanded = isDropdownExpanded,
onDismissRequest = { isDropdownExpanded = false },
) {
items.forEach { item ->
DropdownMenuItem(
DropdownMenuItem(modifier = Modifier.background(Color.Transparent),
text = { Text(item) },
contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding,
onClick = {
text.value = item
isDropdownExpanded = false
hapticFeedback.performHapticFeedback(HapticFeedbackType.LongPress)
}
)
}
}
}
}
}

0 comments on commit 876c116

Please sign in to comment.