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
override fun setUserVisibleHint(isVisibleToUser: Boolean) { | |
isVisibleToUser = isVisibleToUser | |
awaitingRunnable?.let {awaitingRunnable.run()} | |
} |
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 fun initBackStackListener() { | |
supportFragmentManager.addOnBackStackChangedListener { | |
val currentFragment = supportFragmentManager.findFragmentById(fragmentContainer.id) | |
currentFragment.userVisibleHint = true | |
} |
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
class MainActivity : AppCompatActivity() { | |
private lateinit var fragmentContainer: ViewGroup | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
fragmentContainer = findViewById(R.id.fragment_container) as ViewGroup | |
} |
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) | |
} |
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) | |
} |