Skip to content

Conversation

Ayyanchira
Copy link
Member

Needs reduction in code. Lot of repition. Heavy review and testing needed. Committing as inapps are looking stable and are sticking with the layout with back to back phone rotations when inapp performance would fail usually

🔹 Jira Ticket(s) if any

✏️ Description

Please provide a brief description of what this pull request does.

Needs reduction in code. Lot of repition. Heavy review and testing needed. Committing as inapps are looking stable and are sticking with the layout with back to back phone rotations when inapp performance would fail usually
private String messageId;

// Resize debouncing fields
private Handler resizeHandler = new Handler();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Handler.Handler
should be avoided because it has been deprecated.

Copilot Autofix

AI 9 days ago

To fix this issue, we should replace new Handler() with new Handler(Looper.getMainLooper()), which constructs a Handler associated with the main thread's message queue. This is the recommended approach per Android documentation starting in API level 30, and has the same effect as the deprecated default constructor in most cases targeting UI work.

The changes are confined to line 64 in the file iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java. To implement this fix, we also need to import android.os.Looper if it isn't already imported. The rest of the code that uses resizeHandler can remain unchanged.


Suggested changeset 1
iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
@@ -15,6 +15,7 @@
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Looper;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.Gravity;
@@ -61,7 +62,7 @@
     private String messageId;
     
     // Resize debouncing fields
-    private Handler resizeHandler = new Handler();
+    private Handler resizeHandler = new Handler(Looper.getMainLooper());
     private Runnable pendingResizeRunnable;
     private float lastContentHeight = -1;
     private static final int RESIZE_DEBOUNCE_DELAY_MS = 200;
EOF
@@ -15,6 +15,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
@@ -61,7 +62,7 @@
private String messageId;

// Resize debouncing fields
private Handler resizeHandler = new Handler();
private Handler resizeHandler = new Handler(Looper.getMainLooper());
private Runnable pendingResizeRunnable;
private float lastContentHeight = -1;
private static final int RESIZE_DEBOUNCE_DELAY_MS = 200;
Copilot is powered by AI and may make mistakes. Always verify output.
lastOrientation = currentOrientation;

// Use longer delay for orientation changes to allow layout to stabilize
final Handler handler = new Handler();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note

Invoking
Handler.Handler
should be avoided because it has been deprecated.

Copilot Autofix

AI 9 days ago

To resolve the deprecated method usage, replace instances of new Handler() with new Handler(Looper.getMainLooper()) when the handler is to be used for main thread/UI actions (as is the case here, since DialogFragment callback code executes on the main thread). This is a trivial change: update the handler initialization on line 260 to pass Looper.getMainLooper() as an argument to the Handler constructor. To do this, we also need to import android.os.Looper, which is already provided in all Android environments.

Files to edit: only iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java.

  • Add the necessary import for android.os.Looper
  • Update line 260: change new Handler() to new Handler(Looper.getMainLooper())

Suggested changeset 1
iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
--- a/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
+++ b/iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppFragmentHTMLNotification.java
@@ -15,6 +15,7 @@
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Looper;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.Gravity;
@@ -257,7 +258,7 @@
                             lastOrientation = currentOrientation;
                             
                             // Use longer delay for orientation changes to allow layout to stabilize
-                            final Handler handler = new Handler();
+                            final Handler handler = new Handler(Looper.getMainLooper());
                             handler.postDelayed(new Runnable() {
                                 @Override
                                 public void run() {
EOF
@@ -15,6 +15,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
@@ -257,7 +258,7 @@
lastOrientation = currentOrientation;

// Use longer delay for orientation changes to allow layout to stabilize
final Handler handler = new Handler();
final Handler handler = new Handler(Looper.getMainLooper());
handler.postDelayed(new Runnable() {
@Override
public void run() {
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant