|
@@ -38,6 +38,7 @@ import com.kongzue.dialogx.interfaces.NoTouchInterface;
|
|
|
import com.kongzue.dialogx.interfaces.OnBindView;
|
|
|
import com.kongzue.dialogx.interfaces.OnDialogButtonClickListener;
|
|
|
import com.kongzue.dialogx.interfaces.OnSafeInsetsChangeListener;
|
|
|
+import com.kongzue.dialogx.interfaces.PopMoveDisplacementInterceptor;
|
|
|
import com.kongzue.dialogx.util.TextInfo;
|
|
|
import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
|
|
|
|
|
@@ -66,6 +67,8 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
public static long overrideExitDuration = -1;
|
|
|
public static int overrideEnterAnimRes = 0;
|
|
|
public static int overrideExitAnimRes = 0;
|
|
|
+ public static int maxShowCount = Integer.MAX_VALUE;
|
|
|
+ public static PopMoveDisplacementInterceptor<PopTip> moveUpDisplacementInterceptor;
|
|
|
|
|
|
protected OnBindView<PopTip> onBindView;
|
|
|
protected DialogLifecycleCallback<PopTip> dialogLifecycleCallback;
|
|
@@ -315,9 +318,19 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
}
|
|
|
} else {
|
|
|
if (popTipList != null) {
|
|
|
- for (int i = 0; i < popTipList.size(); i++) {
|
|
|
- PopTip popInstance = popTipList.get(i);
|
|
|
- popInstance.moveUp();
|
|
|
+ CopyOnWriteArrayList<PopTip> copyPopTipList = new CopyOnWriteArrayList<>(popTipList);
|
|
|
+ for (int i = 0; i < copyPopTipList.size(); i++) {
|
|
|
+ PopTip popInstance = copyPopTipList.get(i);
|
|
|
+ if (copyPopTipList.size() < maxShowCount) {
|
|
|
+ popInstance.moveBack();
|
|
|
+ } else {
|
|
|
+ if (i <= copyPopTipList.size() - maxShowCount) {
|
|
|
+ popInstance.dismiss();
|
|
|
+ popTipList.remove(popInstance);
|
|
|
+ } else {
|
|
|
+ popInstance.moveBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -373,9 +386,19 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
}
|
|
|
} else {
|
|
|
if (popTipList != null) {
|
|
|
- for (int i = 0; i < popTipList.size(); i++) {
|
|
|
- PopTip popInstance = popTipList.get(i);
|
|
|
- popInstance.moveUp();
|
|
|
+ CopyOnWriteArrayList<PopTip> copyPopTipList = new CopyOnWriteArrayList<>(popTipList);
|
|
|
+ for (int i = 0; i < copyPopTipList.size(); i++) {
|
|
|
+ PopTip popInstance = copyPopTipList.get(i);
|
|
|
+ if (copyPopTipList.size() < maxShowCount) {
|
|
|
+ popInstance.moveBack();
|
|
|
+ } else {
|
|
|
+ if (i <= copyPopTipList.size() - maxShowCount) {
|
|
|
+ popInstance.dismiss();
|
|
|
+ popTipList.remove(popInstance);
|
|
|
+ } else {
|
|
|
+ popInstance.moveBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -720,12 +743,22 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
public void run() {
|
|
|
getDialogXAnimImpl().doExitAnim(me, boxBody);
|
|
|
|
|
|
+ preRecycle = true;
|
|
|
runOnMainDelay(new Runnable() {
|
|
|
@Override
|
|
|
public void run() {
|
|
|
waitForDismiss();
|
|
|
}
|
|
|
}, getExitAnimationDuration(null));
|
|
|
+
|
|
|
+ if (popTipList != null) {
|
|
|
+ //使位于自己之前的PopTip moveDown
|
|
|
+ int index = popTipList.indexOf(me);
|
|
|
+ for (int i = 0; i < index; i++) {
|
|
|
+ PopTip popTip = popTipList.get(i);
|
|
|
+ popTip.moveFront();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
});
|
|
|
}
|
|
@@ -809,10 +842,11 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
return;
|
|
|
}
|
|
|
preRecycle = true;
|
|
|
+ getDialogView().setVisibility(View.GONE);
|
|
|
CopyOnWriteArrayList<PopTip> copyPopTipList = new CopyOnWriteArrayList<>(popTipList);
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
|
copyPopTipList.removeIf(Objects::isNull);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
Iterator<PopTip> iterator = copyPopTipList.iterator();
|
|
|
while (iterator.hasNext()) {
|
|
|
if (iterator.next() == null) {
|
|
@@ -820,21 +854,10 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- boolean allPreRecycled = true;
|
|
|
- for (PopTip popTip : copyPopTipList) {
|
|
|
- if (!popTip.preRecycle) {
|
|
|
- allPreRecycled = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (allPreRecycled) {
|
|
|
- for (PopTip popTip : copyPopTipList) {
|
|
|
- dismiss(popTip.getDialogView());
|
|
|
- }
|
|
|
- }
|
|
|
+ dismiss(getDialogView());
|
|
|
}
|
|
|
|
|
|
- private void moveUp() {
|
|
|
+ private void moveBack() {
|
|
|
if (getDialogImpl() != null && getDialogImpl().boxBody != null) {
|
|
|
if (getDialogImpl() == null || getDialogImpl().boxBody == null) return;
|
|
|
View bodyView = getDialogImpl().boxBody;
|
|
@@ -862,11 +885,16 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
moveAimTop = bodyView.getY() - bodyView.getHeight() * 1.3f;
|
|
|
break;
|
|
|
}
|
|
|
+ if (moveUpDisplacementInterceptor != null) {
|
|
|
+ moveAimTop = moveUpDisplacementInterceptor.resetAnimY(popTipList == null ? 0 : popTipList.indexOf(me), me, bodyView.getY(), moveAimTop, (int) (bodyView.getHeight() / bodyView.getScaleY()), popTipList == null ? 1 : popTipList.size(), true);
|
|
|
+ }
|
|
|
if (bodyView.getTag() instanceof ValueAnimator) {
|
|
|
((ValueAnimator) bodyView.getTag()).end();
|
|
|
}
|
|
|
- log("#Animation from:" + bodyView.getY() + " to:" + moveAimTop);
|
|
|
- ValueAnimator valueAnimator = ValueAnimator.ofFloat(bodyView.getY(), moveAimTop);
|
|
|
+ //log("#Animation from:" + bodyView.getY() + " to:" + moveAimTop);
|
|
|
+ final float fromY = bodyView.getY();
|
|
|
+ float toY = moveAimTop;
|
|
|
+ ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromY, toY);
|
|
|
bodyView.setTag(valueAnimator);
|
|
|
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
@Override
|
|
@@ -876,8 +904,13 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
return;
|
|
|
}
|
|
|
View bodyView = getDialogImpl().boxBody;
|
|
|
+ float value = (Float) animation.getAnimatedValue();
|
|
|
+ float totalDistance = toY - fromY;
|
|
|
+ if (moveUpDisplacementInterceptor != null && moveUpDisplacementInterceptor.animUpdater(popTipList == null ? 0 : popTipList.indexOf(me), me, bodyView, fromY, toY, Math.max(0f, Math.min(1f, (totalDistance == 0f ? 1f : (value - fromY) / totalDistance))), animation, popTipList == null ? 1 : countDisplayPopTipsNum(), true)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (bodyView != null && bodyView.isAttachedToWindow()) {
|
|
|
- bodyView.setY((Float) animation.getAnimatedValue());
|
|
|
+ bodyView.setY(value);
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -888,6 +921,82 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void moveFront() {
|
|
|
+ if (getDialogImpl() != null && getDialogImpl().boxBody != null) {
|
|
|
+ if (getDialogImpl() == null || getDialogImpl().boxBody == null) return;
|
|
|
+ View bodyView = getDialogImpl().boxBody;
|
|
|
+ bodyView.post(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ if (getDialogImpl() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (align == null && style.popTipSettings() != null) {
|
|
|
+ align = style.popTipSettings().align();
|
|
|
+ }
|
|
|
+ if (align == null) align = DialogXStyle.PopTipSettings.ALIGN.TOP;
|
|
|
+ float moveAimTop = 0;
|
|
|
+ switch (align) {
|
|
|
+ case TOP:
|
|
|
+ moveAimTop = bodyView.getY() - bodyView.getHeight() * 1.3f;
|
|
|
+ break;
|
|
|
+ case TOP_INSIDE:
|
|
|
+ moveAimTop = bodyView.getY() - bodyView.getHeight() + bodyView.getPaddingTop();
|
|
|
+ break;
|
|
|
+ case CENTER:
|
|
|
+ case BOTTOM:
|
|
|
+ case BOTTOM_INSIDE:
|
|
|
+ moveAimTop = bodyView.getY() + bodyView.getHeight() * 1.3f;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (moveUpDisplacementInterceptor != null) {
|
|
|
+ moveAimTop = moveUpDisplacementInterceptor.resetAnimY(popTipList == null ? 0 : popTipList.indexOf(me), me, bodyView.getY(), moveAimTop, (int) (bodyView.getHeight() / bodyView.getScaleY()), popTipList == null ? 1 : popTipList.size(), false);
|
|
|
+ }
|
|
|
+ if (bodyView.getTag() instanceof ValueAnimator) {
|
|
|
+ ((ValueAnimator) bodyView.getTag()).end();
|
|
|
+ }
|
|
|
+ //log("#Animation from:" + bodyView.getY() + " to:" + moveAimTop);
|
|
|
+ final float fromY = bodyView.getY();
|
|
|
+ float toY = moveAimTop;
|
|
|
+ ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromY, toY);
|
|
|
+ bodyView.setTag(valueAnimator);
|
|
|
+ valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
|
|
+ @Override
|
|
|
+ public void onAnimationUpdate(ValueAnimator animation) {
|
|
|
+ if (getDialogImpl() == null || !isShow) {
|
|
|
+ animation.cancel();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ View bodyView = getDialogImpl().boxBody;
|
|
|
+ float value = (Float) animation.getAnimatedValue();
|
|
|
+ float totalDistance = toY - fromY;
|
|
|
+ if (moveUpDisplacementInterceptor != null && moveUpDisplacementInterceptor.animUpdater(popTipList == null ? 0 : popTipList.indexOf(me), me, bodyView, fromY, toY, Math.max(0f, Math.min(1f, (totalDistance == 0f ? 1f : (value - fromY) / totalDistance))), animation, popTipList == null ? 1 : countDisplayPopTipsNum(), false)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (bodyView != null && bodyView.isAttachedToWindow()) {
|
|
|
+ bodyView.setY(value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ valueAnimator.setDuration(enterAnimDuration == -1 ? 300 : enterAnimDuration).setInterpolator(new DecelerateInterpolator(2f));
|
|
|
+ valueAnimator.start();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private int countDisplayPopTipsNum() {
|
|
|
+ if (popTipList == null) return 0;
|
|
|
+ int count = 0;
|
|
|
+ for (int i = 0; i < popTipList.size(); i++) {
|
|
|
+ PopTip tips = popTipList.get(i);
|
|
|
+ if (tips != null && !tips.preRecycle) {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
public void refreshUI() {
|
|
|
if (getDialogImpl() == null) return;
|
|
|
runOnMain(new Runnable() {
|
|
@@ -1127,9 +1236,19 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
}
|
|
|
} else {
|
|
|
if (popTipList != null) {
|
|
|
- for (int i = 0; i < popTipList.size(); i++) {
|
|
|
- PopTip popInstance = popTipList.get(i);
|
|
|
- popInstance.moveUp();
|
|
|
+ CopyOnWriteArrayList<PopTip> copyPopTipList = new CopyOnWriteArrayList<>(popTipList);
|
|
|
+ for (int i = 0; i < copyPopTipList.size(); i++) {
|
|
|
+ PopTip popInstance = copyPopTipList.get(i);
|
|
|
+ if (copyPopTipList.size() < maxShowCount) {
|
|
|
+ popInstance.moveBack();
|
|
|
+ } else {
|
|
|
+ if (i <= copyPopTipList.size() - maxShowCount) {
|
|
|
+ popInstance.dismiss();
|
|
|
+ popTipList.remove(popInstance);
|
|
|
+ } else {
|
|
|
+ popInstance.moveBack();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1423,22 +1542,22 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public PopTip cleanAction(int actionId){
|
|
|
+ public PopTip cleanAction(int actionId) {
|
|
|
dialogActionRunnableMap.remove(actionId);
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- public PopTip cleanAllAction(){
|
|
|
+ public PopTip cleanAllAction() {
|
|
|
dialogActionRunnableMap.clear();
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
// for BaseDialog use
|
|
|
- public void callDialogDismiss(){
|
|
|
+ public void callDialogDismiss() {
|
|
|
dismiss();
|
|
|
}
|
|
|
|
|
|
- public PopTip bindDismissWithLifecycleOwner(LifecycleOwner owner){
|
|
|
+ public PopTip bindDismissWithLifecycleOwner(LifecycleOwner owner) {
|
|
|
super.bindDismissWithLifecycleOwnerPrivate(owner);
|
|
|
return this;
|
|
|
}
|