Search in sources :

Example 1 with JobAdapter

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

the class ScrollJobActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scroll_job);
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    flingAdapterView = findViewById(R.id.swipe);
    ArrayList<JobModel> data = new ArrayList<>();
    jobTracker = new HashMap<>();
    arrayAdapter = new JobAdapter(ScrollJobActivity.this, R.layout.item_in_cardview, data);
    flingAdapterView.setAdapter(arrayAdapter);
    db.collection(JobModel.getCollectionId()).get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {

        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot documentSnapshot : task.getResult()) {
                    Log.d(TAG, "onComplete: " + documentSnapshot);
                    new JobDb(ScrollJobActivity.this, new JobDb.OnJobModel() {

                        @Override
                        public void onResult(JobModel jobModel) {
                            new ApplicantDb(ScrollJobActivity.this, new ApplicantDb.OnApplicantModel() {

                                @Override
                                public void onResult(ApplicantModel applicantModel) {
                                    boolean applied = false;
                                    for (DocumentReference application : applicantModel.getApplications()) {
                                        applied = applied | jobModel.getPending().contains(application);
                                    }
                                    if (applied == false) {
                                        data.add(jobModel);
                                        arrayAdapter.notifyDataSetChanged();
                                        jobTracker.put(jobModel, documentSnapshot.getReference());
                                    }
                                }
                            }).getApplicantModel(LoggedInUser.getInstance().getEmail());
                        }
                    }).getJobModel(documentSnapshot.getReference());
                }
            }
        }
    });
    flingAdapterView.setFlingListener(new SwipeFlingAdapterView.onFlingListener() {

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

        @Override
        public void onLeftCardExit(Object o) {
            Toast.makeText(ScrollJobActivity.this, "Skipped Job", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onRightCardExit(Object o) {
            new ApplicationDb(ScrollJobActivity.this, new ApplicationDb.OnApplicationUploadSuccess() {

                @Override
                public void onResult() {
                    Toast.makeText(ScrollJobActivity.this, "Applied", Toast.LENGTH_SHORT).show();
                }
            }).newApplication(LoggedInUser.getInstance().getUserDocRef(), jobTracker.get(o));
        }

        @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(ScrollJobActivity.this, ViewJobActivity.class);
            intent.putExtra(ViewJobActivity.TAG, data.get(i).getDocumentId());
            startActivityForResult(intent, 0);
        }
    });
    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(ScrollJobActivity.this, ApplicationHistoryActivity.class);
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                    return true;
                case R.id.home:
                    return true;
                case R.id.profile:
                    intent = new Intent(ScrollJobActivity.this, ProfileActivity.class);
                    intent.putExtra(ProfileActivity.TAG, LoggedInUser.getInstance().getEmail());
                    startActivity(intent);
                    overridePendingTransition(0, 0);
                    return true;
            }
            return false;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) ApplicantDb(com.example.nftscmers.db.ApplicantDb) JobAdapter(com.example.nftscmers.adapters.JobAdapter) QuerySnapshot(com.google.firebase.firestore.QuerySnapshot) Button(android.widget.Button) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) ViewJobActivity(com.example.nftscmers.commonactivities.ViewJobActivity) 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) QueryDocumentSnapshot(com.google.firebase.firestore.QueryDocumentSnapshot) ApplicantModel(com.example.nftscmers.objectmodels.ApplicantModel) Intent(android.content.Intent) MenuItem(android.view.MenuItem) View(android.view.View) BottomNavigationView(com.google.android.material.bottomnavigation.BottomNavigationView) SwipeFlingAdapterView(com.lorentzos.flingswipe.SwipeFlingAdapterView) 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 JobAdapter (com.example.nftscmers.adapters.JobAdapter)1 ViewJobActivity (com.example.nftscmers.commonactivities.ViewJobActivity)1 ApplicantDb (com.example.nftscmers.db.ApplicantDb)1 ApplicationDb (com.example.nftscmers.db.ApplicationDb)1 JobDb (com.example.nftscmers.db.JobDb)1 ApplicantModel (com.example.nftscmers.objectmodels.ApplicantModel)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 QueryDocumentSnapshot (com.google.firebase.firestore.QueryDocumentSnapshot)1 QuerySnapshot (com.google.firebase.firestore.QuerySnapshot)1 SwipeFlingAdapterView (com.lorentzos.flingswipe.SwipeFlingAdapterView)1 ArrayList (java.util.ArrayList)1