Skip to content

Instantly share code, notes, and snippets.

@youngam
Created September 27, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youngam/38b4a46958c7ef6766d17979f92631f9 to your computer and use it in GitHub Desktop.
Save youngam/38b4a46958c7ef6766d17979f92631f9 to your computer and use it in GitHub Desktop.
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