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
implementation #11
Open
kilinochi
wants to merge
16
commits into
polis-vk:master
Choose a base branch
from
kilinochi: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.
Open
implementation #11
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3076a83
implementation
kilinochi 023cabd
for pull req
kilinochi 02f56f1
some fix
kilinochi 23ff535
some fix
kilinochi 830b128
some fix
kilinochi 2fd6761
Merge branch 'master' of https://github.com/otopba/students_homework
kilinochi 189ada3
some fix
kilinochi 1777846
some fix
kilinochi 36d1acb
some fix
kilinochi 0911b27
some fix
kilinochi 80dac44
some fix
kilinochi b4e133b
все, кроме изменения пола
kilinochi 3a368ba
create Controller
kilinochi 5cb93d9
fix controller
kilinochi d3da531
set checkboxListener
kilinochi 9d03dc0
fix updatePhoto
kilinochi 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
71 changes: 70 additions & 1 deletion
71
app/src/main/java/ru/ok/technopolis/students/MainActivity.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 |
---|---|---|
@@ -1,14 +1,83 @@ | ||
package ru.ok.technopolis.students; | ||
|
||
|
||
import android.content.Intent; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
|
||
import com.getbase.floatingactionbutton.FloatingActionButton; | ||
|
||
import ru.ok.technopolis.students.Repository.StudentDataRepository; | ||
|
||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private StudentDataRepository studentDataRepository = StudentDataRepository.Instance; | ||
private StudentAdapter studentAdapter; | ||
private final String dataResponse = "Student"; | ||
private final int ACTION_ON_STUDENT_CLICK = 2; | ||
private final int ACTION_CREATE_STUDENT_CLICK = 1; | ||
|
||
public class MainActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
setupRecyclerView(); | ||
setupAddButton(); | ||
} | ||
|
||
private void setupAddButton() { | ||
FloatingActionButton addButton = findViewById(R.id.activity_main__add_button); | ||
addButton.setOnClickListener(this); | ||
} | ||
|
||
private void setupRecyclerView() { | ||
RecyclerView recyclerView = findViewById(R.id.activity_main__recyclerview); | ||
studentAdapter = new StudentAdapter(studentDataRepository.studentsOnRepository(), this::onStudentClick); | ||
recyclerView.setAdapter(studentAdapter); | ||
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this); | ||
recyclerView.setLayoutManager(linearLayoutManager); | ||
} | ||
|
||
private void onStudentClick(Student student) { | ||
startActivityForResult(new Intent(this, StudentActivity.class).putExtra(dataResponse, student), ACTION_ON_STUDENT_CLICK); | ||
} | ||
|
||
@Override | ||
public void onClick(View v) { | ||
startActivityForResult(new Intent(this, StudentActivity.class), ACTION_CREATE_STUDENT_CLICK); | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
if (data == null) { | ||
return; | ||
} | ||
Student student; | ||
String dataRequest; | ||
switch (resultCode) { | ||
case 1: | ||
dataRequest = "NewStudent"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
studentDataRepository.add(student); | ||
break; | ||
case 2: | ||
dataRequest = "ModifyStudent"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
studentDataRepository.edit(student); | ||
break; | ||
case 3: | ||
dataRequest = "StudentForDelete"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
studentDataRepository.delete(student); | ||
break; | ||
} | ||
studentAdapter.notifyDataSetChanged(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/ru/ok/technopolis/students/Repository/FemalePhotoRepository.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,40 @@ | ||
package ru.ok.technopolis.students.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Random; | ||
|
||
import ru.ok.technopolis.students.R; | ||
|
||
public class FemalePhotoRepository implements PhotoRepository { | ||
|
||
public static final FemalePhotoRepository Instance = new FemalePhotoRepository(); | ||
|
||
private List<Integer> femalePhotos; | ||
|
||
private FemalePhotoRepository() { | ||
femalePhotos = new ArrayList<Integer>() {{ | ||
this.add(R.drawable.female_1); | ||
this.add(R.drawable.female_2); | ||
this.add(R.drawable.female_3); | ||
}}; | ||
} | ||
|
||
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. Лишняя строка |
||
|
||
@Override | ||
public int getPhotoInRepository() throws NoSuchElementException { | ||
if (femalePhotos.isEmpty()) { | ||
throw new NoSuchElementException(); | ||
} | ||
int indexFemalePhoto = new Random().nextInt(femalePhotos.size()); | ||
int femalePhoto = femalePhotos.get(indexFemalePhoto); | ||
femalePhotos.remove(indexFemalePhoto); | ||
return femalePhoto; | ||
} | ||
|
||
@Override | ||
public void putPhotoInRepository(int photo) { | ||
femalePhotos.add(photo); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/ru/ok/technopolis/students/Repository/MalePhotoRepository.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,39 @@ | ||
package ru.ok.technopolis.students.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.NoSuchElementException; | ||
import java.util.Random; | ||
|
||
import ru.ok.technopolis.students.R; | ||
|
||
public class MalePhotoRepository implements PhotoRepository { | ||
public static final MalePhotoRepository Instance = new MalePhotoRepository(); | ||
|
||
private List<Integer> malePhotos; | ||
|
||
private MalePhotoRepository() { | ||
malePhotos = new ArrayList<Integer>() {{ | ||
this.add(R.drawable.male_1); | ||
this.add(R.drawable.male_2); | ||
this.add(R.drawable.male_3); | ||
}}; | ||
} | ||
|
||
|
||
@Override | ||
public int getPhotoInRepository() throws NoSuchElementException { | ||
if (malePhotos.isEmpty()) { | ||
throw new NoSuchElementException(); | ||
} | ||
int indexMalePhoto = new Random().nextInt(malePhotos.size()); | ||
int malePhoto = malePhotos.get(indexMalePhoto); | ||
malePhotos.remove(indexMalePhoto); | ||
return malePhoto; | ||
} | ||
|
||
@Override | ||
public void putPhotoInRepository(int photo) { | ||
malePhotos.add(photo); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/ru/ok/technopolis/students/Repository/PhotoRepository.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,7 @@ | ||
package ru.ok.technopolis.students.Repository; | ||
|
||
public interface PhotoRepository { | ||
int getPhotoInRepository(); | ||
|
||
void putPhotoInRepository(int photo); | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/ru/ok/technopolis/students/Repository/StudentDataRepository.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,51 @@ | ||
package ru.ok.technopolis.students.Repository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import ru.ok.technopolis.students.Student; | ||
|
||
public class StudentDataRepository implements StudentRepository { | ||
|
||
public static final StudentDataRepository Instance = new StudentDataRepository(); | ||
|
||
private List<Student> students; | ||
|
||
private StudentDataRepository() { | ||
students = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public List<Student> studentsOnRepository() { | ||
return students; | ||
} | ||
|
||
@Override | ||
public void add(Student student) { | ||
students.add(student); | ||
} | ||
|
||
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. Следи за пустыми строками |
||
|
||
@Override | ||
public void delete(Student student) { | ||
Iterator<Student> iterator = students.iterator(); | ||
while (iterator.hasNext()) { | ||
Student nextStudent = iterator.next(); | ||
if (nextStudent.getId().equals(student.getId())) { | ||
iterator.remove(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void edit(Student student) { | ||
for (int i = 0; i < students.size(); i++) { | ||
if (students.get(i).getId().equals(student.getId())) { | ||
students.get(i).setFirstName(student.getFirstName()); | ||
students.get(i).setSecondName(student.getSecondName()); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/ru/ok/technopolis/students/Repository/StudentRepository.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,15 @@ | ||
package ru.ok.technopolis.students.Repository; | ||
|
||
import java.util.List; | ||
|
||
import ru.ok.technopolis.students.Student; | ||
|
||
public interface StudentRepository { | ||
List studentsOnRepository(); | ||
|
||
void add(Student student); | ||
|
||
void delete(Student student); | ||
|
||
void edit(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
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.