Created
May 29, 2017 05:04
-
-
Save sai-sondarkar/4d9e92a5a6068fd620d9742732587bdc to your computer and use it in GitHub Desktop.
Recurit.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package in.techmafiya.sanyukt.Activities.RecuritActivities; | |
import android.content.Intent; | |
import android.content.SharedPreferences; | |
import android.content.pm.PackageManager; | |
import android.graphics.Typeface; | |
import android.support.annotation.NonNull; | |
import android.support.v4.content.ContextCompat; | |
import android.support.v7.app.ActionBar; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.support.v7.widget.Toolbar; | |
import android.util.Log; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.ImageView; | |
import android.widget.ListView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.afollestad.materialdialogs.folderselector.FileChooserDialog; | |
import com.github.angads25.filepicker.controller.DialogSelectionListener; | |
import com.github.angads25.filepicker.model.DialogConfigs; | |
import com.github.angads25.filepicker.model.DialogProperties; | |
import com.github.angads25.filepicker.view.FilePickerDialog; | |
import com.google.android.gms.tasks.OnCompleteListener; | |
import com.google.android.gms.tasks.Task; | |
import com.google.firebase.auth.AuthResult; | |
import com.google.firebase.auth.FirebaseAuth; | |
import com.romainpiel.shimmer.Shimmer; | |
import com.romainpiel.shimmer.ShimmerTextView; | |
import java.io.File; | |
import java.util.ArrayList; | |
import in.techmafiya.sanyukt.Activities.AuthenticationActivites.LoginActivity; | |
import in.techmafiya.sanyukt.Adapters.Recurit_Adapter.RecuritEmployeeUploadFailedAdapter; | |
import in.techmafiya.sanyukt.FirebaseInfo.FirebaseInfo; | |
import in.techmafiya.sanyukt.FirebaseInfo.FirebaseInit; | |
import in.techmafiya.sanyukt.Models.Employee; | |
import in.techmafiya.sanyukt.R; | |
import jxl.Cell; | |
import jxl.Sheet; | |
import jxl.Workbook; | |
import jxl.read.biff.BiffException; | |
public class RecuritActivity extends AppCompatActivity implements FileChooserDialog.FileCallback { | |
public FilePickerDialog dialog; | |
public Button button; | |
public ShimmerTextView tx1; | |
private FirebaseAuth mAuth; | |
public ImageView imageView; | |
public ListView FailedUploadlistView; | |
public RecuritEmployeeUploadFailedAdapter adapter; | |
public ArrayList<Employee> FailedUploadList = new ArrayList<Employee>(); | |
public int CheckIfAnyFalseID; | |
public Shimmer shimmer = new Shimmer(); | |
String firstName,lastname; | |
public static final String Name = "nameKey"; | |
public static final String Email = "emailKey"; | |
public static final String Id = "idKey"; | |
private String abmName,abmEmail,abmEmpId; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_recurit); | |
initToolBar(); | |
getParams(); | |
mAuth = FirebaseAuth.getInstance(); | |
initUiElements(); | |
DialogBoxSettings(); | |
FailedUploadlistView.setAdapter(adapter); | |
} | |
public void initToolBar(){ | |
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); | |
setSupportActionBar(toolbar); | |
ActionBar actionBar = getSupportActionBar(); | |
actionBar.setTitle(" "); | |
actionBar.setHomeAsUpIndicator(R.drawable.ic_actionbar_back); | |
actionBar.setHomeButtonEnabled(true); | |
actionBar.setDisplayHomeAsUpEnabled(true); | |
TextView tx = (TextView) toolbar.findViewById(R.id.tx) ; | |
Typeface custom_font = Typeface.createFromAsset(getAssets(),"fonts/MontserratAlternates-Light.otf"); | |
tx.setTypeface(custom_font); | |
tx1 = (ShimmerTextView) findViewById(R.id.tx1) ; | |
tx1.setTypeface(custom_font); | |
shimmer.start(tx1); | |
} | |
public void initUiElements(){ | |
button = (Button) findViewById(R.id.select_file); | |
imageView = (ImageView) findViewById(R.id.image); | |
FailedUploadlistView = (ListView) findViewById(R.id.failed_uploada_List_View); | |
adapter = new RecuritEmployeeUploadFailedAdapter(RecuritActivity.this, FailedUploadList); | |
button.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
dialog.show(); | |
// DialogBoxNew(); | |
} | |
}); | |
} | |
public void getParams(){ | |
Intent intent = getIntent(); | |
abmEmpId = intent.getStringExtra(FirebaseInfo.Id); | |
abmName = intent.getStringExtra(FirebaseInfo.Name); | |
abmEmail = intent.getStringExtra(FirebaseInfo.Email); | |
} | |
public void DialogBoxSettings(){ | |
String ext[]={".xls"}; | |
DialogProperties properties=new DialogProperties(); | |
properties.selection_mode=DialogConfigs.SINGLE_MODE; | |
properties.selection_type=DialogConfigs.FILE_SELECT; | |
properties.root=new File(DialogConfigs.DEFAULT_DIR); | |
properties.error_dir=new File(DialogConfigs.DEFAULT_DIR); | |
properties.extensions=ext; | |
dialog = new FilePickerDialog(RecuritActivity.this,properties); | |
dialog.setTitle("Select the Excel File"); | |
dialog.setDialogSelectionListener(new DialogSelectionListener() { | |
@Override | |
public void onSelectedFilePaths(String[] files) { | |
//files is the array of the paths of files selected by the Application User. | |
Toast.makeText(RecuritActivity.this,"Location : " + files.toString(),Toast.LENGTH_SHORT).show(); | |
button.setText("File Location : "+files[0]); | |
parsingXLS(files[0]); | |
tx1.setText("Processing List just a Min..."); | |
tx1.setTextColor(ContextCompat.getColor(RecuritActivity.this, R.color.orange)); | |
tx1.setReflectionColor(ContextCompat.getColor(RecuritActivity.this, R.color.orange)); | |
FailedUploadlistView.setVisibility(View.GONE); | |
imageView.setVisibility(View.VISIBLE); | |
FailedUploadList.clear(); | |
} | |
}); | |
} | |
public void parsingXLS(String filename) { | |
Toast.makeText(RecuritActivity.this,"Path got :"+filename,Toast.LENGTH_SHORT).show(); | |
File inputWorkbook = new File(filename); | |
CheckIfAnyFalseID =0; | |
if (inputWorkbook.exists()) { | |
Workbook w; | |
try { | |
w = Workbook.getWorkbook(inputWorkbook); | |
// Get the first sheet | |
Sheet sheet = w.getSheet(0); | |
// Loop over column and lines | |
for (int j = 1; j < sheet.getRows(); j++) { | |
Cell cell; | |
Employee mEmployee = new Employee(); | |
for (int colIndex = 0; colIndex < sheet.getColumns(); colIndex++) { | |
if (colIndex == 0) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Emp. ID",cell.getContents().toString()); | |
mEmployee.setEmployeeId(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 1) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("First Name ",cell.getContents().toString()); | |
firstName = cell.getContents().toString(); | |
mEmployee.setEmployeeName(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 2) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Middle Name",cell.getContents().toString()); | |
mEmployee.setMiddleName(cell.getContents().toString()); | |
} | |
} | |
//TOdo : date of birth , qualification details , | |
if (colIndex == 3) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Last Name",cell.getContents().toString()); | |
lastname = cell.getContents().toString(); | |
mEmployee.setLastName(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 7) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Qualification",cell.getContents().toString()); | |
mEmployee.setQualification(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 19) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("DOB date",cell.getContents().toString()); | |
mEmployee.setDateOfBirth(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 20) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("DOB M",cell.getContents().toString()); | |
mEmployee.setDateOfBirth(mEmployee.getDateOfBirth()+"/"+cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 21) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("DOB Y",cell.getContents().toString()); | |
mEmployee.setDateOfBirth(mEmployee.getDateOfBirth()+"/"+cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 27) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Designation",cell.getContents().toString()); | |
mEmployee.setDesignation(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 26) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("work Location",cell.getContents().toString()); | |
mEmployee.setWorkLocation(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 22) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("BusniessChannel",cell.getContents().toString()); | |
mEmployee.setBusinessChannel(cell.getContents().toString()); | |
} | |
} | |
// if (colIndex == 26) { | |
// cell = sheet.getCell(colIndex, j); | |
// if (cell != null) { | |
// // Found column and there is value in the cell. | |
// Log.d("previous Experience",cell.getContents().toString()); | |
// mEmployee.setPreviousExperience(cell.getContents().toString()); | |
// } | |
// } | |
// if (colIndex == 28) { | |
// cell = sheet.getCell(colIndex, j); | |
// if (cell != null) { | |
// // Found column and there is value in the cell. | |
// Log.d("RHRS emp id",cell.getContents().toString()); | |
// mEmployee.setrHRSEmployeeId(cell.getContents().toString()); | |
// } | |
// } | |
if (colIndex == 29) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Remark",cell.getContents().toString()); | |
mEmployee.setRemark(cell.getContents().toString()); | |
} | |
} | |
//todo : circle - 24, work location - 26 | |
if (colIndex == 8) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("current add.",cell.getContents().toString()); | |
mEmployee.setCurrentAdd(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 9) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("current city",cell.getContents().toString()); | |
mEmployee.setCurrentCity(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 10) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Current Pin",cell.getContents().toString()); | |
if(cell.getContents().toString() != null && !cell.getContents().toString().equals("")){ | |
mEmployee.setCurrentPincode(Integer.parseInt(cell.getContents().toString())); | |
} | |
} | |
} | |
if (colIndex == 17) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Gender",cell.getContents().toString()); | |
mEmployee.setGender(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 11) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("permanent add",cell.getContents().toString()); | |
mEmployee.setPermanentAdd(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 12) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("permanent city",cell.getContents().toString()); | |
mEmployee.setPermanentAdd(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 13) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("permanent pincode",cell.getContents().toString()); | |
if(cell.getContents().toString()!=null&& !cell.getContents().toString().equals("")){ | |
mEmployee.setPermanentPincode(Integer.parseInt(cell.getContents().toString())); | |
} | |
} | |
} | |
if (colIndex == 16) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Email",cell.getContents().toString()); | |
mEmployee.setEmail(cell.getContents().toLowerCase().toString()); | |
}else { | |
mEmployee.setEmail(firstName+"."+lastname+"@execu.com"); | |
} | |
//// TODO: 26-05-2017 GetEmail from Nilesh sir | |
} | |
if (colIndex == 14) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Current Mob",cell.getContents().toString()); | |
mEmployee.setCurrentMobile(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 15) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("permanent Mob",cell.getContents().toString()); | |
mEmployee.setPermanentMobile(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 18) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("emergency contact",cell.getContents().toString()); | |
mEmployee.setEmergencyContactNo(cell.getContents().toString()); | |
} | |
} | |
// TODO: 26-05-2017 date of joinign 19,20,21 | |
if (colIndex == 26) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Work Location",cell.getContents().toString()); | |
mEmployee.setWorkLocation(cell.getContents().toString()); | |
} | |
} | |
if (colIndex == 24) { | |
cell = sheet.getCell(colIndex, j); | |
if (cell != null) { | |
// Found column and there is value in the cell. | |
Log.d("Circle",cell.getContents().toString()); | |
mEmployee.setCircle(cell.getContents().toString()); | |
} | |
} | |
long time= System.currentTimeMillis(); | |
//joda time - 1/01/1970 00.00.00.000.000 | |
mEmployee.setDateOfEntryCreated(time); | |
} | |
Log.d("Object ", mEmployee.getEmployeeName() + " !"); | |
CreateNewUserInDB(mEmployee,sheet.getRows()); | |
continue; | |
} | |
}catch(BiffException e){ | |
Toast.makeText(RecuritActivity.this,"1 Error : " + e,Toast.LENGTH_SHORT).show(); | |
e.printStackTrace(); | |
}catch(Exception e){ | |
Toast.makeText(RecuritActivity.this,"2 Error : " + e,Toast.LENGTH_SHORT).show(); | |
e.printStackTrace(); | |
} | |
} | |
} | |
public void CreateNewUserInDB(final Employee employee , final int rows){ | |
mAuth.createUserWithEmailAndPassword(employee.getEmail(), employee.getEmployeeId()) | |
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { | |
@Override | |
public void onComplete(@NonNull Task<AuthResult> task) { | |
if(task.isSuccessful()){ | |
employee.setAbmEmail(abmEmail); | |
employee.setAbmEmpId(abmEmpId); | |
employee.setAbmName(abmName); | |
FirebaseInit.getDatabase().getReference().child(FirebaseInfo.Employee).push().setValue(employee); | |
CheckIfAnyFalseID ++; | |
} | |
if (!task.isSuccessful()) { | |
Toast.makeText(RecuritActivity.this, employee.getEmployeeName() + " Create account failed check Email Emp. ID. if still error exist id already may exisit!", | |
Toast.LENGTH_LONG).show(); | |
FailedUploadlistView.setVisibility(View.VISIBLE); | |
tx1.setText("Cannot Upload these Entries"); | |
tx1.setTextColor(ContextCompat.getColor(RecuritActivity.this, R.color.red)); | |
tx1.setReflectionColor(ContextCompat.getColor(RecuritActivity.this, R.color.red_dark)); | |
imageView.setVisibility(View.GONE); | |
adapter.add(employee); | |
adapter.notifyDataSetChanged(); | |
} | |
if(CheckIfAnyFalseID == rows-1){ | |
tx1.setText("All the data SuccessFully Uploaded !!"); | |
tx1.setTextColor(ContextCompat.getColor(RecuritActivity.this, R.color.green)); | |
tx1.setReflectionColor(ContextCompat.getColor(RecuritActivity.this, R.color.green_dark)); | |
} | |
} | |
}); | |
} | |
@Override | |
public void onFileSelection(@NonNull FileChooserDialog dialog, @NonNull File file) { | |
// TODO | |
final String tag = dialog.getTag(); // gets tag set from Builder, if you use multiple dialogs | |
Toast.makeText(RecuritActivity.this,"File : "+file.getPath(),Toast.LENGTH_SHORT).show(); | |
button.setText("File Location : "+file.getPath()); | |
parsingXLS(file.getPath().toString()); | |
tx1.setText("Processing List just a Min..."); | |
tx1.setTextColor(ContextCompat.getColor(RecuritActivity.this, R.color.orange)); | |
tx1.setReflectionColor(ContextCompat.getColor(RecuritActivity.this, R.color.orange)); | |
FailedUploadlistView.setVisibility(View.GONE); | |
imageView.setVisibility(View.VISIBLE); | |
FailedUploadList.clear(); | |
} | |
@Override | |
public void onFileChooserDismissed(@NonNull FileChooserDialog dialog) { | |
Toast.makeText(RecuritActivity.this,"Cancle",Toast.LENGTH_SHORT).show(); | |
} | |
@Override | |
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { | |
switch (requestCode) { | |
case FilePickerDialog.EXTERNAL_READ_PERMISSION_GRANT: { | |
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { | |
if(dialog!=null) | |
{ //Show dialog if the read permission has been granted. | |
dialog.show(); | |
} | |
} | |
else { | |
//Permission has not been granted. Notify the user. | |
Toast.makeText(RecuritActivity.this,"Permission is Required for getting list of files",Toast.LENGTH_SHORT).show(); | |
} | |
} | |
} | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
if (item.getItemId() == android.R.id.home) { | |
onBackPressed(); | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
@Override | |
public void onBackPressed() { | |
super.onBackPressed(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment