Skip to content

Commit

Permalink
chore: reuse same code
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantsaini1 committed Jan 28, 2025
1 parent 60245c2 commit 71a1630
Showing 1 changed file with 45 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,78 +330,24 @@ private void setHeaderFooter(TiViewProxy listViewProxy,
// Handle `header` and `footer`.
if (updateHeader) {
if (properties.containsKeyAndNotNull(TiC.PROPERTY_HEADER_TITLE)) {

// Header attributes.
setTitleAttributes("header", context, this.headerTitle);

// Handle header title.
this.headerTitle.setText(properties.getString(TiC.PROPERTY_HEADER_TITLE));
this.headerTitle.setVisibility(View.VISIBLE);
resetLayoutParams();
String titleText = properties.getString(TiC.PROPERTY_HEADER_TITLE);
handleHeaderFooterTitle(context, this.headerTitle, titleText, "header");

} else if (properties.containsKeyAndNotNull(TiC.PROPERTY_HEADER_VIEW)) {

// Handle header view.
final TiViewProxy headerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_HEADER_VIEW);
if ((context instanceof Activity) && (headerProxy.getActivity() != context)) {
headerProxy.releaseViews();
headerProxy.setActivity((Activity) context);
}

final TiUIView view = headerProxy.getOrCreateView();
if (view != null) {
final View headerView = view.getOuterView();
if (headerView != null) {
final ViewGroup parent = (ViewGroup) headerView.getParent();
if (parent != null) {
parent.removeView(headerView);
}

// Amend maximum size for header to parent ListView measured height.
this.header.setChildFillHeight(nativeListView.getMeasuredHeight());

this.header.addView(headerView, view.getLayoutParams());
this.header.setVisibility(View.VISIBLE);
}
}
handleHeaderFooterView(context, nativeListView, this.header, headerProxy);
}
}

if (updateFooter) {
if (properties.containsKeyAndNotNull(TiC.PROPERTY_FOOTER_TITLE)) {

// Footer attributes.
setTitleAttributes("footer", context, this.footerTitle);

// Handle footer title.
this.footerTitle.setText(properties.getString(TiC.PROPERTY_FOOTER_TITLE));
this.footerTitle.setVisibility(View.VISIBLE);
resetLayoutParams();
String titleText = properties.getString(TiC.PROPERTY_FOOTER_TITLE);
handleHeaderFooterTitle(context, this.footerTitle, titleText, "footer");

} else if (properties.containsKeyAndNotNull(TiC.PROPERTY_FOOTER_VIEW)) {

// Handle footer view.
final TiViewProxy footerProxy = (TiViewProxy) properties.get(TiC.PROPERTY_FOOTER_VIEW);
if ((context instanceof Activity) && (footerProxy.getActivity() != context)) {
footerProxy.releaseViews();
footerProxy.setActivity((Activity) context);
}

final TiUIView view = footerProxy.getOrCreateView();
if (view != null) {
final View footerView = view.getOuterView();
if (footerView != null) {
final ViewGroup parent = (ViewGroup) footerView.getParent();
if (parent != null) {
parent.removeView(footerView);
}

// Amend maximum size for footer to parent ListView measured height.
this.footer.setChildFillHeight(nativeListView.getMeasuredHeight());

this.footer.addView(footerView, view.getLayoutParams());
this.footer.setVisibility(View.VISIBLE);
}
}
handleHeaderFooterView(context, nativeListView, this.footer, footerProxy);
}
}
}
Expand Down Expand Up @@ -498,13 +444,47 @@ private void setTitleAttributes(final String prefix, final Context context, fina
}
}

private void resetLayoutParams()
private void handleHeaderFooterTitle(Context context, TextView textView, CharSequence text, String themePrefix)
{
ConstraintLayout.LayoutParams params = new ConstraintLayout.LayoutParams(
// Set attributes.
setTitleAttributes(themePrefix, context, textView);

// Handle title.
textView.setText(text);
textView.setVisibility(View.VISIBLE);

// Reset layout params to trigger layout update.
this.container.setLayoutParams(new ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT
);
));
}

this.container.setLayoutParams(params);
private void handleHeaderFooterView(
Context context,
View nativeListView,
TiCompositeLayout viewContainer,
TiViewProxy headerOrFooterViewProxy)
{
if ((context instanceof Activity) && (headerOrFooterViewProxy.getActivity() != context)) {
headerOrFooterViewProxy.releaseViews();
headerOrFooterViewProxy.setActivity((Activity) context);
}

final TiUIView view = headerOrFooterViewProxy.getOrCreateView();
if (view != null) {
final View headerOrFooterView = view.getOuterView();
if (headerOrFooterView != null) {
final ViewGroup parent = (ViewGroup) headerOrFooterView.getParent();
if (parent != null) {
parent.removeView(headerOrFooterView);
}

// Amend maximum size for header to parent ListView measured height.
viewContainer.setChildFillHeight(nativeListView.getMeasuredHeight());
viewContainer.addView(headerOrFooterView, view.getLayoutParams());
viewContainer.setVisibility(View.VISIBLE);
}
}
}
}

0 comments on commit 71a1630

Please sign in to comment.