|
@@ -31,6 +31,8 @@ public class SideMenuController extends ParentController<DrawerLayout> implement
|
31
|
31
|
private ViewController left;
|
32
|
32
|
private ViewController right;
|
33
|
33
|
private SideMenuPresenter presenter;
|
|
34
|
+ private float prevLeftSlideOffset = 0;
|
|
35
|
+ private float prevRightSlideOffset = 0;
|
34
|
36
|
|
35
|
37
|
public SideMenuController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions, SideMenuPresenter sideMenuOptionsPresenter, Presenter presenter) {
|
36
|
38
|
super(activity, childRegistry, id, presenter, initialOptions);
|
|
@@ -111,15 +113,30 @@ public class SideMenuController extends ParentController<DrawerLayout> implement
|
111
|
113
|
@Override
|
112
|
114
|
public void onDrawerOpened(@NonNull View drawerView) {
|
113
|
115
|
ViewController view = this.getMatchingView(drawerView);
|
114
|
|
- view.mergeOptions(this.getOptionsWithVisability(this.viewIsLeft(drawerView), true));
|
115
|
|
- view.onViewAppeared();
|
|
116
|
+ view.mergeOptions(this.getOptionsWithVisibility(this.viewIsLeft(drawerView), true));
|
116
|
117
|
}
|
117
|
118
|
|
118
|
119
|
@Override
|
119
|
120
|
public void onDrawerClosed(@NonNull View drawerView) {
|
120
|
121
|
ViewController view = this.getMatchingView(drawerView);
|
121
|
|
- view.mergeOptions(this.getOptionsWithVisability(this.viewIsLeft(drawerView), false));
|
122
|
|
- view.onViewDisappear();
|
|
122
|
+ view.mergeOptions(this.getOptionsWithVisibility(this.viewIsLeft(drawerView), false));
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ @Override
|
|
126
|
+ public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
|
127
|
+ int gravity = getSideMenuGravity(drawerView);
|
|
128
|
+ if (gravity == Gravity.LEFT) {
|
|
129
|
+ dispatchSideMenuVisibilityEvents(left, prevLeftSlideOffset, slideOffset);
|
|
130
|
+ prevLeftSlideOffset = slideOffset;
|
|
131
|
+ } else if (gravity == Gravity.RIGHT) {
|
|
132
|
+ dispatchSideMenuVisibilityEvents(right, prevRightSlideOffset, slideOffset);
|
|
133
|
+ prevRightSlideOffset = slideOffset;
|
|
134
|
+ }
|
|
135
|
+ }
|
|
136
|
+
|
|
137
|
+ @Override
|
|
138
|
+ public void onDrawerStateChanged(int newState) {
|
|
139
|
+
|
123
|
140
|
}
|
124
|
141
|
|
125
|
142
|
@Override
|
|
@@ -135,15 +152,15 @@ public class SideMenuController extends ParentController<DrawerLayout> implement
|
135
|
152
|
|
136
|
153
|
public void setLeftController(ViewController controller) {
|
137
|
154
|
this.left = controller;
|
138
|
|
- int height = this.getHeight(options.sideMenuRootOptions.left);
|
139
|
|
- int width = this.getWidth(options.sideMenuRootOptions.left);
|
|
155
|
+ int height = getHeight(options.sideMenuRootOptions.left);
|
|
156
|
+ int width = getWidth(options.sideMenuRootOptions.left);
|
140
|
157
|
getView().addView(controller.getView(), new LayoutParams(width, height, Gravity.LEFT));
|
141
|
158
|
}
|
142
|
159
|
|
143
|
160
|
public void setRightController(ViewController controller) {
|
144
|
161
|
this.right = controller;
|
145
|
|
- int height = this.getHeight(options.sideMenuRootOptions.right);
|
146
|
|
- int width = this.getWidth(options.sideMenuRootOptions.right);
|
|
162
|
+ int height = getHeight(options.sideMenuRootOptions.right);
|
|
163
|
+ int width = getWidth(options.sideMenuRootOptions.right);
|
147
|
164
|
getView().addView(controller.getView(), new LayoutParams(width, height, Gravity.RIGHT));
|
148
|
165
|
}
|
149
|
166
|
|
|
@@ -171,7 +188,11 @@ public class SideMenuController extends ParentController<DrawerLayout> implement
|
171
|
188
|
return (left != null && drawerView.equals(left.getView()));
|
172
|
189
|
}
|
173
|
190
|
|
174
|
|
- private Options getOptionsWithVisability ( boolean isLeft, boolean visible ) {
|
|
191
|
+ private int getSideMenuGravity(View drawerView) {
|
|
192
|
+ return ((LayoutParams) drawerView.getLayoutParams()).gravity;
|
|
193
|
+ }
|
|
194
|
+
|
|
195
|
+ private Options getOptionsWithVisibility(boolean isLeft, boolean visible ) {
|
175
|
196
|
Options options = new Options();
|
176
|
197
|
if (isLeft) {
|
177
|
198
|
options.sideMenuRootOptions.left.visible = new Bool(visible);
|
|
@@ -181,13 +202,11 @@ public class SideMenuController extends ParentController<DrawerLayout> implement
|
181
|
202
|
return options;
|
182
|
203
|
}
|
183
|
204
|
|
184
|
|
- @Override
|
185
|
|
- public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
186
|
|
-
|
187
|
|
- }
|
188
|
|
-
|
189
|
|
- @Override
|
190
|
|
- public void onDrawerStateChanged(int newState) {
|
191
|
|
-
|
|
205
|
+ private void dispatchSideMenuVisibilityEvents(ViewController drawer, float prevOffset, float offset) {
|
|
206
|
+ if (prevOffset == 0 && offset> 0) {
|
|
207
|
+ drawer.onViewAppeared();
|
|
208
|
+ } else if (prevOffset > 0 && offset == 0) {
|
|
209
|
+ drawer.onViewDisappear();
|
|
210
|
+ }
|
192
|
211
|
}
|
193
|
212
|
}
|