-
Notifications
You must be signed in to change notification settings - Fork 21
not full functionality #18
base: master
Are you sure you want to change the base?
Changes from 5 commits
518b6a1
2d0171f
7d646de
d21e43b
e254acb
674ed3c
abf0307
0287e86
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ | |
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/.idea/ | ||
/captures | ||
.externalNativeBuild |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
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; | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
@@ -38,7 +38,7 @@ public void setMaleGender(boolean maleGender) { | |
this.maleGender = maleGender; | ||
} | ||
|
||
public int getPhoto() { | ||
int getPhoto() { | ||
return photo; | ||
} | ||
|
||
|
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); | ||
} | ||
|
||
} |
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> |
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.
Лишние импорты