Skip to content

Проектная работа N2. Цабут Ян#3

Open
yantsabut wants to merge 1 commit into
Yandex-Practicum:mainfrom
yantsabut:main
Open

Проектная работа N2. Цабут Ян#3
yantsabut wants to merge 1 commit into
Yandex-Practicum:mainfrom
yantsabut:main

Conversation

@yantsabut

Copy link
Copy Markdown

No description provided.

@yantsabut yantsabut closed this Dec 20, 2022
@yantsabut yantsabut reopened this Dec 20, 2022

@SeveNChaK SeveNChaK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В некоторых файлах, где были внесены изменения, немного едет код, стоит отрефакторить. Если ты используешь IDE от JetBrains, то можешь пройтись по всем нужным файлам и нажать комбинацию (Windows: Shift + Ctrl + Alt + L, MacOS: Shift + Option + Command + L), затем выбрать какую часть кода хочешь изменить и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).

public static String[] getContactTypes() {
// метод должен возвращать массив строк, перечисленных выше
String[] contacts = {TELEGRAM, WHATS_APP, VIBER, SIGNAL, THREEMA, PHONE, EMAIL};
return contacts;

Copy link
Copy Markdown

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};

import androidx.recyclerview.widget.DiffUtil;

public class BaseListDiffCallback <T extends ListDiffInterface<T>> extends DiffUtil.ItemCallback<T> {
public BaseListDiffCallback() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⏫ Так как конструктор пустой, можно убрать его описание отсюда


@Override
public boolean areContentsTheSame(@NonNull T oldItem, @NonNull T newItem) {
return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ По аналогии с локальными реализациями ListDiffCallback, тут нужно сравнивать oldItem.equals(newItem);

@Nullable
@Override
public Object getChangePayload(@NonNull T oldItem, @NonNull T newItem) {
return super.getChangePayload(oldItem, newItem);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Необходимо возвращать новый айтем: return newItem

package ru.yandex.practicum.contacts.presentation.base;

public interface ListDiffInterface<T> {
boolean theSameAs(ListDiffInterface<T> listDiffInterface);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Здесь типизированный интерфейс для того чтобы сравнивать элементы тип T. Поэтому необходимо правильно описать метод: boolean theSameAs(T listDiffInterface);


@Override
public boolean theSameAs(ListDiffInterface<FilterContactTypeUi> listDiffInterface) {
return this.getContactType() == ((FilterContactTypeUi) listDiffInterface).getContactType();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Когда будет правильно описан интерфейс, реализация здесь станет корректной и красивой: return this.getContactType() == listDiffInterface.getContactType();

private final String phone;
private final String photo;
private final List<String> types;
private final List<ContactType> types;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ContactType содержит в себе существующие типы в строковом виде. Так что здесь по смыслу должен быть список строк, как и было изначально.


@Override
public boolean theSameAs(ListDiffInterface<ContactUi> listDiffInterface) {
return this.hashCode() == ((ContactUi)listDiffInterface).hashCode();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Когда будет правильно описан интерфейс, реализация здесь станет корректной и красивой: return this.hashCode() == listDiffInterface.hashCode();

@Override
@Override
public boolean theSameAs(ListDiffInterface<SortTypeUI> listDiffInterface) {
return this.getSortType() == ((SortTypeUI)listDiffInterface).getSortType();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Когда будет правильно описан интерфейс, реализация здесь станет корректной и красивой: return this.getSortType() == listDiffInterface.getSortType();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants