Skip to content

Commit 63205af

Browse files
committed
refactor multi click
1 parent 3f0a350 commit 63205af

File tree

4 files changed

+54
-70
lines changed

4 files changed

+54
-70
lines changed

app/src/main/java/com/wmods/wppenhacer/listeners/DoubleTapListener.java

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.wmods.wppenhacer.listeners;
2+
3+
import android.view.View;
4+
5+
public abstract class OnMultiClickListener implements View.OnClickListener {
6+
7+
private final int targetClicks;
8+
private final long delay;
9+
private long lastClick = 0;
10+
private int clicks = 0;
11+
12+
public OnMultiClickListener(int targetClicks, long delay) {
13+
if (targetClicks < 2) {
14+
throw new IllegalArgumentException("targetClicks must be greater than 1");
15+
}
16+
this.targetClicks = targetClicks;
17+
this.delay = delay;
18+
}
19+
20+
@Override
21+
public void onClick(View v) {
22+
if (this.lastClick == 0 || System.currentTimeMillis() - this.lastClick < this.delay) {
23+
this.lastClick = System.currentTimeMillis();
24+
this.clicks++;
25+
} else {
26+
this.lastClick = 0;
27+
this.clicks = 0;
28+
}
29+
if (this.clicks >= this.targetClicks) {
30+
this.clicks = 0;
31+
this.lastClick = 0;
32+
onMultiClick(v);
33+
}
34+
}
35+
36+
abstract public void onMultiClick(View v);
37+
38+
}

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/CustomToolbar.java

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import android.os.Bundle;
77
import android.text.TextUtils;
88
import android.view.Gravity;
9+
import android.view.View;
910
import android.widget.LinearLayout;
1011
import android.widget.TextView;
1112

1213
import androidx.annotation.NonNull;
1314

15+
import com.wmods.wppenhacer.listeners.OnMultiClickListener;
1416
import com.wmods.wppenhacer.xposed.core.Feature;
1517
import com.wmods.wppenhacer.xposed.core.WppCore;
1618
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
@@ -109,25 +111,16 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
109111

110112

111113
if (typeArchive.equals("1")) {
112-
var ref = new Object() {
113-
int clickCount = 0;
114-
long lastClickTime = 0L;
115-
};
116-
toolbar.setOnClickListener(v -> {
117-
long currentTime = System.currentTimeMillis();
118-
if (currentTime - ref.lastClickTime < 500) {
119-
ref.clickCount++;
120-
} else {
121-
ref.clickCount = 1;
122-
}
123-
ref.lastClickTime = currentTime;
124-
if (ref.clickCount == 5) {
125-
ref.clickCount = 0;
114+
var onMultiClickListener = new OnMultiClickListener(5, 500) {
115+
116+
@Override
117+
public void onMultiClick(View v) {
126118
Intent intent = new Intent();
127119
intent.setClassName(Utils.getApplication().getPackageName(), "com.whatsapp.conversationslist.ArchivedConversationsActivity");
128120
homeActivity.startActivity(intent);
129121
}
130-
});
122+
};
123+
toolbar.setOnClickListener(onMultiClickListener);
131124
} else if (typeArchive.equals("2")) {
132125
toolbar.setOnLongClickListener(v -> {
133126
Intent intent = new Intent();

app/src/main/java/com/wmods/wppenhacer/xposed/features/general/Others.java

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,17 @@
1212

1313
import androidx.annotation.NonNull;
1414

15+
import com.wmods.wppenhacer.listeners.OnMultiClickListener;
1516
import com.wmods.wppenhacer.xposed.core.Feature;
1617
import com.wmods.wppenhacer.xposed.core.WppCore;
1718
import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator;
1819
import com.wmods.wppenhacer.xposed.utils.AnimationUtil;
19-
import com.wmods.wppenhacer.xposed.utils.DebugUtils;
2020
import com.wmods.wppenhacer.xposed.utils.ReflectionUtils;
2121
import com.wmods.wppenhacer.xposed.utils.ResId;
2222
import com.wmods.wppenhacer.xposed.utils.Utils;
2323

2424
import org.json.JSONObject;
2525

26-
import java.lang.reflect.Method;
2726
import java.util.ArrayList;
2827
import java.util.HashMap;
2928
import java.util.Objects;
@@ -185,11 +184,6 @@ private void callInfo() throws Exception {
185184
return;
186185

187186
var clsCallEventCallback = classLoader.loadClass("com.whatsapp.calling.service.VoiceServiceEventCallback");
188-
for (Method method : clsCallEventCallback.getDeclaredMethods()) {
189-
XposedBridge.hookMethod(method, DebugUtils.getDebugMethodHook(false, false, true, true));
190-
}
191-
192-
193187
Class<?> clsWamCall = classLoader.loadClass("com.whatsapp.fieldstats.events.WamCall");
194188

195189
XposedBridge.hookAllMethods(clsCallEventCallback, "fieldstatsReady",
@@ -250,6 +244,7 @@ private void alwaysOnline() throws Exception {
250244
XposedBridge.hookMethod(stateChange, XC_MethodReplacement.DO_NOTHING);
251245
}
252246

247+
253248
private void doubleTapReaction() throws Exception {
254249

255250
if (!prefs.getBoolean("doubletap2like", false)) return;
@@ -260,22 +255,21 @@ private void doubleTapReaction() throws Exception {
260255
logDebug(Unobfuscator.getMethodDescriptor(bubbleMethod));
261256

262257
XposedBridge.hookMethod(bubbleMethod, new XC_MethodHook() {
263-
@SuppressLint("ClickableViewAccessibility")
258+
264259
@Override
265260
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
266261
var viewGroup = (View) param.thisObject;
267262
if (viewGroup == null) return;
268263

269-
var gestureDetector = new Object() {
270-
271-
public void doubleClick(View view, Object objMessage) {
264+
var onMultiClickListener = new OnMultiClickListener(2, 500) {
265+
@Override
266+
public void onMultiClick(View view) {
272267
var reactionView = (ViewGroup) view.findViewById(Utils.getID("reactions_bubble_layout", "id"));
273268
if (reactionView != null && reactionView.getVisibility() == View.VISIBLE) {
274269
for (int i = 0; i < reactionView.getChildCount(); i++) {
275270
if (reactionView.getChildAt(i) instanceof TextView textView) {
276271
if (textView.getText().toString().contains(emoji)) {
277-
WppCore.sendReaction("", objMessage);
278-
Utils.showToast(emoji, 1);
272+
WppCore.sendReaction("", param.args[2]);
279273
return;
280274
}
281275
}
@@ -284,26 +278,7 @@ public void doubleClick(View view, Object objMessage) {
284278
WppCore.sendReaction(emoji, param.args[2]);
285279
}
286280
};
287-
288-
var auxClick = new Object() {
289-
long lastClick = 0;
290-
long clicks = 0;
291-
};
292-
293-
viewGroup.setOnClickListener(v -> {
294-
if (auxClick.lastClick == 0 || System.currentTimeMillis() - auxClick.lastClick < 1000) {
295-
auxClick.lastClick = System.currentTimeMillis();
296-
auxClick.clicks++;
297-
} else {
298-
auxClick.lastClick = 0;
299-
auxClick.clicks = 0;
300-
}
301-
if (auxClick.clicks > 1) {
302-
auxClick.clicks = 0;
303-
auxClick.lastClick = 0;
304-
gestureDetector.doubleClick(v, param.args[2]);
305-
}
306-
});
281+
viewGroup.setOnClickListener(onMultiClickListener);
307282
}
308283
});
309284
}

0 commit comments

Comments
 (0)