-
Notifications
You must be signed in to change notification settings - Fork 856
Проектная работа N2. Цабут Ян #3
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package ru.yandex.practicum.contacts.presentation.base; | ||
|
|
||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import androidx.recyclerview.widget.DiffUtil; | ||
|
|
||
| public class BaseListDiffCallback <T extends ListDiffInterface<T>> extends DiffUtil.ItemCallback<T> { | ||
| public BaseListDiffCallback() { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ Так как конструктор пустой, можно убрать его описание отсюда |
||
| super(); | ||
| } | ||
| @Override | ||
| public boolean areItemsTheSame(@NonNull T oldItem, @NonNull T newItem) { | ||
| return oldItem.theSameAs(newItem); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean areContentsTheSame(@NonNull T oldItem, @NonNull T newItem) { | ||
| return false; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Nullable | ||
| @Override | ||
| public Object getChangePayload(@NonNull T oldItem, @NonNull T newItem) { | ||
| return super.getChangePayload(oldItem, newItem); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
| 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 theSameAs(ListDiffInterface<T> listDiffInterface); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| boolean equals(Object o); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,12 @@ | |
|
|
||
| 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; | ||
|
|
@@ -21,6 +26,11 @@ public boolean isSelected() { | |
| } | ||
|
|
||
| @Override | ||
| public boolean theSameAs(ListDiffInterface<FilterContactTypeUi> listDiffInterface) { | ||
| return this.getContactType() == ((FilterContactTypeUi) listDiffInterface).getContactType(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,28 +3,31 @@ | |
| import androidx.annotation.NonNull; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import java.lang.String; | ||
| 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; | ||
| private final String photo; | ||
| private final List<String> types; | ||
| private final List<ContactType> types; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⏫ |
||
|
|
||
| public ContactUi( | ||
| @NonNull String name, | ||
| @NonNull String phone, | ||
| @NonNull String photo, | ||
| @NonNull List<String> types | ||
| @NonNull List<ContactType> types | ||
| ) { | ||
| this.name = name; | ||
| this.phone = phone; | ||
| this.photo = photo; | ||
| this.types = types; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
@@ -37,8 +40,15 @@ public String getPhoto() { | |
| return photo; | ||
| } | ||
|
|
||
| public List<String> getTypes() { | ||
| return types; | ||
| public List<ContactType> getTypes() { | ||
| return types; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| @Override | ||
| public boolean theSameAs(ListDiffInterface<ContactUi> listDiffInterface) { | ||
| return this.hashCode() == ((ContactUi)listDiffInterface).hashCode(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,9 +2,13 @@ | |
|
|
||
| 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; | ||
|
|
@@ -14,15 +18,20 @@ public SortTypeUI(@NonNull SortType sortType, boolean selected) { | |
| this.selected = selected; | ||
| } | ||
|
|
||
| public SortType getSortType() { | ||
| return sortType; | ||
| } | ||
| public SortType getSortType() { | ||
| return sortType; | ||
| } | ||
|
|
||
| public boolean isSelected() { | ||
| return selected; | ||
| } | ||
|
|
||
| @Override | ||
| @Override | ||
| public boolean theSameAs(ListDiffInterface<SortTypeUI> listDiffInterface) { | ||
| return this.getSortType() == ((SortTypeUI)listDiffInterface).getSortType(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⏫ Можно сразу вернуть
return new String[]{TELEGRAM, WHATS_APP, VIBER, SIGNAL, THREEMA, PHONE, EMAIL};