Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 54
ADFA-2023 | Refactor layout positioning and drop/restore workflow#606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
069fd0d5a091ae13adc613754b9531274b1e8b45122df1d2a61c678adff47a28acec249a7a95792c400afced360ec3f84a454ee63ebf83127adf8374cf90e7ca55551d0982d650e90c2c93cffe697387105776a4c0501ee3d24aecad0fb66cdc680a6088d7496beccb5c261211cc283b798e588efdb90a7129d21b0d285e2d2a7e6a40258d780104880071b32203cbec3a5c2abd70bd7975bdd2ec03c687fb5464e77015c9484bc7ee44fa0c9677218d131a5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| package org.appdevforall.codeonthego.layouteditor.editor.positioning | ||
| import android.view.View | ||
| import android.view.ViewGroup | ||
| import android.widget.FrameLayout | ||
| import android.widget.GridLayout | ||
| import android.widget.LinearLayout | ||
| import android.widget.RelativeLayout | ||
| import androidx.constraintlayout.widget.ConstraintLayout | ||
| import androidx.coordinatorlayout.widget.CoordinatorLayout | ||
| import org.appdevforall.codeonthego.layouteditor.editor.initializer.AttributeMap | ||
| /** | ||
| * Updates the stored attributes for a [child] view after it is "dropped" | ||
| * at a new position (x, y) within its parent [ViewGroup]. | ||
| * | ||
| * This function orchestrates the process of: | ||
| * 1. Calculating the final, clamped coordinates in Dp. | ||
| * 2. Clearing any previous positioning attributes to prevent conflicts. | ||
| * 3. Applying the correct new attributes based on the parent's layout type. | ||
| * | ||
| * @param child The view being positioned. | ||
| * @param x The raw target X coordinate in container pixels. | ||
| * @param y The raw target Y coordinate in container pixels. | ||
| */ | ||
| fun positionAtDrop(child: View, x: Float, y: Float, viewAttributeMap: HashMap<View, AttributeMap>) { | ||
| val container = child.parent as? ViewGroup ?: return | ||
| val density = container.resources.displayMetrics.density | ||
| val coords = calculateDropCoordinatesInDp(container, child, x, y, density) | ||
| val attributes = viewAttributeMap[child] ?: return | ||
| clearPositioningAttributes(attributes) | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| applyLayoutAttributes(container, child, attributes, coords, x, y, viewAttributeMap) | ||
| } | ||
| /** | ||
| * Acts as a "dynamic mapper" or "strategy" function. | ||
| * It detects the type of the [container] and calls the appropriate | ||
| * helper function to apply layout-specific attributes. | ||
| * | ||
| * @param container The parent ViewGroup. | ||
| * @param attributes The AttributeMap for the child view. | ||
| * @param coords The final Dp coordinates to apply. | ||
| */ | ||
| internal fun applyLayoutAttributes( | ||
| container: ViewGroup, | ||
| child: View, | ||
| attributes: AttributeMap, | ||
| coords: DpCoordinates, | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| x: Float, | ||
| y: Float, | ||
| fullAttributeMap: HashMap<View, AttributeMap> | ||
| ) { | ||
| when (container) { | ||
| is ConstraintLayout -> applyConstraintLayoutAttributes(attributes, coords) | ||
| is FrameLayout, is CoordinatorLayout -> applyGravityMarginAttributes(attributes, coords) | ||
| is RelativeLayout -> applyRelativeLayoutAttributes(attributes, coords) | ||
| is LinearLayout -> applyDragReorder(container, child, x, y) | ||
| is GridLayout -> applyGridLayoutAttributes(container, child, attributes, x, y, fullAttributeMap) | ||
| else -> applyGenericLayoutAttributes(attributes, coords) | ||
jatezzz marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.