mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-29 00:51:44 +01:00
Use restartable two state child owner
This commit is contained in:
@@ -2,8 +2,10 @@ package eu.faircode.email;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.lifecycle.LifecycleRegistry;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
public class TwoStateOwner implements LifecycleOwner {
|
||||
private LifecycleRegistry registry;
|
||||
@@ -12,6 +14,16 @@ public class TwoStateOwner implements LifecycleOwner {
|
||||
registry = new LifecycleRegistry(this);
|
||||
}
|
||||
|
||||
TwoStateOwner(LifecycleOwner owner) {
|
||||
this();
|
||||
owner.getLifecycle().addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_DESTROY)
|
||||
public void onDestroyed() {
|
||||
registry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void start() {
|
||||
registry.handleLifecycleEvent(Lifecycle.Event.ON_START);
|
||||
}
|
||||
@@ -20,6 +32,11 @@ public class TwoStateOwner implements LifecycleOwner {
|
||||
registry.handleLifecycleEvent(Lifecycle.Event.ON_STOP);
|
||||
}
|
||||
|
||||
void restart() {
|
||||
registry.handleLifecycleEvent(Lifecycle.Event.ON_DESTROY);
|
||||
start();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Lifecycle getLifecycle() {
|
||||
|
||||
Reference in New Issue
Block a user