Search in sources :

Example 1 with ApplicantAdapter

use of com.example.nftscmers.adapters.ApplicantAdapter in project HackFest2022-Pretzel by chuanshaof.

the class ScrollApplicationActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scroll_application);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    flingAdapterView = findViewById(R.id.swipe);
    ArrayList<ApplicantModel> item = new ArrayList<>();
    jobTracker = new HashMap<>();
    ApplicantAdapter arrayAdapter = new ApplicantAdapter(ScrollApplicationActivity.this, R.layout.item_in_cardview, item);
    flingAdapterView.setAdapter(arrayAdapter);
    new EmployerDb(ScrollApplicationActivity.this, new EmployerDb.OnEmployerModel() {

        @Override
        public void onResult(EmployerModel employerModel) {
            for (DocumentReference job : employerModel.getJobs()) {
                Toast.makeText(getApplicationContext(), job.toString(), Toast.LENGTH_LONG).show();
                new JobDb(ScrollApplicationActivity.this, new JobDb.OnJobModel() {

                    @Override
                    public void onResult(JobModel jobModel) {
                        if (jobModel.getPending() == null) {
                            return;
                        }
                        for (DocumentReference pending : jobModel.getPending()) {
                            Log.d(TAG, "onResult: " + pending.getId());
                            new ApplicationDb(ScrollApplicationActivity.this, new ApplicationDb.OnApplicationModel() {

                                @Override
                                public void onResult(ApplicationModel applicationModel) {
                                    new ApplicantDb(ScrollApplicationActivity.this, new ApplicantDb.OnApplicantModel() {

                                        @Override
                                        public void onResult(ApplicantModel applicantModel) {
                                            Log.d(TAG, "onResult: " + applicantModel);
                                            item.add(applicantModel);
                                            ArrayList<DocumentReference> tracker = new ArrayList<>();
                                            tracker.add(pending);
                                            tracker.add(job);
                                            jobTracker.put(applicantModel, tracker);
                                            arrayAdapter.notifyDataSetChanged();
                                        }
                                    }).getApplicantModel(applicationModel.getApplicant());
                                }
                            }).getApplicationModel(pending);
                        }
                    }
                }).getJobModel(job);
            }
        }
    }).getEmployerModel(LoggedInUser.getInstance().getEmail());
    flingAdapterView.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {

        @Override
        public void removeFirstObjectInAdapter() {
            item.remove(0);
            arrayAdapter.notifyDataSetChanged();
        }

        @Override
        public void onLeftCardExit(Object o) {
            new JobDb(ScrollApplicationActivity.this, new JobDb.OnJobUploadSuccess() {

                @Override
                public void onResult() {
                    new ApplicationDb(ScrollApplicationActivity.this, new ApplicationDb.OnApplicationUploadSuccess() {

                        @Override
                        public void onResult() {
                            Toast.makeText(ScrollApplicationActivity.this, "Rejected", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(ScrollApplicationActivity.this, FeedbackActivity.class);
                            intent.putExtra(FeedbackActivity.TAG, jobTracker.get(o).get(0).getId());
                            startActivityForResult(intent, 0);
                        }
                    }).updateApplicationStatus(ApplicationModel.REJECTED, jobTracker.get(o).get(0));
                }
            }).deletePending(jobTracker.get(o).get(0), jobTracker.get(o).get(1));
        }

        @Override
        public void onRightCardExit(Object o) {
            Log.d(TAG, "onRightCardExit: " + o);
            new JobDb(ScrollApplicationActivity.this, new JobDb.OnJobUploadSuccess() {

                @Override
                public void onResult() {
                    new ApplicationDb(ScrollApplicationActivity.this, new ApplicationDb.OnApplicationUploadSuccess() {

                        @Override
                        public void onResult() {
                            Toast.makeText(ScrollApplicationActivity.this, "Accepted", Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent(ScrollApplicationActivity.this, FeedbackActivity.class);
                            intent.putExtra(FeedbackActivity.TAG, jobTracker.get(o).get(0).getId());
                            startActivityForResult(intent, 0);
                        }
                    }).updateApplicationStatus(ApplicationModel.ACCEPTED, jobTracker.get(o).get(0));
                }
            }).deletePending(jobTracker.get(o).get(0), jobTracker.get(o).get(1));
        }

        @Override
        public void onAdapterAboutToEmpty(int i) {
        }

        @Override
        public void onScroll(float v) {
        }
    });
    flingAdapterView.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() {

        @Override
        public void onItemClicked(int i, Object o) {
            Intent intent = new Intent(ScrollApplicationActivity.this, com.example.nftscmers.applicantactivities.ProfileActivity.class);
            intent.putExtra(com.example.nftscmers.applicantactivities.ProfileActivity.TAG, item.get(i).getDocumentId());
            startActivity(intent);
        }
    });
    Button like, dislike;
    like = findViewById(R.id.like);
    dislike = findViewById(R.id.dislike);
    like.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            flingAdapterView.getTopCardListener().selectRight();
        }
    });
    dislike.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            flingAdapterView.getTopCardListener().selectLeft();
        }
    });
    // Initialize and assign variable
    BottomNavigationView bottomNavigationView = findViewById(R.id.bottom_navigation);
    // Set Home selected
    bottomNavigationView.setSelectedItemId(R.id.home);
    // Perform item selected listener
    bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            Intent intent;
            switch(item.getItemId()) {
                case R.id.history:
                    intent = new Intent(ScrollApplicationActivity.this, JobHistoryActivity.class);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                    return true;
                case R.id.home:
                    return true;
                case R.id.create:
                    startActivity(new Intent(getApplicationContext(), EditJobActivity.class));
                    overridePendingTransition(0, 0);
                    return true;
                case R.id.profile:
                    intent = new Intent(ScrollApplicationActivity.this, ProfileActivity.class);
                    intent.putExtra(ProfileActivity.TAG, LoggedInUser.getInstance().getEmail());
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                    return true;
            }
            return false;
        }
    });
}
Also used : ApplicantAdapter(com.example.nftscmers.adapters.ApplicantAdapter) ArrayList(java.util.ArrayList) ApplicationModel(com.example.nftscmers.objectmodels.ApplicationModel) ApplicantDb(com.example.nftscmers.db.ApplicantDb) Button(android.widget.Button) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) ApplicationDb(com.example.nftscmers.db.ApplicationDb) JobModel(com.example.nftscmers.objectmodels.JobModel) DocumentReference(com.google.firebase.firestore.DocumentReference) SwipeFlingAdapterView(com.lorentzos.flingswipe.SwipeFlingAdapterView) FirebaseFirestore(com.google.firebase.firestore.FirebaseFirestore) FeedbackActivity(com.example.nftscmers.commonactivities.FeedbackActivity) ApplicantModel(com.example.nftscmers.objectmodels.ApplicantModel) EmployerModel(com.example.nftscmers.objectmodels.EmployerModel) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) SwipeFlingAdapterView(com.lorentzos.flingswipe.SwipeFlingAdapterView) EmployerDb(com.example.nftscmers.db.EmployerDb) JobDb(com.example.nftscmers.db.JobDb)

Aggregations

Intent (android.content.Intent)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 Button (android.widget.Button)1 ApplicantAdapter (com.example.nftscmers.adapters.ApplicantAdapter)1 FeedbackActivity (com.example.nftscmers.commonactivities.FeedbackActivity)1 ApplicantDb (com.example.nftscmers.db.ApplicantDb)1 ApplicationDb (com.example.nftscmers.db.ApplicationDb)1 EmployerDb (com.example.nftscmers.db.EmployerDb)1 JobDb (com.example.nftscmers.db.JobDb)1 ApplicantModel (com.example.nftscmers.objectmodels.ApplicantModel)1 ApplicationModel (com.example.nftscmers.objectmodels.ApplicationModel)1 EmployerModel (com.example.nftscmers.objectmodels.EmployerModel)1 JobModel (com.example.nftscmers.objectmodels.JobModel)1 BottomNavigationView (com.google.android.material.bottomnavigation.BottomNavigationView)1 DocumentReference (com.google.firebase.firestore.DocumentReference)1 FirebaseFirestore (com.google.firebase.firestore.FirebaseFirestore)1 SwipeFlingAdapterView (com.lorentzos.flingswipe.SwipeFlingAdapterView)1 ArrayList (java.util.ArrayList)1