Skip to content

Commit

Permalink
优化页面过滤
Browse files Browse the repository at this point in the history
  • Loading branch information
princekin-f committed Jan 8, 2020
1 parent 5ead4c8 commit bcc7ee7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 42 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ allprojects {
- **在应用模块的`build.gradle`添加:**
```
dependencies {
implementation 'com.github.princekin-f:EasyFloat:1.2.4'
implementation 'com.github.princekin-f:EasyFloat:1.2.5'
}
```

Expand Down Expand Up @@ -244,6 +244,14 @@ InputMethodUtils.closedInputMethod(tag)
## 关于更新:
- [查看版本更新日志](https://github.com/princekin-f/EasyFloat/blob/master/UpdateDoc.md)

## 交流和激励:
- **为了大家更好的交流和反馈,我们创建了QQ群:`818756969`**
- 如果该库对你提供了帮助,你可以小小的赏赞一下作者,同样作者也会非常感谢你!我们一起众筹云测😘

|QQ 交流群|Alipay|WeChat Pay|
|:---:|:---:|:---:|
|![](https://github.com/princekin-f/EasyFloat/blob/master/gif/EasyFloatGroup.jpeg)|![](https://github.com/princekin-f/EasyFloat/blob/master/gif/Alipay.jpeg)|![](https://github.com/princekin-f/EasyFloat/blob/master/gif/WeChatPay.jpeg)|

License
-------

Expand Down
3 changes: 3 additions & 0 deletions UpdateDoc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 版本更新日志
#### v 1.2.5:
- 优化页面过滤。

#### v 1.2.4:
- 优化全面屏适配。

Expand Down
92 changes: 51 additions & 41 deletions easyfloat/src/main/java/com/lzf/easyfloat/utils/LifecycleUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,57 +21,67 @@ internal object LifecycleUtils {
application.registerActivityLifecycleCallbacks(object :
Application.ActivityLifecycleCallbacks {

override fun onActivityPaused(activity: Activity?) {}

override fun onActivityResumed(activity: Activity?) {}

override fun onActivityStarted(activity: Activity?) {
if (activity == null) return
activityCount++
FloatManager.floatMap.forEach { (tag, manager) ->
// 仅后台显示模式下,隐藏浮窗
if (manager.config.showPattern == ShowPattern.BACKGROUND) {
setVisible(false, tag)
return
}

// 如果手动隐藏浮窗,不再考虑过滤信息
if (!manager.config.needShow) return

// 过滤不需要显示浮窗的页面
manager.config.filterSet.forEach filterSet@{
if (it == activity.componentName.className) {
setVisible(false, tag)
manager.config.needShow = false
logger.i("过滤浮窗显示: $it, tag: $tag")
return@filterSet
}
}

// 当过滤信息没有匹配上时,需要发送广播,反之修改needShow为默认值
if (manager.config.needShow) setVisible(tag = tag)
else manager.config.needShow = true
}
}
override fun onActivityPaused(activity: Activity?) = checkHide(activity)

override fun onActivityResumed(activity: Activity?) = checkShow(activity)

override fun onActivityStarted(activity: Activity?) {}

override fun onActivityDestroyed(activity: Activity?) {}

override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {}

override fun onActivityStopped(activity: Activity?) {
if (activity == null) return
activityCount--
if (isForeground()) return
FloatManager.floatMap.forEach { (tag, manager) ->
// 当app处于后台时,不是仅前台显示的浮窗,都需要显示
setVisible(manager.config.showPattern != ShowPattern.FOREGROUND, tag)
}
}
override fun onActivityStopped(activity: Activity?) {}

override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {}
})
}

/**
* 判断浮窗是否需要显示
*/
private fun checkShow(activity: Activity?) {
if (activity == null) return
activityCount++
FloatManager.floatMap.forEach { (tag, manager) ->
// 仅后台显示模式下,隐藏浮窗
if (manager.config.showPattern == ShowPattern.BACKGROUND) {
setVisible(false, tag)
return
}

// 如果手动隐藏浮窗,不再考虑过滤信息
if (!manager.config.needShow) return

// 过滤不需要显示浮窗的页面
manager.config.filterSet.forEach filterSet@{
if (it == activity.componentName.className) {
setVisible(false, tag)
manager.config.needShow = false
logger.i("过滤浮窗显示: $it, tag: $tag")
return@filterSet
}
}

// 当过滤信息没有匹配上时,需要发送广播,反之修改needShow为默认值
if (manager.config.needShow) setVisible(tag = tag)
else manager.config.needShow = true
}
}

/**
* 判断浮窗是否需要隐藏
*/
private fun checkHide(activity: Activity?) {
if (activity == null) return
activityCount--
if (isForeground()) return
FloatManager.floatMap.forEach { (tag, manager) ->
// 当app处于后台时,不是仅前台显示的浮窗,都需要显示
setVisible(manager.config.showPattern != ShowPattern.FOREGROUND, tag)
}
}

private fun isForeground() = activityCount > 0

private fun setVisible(boolean: Boolean = isForeground(), tag: String?) =
Expand Down
Binary file added gif/EasyFloatGroup.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit bcc7ee7

Please sign in to comment.