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 5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
|
||
import com.getbase.floatingactionbutton.FloatingActionButton; | ||
|
||
import ru.ok.technopolis.students.Repository.StudentDataRepository; | ||
import ru.ok.technopolis.students.repository.StudentDataRepository; | ||
|
||
|
||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
@@ -21,6 +21,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe | |
private final String dataResponse = "Student"; | ||
private final int ACTION_ON_STUDENT_CLICK = 2; | ||
private final int ACTION_CREATE_STUDENT_CLICK = 1; | ||
private final String dataRequestNewStudent = "NewStudent"; | ||
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 final String dataRequestModifyStudent = "ModifyStudent"; | ||
private final String dataRequestDeleteStudent = "StudentForDelete"; | ||
|
||
|
||
@Override | ||
|
@@ -60,21 +63,17 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten | |
return; | ||
} | ||
Student student; | ||
String dataRequest; | ||
switch (resultCode) { | ||
case 1: | ||
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.
|
||
dataRequest = "NewStudent"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
student = (Student) data.getSerializableExtra(dataRequestNewStudent); | ||
studentDataRepository.add(student); | ||
break; | ||
case 2: | ||
dataRequest = "ModifyStudent"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
student = (Student) data.getSerializableExtra(dataRequestModifyStudent); | ||
studentDataRepository.edit(student); | ||
break; | ||
case 3: | ||
dataRequest = "StudentForDelete"; | ||
student = (Student) data.getSerializableExtra(dataRequest); | ||
student = (Student) data.getSerializableExtra(dataRequestDeleteStudent); | ||
studentDataRepository.delete(student); | ||
break; | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,29 @@ | |
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.CheckBox; | ||
import android.widget.CompoundButton; | ||
import android.widget.EditText; | ||
import android.widget.ImageView; | ||
import android.widget.Toast; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import ru.ok.technopolis.students.Repository.FemalePhotoRepository; | ||
import ru.ok.technopolis.students.Repository.MalePhotoRepository; | ||
import ru.ok.technopolis.students.Repository.PhotoRepository; | ||
|
||
import ru.ok.technopolis.students.controller.StudentActivityController; | ||
|
||
public class StudentActivity extends AppCompatActivity implements View.OnClickListener { | ||
|
||
private ImageView studentImageViewPhoto; | ||
private EditText studentFirstName; | ||
private EditText studentSecondName; | ||
private CheckBox genderCheckbox; | ||
private Student currentStudent; | ||
private PhotoRepository photoRepository; | ||
private String firstName; | ||
private String secondName; | ||
private boolean isMale; | ||
private StudentActivityController studentActivityController = StudentActivityController.Instance; | ||
private final int CREATE_STUDENT_RESULT_CODE = 1; | ||
private final int MODIFY_STUDENT_RESULT_CODE = 2; | ||
private final int DELETE_STUDENT_RESULT_CODE = 3; | ||
private final String RESPONSE_CREATE_STUDENT = "NewStudent"; | ||
private final String RESPONSE_DELETE_STUDENT = "StudentForDelete"; | ||
private final String RESPONSE_MODIFY_STUDENT = "ModifyStudent"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
|
@@ -36,92 +41,64 @@ protected void onCreate(Bundle savedInstanceState) { | |
genderCheckbox = findViewById(R.id.checkBox__gender); | ||
studentImageViewPhoto = findViewById(R.id.student_activity__photo); | ||
if (getIntent().getExtras() != null) { | ||
currentStudent = (Student) getIntent().getExtras().getSerializable("Student"); | ||
if (currentStudent.isMaleGender()) { | ||
photoRepository = MalePhotoRepository.Instance; | ||
} else { | ||
photoRepository = FemalePhotoRepository.Instance; | ||
} | ||
genderCheckbox.setVisibility(View.GONE); | ||
setStudent(); | ||
studentActivityController.setCurrentStudent((Student) getIntent().getExtras().getSerializable("Student")); | ||
studentFirstName.setText(studentActivityController.getCurrentStudent().getFirstName()); | ||
studentSecondName.setText(studentActivityController.getCurrentStudent().getSecondName()); | ||
if (studentActivityController.getCurrentStudent().isMaleGender()) | ||
genderCheckbox.setChecked(true); | ||
studentImageViewPhoto.setImageResource(studentActivityController.getCurrentStudent().getPhoto()); | ||
genderCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { | ||
@Override | ||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { | ||
studentActivityController.putPhotoInPhotoRepository(studentActivityController.getCurrentStudent()); | ||
if(isChecked) { | ||
studentActivityController.createStudent(isMale); | ||
} | ||
else { | ||
studentActivityController.createStudent(isMale); | ||
} | ||
} | ||
}); | ||
} else { | ||
currentStudent = new Student(); | ||
studentActivityController.setCurrentStudent(new Student()); | ||
deleteStudent.setVisibility(View.GONE); | ||
} | ||
saveStudent.setOnClickListener(this); | ||
deleteStudent.setOnClickListener(this); | ||
} | ||
|
||
|
||
private void setStudent() { | ||
studentFirstName.setText(currentStudent.getFirstName()); | ||
studentSecondName.setText(currentStudent.getSecondName()); | ||
if (currentStudent.isMaleGender()) | ||
genderCheckbox.isChecked(); | ||
studentImageViewPhoto.setImageResource(currentStudent.getPhoto()); | ||
private void setFields() { | ||
firstName = studentFirstName.getText().toString(); | ||
secondName = studentSecondName.getText().toString(); | ||
isMale = genderCheckbox.isChecked(); | ||
} | ||
|
||
|
||
private boolean createStudent() { | ||
try { | ||
if (genderCheckbox.isChecked()) { | ||
photoRepository = MalePhotoRepository.Instance; | ||
} else { | ||
photoRepository = FemalePhotoRepository.Instance; | ||
} | ||
currentStudent.setPhoto(photoRepository.getPhotoInRepository()); | ||
} catch (NoSuchElementException e) { | ||
Toast.makeText(StudentActivity.this, "No Photo in DataBase", Toast.LENGTH_LONG).show(); | ||
return false; | ||
} | ||
setInitials(); | ||
return true; | ||
} | ||
|
||
private boolean modifyStudent() { | ||
if (currentStudent.getPhoto() == 0) { | ||
return false; | ||
} | ||
setInitials(); | ||
return true; | ||
} | ||
|
||
private void setInitials() { | ||
currentStudent.setMaleGender(genderCheckbox.isChecked()); | ||
currentStudent.setFirstName(studentFirstName.getText().toString()); | ||
currentStudent.setSecondName(studentSecondName.getText().toString()); | ||
} | ||
|
||
|
||
@Override | ||
public void onClick(View v) { | ||
int resultCode; | ||
String dataResponse; | ||
setFields(); | ||
studentActivityController.setStudentInitials(firstName, secondName, isMale); | ||
Student student = studentActivityController.getCurrentStudent(); | ||
switch (v.getId()) { | ||
case R.id.activity_student__save_button: { | ||
if (studentFirstName.getText().toString().equals("") || studentSecondName.getText().toString().equals("")) { | ||
Toast.makeText(StudentActivity.this, "Please, fill all the fields", Toast.LENGTH_LONG).show(); | ||
return; | ||
} | ||
if (modifyStudent()) { | ||
resultCode = 2; | ||
dataResponse = "ModifyStudent"; | ||
setResult(resultCode, new Intent().putExtra(dataResponse, currentStudent)); | ||
studentImageViewPhoto.setImageResource(currentStudent.getPhoto()); | ||
} else if (createStudent()) { | ||
resultCode = 1; | ||
dataResponse = "NewStudent"; | ||
setResult(resultCode, new Intent().putExtra(dataResponse, currentStudent)); | ||
studentImageViewPhoto.setImageResource(currentStudent.getPhoto()); | ||
if (studentActivityController.modifyStudent()) { | ||
setResult(MODIFY_STUDENT_RESULT_CODE, new Intent().putExtra(RESPONSE_MODIFY_STUDENT, student)); | ||
studentImageViewPhoto.setImageResource(student.getPhoto()); | ||
} else if (studentActivityController.createStudent(isMale)) { | ||
setResult(CREATE_STUDENT_RESULT_CODE, new Intent().putExtra(RESPONSE_CREATE_STUDENT, student)); | ||
studentImageViewPhoto.setImageResource(student.getPhoto()); | ||
} else { | ||
Toast.makeText(StudentActivity.this, "No Photo in DataBase", Toast.LENGTH_LONG).show(); | ||
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. Можно просто this |
||
} | ||
finish(); | ||
break; | ||
} | ||
case R.id.activity_student__delete_button: { | ||
resultCode = 3; | ||
dataResponse = "StudentForDelete"; | ||
setResult(resultCode, new Intent().putExtra(dataResponse, currentStudent)); | ||
photoRepository.putPhotoInRepository(currentStudent.getPhoto()); | ||
setResult(DELETE_STUDENT_RESULT_CODE, new Intent().putExtra(RESPONSE_DELETE_STUDENT, 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. |
||
studentActivityController.putPhotoInPhotoRepository(student); | ||
finish(); | ||
break; | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
app/src/main/java/ru/ok/technopolis/students/controller/StudentActivityController.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.controller; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
import ru.ok.technopolis.students.Student; | ||
import ru.ok.technopolis.students.repository.FemalePhotoRepository; | ||
import ru.ok.technopolis.students.repository.MalePhotoRepository; | ||
import ru.ok.technopolis.students.repository.PhotoRepository; | ||
|
||
public class StudentActivityController { | ||
|
||
public static final StudentActivityController Instance = new StudentActivityController(); | ||
|
||
private PhotoRepository photoRepository; | ||
private Student currentStudent; | ||
|
||
public void setCurrentStudent(Student student) { | ||
currentStudent = student; | ||
} | ||
|
||
public Student getCurrentStudent() { | ||
return currentStudent; | ||
} | ||
|
||
private StudentActivityController() { | ||
|
||
} | ||
|
||
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 boolean modifyStudent() { | ||
return currentStudent.photoAvailable(); | ||
} | ||
|
||
|
||
private void setPhotoRepository(boolean genderFlag) { | ||
if (genderFlag) { | ||
photoRepository = MalePhotoRepository.Instance; | ||
} else { | ||
photoRepository = FemalePhotoRepository.Instance; | ||
} | ||
} | ||
|
||
public void putPhotoInPhotoRepository(Student student) { | ||
setPhotoRepository(student.isMaleGender()); | ||
photoRepository.putPhotoInRepository(student.getPhoto()); | ||
} | ||
|
||
|
||
public boolean createStudent(boolean genderFlag) { | ||
return setPhotoForStudent(genderFlag); | ||
} | ||
|
||
private boolean setPhotoForStudent(boolean isChecked) { | ||
try { | ||
setPhotoRepository(isChecked); | ||
currentStudent.setPhoto(photoRepository.getPhotoInRepository()); | ||
} catch (NoSuchElementException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public void setStudentInitials(String firstName, String secondName, boolean isMale) { | ||
currentStudent.setMaleGender(isMale); | ||
currentStudent.setFirstName(firstName); | ||
currentStudent.setSecondName(secondName); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
...dents/Repository/MalePhotoRepository.java → ...dents/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
2 changes: 1 addition & 1 deletion
2
.../students/Repository/PhotoRepository.java → .../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
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
2 changes: 1 addition & 1 deletion
2
...tudents/Repository/StudentRepository.java → ...tudents/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
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.
Зачем добавил эти зависимости?