mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-28 08:32:16 +01:00
Improved two state lifecycles
This commit is contained in:
@@ -15,19 +15,7 @@ public class TwoStateOwner implements LifecycleOwner {
|
||||
|
||||
TwoStateOwner(String aname) {
|
||||
name = aname;
|
||||
|
||||
// Initialize
|
||||
registry = new LifecycleRegistry(this);
|
||||
registry.markState(Lifecycle.State.CREATED);
|
||||
|
||||
// Logging
|
||||
registry.addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
public void onAny() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.i("LifeCycle " + name + " state=" + registry.getCurrentState());
|
||||
}
|
||||
});
|
||||
create();
|
||||
}
|
||||
|
||||
TwoStateOwner(LifecycleOwner owner, String aname) {
|
||||
@@ -44,6 +32,20 @@ public class TwoStateOwner implements LifecycleOwner {
|
||||
});
|
||||
}
|
||||
|
||||
private void create() {
|
||||
// Initialize
|
||||
registry = new LifecycleRegistry(this);
|
||||
registry.addObserver(new LifecycleObserver() {
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_ANY)
|
||||
public void onAny() {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.i("LifeCycle " + name + " state=" + registry.getCurrentState() + " " + registry);
|
||||
}
|
||||
});
|
||||
|
||||
registry.markState(Lifecycle.State.CREATED);
|
||||
}
|
||||
|
||||
void start() {
|
||||
registry.markState(Lifecycle.State.STARTED);
|
||||
}
|
||||
@@ -57,6 +59,11 @@ public class TwoStateOwner implements LifecycleOwner {
|
||||
start();
|
||||
}
|
||||
|
||||
void recreate() {
|
||||
destroy();
|
||||
create();
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
Lifecycle.State state = registry.getCurrentState();
|
||||
if (!state.equals(Lifecycle.State.CREATED))
|
||||
|
||||
Reference in New Issue
Block a user