Skip to content

Commit

Permalink
feat: 感覚フィードバックをよりきめ細かく表現するように
Browse files Browse the repository at this point in the history
  • Loading branch information
pantasystem committed Nov 22, 2023
1 parent 3d4cb5e commit 9df4be6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ object HapticFeedbackController {
}
}

fun performLongClickHapticFeedback(view: View) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
}
}

fun performToggledHapticFeedback(view: View, isChecked: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
if (isChecked) {
view.performHapticFeedback(HapticFeedbackConstants.TOGGLE_ON)
} else {
view.performHapticFeedback(HapticFeedbackConstants.TOGGLE_OFF)
}
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
view.performHapticFeedback(HapticFeedbackConstants.CONTEXT_CLICK)
}
}

@Suppress("DEPRECATION")
fun performTickVibrateHapticFeedback(context: Context) {
val vibratorManager =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,15 @@ object MediaPreviewHelper {
binding.nsfwMessage.setHideImageMessage(previewAbleFile, mediaViewData.config)
binding.toggleVisibilityButton.setImageResource(if (previewAbleFile.isHiding) R.drawable.ic_baseline_image_24 else R.drawable.ic_baseline_hide_image_24)
binding.toggleVisibilityButton.setOnClickListener {
HapticFeedbackController.performClickHapticFeedback(it)
val visibleState = previewAbleFile.isHidingWithNetworkStateAndConfig(
isMobileNetwork = !isWifiConnected,
mediaDisplayMode = mediaViewData.config?.mediaDisplayMode ?: DefaultConfig.config.mediaDisplayMode
)

// NOTE: ここでのネットワークの状態はbind時のものを使う
// なぜなら表示状態はbindされた時のネットワークの状態を使っているから
mediaViewData.toggleVisibility(index, isMobileNetwork = !isWifiConnected, mediaDisplayMode = mediaViewData.config?.mediaDisplayMode ?: DefaultConfig.config.mediaDisplayMode)
HapticFeedbackController.performToggledHapticFeedback(it, !visibleState)
}

if (existsView == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView
import net.pantasystem.milktea.common.glide.GlideApp
import net.pantasystem.milktea.common_android.ui.VisibilityHelper.setMemoVisibility
import net.pantasystem.milktea.common_android.ui.haptic.HapticFeedbackController
import net.pantasystem.milktea.model.note.reaction.LegacyReaction
import net.pantasystem.milktea.note.EmojiListItemType
import net.pantasystem.milktea.note.EmojiType
Expand Down Expand Up @@ -126,9 +127,11 @@ class EmojiListItemsAdapter(
}
}
binding.root.setOnClickListener {
HapticFeedbackController.performClickHapticFeedback(it)
onEmojiSelected(item)
}
binding.root.setOnLongClickListener {
HapticFeedbackController.performLongClickHapticFeedback(it)
onEmojiLongClicked(item)
}
binding.executePendingBindings()
Expand Down

0 comments on commit 9df4be6

Please sign in to comment.