Skip to content

Instantly share code, notes, and snippets.

@jmarsican
Last active October 23, 2021 00:11
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 jmarsican/0474f87869f6e4c9ba98c5033c06cdac to your computer and use it in GitHub Desktop.
Save jmarsican/0474f87869f6e4c9ba98c5033c06cdac to your computer and use it in GitHub Desktop.
Example using window layout info to be notified when user changes foldable screen state
windowInfoRepository
.windowLayoutInfoObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe{ windowLayoutInfo ->
windowLayoutInfo.displayFeatures.filterIsInstance(FoldingFeature::class.java)
.firstOrNull ()?.let { foldingFeature ->
if (foldingFeature.state == FoldingFeature.State.HALF_OPENED) {
recyclerView.layoutManager = LinearLayoutManager(
context,
LinearLayoutManager.HORIZONTAL,
false
)
} else {
recyclerView.layoutManager = GridLayoutManager(
context,
3,
LinearLayoutManager.VERTICAL,
false
)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment