Avoid recreating views in SmartSpaceComplicationViewHolder.

Also fixed the length of ComplicationHostViewController.TAG (30 -> 23).

Note: we'll still get multiple instances of the same type of view, when
updateComplications is called multiple times.

Bug: 231251252
Bug: 235625099
Test: on device via added logging
Change-Id: Ia80650dea1cdac7b19b34034b8dc41916134cace
This commit is contained in:
Xiaowen Lei
2022-06-13 16:59:52 +00:00
parent 700595a1f2
commit d03aa92e0a
2 changed files with 6 additions and 1 deletions

View File

@@ -89,6 +89,7 @@ public class SmartSpaceComplication implements Complication {
}
private static class SmartSpaceComplicationViewHolder implements ViewHolder {
private View mView = null;
private static final int SMARTSPACE_COMPLICATION_WEIGHT = 10;
private final DreamSmartspaceController mSmartSpaceController;
private final Context mContext;
@@ -102,12 +103,16 @@ public class SmartSpaceComplication implements Complication {
@Override
public View getView() {
if (mView != null) {
return mView;
}
final FrameLayout smartSpaceContainer = new FrameLayout(mContext);
smartSpaceContainer.addView(
mSmartSpaceController.buildAndConnectView(smartSpaceContainer),
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
mView = smartSpaceContainer;
return smartSpaceContainer;
}

View File

@@ -44,7 +44,7 @@ import javax.inject.Named;
* a {@link ComplicationLayoutEngine}.
*/
public class ComplicationHostViewController extends ViewController<ConstraintLayout> {
public static final String TAG = "ComplicationHostViewController";
public static final String TAG = "ComplicationHostVwCtrl";
private final ComplicationLayoutEngine mLayoutEngine;
private final LifecycleOwner mLifecycleOwner;