Skip to content

Commit 9f10d35

Browse files
committed
Revert "解决xtoast内存泄漏的问题"
This reverts commit 8ef453a
1 parent 8ef453a commit 9f10d35

File tree

2 files changed

+7
-29
lines changed

2 files changed

+7
-29
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ dependencies {
103103
implementation 'com.github.bumptech.glide:glide:4.12.0'
104104

105105
// XUI框架
106-
implementation project(':xui_lib')
107-
// implementation 'com.github.xuexiangjys:XUI:1.1.9'
106+
// implementation project(':xui_lib')
107+
implementation 'com.github.xuexiangjys:XUI:1.1.9'
108108
// implementation 'com.qmuiteam:qmui:1.2.0'
109109

110110
// 工具类

xui_lib/src/main/java/com/xuexiang/xui/widget/toast/XToast.java

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.Context;
55
import android.graphics.Typeface;
66
import android.graphics.drawable.Drawable;
7-
import android.os.Build;
87
import android.util.TypedValue;
98
import android.view.LayoutInflater;
109
import android.view.View;
@@ -312,9 +311,6 @@ public static Toast custom(@NonNull Context context, @NonNull CharSequence messa
312311
if (icon == null) {
313312
throw new IllegalArgumentException("Avoid passing 'icon' as null if 'withIcon' is set to true");
314313
}
315-
if (Config.get().isRTL && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
316-
toastLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
317-
}
318314
Utils.setBackground(toastIcon, Config.get().tintIcon ? Utils.tintIcon(icon, textColor) : icon);
319315
} else {
320316
toastIcon.setVisibility(View.GONE);
@@ -330,26 +326,15 @@ public static Toast custom(@NonNull Context context, @NonNull CharSequence messa
330326
toastLayout.getBackground().setAlpha(Config.get().alpha);
331327
}
332328
currentToast.setView(toastLayout);
333-
if (Config.get().gravity != -1) {
334-
currentToast.setGravity(Config.get().gravity, Config.get().xOffset, Config.get().yOffset);
335-
}
329+
336330
if (!Config.get().allowQueue) {
337331
if (lastToast != null) {
338332
lastToast.cancel();
339333
}
340334
lastToast = currentToast;
341-
// solve the problem of lastToast memory leak
342-
currentToast.getView().addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
343-
@Override
344-
public void onViewAttachedToWindow(View v) {}
345-
@Override
346-
public void onViewDetachedFromWindow(View v) {
347-
v.removeOnAttachStateChangeListener(this);
348-
if (currentToast == lastToast) {
349-
lastToast = null;
350-
}
351-
}
352-
});
335+
}
336+
if (Config.get().gravity != -1) {
337+
currentToast.setGravity(Config.get().gravity, Config.get().xOffset, Config.get().yOffset);
353338
}
354339
return currentToast;
355340
}
@@ -366,7 +351,6 @@ public static class Config {
366351
private int gravity = -1;
367352
private int xOffset = 0;
368353
private int yOffset = 0;
369-
private boolean isRTL = false;
370354

371355
private Config() {
372356

@@ -375,7 +359,7 @@ private Config() {
375359
/**
376360
* 获取单例
377361
*
378-
* @return 配置
362+
* @return
379363
*/
380364
public static Config get() {
381365
if (sInstance == null) {
@@ -397,7 +381,6 @@ public void reset() {
397381
gravity = -1;
398382
xOffset = 0;
399383
yOffset = 0;
400-
isRTL = false;
401384
}
402385

403386
@CheckResult
@@ -459,10 +442,5 @@ public Config setYOffset(int yOffset) {
459442
this.yOffset = yOffset;
460443
return this;
461444
}
462-
463-
public Config setRTL(boolean isRTL) {
464-
this.isRTL = isRTL;
465-
return this;
466-
}
467445
}
468446
}

0 commit comments

Comments
 (0)