Skip to content

Commit 35ee7a5

Browse files
romtsnclaude
andcommitted
ref(feedback): Extract shared shake listener in SentryUserFeedbackForm
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 929b476 commit 35ee7a5

1 file changed

Lines changed: 17 additions & 26 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackForm.java

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,7 @@ private void maybeStartShakeDetection(final @NotNull Context context) {
7070
final @NotNull SentryOptions options = Sentry.getCurrentScopes().getOptions();
7171
shakeDetector = new SentryShakeDetector(options.getLogger());
7272
final @NotNull WeakReference<Activity> activityRef = new WeakReference<>(activity);
73-
shakeDetector.start(
74-
activity,
75-
() -> {
76-
final @Nullable Activity active = activityRef.get();
77-
if (active != null && !active.isFinishing() && !active.isDestroyed()) {
78-
active.runOnUiThread(
79-
() -> {
80-
if (!active.isFinishing() && !active.isDestroyed()) {
81-
show();
82-
}
83-
});
84-
}
85-
});
73+
shakeDetector.start(activity, shakeListener(activityRef));
8674
final @NotNull Application app = activity.getApplication();
8775
shakeLifecycleCallbacks = new ShakeLifecycleCallbacks(activityRef);
8876
app.registerActivityLifecycleCallbacks(shakeLifecycleCallbacks);
@@ -102,6 +90,21 @@ private void stopShakeDetection() {
10290
}
10391
}
10492

93+
private @NotNull SentryShakeDetector.Listener shakeListener(
94+
final @NotNull WeakReference<Activity> activityRef) {
95+
return () -> {
96+
final @Nullable Activity active = activityRef.get();
97+
if (active != null && !active.isFinishing() && !active.isDestroyed()) {
98+
active.runOnUiThread(
99+
() -> {
100+
if (!active.isFinishing() && !active.isDestroyed()) {
101+
show();
102+
}
103+
});
104+
}
105+
};
106+
}
107+
105108
private static @Nullable Activity getActivity(final @NotNull Context context) {
106109
Context current = context;
107110
while (current instanceof ContextWrapper) {
@@ -123,19 +126,7 @@ private class ShakeLifecycleCallbacks implements Application.ActivityLifecycleCa
123126
@Override
124127
public void onActivityResumed(final @NotNull Activity activity) {
125128
if (activity == activityRef.get() && shakeDetector != null) {
126-
shakeDetector.start(
127-
activity,
128-
() -> {
129-
final @Nullable Activity active = activityRef.get();
130-
if (active != null && !active.isFinishing() && !active.isDestroyed()) {
131-
active.runOnUiThread(
132-
() -> {
133-
if (!active.isFinishing() && !active.isDestroyed()) {
134-
show();
135-
}
136-
});
137-
}
138-
});
129+
shakeDetector.start(activity, shakeListener(activityRef));
139130
}
140131
}
141132

0 commit comments

Comments
 (0)