Skip to content
This repository has been archived by the owner on Mar 1, 2021. It is now read-only.

not full functionality #18

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
/.idea/assetWizardSettings.xml
.DS_Store
/build
/.idea/
/captures
.externalNativeBuild
29 changes: 0 additions & 29 deletions .idea/codeStyles/Project.xml

This file was deleted.

18 changes: 0 additions & 18 deletions .idea/gradle.xml

This file was deleted.

14 changes: 0 additions & 14 deletions .idea/misc.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
}
130 changes: 128 additions & 2 deletions app/src/main/java/ru/ok/technopolis/students/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,140 @@
package ru.ok.technopolis.students;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.KeyEvent;
Copy link

Choose a reason for hiding this comment

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

Лишние импорты

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
Copy link

Choose a reason for hiding this comment

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

Лишний импорт


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class MainActivity extends AppCompatActivity {
private Random random = new Random(2);
Copy link

Choose a reason for hiding this comment

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

Зачем это поле?

private int randomIcon;
private boolean sexOfStudent;
private Student currentStudent;

List<Student> students;
TextView text;
Copy link

Choose a reason for hiding this comment

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

где-то область видимости указывается явно, а где-то нет. Лучше всегда указывать явно

EditText firstName;
EditText secondName;
ImageView icon;
FloatingActionButton add;
View bottomView;
RadioGroup sex;
RadioButton male;
RadioButton female;
Button delete;
Button save;

@Override
protected void onCreate(Bundle savedInstanceState) {
Copy link

Choose a reason for hiding this comment

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

Не стоит делать такие длинные методы. Раздели на несколько

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

sex = findViewById(R.id.activity_main_sex);
male = findViewById(R.id.activity_main_sex_male);
Copy link

Choose a reason for hiding this comment

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

Названия переменных стоит давать более полные. Что бы можно было отличить кнопку от текста

female = findViewById(R.id.activity_main_sex_female);
add = findViewById(R.id.activity_main_fb_add);
text = findViewById(R.id.recycler_view_item_name);
firstName = findViewById(R.id.activity_main_first_name);
secondName = findViewById(R.id.activity_main_second_name);
icon = findViewById(R.id.activity_main_icon);
bottomView = findViewById(R.id.activity_main_bottom_view);
delete = findViewById(R.id.activity_main_delete);
save = findViewById(R.id.activity_main_save);
RecyclerView recyclerView = findViewById(R.id.activity_main_recycler_view);

StudentAdapter studentAdapter = new StudentAdapter(generateStudentList(),
new StudentAdapter.Listener() {
@Override
public void onStudentClick(Student student) {
currentStudent = student;
firstName.setText(student.getFirstName());
secondName.setText(student.getSecondName());
icon.setImageResource(student.getPhoto());
add.hide();
bottomView.setVisibility(View.VISIBLE);

if (student.isMaleGender())
Copy link

Choose a reason for hiding this comment

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

Лучше всегда расставлять фигурные скобки

male.toggle();
else female.toggle();
}
});

recyclerView.setAdapter(studentAdapter);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);

add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
add.hide();
bottomView.setVisibility(View.VISIBLE);

firstName.setText("");
secondName.setText("");
sex.clearCheck();
icon.setVisibility(View.GONE);
}
});

delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
students.remove(currentStudent);
bottomView.setVisibility(View.GONE);
add.show();

}
});

save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Student student = new Student(firstName.getText().toString(),
secondName.getText().toString(),
sexOfStudent,
randomIcon);
students.add(student);

bottomView.setVisibility(View.GONE);
add.show();
}
});

sex.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.activity_main_sex_male:
sexOfStudent = true;
randomIcon = R.drawable.male_3;
break;
case R.id.activity_main_sex_female:
sexOfStudent = false;
randomIcon = R.drawable.female_3;
}
}
});
}

}
private List<Student> generateStudentList() {
students = new LinkedList<>();
students.add(new Student("Вася", "Пупкин", true, R.drawable.male_1));
students.add(new Student("Инна", "Вупкина", false, R.drawable.female_1));
students.add(new Student("Лариса", "Купкина", false, R.drawable.female_2));
return students;
}
}
6 changes: 3 additions & 3 deletions app/src/main/java/ru/ok/technopolis/students/Student.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ public class Student {
private boolean maleGender;
private int photo;

public Student(String firstName, String secondName, boolean maleGender, int photo) {
Student(String firstName, String secondName, boolean maleGender, int photo) {
Copy link

Choose a reason for hiding this comment

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

Зачем убрал public?

this.firstName = firstName;
this.secondName = secondName;
this.maleGender = maleGender;
this.photo = photo;
}

public String getFirstName() {
String getFirstName() {
return firstName;
}

Expand All @@ -38,7 +38,7 @@ public void setMaleGender(boolean maleGender) {
this.maleGender = maleGender;
}

public int getPhoto() {
int getPhoto() {
return photo;
}

Expand Down
69 changes: 69 additions & 0 deletions app/src/main/java/ru/ok/technopolis/students/StudentAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package ru.ok.technopolis.students;

import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v7.widget.RecyclerView;

import java.util.List;

public class StudentAdapter extends RecyclerView.Adapter<StudentAdapter.StudentViewHolder> {
private final Listener onStudentClickListener;
private final List<Student> students;

StudentAdapter(List<Student> students, Listener onStudentClickListener) {
this.students = students;
this.onStudentClickListener = onStudentClickListener;
}

@NonNull
@Override
public StudentViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.recycler_view_item,
viewGroup, false);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onStudentClickListener.onStudentClick((Student) v.getTag());
}
});
return new StudentViewHolder(view);
}

@Override
public void onBindViewHolder(@NonNull StudentViewHolder viewHolder, int i) {
Student student = students.get(i);
viewHolder.bind(student);
viewHolder.itemView.setTag(student);
}

@Override
public int getItemCount() {
return students.size();
}

static final class StudentViewHolder extends RecyclerView.ViewHolder {

private final TextView nameTextView;
private final ImageView iconImageView;

StudentViewHolder(@NonNull View itemView) {
super(itemView);
nameTextView = itemView.findViewById(R.id.recycler_view_item_name);
iconImageView = itemView.findViewById(R.id.recycler_view_item_icon);
}

private void bind(@NonNull Student student) {
nameTextView.setText(String.format("%s %s", student.getFirstName(), student.getSecondName()));
iconImageView.setImageResource(student.getPhoto());
}
}

interface Listener {
void onStudentClick(Student student);
}

}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/recycler_view_item_circle_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<stroke android:width="10dp" />
</shape>
</item>
</selector>
Loading