-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
62 changed files
with
533 additions
and
474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 26 additions & 7 deletions
33
JetpackMvvm/src/main/java/me/hgj/jetpackmvvm/callback/livedata/event/Event.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
package me.hgj.jetpackmvvm.callback.livedata.event | ||
|
||
import java.util.* | ||
|
||
/** | ||
* 配合 MutableLiveData & EventViewModel 的使用 | ||
* @author : hgj | ||
* @date : 2020/6/8 | ||
* @date : 2020/7/3 | ||
*/ | ||
class Event<T>(private val content: T?) { | ||
|
||
class Event<T>(content: T) { | ||
private var content: T? | ||
private var hasHandled = false | ||
private var isDelaying = false | ||
fun getContent(): T? { | ||
if (hasHandled) { | ||
return null | ||
return if (!hasHandled) { | ||
hasHandled = true | ||
isDelaying = true | ||
val timer = Timer() | ||
val task: TimerTask = object : TimerTask() { | ||
override fun run() { | ||
content = null | ||
isDelaying = false | ||
} | ||
} | ||
timer.schedule(task, 1000) | ||
content | ||
} else if (isDelaying) { | ||
content | ||
} else { | ||
null | ||
} | ||
hasHandled = true | ||
return content | ||
} | ||
|
||
init { | ||
this.content = content | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.