From f0506b4b590eaf29f7576e1a7405f09181e9bfde Mon Sep 17 00:00:00 2001
From: Harshad Vedartham <harshad1@zoho.com>
Date: Tue, 4 Jun 2024 23:12:14 -0700
Subject: [PATCH] Switching from blink to ripple

---
 .../filebrowser/GsFileBrowserListAdapter.java |  4 +--
 .../gsantner/opoc/util/GsContextUtils.java    | 26 +++++++++++++++----
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java
index 04361e3b4c..7b54bd2804 100644
--- a/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java
+++ b/app/src/main/java/net/gsantner/opoc/frontend/filebrowser/GsFileBrowserListAdapter.java
@@ -596,7 +596,7 @@ private void showAndFlash(final File file) {
             _recyclerView.postDelayed(() -> {
                 final RecyclerView.ViewHolder holder = _recyclerView.findViewHolderForLayoutPosition(pos);
                 if (holder != null) {
-                    GsContextUtils.blinkView(holder.itemView);
+                    GsContextUtils.rippleView(holder.itemView);
                 }
             }, 100);
         }
@@ -621,7 +621,7 @@ public int getFilePosition(final File file) {
     private void stopBlinking() {
         if (_recyclerView != null) {
             for (int i = 0; i < _recyclerView.getChildCount(); i++) {
-                GsContextUtils.stopBlinking(_recyclerView.getChildAt(i));
+                GsContextUtils.stopRipple(_recyclerView.getChildAt(i));
             }
         }
     }
diff --git a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
index 94c2120e8f..26d73fe4ca 100644
--- a/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
+++ b/app/src/main/java/net/gsantner/opoc/util/GsContextUtils.java
@@ -50,6 +50,7 @@
 import android.graphics.drawable.AdaptiveIconDrawable;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.graphics.drawable.RippleDrawable;
 import android.graphics.drawable.VectorDrawable;
 import android.media.MediaMetadataRetriever;
 import android.media.MediaScannerConnection;
@@ -2881,11 +2882,6 @@ public boolean isDarkModeEnabled(final Context context) {
         return false;
     }
 
-    /**
-     * Blinks the view passed in as parameter
-     *
-     * @param view View to be blinked
-     */
     public static void blinkView(final View view) {
 
         if (view == null) {
@@ -2927,6 +2923,26 @@ public static void stopBlinking(final View view) {
 
     }
 
+    public static void rippleView(final View view) {
+        if (view != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            final Drawable drawable = view.getForeground();
+            if (drawable instanceof RippleDrawable) {
+                drawable.setState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled});
+                view.postDelayed(() -> drawable.setState(new int[]{}), 250);
+            }
+        }
+    }
+
+    public static void stopRipple(final View view) {
+        if (view != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+            Drawable drawable = view.getForeground();
+            if (drawable instanceof RippleDrawable) {
+                drawable.setState(new int[]{});
+                drawable.jumpToCurrentState();
+            }
+        }
+    }
+
     public static boolean fadeInOut(final View in, final View out, final boolean animate) {
         // Do nothing if we are already in the correct state
         if (in.getVisibility() == View.VISIBLE && out.getVisibility() == View.GONE) {