-
Notifications
You must be signed in to change notification settings - Fork 21
Igor Lopatinskiy #23
base: master
Are you sure you want to change the base?
Igor Lopatinskiy #23
Conversation
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.
Задание сделано хорошо, нужно поправить небольшие замечания что оставлены к коду.
Общие замечания:
- Нет выделение активного элемента в RecyclerView
- Очень длинное имя разламывает верстку
@Override | ||
public void onClick(View v) { | ||
clearFields(); | ||
adapter.setActiveStudent(adapter.NO_STUDENT); |
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.
NO_STUDENT статичное поле, можно обращаться прямо через класс
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.
Пофиксил
} | ||
|
||
private void saveStudent() { | ||
|
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.
Следи за лишними строками
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.
Пофиксил
Казалось, что так более читабельно)
|
||
private void saveStudent() { | ||
|
||
String firstNameStr = firstName.getText().toString(); |
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.
firstName.getText() может вернуть null
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.
Пофиксил
|
||
private void saveStudent() { | ||
|
||
String firstNameStr = firstName.getText().toString(); |
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.
Нужно ли в названии переменно пояснять что это стринг?
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.
У меня уже есть переменная firstName, в которой хранится само поле ввода
Если не пояснять, что это стринг, то придётся назвать ту переменную firstNameField
В итоге так или иначе нужно пояснять
Не знаю, как лучше сделать)
@@ -4,13 +4,13 @@ | |||
|
|||
private String firstName; | |||
private String secondName; | |||
private boolean maleGender; | |||
private boolean isMale; |
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.
обычно называют переменную male, что бы геттер можно было назвать isMale
С твоим названием, сеттер должен иметь название не setMale а setIsMale
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.
Назвал "male"
@@ -45,4 +45,11 @@ public int getPhoto() { | |||
public void setPhoto(int photo) { | |||
this.photo = photo; | |||
} | |||
|
|||
public void copy(Student student) { | |||
this.firstName = student.firstName; |
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.
Не забывай что присваивая значение объекта ты не копируешь его, а лишь устанавливаешь ссылку
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.
Пофиксил, но не уверен что правильно
|
||
public static final int NO_STUDENT = -1; | ||
private MainActivity context; | ||
private List<Student> students = new LinkedList<>(); |
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.
Тут нужен именно LinkedList?
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.
Делал LinkedList опираясь на то, что студентов будут часто удалять
Думаю, разумнее будет всё же ArrayList, так как чаще всего элементы достаются из списка, чем удаляются
Переделал
public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.StudentViewHolder> { | ||
|
||
public static final int NO_STUDENT = -1; | ||
private MainActivity context; |
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.
Плохой паттерн передавать активити в адаптер. Для работы с активити у тебя есть лисенеры
@@ -0,0 +1,13 @@ | |||
package ru.ok.technopolis.students; |
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.
Зачем нужен этот класс?
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.
Случайно оставил
Теперь удалил
@@ -1,9 +1,134 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
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.
Большая вложенность. Чем меньше вложенность тем лучше. Пробуй использовать более сложные лейауты
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.
До сих пор очень высокая вложенность
@@ -45,4 +54,12 @@ public int getPhoto() { | |||
public void setPhoto(int photo) { | |||
this.photo = photo; | |||
} | |||
|
|||
public void copy(Student student) { | |||
this.firstName = new String(student.firstName); |
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.
Зачем тут создаются новые объекты?
} | ||
|
||
private void bind(Student student) { | ||
if (student.isSelected()) |
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.
Лучше всегда ставить фигурные скобки
@@ -1,9 +1,134 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
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.
До сих пор очень высокая вложенность
Работа принята |
it works