1
0
kongzue 4 жил өмнө
parent
commit
02f5083ff4

+ 1 - 1
DialogX/src/main/java/com/kongzue/dialogx/DialogX.java

@@ -38,7 +38,7 @@ public class DialogX {
     public static boolean autoShowInputKeyboard = true;
     
     //同时只显示一个 PopTip
-    public static boolean onlyOnePopTip = true;
+    public static boolean onlyOnePopTip = false;
     
     //默认按钮文字样式
     public static TextInfo buttonTextInfo;

+ 96 - 18
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java

@@ -35,6 +35,8 @@ import com.kongzue.dialogx.util.TextInfo;
 import com.kongzue.dialogx.util.views.DialogXBaseRelativeLayout;
 
 import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -48,8 +50,8 @@ import java.util.TimerTask;
 public class PopTip extends BaseDialog {
     
     public static final int TIME_NO_AUTO_DISMISS_DELAY = -1;
+    protected static List<PopTip> popTipList;
     
-    protected static WeakReference<PopTip> oldInstance;
     protected OnBindView<PopTip> onBindView;
     protected DialogLifecycleCallback<PopTip> dialogLifecycleCallback;
     protected PopTip me = this;
@@ -245,11 +247,23 @@ public class PopTip extends BaseDialog {
     public void show() {
         super.beforeShow();
         if (DialogX.onlyOnePopTip) {
-            if (oldInstance != null && oldInstance.get() != null) {
-                oldInstance.get().dismiss();
+            PopTip oldInstance = null;
+            if (popTipList != null && !popTipList.isEmpty()) {
+                oldInstance = popTipList.get(popTipList.size() - 1);
+            }
+            if (oldInstance != null) {
+                oldInstance.dismiss();
+            }
+        } else {
+            if (popTipList != null) {
+                for (int i = 0; i < popTipList.size(); i++) {
+                    PopTip popInstance = popTipList.get(i);
+                    popInstance.moveUp();
+                }
             }
         }
-        oldInstance = new WeakReference<>(this);
+        if (popTipList == null) popTipList = new ArrayList<>();
+        popTipList.add(PopTip.this);
         int layoutResId = isLightTheme() ? R.layout.layout_dialogx_poptip_material : R.layout.layout_dialogx_poptip_material_dark;
         if (style.popTipSettings() != null) {
             if (style.popTipSettings().layout(isLightTheme()) != 0) {
@@ -269,11 +283,23 @@ public class PopTip extends BaseDialog {
     public void show(Activity activity) {
         super.beforeShow();
         if (DialogX.onlyOnePopTip) {
-            if (oldInstance != null && oldInstance.get() != null) {
-                oldInstance.get().dismiss();
+            PopTip oldInstance = null;
+            if (popTipList != null && !popTipList.isEmpty()) {
+                oldInstance = popTipList.get(popTipList.size() - 1);
+            }
+            if (oldInstance != null) {
+                oldInstance.dismiss();
+            }
+        } else {
+            if (popTipList != null) {
+                for (int i = 0; i < popTipList.size(); i++) {
+                    PopTip popInstance = popTipList.get(i);
+                    popInstance.moveUp();
+                }
             }
         }
-        oldInstance = new WeakReference<>(this);
+        if (popTipList == null) popTipList = new ArrayList<>();
+        popTipList.add(PopTip.this);
         int layoutResId = isLightTheme() ? R.layout.layout_dialogx_poptip_material : R.layout.layout_dialogx_poptip_material_dark;
         if (style.popTipSettings() != null) {
             if (style.popTipSettings().layout(isLightTheme()) != 0) {
@@ -326,7 +352,7 @@ public class PopTip extends BaseDialog {
         return this;
     }
     
-    public class DialogImpl implements DialogConvertViewInterface  {
+    public class DialogImpl implements DialogConvertViewInterface {
         
         public DialogXBaseRelativeLayout boxRoot;
         public LinearLayout boxBody;
@@ -356,7 +382,7 @@ public class PopTip extends BaseDialog {
             if (autoDismissTimer == null) {
                 showShort();
             }
-    
+            
             boxRoot.setParentDialog(me);
             boxRoot.setAutoUnsafePlacePadding(false);
             boxRoot.setOnLifecycleCallBack(new DialogXBaseRelativeLayout.OnLifecycleCallBack() {
@@ -372,8 +398,8 @@ public class PopTip extends BaseDialog {
                 
                 @Override
                 public void onDismiss() {
+                    if (popTipList != null) popTipList.remove(PopTip.this);
                     isShow = false;
-                    if (oldInstance.get() == me) oldInstance.clear();
                     getDialogLifecycleCallback().onDismiss(me);
                 }
             });
@@ -408,7 +434,7 @@ public class PopTip extends BaseDialog {
                     }
                 }
             });
-    
+            
             boxRoot.setOnBackPressedListener(new OnBackPressedListener() {
                 @Override
                 public boolean onBackPressed() {
@@ -422,13 +448,13 @@ public class PopTip extends BaseDialog {
                     
                     Animation enterAnim = AnimationUtils.loadAnimation(getContext(), enterAnimResId);
                     enterAnim.setInterpolator(new DecelerateInterpolator(2f));
-                    if (enterAnimDuration!=-1){
+                    if (enterAnimDuration != -1) {
                         enterAnim.setDuration(enterAnimDuration);
                     }
                     boxBody.startAnimation(enterAnim);
                     
                     boxRoot.animate()
-                            .setDuration(enterAnimDuration==-1?enterAnim.getDuration():enterAnimDuration)
+                            .setDuration(enterAnimDuration == -1 ? enterAnim.getDuration() : enterAnimDuration)
                             .alpha(1f)
                             .setInterpolator(new DecelerateInterpolator())
                             .setListener(null);
@@ -510,7 +536,7 @@ public class PopTip extends BaseDialog {
                     if (v != null) v.setEnabled(false);
                     
                     Animation exitAnim = AnimationUtils.loadAnimation(getContext(), exitAnimResId);
-                    if (exitAnimDuration!=-1){
+                    if (exitAnimDuration != -1) {
                         exitAnim.setDuration(exitAnimResId);
                     }
                     boxBody.startAnimation(exitAnim);
@@ -530,6 +556,43 @@ public class PopTip extends BaseDialog {
         }
     }
     
+    private void moveUp() {
+        if (getDialogImpl()!=null && getDialogImpl().boxBody!=null){
+            getDialogImpl().boxBody.post(new Runnable() {
+                @Override
+                public void run() {
+                    if (style.popTipSettings() != null) align = style.popTipSettings().align();
+                    if (align == null) align = DialogXStyle.PopTipSettings.ALIGN.BOTTOM;
+                    switch (align) {
+                        case TOP:
+                            getDialogImpl().boxBody.animate()
+                                    .y(getDialogImpl().boxBody.getY() + getDialogImpl().boxBody.getHeight() * 1.3f)
+                                    .setDuration(enterAnimDuration == -1 ? 300 : enterAnimDuration)
+                                    .setInterpolator(new DecelerateInterpolator(2f))
+                            ;
+                            break;
+                        case TOP_INSIDE:
+                            getDialogImpl().boxBody.animate()
+                                    .y(getDialogImpl().boxBody.getY() + getDialogImpl().boxBody.getHeight() -getDialogImpl().boxBody.getPaddingTop())
+                                    .setDuration(enterAnimDuration == -1 ? 300 : enterAnimDuration)
+                                    .setInterpolator(new DecelerateInterpolator(2f))
+                            ;
+                            break;
+                        case CENTER:
+                        case BOTTOM:
+                        case BOTTOM_INSIDE:
+                            getDialogImpl().boxBody.animate()
+                                    .y(getDialogImpl().boxBody.getY() - getDialogImpl().boxBody.getHeight() * 1.3f)
+                                    .setDuration(enterAnimDuration == -1 ? 300 : enterAnimDuration)
+                                    .setInterpolator(new DecelerateInterpolator(2f))
+                            ;
+                            break;
+                    }
+                }
+            });
+        }
+    }
+    
     public void refreshUI() {
         if (getRootFrameLayout() == null) return;
         getRootFrameLayout().post(new Runnable() {
@@ -720,6 +783,7 @@ public class PopTip extends BaseDialog {
         refreshUI();
         return this;
     }
+    
     public long getEnterAnimDuration() {
         return enterAnimDuration;
     }
@@ -743,15 +807,29 @@ public class PopTip extends BaseDialog {
         if (dialogView != null) {
             dismiss(dialogView);
         }
-        if (getDialogImpl().boxCustom!=null){
+        if (getDialogImpl().boxCustom != null) {
             getDialogImpl().boxCustom.removeAllViews();
         }
+        
         if (DialogX.onlyOnePopTip) {
-            if (oldInstance != null && oldInstance.get() != null) {
-                oldInstance.get().dismiss();
+            PopTip oldInstance = null;
+            if (popTipList != null && !popTipList.isEmpty()) {
+                oldInstance = popTipList.get(popTipList.size() - 1);
+            }
+            if (oldInstance != null) {
+                oldInstance.dismiss();
+            }
+        } else {
+            if (popTipList != null) {
+                for (int i = 0; i < popTipList.size(); i++) {
+                    PopTip popInstance = popTipList.get(i);
+                    popInstance.moveUp();
+                }
             }
         }
-        oldInstance = new WeakReference<>(this);
+        if (popTipList == null) popTipList = new ArrayList<>();
+        popTipList.add(PopTip.this);
+        
         int layoutResId = isLightTheme() ? R.layout.layout_dialogx_poptip_material : R.layout.layout_dialogx_poptip_material_dark;
         if (style.popTipSettings() != null) {
             if (style.popTipSettings().layout(isLightTheme()) != 0) {

+ 0 - 3
DialogX/src/main/java/com/kongzue/dialogx/style/MaterialStyle.java

@@ -16,9 +16,6 @@ import com.kongzue.dialogx.util.views.ProgressView;
  */
 public class MaterialStyle implements DialogXStyle {
     
-    private MaterialStyle() {
-    }
-    
     public static MaterialStyle style() {
         return new MaterialStyle();
     }

+ 1 - 1
DialogX/src/main/res/anim/anim_dialogx_default_enter.xml

@@ -12,6 +12,6 @@
 
     <alpha
         android:duration="300"
-        android:fromAlpha="1.0"
+        android:fromAlpha="0.0"
         android:toAlpha="1.0" />
 </set>

+ 1 - 1
DialogX/src/main/res/anim/anim_dialogx_default_exit.xml

@@ -4,6 +4,6 @@
     <alpha
         android:duration="300"
         android:fromAlpha="1.0"
-        android:toAlpha="1.0" />
+        android:toAlpha="0.0" />
 
 </set>

+ 0 - 3
DialogXIOSStyle/src/main/java/com/kongzue/dialogx/style/IOSStyle.java

@@ -17,9 +17,6 @@ import com.kongzue.dialogx.style.views.ProgressView;
  */
 public class IOSStyle implements DialogXStyle {
     
-    private IOSStyle() {
-    }
-    
     public static IOSStyle style() {
         return new IOSStyle();
     }

+ 0 - 3
DialogXKongzueStyle/src/main/java/com/kongzue/dialogx/style/KongzueStyle.java

@@ -15,9 +15,6 @@ import com.kongzue.dialogx.kongzuetheme.R;
  */
 public class KongzueStyle implements DialogXStyle {
     
-    private KongzueStyle() {
-    }
-    
     public static KongzueStyle style() {
         return new KongzueStyle();
     }

+ 0 - 3
DialogXMIUIStyle/src/main/java/com/kongzue/dialogx/style/MIUIStyle.java

@@ -15,9 +15,6 @@ import com.kongzue.dialogx.miuistyle.R;
  */
 public class MIUIStyle implements DialogXStyle {
     
-    private MIUIStyle() {
-    }
-    
     public static MIUIStyle style() {
         return new MIUIStyle();
     }

+ 2 - 2
README.md

@@ -104,7 +104,7 @@ DialogX 采用了主题分离结构,主框架仅包含 Material 设计风格
 想要在您的项目引入 DialogX,您需要在 app 的 build.gradle 文件中找到 `dependencies{}` 代码块,并在其中加入以下语句:
 
 ```
-implementation 'com.kongzue.dialogx:DialogX:0.0.32'
+implementation 'com.kongzue.dialogx:DialogX:0.0.33'
 ```
 
 若有需要,也可以手动配置 Maven:
@@ -113,7 +113,7 @@ implementation 'com.kongzue.dialogx:DialogX:0.0.32'
 <dependency>
   <groupId>com.kongzue.dialogx</groupId>
   <artifactId>DialogX</artifactId>
-  <version>0.0.32</version>
+  <version>0.0.33</version>
   <type>pom</type>
 </dependency>
 ```

+ 2 - 0
app/src/main/java/com/kongzue/dialogxdemo/MainActivity.java

@@ -147,6 +147,7 @@ public class MainActivity extends BaseActivity {
         refreshUIMode();
         DialogX.globalStyle = MaterialStyle.style();
         DialogX.globalTheme = DialogX.THEME.AUTO;
+        DialogX.onlyOnePopTip = true;
         
         boolean showBreak = parameter.getBoolean("showBreak");
         if (showBreak) {
@@ -647,6 +648,7 @@ public class MainActivity extends BaseActivity {
                         @Override
                         public boolean onClick(PopTip popTip, View v) {
                             //点击“撤回”按钮回调
+                            toastS("邮件已撤回");
                             return false;
                         }
                     }).showLong();

+ 2 - 2
gradle.properties

@@ -18,5 +18,5 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.32.beta2
-BUILD_VERSION_INT=32
+BUILD_VERSION=0.0.33
+BUILD_VERSION_INT=33