Last active
October 23, 2021 00:11
-
-
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
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
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