Skip to content

Instantly share code, notes, and snippets.

@jmarsican
jmarsican / FoldingFeature.kt
Last active October 23, 2021 00:11
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,
@jmarsican
jmarsican / VRActivity.kt
Created June 17, 2020 01:42
Sample app for an easy Virtual Reality integration with ExoPlayer. This is achieved playing 360 videos (spherical) and using device motion sensors to navigate within them
class VRActivity : AppCompatActivity() {
private var player: SimpleExoPlayer? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.video_player_layout)
(player_view.videoSurfaceView as SphericalGLSurfaceView)
.setDefaultStereoMode(C.STEREO_MODE_TOP_BOTTOM)
@jmarsican
jmarsican / build.gradle
Created April 7, 2020 01:51
Gradle function to create a custom task to be executed upon other and copy the apk file in the desired location
task getDebugAppInDesktopFolder(dependsOn: 'assembleDebug') {
doLast {
def destination = "Put the desired path"
def desiredName = "Put the desired name"
ext.apk = file("build/outputs/apk/debug/app-debug.apk")
if (ext.apk.exists()) {
copy {
from ext.apk.absolutePath
into destination
@jmarsican
jmarsican / PolymorphicProgram.kt
Created November 23, 2019 20:52 — forked from JorgeCastilloPrz/PolymorphicProgram.kt
PolymorphicProgram.kt
package me.jorgecastillo.polymorphicapps.polymorphic
import arrow.Kind
import arrow.core.Option
import arrow.core.left
import arrow.core.right
import arrow.effects.IO
import arrow.effects.async
import arrow.effects.fix
import arrow.effects.typeclasses.Async
@jmarsican
jmarsican / RxApp.kt
Created November 23, 2019 20:48 — forked from JorgeCastilloPrz/RxApp.kt
Sample snippet for a canonical problem resolved using RxJava
interface DataSource {
fun allTasksByUser(user: User): Observable<List<Task>>
}
class LocalDataSource : DataSource {
private val localCache: Map<User, List<Task>> =
mapOf(User(UserId("user1")) to listOf(Task("LocalTask assigned to user1")))
override fun allTasksByUser(user: User): Observable<List<Task>> = Observable.create { emitter ->
val cachedUser = localCache[user]