File tree Expand file tree Collapse file tree
app/src/legacy/kotlin/app/fyreplace/fyreplace/legacy Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package app.fyreplace.fyreplace.legacy.extensions
22
33import android.content.Context
4+ import android.os.Build
5+ import android.view.HapticFeedbackConstants
46import android.view.View
57import android.view.inputmethod.InputMethodManager
68import androidx.core.graphics.Insets
@@ -38,3 +40,29 @@ fun View.hideSoftInput() {
3840 context.getSystemService(InputMethodManager ::class .java)
3941 ?.hideSoftInputFromWindow(windowToken, 0 )
4042}
43+
44+ fun View.provideHapticFeedback (type : HapticType = HapticType .SIMPLE ) {
45+ performHapticFeedback(
46+ when {
47+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE -> when (type) {
48+ HapticType .TOGGLE_ON -> HapticFeedbackConstants .TOGGLE_ON
49+ HapticType .TOGGLE_OFF -> HapticFeedbackConstants .TOGGLE_OFF
50+ else -> HapticFeedbackConstants .CONFIRM
51+ }
52+
53+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .R -> HapticFeedbackConstants .CONFIRM
54+ else -> HapticFeedbackConstants .VIRTUAL_KEY
55+ }
56+ )
57+ }
58+
59+ fun View.provideHapticFeedback (positive : Boolean ) = provideHapticFeedback(
60+ if (positive) HapticType .TOGGLE_ON
61+ else HapticType .TOGGLE_OFF
62+ )
63+
64+ enum class HapticType {
65+ TOGGLE_ON ,
66+ TOGGLE_OFF ,
67+ SIMPLE
68+ }
Original file line number Diff line number Diff line change 11package app.fyreplace.fyreplace.legacy.ui
22
3- import android.os.Build
4- import android.view.HapticFeedbackConstants
53import android.view.View
64import androidx.annotation.StringRes
5+ import app.fyreplace.fyreplace.legacy.extensions.HapticType
6+ import app.fyreplace.fyreplace.legacy.extensions.provideHapticFeedback
77import com.google.android.material.snackbar.BaseTransientBottomBar
88import com.google.android.material.snackbar.Snackbar
99
@@ -22,30 +22,4 @@ interface BasePresenter : ContextHolder {
2222 rootView.provideHapticFeedback(haptics)
2323 }
2424 }
25-
26- fun View.provideHapticFeedback (type : HapticType = HapticType .SIMPLE ) {
27- performHapticFeedback(
28- when {
29- Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE -> when (type) {
30- HapticType .TOGGLE_ON -> HapticFeedbackConstants .TOGGLE_ON
31- HapticType .TOGGLE_OFF -> HapticFeedbackConstants .TOGGLE_OFF
32- else -> HapticFeedbackConstants .CONFIRM
33- }
34-
35- Build .VERSION .SDK_INT >= Build .VERSION_CODES .R -> HapticFeedbackConstants .CONFIRM
36- else -> HapticFeedbackConstants .VIRTUAL_KEY
37- }
38- )
39- }
40-
41- fun View.provideHapticFeedback (positive : Boolean ) = provideHapticFeedback(
42- if (positive) HapticType .TOGGLE_ON
43- else HapticType .TOGGLE_OFF
44- )
45-
46- enum class HapticType {
47- TOGGLE_ON ,
48- TOGGLE_OFF ,
49- SIMPLE
50- }
5125}
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import app.fyreplace.fyreplace.databinding.ItemFeedPostTextBinding
1212import app.fyreplace.fyreplace.legacy.events.EventsManager
1313import app.fyreplace.fyreplace.legacy.events.RemoteNotificationWasReceivedEvent
1414import app.fyreplace.fyreplace.legacy.extensions.firstChapter
15+ import app.fyreplace.fyreplace.legacy.extensions.provideHapticFeedback
1516import app.fyreplace.fyreplace.legacy.ui.adapters.holders.PreviewHolder
1617import app.fyreplace.protos.Post
1718import kotlinx.coroutines.MainScope
@@ -115,6 +116,8 @@ class FeedAdapter(
115116 fun onUpClicked (view : View ) = vote(view)
116117
117118 private fun vote (button : View ) {
119+ button.provideHapticFeedback(positive = button == up)
120+
118121 if (! isVoting) scope.launch {
119122 button.isActivated = true
120123 delay(500 )
Original file line number Diff line number Diff line change @@ -91,10 +91,7 @@ class FeedFragment :
9191 }
9292
9393 override fun onPostVoted (view : View , position : Int , spread : Boolean ) {
94- view.provideHapticFeedback(positive = spread)
95- launch {
96- vm.vote(position, spread)
97- }
94+ launch { vm.vote(position, spread) }
9895 }
9996
10097 override fun onCreateMenu (menu : Menu , menuInflater : MenuInflater ) {
You can’t perform that action at this time.
0 commit comments