Skip to content

Commit 3ce9b0e

Browse files
Updated the project structure
1 parent 8c0e23e commit 3ce9b0e

File tree

3 files changed

+50
-43
lines changed

3 files changed

+50
-43
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.d4rk.netprobe.data.model
2+
3+
enum class ButtonState { Pressed , Idle }
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.d4rk.netprobe.utils
2+
3+
import android.annotation.SuppressLint
4+
import androidx.compose.animation.core.animateFloatAsState
5+
import androidx.compose.foundation.clickable
6+
import androidx.compose.foundation.gestures.awaitFirstDown
7+
import androidx.compose.foundation.gestures.waitForUpOrCancellation
8+
import androidx.compose.foundation.interaction.MutableInteractionSource
9+
import androidx.compose.runtime.Composable
10+
import androidx.compose.runtime.getValue
11+
import androidx.compose.runtime.mutableStateOf
12+
import androidx.compose.runtime.remember
13+
import androidx.compose.runtime.setValue
14+
import androidx.compose.ui.Modifier
15+
import androidx.compose.ui.composed
16+
import androidx.compose.ui.graphics.graphicsLayer
17+
import androidx.compose.ui.input.pointer.pointerInput
18+
import com.d4rk.netprobe.data.model.ButtonState
19+
20+
@SuppressLint("ReturnFromAwaitPointerEventScope")
21+
@Composable
22+
fun Modifier.bounceClick() = composed {
23+
var buttonState by remember { mutableStateOf(ButtonState.Idle) }
24+
val scale by animateFloatAsState(
25+
if (buttonState == ButtonState.Pressed) 0.95f else 1f , label = ""
26+
)
27+
this
28+
.graphicsLayer {
29+
scaleX = scale
30+
scaleY = scale
31+
}
32+
.clickable(interactionSource = remember { MutableInteractionSource() } ,
33+
indication = null ,
34+
onClick = { })
35+
.pointerInput(buttonState) {
36+
awaitPointerEventScope {
37+
buttonState = if (buttonState == ButtonState.Pressed) {
38+
waitForUpOrCancellation()
39+
ButtonState.Idle
40+
}
41+
else {
42+
awaitFirstDown(false)
43+
ButtonState.Pressed
44+
}
45+
}
46+
}
47+
}

app/src/main/kotlin/com/d4rk/netprobe/utils/ComposablesUtils.kt renamed to app/src/main/kotlin/com/d4rk/netprobe/utils/SettingsComposablesUtils.kt

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
package com.d4rk.netprobe.utils
22

3-
import android.annotation.SuppressLint
4-
import androidx.compose.animation.core.animateFloatAsState
53
import androidx.compose.foundation.clickable
6-
import androidx.compose.foundation.gestures.awaitFirstDown
7-
import androidx.compose.foundation.gestures.waitForUpOrCancellation
8-
import androidx.compose.foundation.interaction.MutableInteractionSource
94
import androidx.compose.foundation.layout.Arrangement
105
import androidx.compose.foundation.layout.Column
116
import androidx.compose.foundation.layout.Row
@@ -28,17 +23,10 @@ import androidx.compose.material3.Text
2823
import androidx.compose.material3.VerticalDivider
2924
import androidx.compose.runtime.Composable
3025
import androidx.compose.runtime.State
31-
import androidx.compose.runtime.getValue
32-
import androidx.compose.runtime.mutableStateOf
33-
import androidx.compose.runtime.remember
34-
import androidx.compose.runtime.setValue
3526
import androidx.compose.ui.Alignment
3627
import androidx.compose.ui.Modifier
37-
import androidx.compose.ui.composed
3828
import androidx.compose.ui.draw.clip
39-
import androidx.compose.ui.graphics.graphicsLayer
4029
import androidx.compose.ui.graphics.vector.ImageVector
41-
import androidx.compose.ui.input.pointer.pointerInput
4230
import androidx.compose.ui.text.font.FontWeight
4331
import androidx.compose.ui.unit.dp
4432

@@ -267,35 +255,4 @@ fun SwitchPreferenceItemWithDivider(
267255
} , modifier = Modifier.padding(16.dp))
268256

269257
}
270-
}
271-
272-
enum class ButtonState { Pressed , Idle }
273-
274-
@SuppressLint("ReturnFromAwaitPointerEventScope")
275-
@Composable
276-
fun Modifier.bounceClick() = composed {
277-
var buttonState by remember { mutableStateOf(ButtonState.Idle) }
278-
val scale by animateFloatAsState(
279-
if (buttonState == ButtonState.Pressed) 0.95f else 1f , label = ""
280-
)
281-
this
282-
.graphicsLayer {
283-
scaleX = scale
284-
scaleY = scale
285-
}
286-
.clickable(interactionSource = remember { MutableInteractionSource() } ,
287-
indication = null ,
288-
onClick = { })
289-
.pointerInput(buttonState) {
290-
awaitPointerEventScope {
291-
buttonState = if (buttonState == ButtonState.Pressed) {
292-
waitForUpOrCancellation()
293-
ButtonState.Idle
294-
}
295-
else {
296-
awaitFirstDown(false)
297-
ButtonState.Pressed
298-
}
299-
}
300-
}
301258
}

0 commit comments

Comments
 (0)