Skip to content

Commit

Permalink
Use view binding inside PreferenceViewHolder
Browse files Browse the repository at this point in the history
  • Loading branch information
litetex committed Jan 24, 2022
1 parent 6405a06 commit cef71f8
Showing 1 changed file with 19 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.SettingsPreferencesearchListItemResultBinding;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -22,37 +21,38 @@ class PreferenceSearchAdapter

@NonNull
@Override
public PreferenceSearchAdapter.PreferenceViewHolder onCreateViewHolder(
public PreferenceViewHolder onCreateViewHolder(
@NonNull final ViewGroup parent,
final int viewType
) {
return new PreferenceViewHolder(
LayoutInflater
.from(parent.getContext())
.inflate(R.layout.settings_preferencesearch_list_item_result, parent, false));
SettingsPreferencesearchListItemResultBinding.inflate(
LayoutInflater.from(parent.getContext()),
parent,
false));
}

@Override
public void onBindViewHolder(
@NonNull final PreferenceSearchAdapter.PreferenceViewHolder holder,
@NonNull final PreferenceViewHolder holder,
final int position
) {
final PreferenceSearchItem item = dataset.get(position);

holder.title.setText(item.getTitle());
holder.binding.title.setText(item.getTitle());

if (TextUtils.isEmpty(item.getSummary())) {
holder.summary.setVisibility(View.GONE);
holder.binding.summary.setVisibility(View.GONE);
} else {
holder.summary.setVisibility(View.VISIBLE);
holder.summary.setText(item.getSummary());
holder.binding.summary.setVisibility(View.VISIBLE);
holder.binding.summary.setText(item.getSummary());
}

if (TextUtils.isEmpty(item.getBreadcrumbs())) {
holder.breadcrumbs.setVisibility(View.GONE);
holder.binding.breadcrumbs.setVisibility(View.GONE);
} else {
holder.breadcrumbs.setVisibility(View.VISIBLE);
holder.breadcrumbs.setText(item.getBreadcrumbs());
holder.binding.breadcrumbs.setVisibility(View.VISIBLE);
holder.binding.breadcrumbs.setText(item.getBreadcrumbs());
}

holder.itemView.setOnClickListener(v -> {
Expand All @@ -77,15 +77,11 @@ void setOnItemClickListener(final Consumer<PreferenceSearchItem> onItemClickList
}

static class PreferenceViewHolder extends RecyclerView.ViewHolder {
final TextView title;
final TextView summary;
final TextView breadcrumbs;

PreferenceViewHolder(final View v) {
super(v);
title = v.findViewById(R.id.title);
summary = v.findViewById(R.id.summary);
breadcrumbs = v.findViewById(R.id.breadcrumbs);
final SettingsPreferencesearchListItemResultBinding binding;

PreferenceViewHolder(final SettingsPreferencesearchListItemResultBinding binding) {
super(binding.getRoot());
this.binding = binding;
}
}
}

0 comments on commit cef71f8

Please sign in to comment.