mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 08:35:37 -04:00
Refactor(quick settings): better lifecycle interface
This commit is contained in:
parent
1aface5d17
commit
6888de85fc
@ -149,17 +149,16 @@ public abstract class SideDialogView {
|
||||
|
||||
/**
|
||||
* Slide the layout into the visible screen area
|
||||
* @return Whether the layout position has changed
|
||||
*/
|
||||
@CallSuper
|
||||
public final void appear(boolean fromRight) {
|
||||
boolean willBuild = !mIsInstantiated;
|
||||
if (!mIsInstantiated) {
|
||||
inflateLayout();
|
||||
onInflate();
|
||||
}
|
||||
|
||||
// To avoid UI sizing issue when the dialog is not fully inflated
|
||||
onAppear(willBuild);
|
||||
onAppear();
|
||||
Tools.runOnUiThread(() -> {
|
||||
if (fromRight) {
|
||||
if (!mDisplaying || !isAtRight()) {
|
||||
@ -190,7 +189,8 @@ public abstract class SideDialogView {
|
||||
public final void disappear(boolean destroy) {
|
||||
if (!mDisplaying) {
|
||||
if(destroy) {
|
||||
onDisappear(true);
|
||||
onDisappear();
|
||||
onDestroy();
|
||||
deflateLayout();
|
||||
}
|
||||
return;
|
||||
@ -203,7 +203,8 @@ public abstract class SideDialogView {
|
||||
mSideDialogAnimator.setFloatValues(mMargin, -mDialogLayout.getWidth());
|
||||
|
||||
if(destroy) {
|
||||
onDisappear(true);
|
||||
onDisappear();
|
||||
onDestroy();
|
||||
mSideDialogAnimator.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
@ -222,16 +223,25 @@ public abstract class SideDialogView {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called after the dialog has appeared with an inflated layout
|
||||
* @param hasBuilt Whether the layout has JUST been built. If false, the layout has been built before
|
||||
* Called when the dialog is inflated, ideal for setting up UI elements bindings
|
||||
*/
|
||||
protected abstract void onAppear(boolean hasBuilt);
|
||||
protected void onInflate() {}
|
||||
|
||||
/**
|
||||
* Called after the dialog has appeared
|
||||
*/
|
||||
protected void onAppear() {}
|
||||
|
||||
/**
|
||||
* Called after the dialog has disappeared
|
||||
* @param willDestroy Whether the dialog will be destroyed after disappearing
|
||||
*/
|
||||
protected abstract void onDisappear(boolean willDestroy);
|
||||
protected void onDisappear() {}
|
||||
|
||||
/**
|
||||
* Called before the dialog gets destroyed (removing views from parent)
|
||||
* Ideal for cleaning up resources
|
||||
*/
|
||||
protected void onDestroy() {}
|
||||
|
||||
|
||||
}
|
||||
|
@ -91,21 +91,16 @@ public class EditControlSideDialog extends SideDialogView {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAppear(boolean hasBuilt) {
|
||||
if(hasBuilt) {
|
||||
bindLayout();
|
||||
buildColorSelector();
|
||||
|
||||
loadAdapter();
|
||||
setupRealTimeListeners();
|
||||
}
|
||||
protected void onInflate() {
|
||||
bindLayout();
|
||||
buildColorSelector();
|
||||
loadAdapter();
|
||||
setupRealTimeListeners();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisappear(boolean willDestroy) {
|
||||
if (willDestroy) {
|
||||
mParent.removeView(mColorSelector.getRootView());
|
||||
}
|
||||
protected void onDestroy() {
|
||||
mParent.removeView(mColorSelector.getRootView());
|
||||
}
|
||||
|
||||
/* While the selector could be retrofitted to side dialog, it's not worth the effort */
|
||||
|
@ -48,16 +48,14 @@ public abstract class QuickSettingSideDialog extends com.kdt.SideDialogView {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAppear(boolean hasBuilt) {
|
||||
if (hasBuilt) {
|
||||
bindLayout();
|
||||
Tools.runOnUiThread(this::setupListeners);
|
||||
}
|
||||
protected void onInflate() {
|
||||
bindLayout();
|
||||
Tools.runOnUiThread(this::setupListeners);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisappear(boolean willDestroy) {
|
||||
if (willDestroy) removeListeners();
|
||||
protected void onDestroy() {
|
||||
removeListeners();
|
||||
}
|
||||
|
||||
private void bindLayout() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user