-
Notifications
You must be signed in to change notification settings - Fork 21
implementation #11
base: master
Are you sure you want to change the base?
implementation #11
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.
Нужно поправить небольшие замечания что оставлены к коду.
- Код стаил в java выглядит по-другому. Сейчас очень напоминает C
- Если не заполнить какие-то поля и нажать “save” все сбрасывается. Это не удобно
- Если менять уже созданного студента, то можно поставить ему пустые поля
- Пожалуйста, удали из репозитория папку .idea. Это моя изначальная ошибка. Можно забрать изменения из моего репозитория, там исправлена эта проблема
|
||
private void onStudentClick(Student student) | ||
{ | ||
startActivityForResult(new Intent(this, StudentActivity.class).putExtra("Student", student), 2); |
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 List <Integer> femalePhotos; | ||
|
||
private FemalePhotoRepository() { | ||
femalePhotos = new ArrayList(){{ |
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.
Не хватает даймондов для описания типа дженерика
|
||
import ru.ok.technopolis.students.R; | ||
|
||
public class MalePhotoRepository implements PhotoRepository |
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.
Можно было не разделять фото на 2 репозитория, а сделать один с параметром. Или хотя бы унифицировать методы. Различие только в списке фоток, остальные методы одинаковы
|
||
public class MalePhotoRepository implements PhotoRepository | ||
{ | ||
private static final MalePhotoRepository ourInstance = new MalePhotoRepository(); |
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.
можно просто instance или repository
public interface PhotoRepository | ||
{ | ||
Integer getPhotoInRepository (); | ||
void putPhotoInRepository (Integer photo); |
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.
Почему Integer и не int?
|
||
|
||
@Override | ||
public void delete(Student 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.
Если идти по списку и удалять что-то из него можно упасть. В таких случаях следует использовать итератор
} | ||
|
||
@Override | ||
public List studentsOnRepository() |
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.
Лучше использовать дженерики и указывать тип списка
@otopba, здравствуйте, что сумел профиксил, написал в личку что осталось |
fixed |
|
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
setupRecyclerView(); | ||
setupAddButton(); | ||
} | ||
|
||
private void setupAddButton() | ||
{ | ||
private void setupAddButton(){ |
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.
Форматирование стало лучше, но после закрывающейся скобки лучше оставлять пробел setupAddButton(){ -> setupAddButton() {
{ | ||
startActivityForResult(new Intent(this, StudentActivity.class),1); | ||
public void onClick(View v){ | ||
requestCode = 1; |
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.
Магические цифры и строки должны быть вынесены в константы
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) | ||
{ | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data){ |
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.
Intent data помечен как Nullable, значит нельзя напрямую обращаться к его методам data.getSerializableExtra() . Нужно добавить проверку на нул
{ | ||
Integer getPhotoInRepository (); | ||
public interface PhotoRepository { | ||
int getPhotoInRepository (); | ||
void putPhotoInRepository (Integer photo); |
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 static final StudentDataRepository ourInstance = new StudentDataRepository(); | ||
public class StudentDataRepository implements StudentRepository { | ||
private static final StudentDataRepository instance = new StudentDataRepository(); |
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.
Если поле static final и есть необходимость использовать его где-то во вне, то правильнее седлать public static final и убрать геттер.
return students; | ||
} | ||
|
||
@Override | ||
public void add(Student student) | ||
{ | ||
public void add(Student student){ | ||
students.add(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.
Следи за пустыми строками
if (students.get(i).getId().equals(student.getId())){ | ||
students.remove(i); | ||
public void delete(Student student) { | ||
Iterator <Student> iterator = students.iterator(); |
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.
Проверяй как расставляются пробелы
Iterator iterator = students.iterator();
->
Iterator iterator = students.iterator();
Student student; | ||
String dataRequest; | ||
switch (resultCode) { | ||
case 1: |
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.
- Константы создал, а чего не используешь? ACTION_CREATE_STUDENT_CLICK?
- "NewStudent" это тоже константа
this.add(R.drawable.female_3); | ||
}}; | ||
} | ||
|
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,130 @@ | |||
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.
Пустые строки, константы
@@ -21,6 +21,9 @@ | |||
private final String dataResponse = "Student"; | |||
private final int ACTION_ON_STUDENT_CLICK = 2; | |||
private final int ACTION_CREATE_STUDENT_CLICK = 1; | |||
private final String dataRequestNewStudent = "NewStudent"; |
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 static final
- Имя константы пишется капсом через подчеркивание, как у ACTION_CREATE_STUDENT_CLICK
dataResponse = "StudentForDelete"; | ||
setResult(resultCode, new Intent().putExtra(dataResponse, currentStudent)); | ||
photoRepository.putPhotoInRepository(currentStudent.getPhoto()); | ||
setResult(DELETE_STUDENT_RESULT_CODE, new Intent().putExtra(RESPONSE_DELETE_STUDENT, 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.
setResult(CREATE_STUDENT_RESULT_CODE, new Intent().putExtra(RESPONSE_CREATE_STUDENT, student)); | ||
studentImageViewPhoto.setImageResource(student.getPhoto()); | ||
} else { | ||
Toast.makeText(StudentActivity.this, "No Photo in DataBase", Toast.LENGTH_LONG).show(); |
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.
Можно просто this
private StudentActivityController() { | ||
|
||
} | ||
|
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.
Следи за лишними строками
@@ -28,6 +28,10 @@ dependencies { | |||
implementation 'com.android.support:recyclerview-v7:28.0.0' | |||
implementation 'com.android.support.constraint:constraint-layout:1.1.3' | |||
implementation 'com.getbase:floatingactionbutton:1.9.1' | |||
implementation 'com.google.dagger:dagger-android:2.20' |
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.
Зачем добавил эти зависимости?
Работа принята. Молодец что быстро реагируешь на замечания |
Спустя три дня работы и изучения паттерна "Репозиторий"