use of com.example.nftscmers.fragments.DatePickerDialogFragment in project HackFest2022-Pretzel by chuanshaof.
the class EditJobActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_employer_edit_job);
backButton = findViewById(R.id.back_button);
position = findViewById(R.id.edit_job_position);
description = findViewById(R.id.edit_job_description);
deadline = findViewById(R.id.edit_job_deadline);
location = findViewById(R.id.edit_job_location);
skills = findViewById(R.id.edit_job_skills);
confirm = findViewById(R.id.edit_job_confirm);
if (getIntent().getStringExtra(ViewJobActivity.TAG) != null) {
// Loading of previous job data
new JobDb(EditJobActivity.this, new JobDb.OnJobModel() {
@Override
public void onResult(JobModel jobModel) {
Log.d(TAG, "onResult: " + jobModel);
job = jobModel;
Utils.setValid(position, job.getPosition());
Utils.setValid(description, job.getDescription());
Utils.setValid(deadline, Globals.DATEFORMAT.format(job.getDeadline()));
Utils.setValid(location, job.getLocation());
position.setEnabled(false);
Utils.uneditableField(position);
SkillsFragment skillsFragment = new SkillsFragment(job.getSkills());
getSupportFragmentManager().beginTransaction().replace(R.id.applicant_skills_list, skillsFragment).commit();
}
}).getJobModel(getIntent().getStringExtra(ViewJobActivity.TAG));
} else {
job = new JobModel(LoggedInUser.getInstance().getUserDocRef());
}
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(EditJobActivity.this, ScrollApplicationActivity.class);
startActivity(intent);
}
});
deadline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new DatePickerDialogFragment(new DatePickerDialogFragment.OnDateSetListener() {
@Override
public void onResult(Calendar calendar) {
deadlineCalendar = calendar;
Utils.setValid(deadline, Globals.DATEFORMAT.format(calendar.getTime()));
}
}).setMinDate(Calendar.getInstance()).show(getSupportFragmentManager(), TAG);
}
});
skills.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new SkillsDialogFragment(job.getSkills(), new SkillsDialogFragment.onConfirmListener() {
@Override
public void onResult(ArrayList<DocumentReference> skillsList) {
Log.d(TAG, "onResult: " + skillsList);
job.setSkills(skillsList);
SkillsFragment skillsFragment = new SkillsFragment(job.getSkills());
getSupportFragmentManager().beginTransaction().replace(R.id.edit_job_skills_list, skillsFragment).commit();
}
}).show(getSupportFragmentManager(), TAG);
}
});
confirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (Utils.invalidData(position, deadline, description)) {
return;
}
job.setDeadline(deadlineCalendar.getTime());
job.setLocation(location.getText().toString());
job.setDescription(description.getText().toString());
job.setPosition(position.getText().toString());
JobDb jobDb = new JobDb(EditJobActivity.this, new JobDb.OnJobUploadSuccess() {
@Override
public void onResult() {
Intent intent = new Intent(EditJobActivity.this, ScrollApplicationActivity.class);
startActivity(intent);
}
});
// Handling if it is an existing job or new job
if (job.getDocumentId() == null) {
jobDb.createJob(job, LoggedInUser.getInstance().getEmail());
} else {
jobDb.updateJob(job);
}
}
});
}
Aggregations