From 1439ed4bb4da048deb7bd7a764974b51e965f880 Mon Sep 17 00:00:00 2001 From: Vadim Dyachkov Date: Tue, 26 Feb 2019 23:58:01 +0300 Subject: [PATCH 1/7] implement student list & short info --- .gitignore | 1 + .idea/codeStyles/Project.xml | 29 ----- .idea/gradle.xml | 18 --- .idea/misc.xml | 14 --- .idea/runConfigurations.xml | 12 -- .idea/vcs.xml | 6 - app/build.gradle | 2 + .../ok/technopolis/students/MainActivity.java | 21 +++- .../technopolis/students/StudentsAdapter.java | 57 +++++++++ app/src/main/res/layout/activity_main.xml | 33 ++++++ app/src/main/res/layout/student_form.xml | 108 ++++++++++++++++++ app/src/main/res/layout/student_list_item.xml | 34 ++++++ app/src/main/res/values/dimens.xml | 8 ++ 13 files changed, 263 insertions(+), 80 deletions(-) delete mode 100644 .idea/codeStyles/Project.xml delete mode 100644 .idea/gradle.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/runConfigurations.xml delete mode 100644 .idea/vcs.xml create mode 100644 app/src/main/java/ru/ok/technopolis/students/StudentsAdapter.java create mode 100644 app/src/main/res/layout/student_form.xml create mode 100644 app/src/main/res/layout/student_list_item.xml create mode 100644 app/src/main/res/values/dimens.xml diff --git a/.gitignore b/.gitignore index 2b75303..0ffe766 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ /build /captures .externalNativeBuild +.idea diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index 30aa626..0000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 7ac24c7..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index af0bbdd..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3710062..9fd9151 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -22,6 +22,8 @@ dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support.constraint:constraint-layout:1.1.3' + implementation 'com.android.support:recyclerview-v7:28.0.0' + implementation 'de.hdodenhof:circleimageview:2.2.0' 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' diff --git a/app/src/main/java/ru/ok/technopolis/students/MainActivity.java b/app/src/main/java/ru/ok/technopolis/students/MainActivity.java index adde500..34c3ac1 100644 --- a/app/src/main/java/ru/ok/technopolis/students/MainActivity.java +++ b/app/src/main/java/ru/ok/technopolis/students/MainActivity.java @@ -1,7 +1,12 @@ package ru.ok.technopolis.students; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; + +import java.util.ArrayList; +import java.util.List; public class MainActivity extends AppCompatActivity { @@ -9,6 +14,20 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + RecyclerView recyclerView = findViewById(R.id.activity_main__student_list); + StudentsAdapter adapter = new StudentsAdapter(studentsStub()); + recyclerView.setAdapter(adapter); + LinearLayoutManager layoutManager = new LinearLayoutManager(this); + recyclerView.setLayoutManager(layoutManager); + } + + List studentsStub() { + List students = new ArrayList<>(); + students.add(new Student("Иван", "Иванов", true, R.drawable.male_1)); + students.add(new Student("Петр", "Петров", true, R.drawable.male_2)); + students.add(new Student("Анастасия", "Медведева", false, R.drawable.female_1)); + return students; } } diff --git a/app/src/main/java/ru/ok/technopolis/students/StudentsAdapter.java b/app/src/main/java/ru/ok/technopolis/students/StudentsAdapter.java new file mode 100644 index 0000000..53a94d9 --- /dev/null +++ b/app/src/main/java/ru/ok/technopolis/students/StudentsAdapter.java @@ -0,0 +1,57 @@ +package ru.ok.technopolis.students; + +import android.annotation.SuppressLint; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import java.util.List; + +public class StudentsAdapter extends RecyclerView.Adapter { + + private final List students; + + public StudentsAdapter(List students) { + this.students = students; + } + + @NonNull + @Override + public StudentViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.student_list_item, viewGroup, false); + return new StudentViewHolder(view); + } + + @Override + public void onBindViewHolder(@NonNull StudentViewHolder viewHolder, int i) { + viewHolder.bind(students.get(i)); + } + + @Override + public int getItemCount() { + return students.size(); + } + + static final class StudentViewHolder extends RecyclerView.ViewHolder { + + private final ImageView photo; + private final TextView name; + + StudentViewHolder(@NonNull View itemView) { + super(itemView); + photo = itemView.findViewById(R.id.students_list_item_photo); + name = itemView.findViewById(R.id.students_list_item_name); + } + + @SuppressLint("SetTextI18n") + private void bind(@NonNull Student student) { + photo.setImageResource(student.getPhoto()); + name.setText(student.getFirstName() + " " + student.getSecondName()); + } + } + +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 304e72d..e738ca0 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,9 +1,42 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/student_form.xml b/app/src/main/res/layout/student_form.xml new file mode 100644 index 0000000..6efa28b --- /dev/null +++ b/app/src/main/res/layout/student_form.xml @@ -0,0 +1,108 @@ + + + + + + + + + + + + + +