Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test1 #261

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

test1 #261

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ru.yandex.practicum.contacts.presentation.base;

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

public class BaseListDiffCallback<T extends ListDiffInterface<BaseListDiffCallback>> extends DiffUtil.ItemCallback<T> {
@Override
public boolean areItemsTheSame(@NonNull T oldItem, @NonNull T newItem) {
return false;
}

@Override
public boolean areContentsTheSame(@NonNull T oldItem, @NonNull T newItem) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package ru.yandex.practicum.contacts.presentation.base;

public interface ListDiffInterface<T> {
boolean theSame(T t);
boolean equals(Object o);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import ru.yandex.practicum.contacts.databinding.ItemFilterBinding;
import ru.yandex.practicum.contacts.model.ContactType;
import ru.yandex.practicum.contacts.presentation.base.BaseListDiffCallback;
import ru.yandex.practicum.contacts.presentation.filter.model.FilterContactType;
import ru.yandex.practicum.contacts.presentation.filter.model.FilterContactTypeUi;
import ru.yandex.practicum.contacts.utils.model.ContactTypeUtils;
Expand All @@ -26,7 +27,7 @@ public class FilterContactTypeAdapter extends RecyclerView.Adapter<FilterContact

private final AsyncListDiffer<FilterContactTypeUi> differ = new AsyncListDiffer<>(
new AdapterListUpdateCallback(this),
new AsyncDifferConfig.Builder<>(new ListDiffCallback()).build()
new AsyncDifferConfig.Builder<>(new BaseListDiffCallback()).build()
);

private final Consumer<FilterContactTypeUi> clickListener;
Expand Down Expand Up @@ -85,23 +86,5 @@ public void bind(FilterContactTypeUi data) {
}
}
}

static class ListDiffCallback extends DiffUtil.ItemCallback<FilterContactTypeUi> {

@Override
public boolean areItemsTheSame(@NonNull FilterContactTypeUi oldItem, @NonNull FilterContactTypeUi newItem) {
return oldItem.getContactType() == newItem.getContactType();
}

@Override
public boolean areContentsTheSame(@NonNull FilterContactTypeUi oldItem, @NonNull FilterContactTypeUi newItem) {
return oldItem.equals(newItem);
}

@Nullable
@Override
public Object getChangePayload(@NonNull FilterContactTypeUi oldItem, @NonNull FilterContactTypeUi newItem) {
return newItem;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import androidx.annotation.NonNull;

public class FilterContactTypeUi {
import ru.yandex.practicum.contacts.presentation.base.ListDiffInterface;

public class FilterContactTypeUi implements ListDiffInterface<FilterContactTypeUi> {

private final FilterContactType contactType;
private final boolean selected;
Expand All @@ -20,6 +22,12 @@ public boolean isSelected() {
return selected;
}


@Override
public boolean theSame(FilterContactTypeUi filterContactTypeUi) {
return this == filterContactTypeUi;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@

import ru.yandex.practicum.contacts.R;
import ru.yandex.practicum.contacts.databinding.ItemContactBinding;
import ru.yandex.practicum.contacts.presentation.base.BaseListDiffCallback;

public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.ViewHolder> {

private final AsyncListDiffer<ContactUi> differ = new AsyncListDiffer<>(
new AdapterListUpdateCallback(this),
new AsyncDifferConfig.Builder<>(new ListDiffCallback()).build()
new AsyncDifferConfig.Builder<>(new BaseListDiffCallback()).build()
);

@NonNull
Expand Down Expand Up @@ -92,23 +93,4 @@ private void loadAvatar(ContactUi contact) {
.into(binding.contactPhoto);
}
}

static class ListDiffCallback extends DiffUtil.ItemCallback<ContactUi> {

@Override
public boolean areItemsTheSame(@NonNull ContactUi oldItem, @NonNull ContactUi newItem) {
return oldItem.hashCode() == newItem.hashCode();
}

@Override
public boolean areContentsTheSame(@NonNull ContactUi oldItem, @NonNull ContactUi newItem) {
return oldItem.equals(newItem);
}

@Nullable
@Override
public Object getChangePayload(@NonNull ContactUi oldItem, @NonNull ContactUi newItem) {
return newItem;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import java.util.List;

import ru.yandex.practicum.contacts.model.ContactType;
import ru.yandex.practicum.contacts.presentation.base.ListDiffInterface;

public class ContactUi {
public class ContactUi implements ListDiffInterface<ContactUi> {

private final String name;
private final String phone;
Expand Down Expand Up @@ -41,6 +42,11 @@ public List<ContactType> getTypes() {
return types;
}

@Override
public boolean theSame(ContactUi contactUi) {
return this == contactUi;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

import ru.yandex.practicum.contacts.R;
import ru.yandex.practicum.contacts.databinding.ItemSortBinding;
import ru.yandex.practicum.contacts.presentation.base.BaseListDiffCallback;
import ru.yandex.practicum.contacts.presentation.sort.model.SortType;

public class SortTypeAdapter extends RecyclerView.Adapter<SortTypeAdapter.ViewHolder> {

private final AsyncListDiffer<SortTypeUI> differ = new AsyncListDiffer<>(
new AdapterListUpdateCallback(this),
new AsyncDifferConfig.Builder<>(new ListDiffCallback()).build()
new AsyncDifferConfig.Builder<>(new BaseListDiffCallback()).build()
);

private final Consumer<SortTypeUI> clickListener;
Expand Down Expand Up @@ -88,23 +89,4 @@ private int resource(SortType sortType) {
}
}
}

static class ListDiffCallback extends DiffUtil.ItemCallback<SortTypeUI> {

@Override
public boolean areItemsTheSame(@NonNull SortTypeUI oldItem, @NonNull SortTypeUI newItem) {
return oldItem.getSortType() == newItem.getSortType();
}

@Override
public boolean areContentsTheSame(@NonNull SortTypeUI oldItem, @NonNull SortTypeUI newItem) {
return oldItem.equals(newItem);
}

@Nullable
@Override
public Object getChangePayload(@NonNull SortTypeUI oldItem, @NonNull SortTypeUI newItem) {
return newItem;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import androidx.annotation.NonNull;

import ru.yandex.practicum.contacts.presentation.base.ListDiffInterface;
import ru.yandex.practicum.contacts.presentation.sort.model.SortType;

public class SortTypeUI {
public class SortTypeUI implements ListDiffInterface<SortTypeUI> {

private final SortType sortType;
private final boolean selected;
Expand All @@ -22,6 +23,11 @@ public boolean isSelected() {
return selected;
}

@Override
public boolean theSame(SortTypeUI sortTypeUI) {
return this == sortTypeUI;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down