mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-18 09:07:48 -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
|
* Slide the layout into the visible screen area
|
||||||
* @return Whether the layout position has changed
|
|
||||||
*/
|
*/
|
||||||
@CallSuper
|
@CallSuper
|
||||||
public final void appear(boolean fromRight) {
|
public final void appear(boolean fromRight) {
|
||||||
boolean willBuild = !mIsInstantiated;
|
|
||||||
if (!mIsInstantiated) {
|
if (!mIsInstantiated) {
|
||||||
inflateLayout();
|
inflateLayout();
|
||||||
|
onInflate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// To avoid UI sizing issue when the dialog is not fully inflated
|
// To avoid UI sizing issue when the dialog is not fully inflated
|
||||||
onAppear(willBuild);
|
onAppear();
|
||||||
Tools.runOnUiThread(() -> {
|
Tools.runOnUiThread(() -> {
|
||||||
if (fromRight) {
|
if (fromRight) {
|
||||||
if (!mDisplaying || !isAtRight()) {
|
if (!mDisplaying || !isAtRight()) {
|
||||||
@ -190,7 +189,8 @@ public abstract class SideDialogView {
|
|||||||
public final void disappear(boolean destroy) {
|
public final void disappear(boolean destroy) {
|
||||||
if (!mDisplaying) {
|
if (!mDisplaying) {
|
||||||
if(destroy) {
|
if(destroy) {
|
||||||
onDisappear(true);
|
onDisappear();
|
||||||
|
onDestroy();
|
||||||
deflateLayout();
|
deflateLayout();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -203,7 +203,8 @@ public abstract class SideDialogView {
|
|||||||
mSideDialogAnimator.setFloatValues(mMargin, -mDialogLayout.getWidth());
|
mSideDialogAnimator.setFloatValues(mMargin, -mDialogLayout.getWidth());
|
||||||
|
|
||||||
if(destroy) {
|
if(destroy) {
|
||||||
onDisappear(true);
|
onDisappear();
|
||||||
|
onDestroy();
|
||||||
mSideDialogAnimator.addListener(new AnimatorListenerAdapter() {
|
mSideDialogAnimator.addListener(new AnimatorListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationEnd(Animator animation) {
|
public void onAnimationEnd(Animator animation) {
|
||||||
@ -222,16 +223,25 @@ public abstract class SideDialogView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after the dialog has appeared with an inflated layout
|
* Called when the dialog is inflated, ideal for setting up UI elements bindings
|
||||||
* @param hasBuilt Whether the layout has JUST been built. If false, the layout has been built before
|
|
||||||
*/
|
*/
|
||||||
protected abstract void onAppear(boolean hasBuilt);
|
protected void onInflate() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after the dialog has appeared
|
||||||
|
*/
|
||||||
|
protected void onAppear() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called after the dialog has disappeared
|
* 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
|
@Override
|
||||||
protected void onAppear(boolean hasBuilt) {
|
protected void onInflate() {
|
||||||
if(hasBuilt) {
|
bindLayout();
|
||||||
bindLayout();
|
buildColorSelector();
|
||||||
buildColorSelector();
|
loadAdapter();
|
||||||
|
setupRealTimeListeners();
|
||||||
loadAdapter();
|
|
||||||
setupRealTimeListeners();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDisappear(boolean willDestroy) {
|
protected void onDestroy() {
|
||||||
if (willDestroy) {
|
mParent.removeView(mColorSelector.getRootView());
|
||||||
mParent.removeView(mColorSelector.getRootView());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* While the selector could be retrofitted to side dialog, it's not worth the effort */
|
/* 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
|
@Override
|
||||||
protected void onAppear(boolean hasBuilt) {
|
protected void onInflate() {
|
||||||
if (hasBuilt) {
|
bindLayout();
|
||||||
bindLayout();
|
Tools.runOnUiThread(this::setupListeners);
|
||||||
Tools.runOnUiThread(this::setupListeners);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDisappear(boolean willDestroy) {
|
protected void onDestroy() {
|
||||||
if (willDestroy) removeListeners();
|
removeListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindLayout() {
|
private void bindLayout() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user