use of com.example.nftscmers.db.ApplicantDb 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;
}
});
}
Aggregations