Skip to content

Commit

Permalink
feat: ActivityStack 增加为空时候的事件
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojinzi123 committed Aug 30, 2023
1 parent a45090a commit 2ed94d3
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib-activity-stack/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ android {

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
api project(':lib-ktx')
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import android.app.Application
import android.os.Build
import android.os.Bundle
import android.util.Log
import com.xiaojinzi.support.ktx.CacheSharedFlow
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import java.util.Stack

@Retention(
Expand Down Expand Up @@ -169,6 +173,13 @@ object ActivityStack {
*/
private val activityStack: Stack<Activity> = Stack()

private val _emptyStackEvent = CacheSharedFlow<Unit>()

/**
* 启动的时候就是 Empty 的情况不会有事件
*/
val emptyStackEvent: Flow<Unit> = _emptyStackEvent

/**
* @return whether the the size of stack of Activity is zero or not
*/
Expand Down Expand Up @@ -310,6 +321,11 @@ object ActivityStack {
TAG, "removeActivity: $activity"
)
activityStack.remove(activity)
if (activityStack.isEmpty()) {
_emptyStackEvent.add(
value = Unit
)
}
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.xiaojinzi.support.ktx

import com.xiaojinzi.support.annotation.HotObservable
import com.xiaojinzi.support.ktx.NormalMutableSharedFlow
import kotlinx.coroutines.flow.MutableSharedFlow

/**
Expand Down

0 comments on commit 2ed94d3

Please sign in to comment.