Search in sources :

Example 1 with DatePickerDialogFragment

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);
            }
        }
    });
}
Also used : DatePickerDialogFragment(com.example.nftscmers.fragments.DatePickerDialogFragment) SkillsDialogFragment(com.example.nftscmers.fragments.SkillsDialogFragment) Calendar(java.util.Calendar) SkillsFragment(com.example.nftscmers.fragments.SkillsFragment) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) TextView(android.widget.TextView) JobModel(com.example.nftscmers.objectmodels.JobModel) JobDb(com.example.nftscmers.db.JobDb) DocumentReference(com.google.firebase.firestore.DocumentReference)

Aggregations

Intent (android.content.Intent)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JobDb (com.example.nftscmers.db.JobDb)1 DatePickerDialogFragment (com.example.nftscmers.fragments.DatePickerDialogFragment)1 SkillsDialogFragment (com.example.nftscmers.fragments.SkillsDialogFragment)1 SkillsFragment (com.example.nftscmers.fragments.SkillsFragment)1 JobModel (com.example.nftscmers.objectmodels.JobModel)1 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 Calendar (java.util.Calendar)1