Created
September 27, 2017 15:44
-
-
Save youngam/38b4a46958c7ef6766d17979f92631f9 to your computer and use it in GitHub Desktop.
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
public class DetectingVisibilityFragment extends Fragment { | |
// will talk about this flag later | |
private var isVisibleToUser: Boolean = true | |
private var awaitingRunnable: Runnable? = null | |
// triggered when notification from Server or client EventBus came | |
override fun onNotification(newName: String) { | |
if(isVisibleToUser) show(newName) | |
else awaitingRunnable = () -> show(newName) | |
} | |
// some methods that I tried to find in standard Fragment API | |
override fun onBecomesVisible(isVisible: Boolean) { | |
isVisibleToUser = isVisible | |
awaitingRunnable?.let {awaitingRunnable.run()} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment