/
FullGroupSection.java
617 lines (543 loc) · 19.1 KB
/
FullGroupSection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
/*
* Copyright 2018-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.facebook.litho.sections.processor.integration.resources;
import android.widget.TextView;
import androidx.annotation.AttrRes;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import com.facebook.litho.ClickEvent;
import com.facebook.litho.CommonUtils;
import com.facebook.litho.Component;
import com.facebook.litho.Diff;
import com.facebook.litho.EventDispatcher;
import com.facebook.litho.EventHandler;
import com.facebook.litho.HasEventDispatcher;
import com.facebook.litho.StateContainer;
import com.facebook.litho.StateValue;
import com.facebook.litho.TreeProps;
import com.facebook.litho.annotations.Comparable;
import com.facebook.litho.annotations.Prop;
import com.facebook.litho.annotations.ResType;
import com.facebook.litho.annotations.State;
import com.facebook.litho.annotations.TreeProp;
import com.facebook.litho.sections.ChangesInfo;
import com.facebook.litho.sections.Children;
import com.facebook.litho.sections.LoadingEvent;
import com.facebook.litho.sections.Section;
import com.facebook.litho.sections.SectionContext;
import com.facebook.litho.sections.SectionLifecycle;
import java.util.BitSet;
/**
* Comment to be copied in generated section
*
* <p>
*
* @prop-required prop1 int
* @prop-optional prop2 java.lang.String
* @prop-required prop3 com.facebook.litho.Component
* @prop-required prop4 java.lang.String
* @prop-required prop5 com.facebook.litho.sections.Section
* @see com.facebook.litho.sections.processor.integration.resources.FullGroupSectionSpec
*/
final class FullGroupSection<T> extends Section implements TestTag {
@Comparable(type = 14)
private FullGroupSectionStateContainer mStateContainer;
@Prop(resType = ResType.NONE, optional = false)
@Comparable(type = 3)
int prop1;
@Prop(resType = ResType.NONE, optional = true)
@Comparable(type = 13)
String prop2;
@Prop(resType = ResType.NONE, optional = false)
@Comparable(type = 10)
Component prop3;
@Prop(resType = ResType.STRING, optional = false)
@Comparable(type = 13)
String prop4;
@Prop(resType = ResType.NONE, optional = false)
@Comparable(type = 15)
Section prop5;
@TreeProp
@Comparable(type = 13)
FullGroupSectionSpec.TreePropWrapper treeProp;
String _service;
EventHandler testEventHandler;
private FullGroupSection() {
super("FullGroupSection");
mStateContainer = new FullGroupSectionStateContainer();
}
@Override
protected StateContainer getStateContainer() {
return mStateContainer;
}
@Override
public boolean isEquivalentTo(Section other) {
if (this == other) {
return true;
}
if (other == null || getClass() != other.getClass()) {
return false;
}
FullGroupSection fullGroupSectionRef = (FullGroupSection) other;
if (prop1 != fullGroupSectionRef.prop1) {
return false;
}
if (prop2 != null
? !prop2.equals(fullGroupSectionRef.prop2)
: fullGroupSectionRef.prop2 != null) {
return false;
}
if (prop3 != null
? !prop3.isEquivalentTo(fullGroupSectionRef.prop3)
: fullGroupSectionRef.prop3 != null) {
return false;
}
if (prop4 != null
? !prop4.equals(fullGroupSectionRef.prop4)
: fullGroupSectionRef.prop4 != null) {
return false;
}
if (prop5 != null
? !prop5.isEquivalentTo(fullGroupSectionRef.prop5)
: fullGroupSectionRef.prop5 != null) {
return false;
}
if (mStateContainer.state1 != null
? !mStateContainer.state1.equals(fullGroupSectionRef.mStateContainer.state1)
: fullGroupSectionRef.mStateContainer.state1 != null) {
return false;
}
if (mStateContainer.state2 != null
? !mStateContainer.state2.equals(fullGroupSectionRef.mStateContainer.state2)
: fullGroupSectionRef.mStateContainer.state2 != null) {
return false;
}
if (treeProp != null
? !treeProp.equals(fullGroupSectionRef.treeProp)
: fullGroupSectionRef.treeProp != null) {
return false;
}
return true;
}
private UpdateStateStateUpdate createUpdateStateStateUpdate(Object param) {
return new UpdateStateStateUpdate(param);
}
@Override
public FullGroupSection makeShallowCopy(boolean deepCopy) {
FullGroupSection component = (FullGroupSection) super.makeShallowCopy(deepCopy);
component.prop3 = component.prop3 != null ? component.prop3.makeShallowCopy() : null;
component.prop5 = component.prop5 != null ? component.prop5.makeShallowCopy() : null;
if (!deepCopy) {
component.mStateContainer = new FullGroupSectionStateContainer();
}
return component;
}
public static <T> Builder<T> create(SectionContext context) {
final Builder builder = new Builder();
FullGroupSection instance = new FullGroupSection();
builder.init(context, instance);
return builder;
}
@Override
protected void transferState(
StateContainer _prevStateContainer, StateContainer _nextStateContainer) {
FullGroupSectionStateContainer<T> prevStateContainer =
(FullGroupSectionStateContainer<T>) _prevStateContainer;
FullGroupSectionStateContainer<T> nextStateContainer =
(FullGroupSectionStateContainer<T>) _nextStateContainer;
nextStateContainer.state1 = prevStateContainer.state1;
nextStateContainer.state2 = prevStateContainer.state2;
}
private FullGroupSectionStateContainer getStateContainerWithLazyStateUpdatesApplied(
SectionContext c, FullGroupSection component) {
FullGroupSectionStateContainer stateContainer = new FullGroupSectionStateContainer();
transferState(component.mStateContainer, stateContainer);
c.applyLazyStateUpdatesForContainer(stateContainer);
return stateContainer;
}
protected static void updateState(SectionContext c, Object param) {
Section _component = c.getSectionScope();
if (_component == null) {
return;
}
FullGroupSection.UpdateStateStateUpdate _stateUpdate =
((FullGroupSection) _component).createUpdateStateStateUpdate(param);
c.updateStateAsync(_stateUpdate, "FullGroupSection.updateState");
}
protected static void updateStateAsync(SectionContext c, Object param) {
Section _component = c.getSectionScope();
if (_component == null) {
return;
}
FullGroupSection.UpdateStateStateUpdate _stateUpdate =
((FullGroupSection) _component).createUpdateStateStateUpdate(param);
c.updateStateAsync(_stateUpdate, "FullGroupSection.updateState");
}
protected static void updateStateSync(SectionContext c, Object param) {
Section _component = c.getSectionScope();
if (_component == null) {
return;
}
FullGroupSection.UpdateStateStateUpdate _stateUpdate =
((FullGroupSection) _component).createUpdateStateStateUpdate(param);
c.updateStateSync(_stateUpdate, "FullGroupSection.updateState");
}
protected static void lazyUpdateState2(SectionContext c, final Object lazyUpdateValue) {
Section _component = c.getSectionScope();
if (_component == null) {
return;
}
SectionLifecycle.StateUpdate _stateUpdate =
new SectionLifecycle.StateUpdate() {
@Override
public void updateState(StateContainer _stateContainer) {
FullGroupSectionStateContainer stateContainer =
(FullGroupSectionStateContainer) _stateContainer;
stateContainer.state2 = lazyUpdateValue;
}
};
c.updateStateLazy(_stateUpdate);
}
public static EventHandler getTestEventHandler(SectionContext context) {
if (context.getSectionScope() == null) {
return null;
}
return ((FullGroupSection) context.getSectionScope()).testEventHandler;
}
static boolean dispatchTestEvent(EventHandler _eventHandler, Object object) {
final TestEvent _eventState = new TestEvent();
_eventState.object = object;
EventDispatcher _lifecycle = _eventHandler.mHasEventDispatcher.getEventDispatcher();
return (boolean) _lifecycle.dispatchOnEvent(_eventHandler, _eventState);
}
private void testEvent(
HasEventDispatcher _abstract, SectionContext c, TextView view, int someParam) {
FullGroupSection _ref = (FullGroupSection) _abstract;
FullGroupSectionStateContainer stateContainer = getStateContainerWithLazyStateUpdatesApplied(c,
_ref);
FullGroupSectionSpec.testEvent(
c,
view,
someParam,
(Object) stateContainer.state2,
(String) _ref.prop2);
}
public static EventHandler<ClickEvent> testEvent(SectionContext c, int someParam) {
return newEventHandler(
c,
-1204074200,
new Object[] {
c, someParam,
});
}
@Override
public Object dispatchOnEvent(final EventHandler eventHandler, final Object eventState) {
int id = eventHandler.id;
switch (id) {
case -1204074200:
{
ClickEvent _event = (ClickEvent) eventState;
testEvent(
eventHandler.mHasEventDispatcher,
(SectionContext) eventHandler.params[0],
(TextView) _event.view,
(int) eventHandler.params[1]);
return null;
}
default:
return null;
}
}
@Override
protected void createInitialState(SectionContext c) {
StateValue<T> state1 = new StateValue<>();
StateValue<Object> state2 = new StateValue<>();
FullGroupSectionSpec.onCreateInitialState(
(SectionContext) c, (int) prop1, (StateValue<T>) state1, (StateValue<Object>) state2);
mStateContainer.state1 = state1.get();
mStateContainer.state2 = state2.get();
}
private String onCreateService(SectionContext c) {
String _result;
_result = (String) FullGroupSectionSpec.onCreateService((SectionContext) c, (String) prop2);
return _result;
}
@Override
public void createService(SectionContext context) {
_service = onCreateService(context);
}
@Override
protected void transferService(SectionContext c, Section previous, Section next) {
FullGroupSection previousSection = (FullGroupSection) previous;
FullGroupSection nextSection = (FullGroupSection) next;
nextSection._service = previousSection._service;
}
@Override
protected Object getService(Section section) {
return ((FullGroupSection) section)._service;
}
@Override
protected Children createChildren(SectionContext c) {
Children _result;
_result =
(Children)
FullGroupSectionSpec.onCreateChildren(
(SectionContext) c,
(Component) prop3,
(String) prop4,
(Section) prop5,
(T) mStateContainer.state1);
return _result;
}
@Override
protected void bindService(SectionContext c) {
FullGroupSectionSpec.bindService(
(SectionContext) c, (String) _service, (int) prop1, (Object) mStateContainer.state2);
}
@Override
protected void unbindService(SectionContext c) {
FullGroupSectionSpec.unbindService(
(SectionContext) c, (String) _service, (int) prop1, (Object) mStateContainer.state2);
}
@Override
protected void refresh(SectionContext c) {
FullGroupSectionSpec.onRefresh((SectionContext) c, (String) _service, (String) prop2);
}
@Override
protected void dataBound(SectionContext c) {
FullGroupSectionSpec.onDataBound(
(SectionContext) c, (Component) prop3, (Object) mStateContainer.state2);
}
@Override
protected boolean shouldUpdate(Section _prevAbstractImpl, Section _nextAbstractImpl) {
FullGroupSection _prevImpl = (FullGroupSection) _prevAbstractImpl;
FullGroupSection _nextImpl = (FullGroupSection) _nextAbstractImpl;
boolean _result;
Diff<Integer> prop1 =
new Diff<Integer>(
_prevImpl == null ? null : _prevImpl.prop1,
_nextImpl == null ? null : _nextImpl.prop1);
_result = (boolean) FullGroupSectionSpec.shouldUpdate((Diff<Integer>) prop1);
return _result;
}
@Override
protected void viewportChanged(
SectionContext c,
int firstVisibleIndex,
int lastVisibleIndex,
int totalCount,
int firstFullyVisibleIndex,
int lastFullyVisibleIndex) {
FullGroupSectionSpec.onViewportChanged(
(SectionContext) c,
(int) firstVisibleIndex,
(int) lastVisibleIndex,
(int) totalCount,
(int) firstFullyVisibleIndex,
(int) lastFullyVisibleIndex,
(T) mStateContainer.state1,
(Object) mStateContainer.state2,
(int) prop1,
(String) prop2,
(Component) prop3);
}
@Override
protected void dataRendered(
SectionContext c,
boolean isDataChanged,
boolean isMounted,
long uptimeMillis,
int firstVisibleIndex,
int lastVisibleIndex,
ChangesInfo changesInfo) {
FullGroupSectionSpec.onDataRendered(
(SectionContext) c,
(boolean) isDataChanged,
(boolean) isMounted,
(long) uptimeMillis,
(int) firstVisibleIndex,
(int) lastVisibleIndex,
(ChangesInfo) changesInfo,
(int) prop1,
(Object) mStateContainer.state2,
(Integer) getCached());
}
@Override
protected void populateTreeProps(TreeProps treeProps) {
if (treeProps == null) {
return;
}
treeProp =
treeProps.get(
com.facebook.litho.sections.processor.integration.resources.FullGroupSectionSpec
.TreePropWrapper.class);
}
@Override
protected TreeProps getTreePropsForChildren(SectionContext c, TreeProps parentTreeProps) {
final TreeProps childTreeProps = TreeProps.acquire(parentTreeProps);
childTreeProps.put(
com.facebook.litho.sections.processor.integration.resources.FullGroupSectionSpec
.TreePropWrapper.class,
FullGroupSectionSpec.onCreateTreeProp((SectionContext) c, treeProp));
return childTreeProps;
}
private int getCached() {
SectionContext c = getScopedContext();
final CachedInputs inputs = new CachedInputs(prop1);
Integer cached = (Integer) c.getCachedValue(inputs);
if (cached == null) {
cached = FullGroupSectionSpec.onCalculateCached(prop1);
c.putCachedValue(inputs, cached);
}
return cached;
}
@VisibleForTesting(otherwise = 2)
static class FullGroupSectionStateContainer<T> implements StateContainer {
@State
@Comparable(type = 13)
T state1;
@State
@Comparable(type = 13)
Object state2;
}
public static final class Builder<T> extends Section.Builder<Builder<T>> {
FullGroupSection mFullGroupSection;
SectionContext mContext;
private final String[] REQUIRED_PROPS_NAMES = new String[] {"prop1", "prop3", "prop4", "prop5"};
private final int REQUIRED_PROPS_COUNT = 4;
private final BitSet mRequired = new BitSet(REQUIRED_PROPS_COUNT);
private void init(SectionContext context, FullGroupSection fullGroupSectionRef) {
super.init(context, fullGroupSectionRef);
mFullGroupSection = fullGroupSectionRef;
mContext = context;
mRequired.clear();
}
public Builder<T> prop1(int prop1) {
this.mFullGroupSection.prop1 = prop1;
mRequired.set(0);
return this;
}
public Builder<T> prop2(String prop2) {
this.mFullGroupSection.prop2 = prop2;
return this;
}
public Builder<T> prop3(Component prop3) {
this.mFullGroupSection.prop3 = prop3 == null ? null : prop3.makeShallowCopy();
mRequired.set(1);
return this;
}
public Builder<T> prop3(Component.Builder<?> prop3Builder) {
this.mFullGroupSection.prop3 = prop3Builder == null ? null : prop3Builder.build();
mRequired.set(1);
return this;
}
public Builder<T> prop4(String prop4) {
this.mFullGroupSection.prop4 = prop4;
mRequired.set(2);
return this;
}
public Builder<T> prop4Res(@StringRes int resId) {
this.mFullGroupSection.prop4 = mResourceResolver.resolveStringRes(resId);
mRequired.set(2);
return this;
}
public Builder<T> prop4Res(@StringRes int resId, Object... formatArgs) {
this.mFullGroupSection.prop4 = mResourceResolver.resolveStringRes(resId, formatArgs);
mRequired.set(2);
return this;
}
public Builder<T> prop4Attr(@AttrRes int attrResId, @StringRes int defResId) {
this.mFullGroupSection.prop4 = mResourceResolver.resolveStringAttr(attrResId, defResId);
mRequired.set(2);
return this;
}
public Builder<T> prop4Attr(@AttrRes int attrResId) {
this.mFullGroupSection.prop4 = mResourceResolver.resolveStringAttr(attrResId, 0);
mRequired.set(2);
return this;
}
public Builder<T> prop5(Section prop5) {
this.mFullGroupSection.prop5 = prop5;
mRequired.set(3);
return this;
}
public Builder<T> prop5(Section.Builder<?> prop5Builder) {
this.mFullGroupSection.prop5 = prop5Builder == null ? null : prop5Builder.build();
mRequired.set(3);
return this;
}
public Builder<T> testEventHandler(EventHandler testEventHandler) {
this.mFullGroupSection.testEventHandler = testEventHandler;
return this;
}
@Override
public Builder<T> key(String key) {
return super.key(key);
}
@Override
public Builder<T> loadingEventHandler(EventHandler<LoadingEvent> loadingEventHandler) {
return super.loadingEventHandler(loadingEventHandler);
}
@Override
public Builder<T> getThis() {
return this;
}
@Override
public FullGroupSection build() {
checkArgs(REQUIRED_PROPS_COUNT, mRequired, REQUIRED_PROPS_NAMES);
return mFullGroupSection;
}
}
private static class UpdateStateStateUpdate<T> implements SectionLifecycle.StateUpdate {
private Object mParam;
UpdateStateStateUpdate(Object param) {
mParam = param;
}
@Override
public void updateState(StateContainer _stateContainer) {
FullGroupSectionStateContainer<T> stateContainer =
(FullGroupSectionStateContainer<T>) _stateContainer;
StateValue<Object> state2 = new StateValue<Object>();
state2.set(stateContainer.state2);
FullGroupSectionSpec.updateState(state2, mParam);
stateContainer.state2 = state2.get();
}
}
private static class CachedInputs {
private final int prop1;
CachedInputs(int prop1) {
this.prop1 = prop1;
}
@Override
public int hashCode() {
return CommonUtils.hash(prop1);
}
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null || !(other instanceof CachedInputs)) {
return false;
}
CachedInputs cachedValueInputs = (CachedInputs) other;
if (prop1 != cachedValueInputs.prop1) {
return false;
}
return true;
}
}
}