This repository has been archived by the owner on Mar 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
HW2 #16
Open
irvasek
wants to merge
4
commits into
polis-vk:master
Choose a base branch
from
irvasek:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+377
−0
Open
HW2 #16
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
app/src/main/java/ru/ok/technopolis/students/StudentsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package ru.ok.technopolis.students; | ||
|
||
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<StudentsAdapter.StudentViewHolder> { | ||
|
||
irvasek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private final List<Student> students; | ||
private final Listener onStudentClickListener; | ||
private int focusedItem = -1; | ||
|
||
public StudentsAdapter(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.student_item, viewGroup, false); | ||
view.setOnClickListener(v -> { | ||
focusedItem = ((RecyclerView.LayoutParams) v.getLayoutParams()).getViewLayoutPosition(); | ||
notifyDataSetChanged(); | ||
onStudentClickListener.onStudentClick((Student) v.getTag()); | ||
}); | ||
return new StudentViewHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull StudentViewHolder viewHolder, final int i) { | ||
Student student = students.get(i); | ||
viewHolder.bind(student); | ||
viewHolder.itemView.setTag(student); | ||
viewHolder.itemView.setSelected(focusedItem == i); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return students.size(); | ||
} | ||
|
||
static final class StudentViewHolder extends RecyclerView.ViewHolder { | ||
private final TextView nameView; | ||
private final ImageView photoView; | ||
|
||
private StudentViewHolder(@NonNull View itemView) { | ||
super(itemView); | ||
nameView = itemView.findViewById(R.id.student_item_name); | ||
photoView = itemView.findViewById(R.id.student_item_photo); | ||
} | ||
|
||
private void bind(@NonNull Student student) { | ||
nameView.setText(student.getFirstName() + " " + student.getSecondName()); | ||
photoView.setImageResource(student.getPhoto()); | ||
} | ||
} | ||
|
||
interface Listener { | ||
void onStudentClick(Student student); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:drawable="@color/colorGray" android:state_selected="true" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,101 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".MainActivity"> | ||
|
||
<android.support.constraint.Guideline | ||
android:id="@+id/activity_main_line_bottom" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="horizontal" | ||
app:layout_constraintGuide_percent="0.95" /> | ||
|
||
<android.support.constraint.Guideline | ||
android:id="@+id/activity_main_line_left" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
app:layout_constraintGuide_percent="0.05" /> | ||
|
||
<android.support.constraint.Guideline | ||
android:id="@+id/activity_main_line_right" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:orientation="vertical" | ||
app:layout_constraintGuide_percent="0.95" /> | ||
|
||
<android.support.v7.widget.RecyclerView | ||
android:id="@+id/activity_main_students_list" | ||
android:layout_width="0dp" | ||
android:layout_height="0dp" | ||
app:layout_constraintBottom_toTopOf="@+id/activity_main_button_add" | ||
app:layout_constraintEnd_toStartOf="@+id/activity_main_line_right" | ||
app:layout_constraintStart_toEndOf="@+id/activity_main_line_left" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
<Button | ||
android:id="@+id/activity_main_button_add" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/button_add" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_student_photo" | ||
app:layout_constraintEnd_toStartOf="@id/activity_main_line_right" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_line_left" /> | ||
|
||
<Button | ||
android:id="@+id/activity_main_button_delete" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/button_delete" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_line_bottom" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_line_left" /> | ||
|
||
<Button | ||
android:id="@+id/activity_main_button_save" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/button_save" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_line_bottom" | ||
app:layout_constraintEnd_toStartOf="@id/activity_main_line_right" /> | ||
|
||
<de.hdodenhof.circleimageview.CircleImageView | ||
android:id="@+id/activity_main_student_photo" | ||
android:layout_width="100dp" | ||
android:layout_height="100dp" | ||
android:src="@color/colorGray" | ||
app:layout_constraintBottom_toBottomOf="@id/activity_main_student_first_name" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_line_left" /> | ||
|
||
<EditText | ||
android:id="@+id/activity_main_student_last_name" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/last_name" | ||
android:maxLines="1" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_student_first_name" | ||
app:layout_constraintEnd_toStartOf="@id/activity_main_line_right" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_student_photo" /> | ||
|
||
<EditText | ||
android:id="@+id/activity_main_student_first_name" | ||
android:layout_width="0dp" | ||
android:layout_height="wrap_content" | ||
android:hint="@string/first_name" | ||
android:maxLines="1" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_student_gender" | ||
app:layout_constraintEnd_toStartOf="@id/activity_main_line_right" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_student_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. Лишняя строка |
||
|
||
<CheckBox | ||
android:id="@+id/activity_main_student_gender" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:text="@string/male" | ||
app:layout_constraintBottom_toTopOf="@id/activity_main_button_delete" | ||
app:layout_constraintStart_toEndOf="@id/activity_main_student_photo" /> | ||
|
||
</android.support.constraint.ConstraintLayout> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Лучше не заворачивать всю конструкцию в try-catch. Возьми отдельно значение getText и проверяй его