LibreTube/app/src/main/java/com/github/libretube/helpers/ContextHelper.kt

16 lines
496 B
Kotlin
Raw Normal View History

package com.github.libretube.helpers
import android.content.Context
import android.content.ContextWrapper
import com.github.libretube.ui.activities.MainActivity
object ContextHelper {
fun unwrapActivity(context: Context): MainActivity {
var correctContext: Context? = context
while (correctContext !is MainActivity && correctContext is ContextWrapper) {
correctContext = correctContext.baseContext
}
return correctContext as MainActivity
}
}