Skip to content

Commit

Permalink
把中断接口放到容器中
Browse files Browse the repository at this point in the history
  • Loading branch information
ekwong committed Apr 6, 2020
1 parent 603b4c9 commit 9eebc3d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {

```groovy
dependencies {
implementation 'com.github.EKwongChum:EkPopWindow:1.2.1'
implementation 'com.github.EKwongChum:EkPopWindow:1.2.2'
}
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ allprojects {
$minSdkVersion = 21
$compileSdkVersion = 28
$supportVersion = "28.0.0"
$versionCode = 5
$versionName = "1.2.1"
$versionCode = 6
$versionName = "1.2.2"
}
}

Expand Down
17 changes: 7 additions & 10 deletions ekpopwindowlib/src/main/java/com/ekwong/lib/EkPopWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.view.View;

import com.ekwong.ekpopwindowlib.R;
import com.ekwong.lib.interrupt.BackInterruption;
import com.ekwong.lib.interrupt.Interruption;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -29,7 +31,7 @@ public abstract class EkPopWindow {

private Set<BackPressedListener> backPressedListeners = new HashSet<>();

private Set<BackInterruption> backInterruptions = new HashSet<>();
private Interruption interruption = new Interruption();

public EkPopWindow(Context context, int resLayout, View decorView) {
mContext = context;
Expand All @@ -54,13 +56,10 @@ public boolean removeBackPressedListener(BackPressedListener listener) {
return backPressedListeners.remove(listener);
}

public boolean addBackInterruption(BackInterruption interruption) {
return backInterruptions.add(interruption);
public boolean addBackInterruption(BackInterruption backInterruption) {
return interruption.addBackInterruption(backInterruption);
}

public boolean removeBackInterruption(BackInterruption interruption) {
return backInterruptions.remove(interruption);
}

/**
* 设置弹窗的配置
Expand Down Expand Up @@ -118,10 +117,8 @@ public boolean isShow() {
* 当返回按钮被点击的时候调用
*/
public void onBackPressed() {
if (!backInterruptions.isEmpty()) {
for (BackInterruption listener : backInterruptions) {
listener.interrupt();
}
if (interruption.isEnable()) {
interruption.exec();
} else {
if (!backPressedListeners.isEmpty()) {
for (BackPressedListener listener : backPressedListeners) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ekwong.lib;
package com.ekwong.lib.interrupt;

/**
* @author ekwong
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.ekwong.lib.interrupt;

import java.util.HashSet;
import java.util.Set;

/**
* @author ekwong
*/
public class Interruption {

private Set<BackInterruption> backInterruptions = new HashSet<>();

public boolean addBackInterruption(BackInterruption interruption) {
return backInterruptions.add(interruption);
}

public boolean isEnable() {
return !backInterruptions.isEmpty();
}

public void exec() {
for (BackInterruption interruption : backInterruptions) {
interruption.interrupt();
}
backInterruptions.clear();
}
}

0 comments on commit 9eebc3d

Please sign in to comment.