Skip to content

Instantly share code, notes, and snippets.

View rishabhkohli's full-sized avatar

Rishabh Kohli rishabhkohli

View GitHub Profile
@jamiesanson
jamiesanson / ViewLifecycleLazy.kt
Last active March 26, 2024 13:17
A Kotlin lazy implementation which automatically clears itself at appropriate times in the View Lifecycle, with a Fragment example
import androidx.fragment.app.Fragment
import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KProperty
fun <T> Fragment.viewLifecycleLazy(initialise: () -> T): ReadOnlyProperty<Fragment, T> =
object : ReadOnlyProperty<Fragment, T>, DefaultLifecycleObserver {
@kshivang
kshivang / BaseActivity.java
Last active October 11, 2020 16:16
Instagram like ViewPager implementation with bottom tab layout, without recreating fragments in fragment manager on tab select or back click. Implementation is prescribed for ViewPager inside fragment(more complex case) similar thing could be achieved for ViewPager in activity as well.
public abstract class BaseActivity extends AppCompatActivity {
public void moveBack() {
super.onBackPressed();
}
public abstract void onBackWhenNoFragment();
@Override
public void onBackPressed() {