-
Notifications
You must be signed in to change notification settings - Fork 21
ДЗ_2_Сагадеева Светлана #22
base: master
Are you sure you want to change the base?
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.
Визуально приложение работает и выполняет поставленную задачу. Но очень много захардкоженных цифр и строк. Нужно все выносить в константы. Так же, многие лейауты имеют излишнюю вложенность. Большенство замечаний повторяются от файла к файлу, когда будешь править замечания, сразу же проверяй другие файлы на предмет такой же проблемы.
Общие замечания:
- Можно сохранить студента без имени и фамилии
- Лучше в EditText использовать подсказки, нежели дефолтные значения (Second Name, First Name), иначе их приходится постоянно стирать
- Язык во всем приложении должен быть един. Кнопки называются на русском, а активити почему-то на английском
import java.util.Random; | ||
|
||
public class AdditionActivity extends AppCompatActivity implements View.OnClickListener { | ||
TextView secondName; |
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,private...)
RadioButton isMale; | ||
Button saver; | ||
|
||
private String[] image_names; |
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.
Стоит использовать camelCase
this.setTitle("Addition"); | ||
setContentView(R.layout.student_addition); | ||
Random random = new Random(); | ||
Intent data = getIntent(); |
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 void onClick(View v) { | ||
|
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.
Лишняя строка
|
||
boolean male = isMale.isChecked(); | ||
Intent intent = new Intent(); | ||
intent.putExtra("secondName", secondName.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.
secondName.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.
ошибки ввода пользователем (попытки добавить или изменить студента, оставив его с пустой фамилией или именем) обрабатываю в InfoActivity и AdditionActivity соответственно
int index = data.getIntExtra("index", -1); | ||
switch (op) { | ||
case 2: | ||
if (students.isEmpty()) |
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 String secondName; | ||
private boolean maleGender; | ||
private int photo; | ||
public String 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.
Не стоит напрямую обращаться к полям модели. Лучше делать поля приватными и обращаться через гетеры/сеттеры. Что бы защититься от случайного изменения
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<!--suppress ALL --> |
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,105 @@ | |||
<?xml version="1.0" encoding="utf-8"?> |
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.
Вложенность имеет 3 уровня. Можно было бы этого избежать использовав более сложные лейауты
@@ -0,0 +1,118 @@ | |||
<?xml version="1.0" encoding="utf-8"?> |
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.
Не все замечания поправлены.
Что чаще всего встречается:
- Неиспользуемые поля класса
- Лишние поля класса
- Константы не вынесены, а захардкожены
- Написание переменных не должно быть в стиле С student_to_change, а стоит использовать camelCase
private TextView secondName; | ||
private TextView firstName; | ||
private ImageView photo; | ||
private RadioButton isFemale; |
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.
- Зачем тебе это радиобаттон, если нигде не используешь? isFemale
- photo, saver, imageNames могу быть локальными переменными
intent.putExtra("photo", pic_id); | ||
setResult(RESULT_OK, intent); | ||
finish(); | ||
if ((secondName.getText().toString().trim().length() != 0) || |
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.
secondName.getText() может вернуть null
|
||
private String[] image_names; | ||
private String[] imageNames; |
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.
- imageNames нигде не используется
- photo, isFemale, isMale, saver, deleter могут быть локальными
photo.setImageResource(pic_id); | ||
boolean male; | ||
boolean female; | ||
male = data.getBooleanExtra("male", 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.
Зачем тут инициализация в 2 строки? Можно сделать одной
female = !male; | ||
secondName.setText(data.getStringExtra("second_name")); | ||
firstName.setText(data.getStringExtra("first_name")); | ||
if (male) |
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.
@gilgenbergg Все еще актуально
photo.setImageResource(pic_id); | ||
boolean male; | ||
boolean female; | ||
male = data.getBooleanExtra("male", 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.
@gilgenbergg Все еще актуально
@@ -16,7 +16,7 @@ | |||
public class MainActivity extends AppCompatActivity { | |||
private ArrayList<Student> students; | |||
private StudentAdapter studentAdapter; | |||
private String[] image_names; | |||
private String[] imageNames; |
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.
- Зачем image_names?
- Random стоит сделать private
app/src/main/res/values/strings.xml
Outdated
@@ -1,5 +1,11 @@ | |||
<resources> | |||
<string name="app_name">Students</string> | |||
<string name="SecondName">SecondName</string> |
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 String[] imageNames; | ||
int pic_id; | ||
int picID; |
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?
|
||
private String[] imageNames; | ||
private static final String PROCESS_NAME = "Editor"; |
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.
наверное не процесс, а title?
boolean male = data.getBooleanExtra(MainActivity.MALE_EXTRA, false); | ||
secondName.setText(data.getStringExtra(MainActivity.SECOND_NAME_EXTRA)); | ||
firstName.setText(data.getStringExtra(MainActivity.FIRST_NAME_EXTRA)); | ||
if (male) { | ||
isMale.setChecked(true); |
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.
можно прям поставить результат в радиобаттон isMale.setChecked(male);
static final String PHOTO_EXTRA = "photo"; | ||
static final String STUDENT_INDEX_EXTRA = "studentIndex"; | ||
static final String BUTTON_CODE_EXTRA = "buttonCode"; | ||
|
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.
Лишняя строка
Random random; | ||
private Random random; | ||
|
||
static final String SECOND_NAME_EXTRA = "secondName"; |
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
@@ -16,8 +16,15 @@ | |||
public class MainActivity extends AppCompatActivity { | |||
private ArrayList<Student> 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.
А нужно ли тебе здесь указывать тип? Лучше оперировать на уровне интерфейсов List students;
|
||
case R.id.student_info__b_delete: | ||
intent.putExtra("button_code", 2); | ||
intent.putExtra("index", getIntent().getIntExtra("index", -1)); | ||
intent.putExtra(MainActivity.BUTTON_CODE_EXTRA, 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.
Строчки смотрю вынесла, но вот числа не везде. Что означает цифра 2? Откуда она взялась? Эта же двойка будет использоваться далее зачем каждый раз помнить что именно означает цифра 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.
Да, использую два типа кодов: для разделения InfoActivity и AdditionActivity и для разграничения операции удаление/сохранение при работе с InfoActivity. Перенесла в константы.
Работа принята. |
No description provided.