Skip to content

Commit

Permalink
Agent Ride Details done
Browse files Browse the repository at this point in the history
  • Loading branch information
prathviksankaliya committed Feb 11, 2023
1 parent 194e07c commit bfc68aa
Show file tree
Hide file tree
Showing 8 changed files with 245 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.itcraftsolution.raido.Fragments;

import android.app.Dialog;
import android.app.TimePickerDialog;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TimePicker;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.Task;
Expand All @@ -27,7 +28,11 @@
import com.itcraftsolution.raido.databinding.FragmentAgentDetailBinding;
import com.itcraftsolution.raido.spf.SpfUserData;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;

public class AgentDetailFragment extends Fragment {
Expand Down Expand Up @@ -82,6 +87,41 @@ public void onNothingSelected(AdapterView<?> adapterView) {
}
});

binding.txAdminRideArrivalTIme.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int min = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(requireContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
binding.txAdminRideArrivalTIme.setText(timePicker.getHour() + " : " + timePicker.getMinute());
}
}, hour, min, false);

timePickerDialog.show();
}
});

binding.txAdminRideDepTime.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int min = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(requireContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
binding.txAdminRideDepTime.setText(i + " : " + i1);

}
}, hour, min, false);

timePickerDialog.show();
}
});

binding.spAdminJourneyLoc.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Expand Down Expand Up @@ -126,7 +166,7 @@ public void onClick(View view) {
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.txAdminJourneySource.requestFocus();
}else if(selectedDistrictSource.equals("Destination")){
}else if(selectedDistrictDestination.equals("Destination")){
Snackbar.make(binding.mainAgentDetails,"Please Select Destination City!!", Snackbar.LENGTH_LONG)
.setBackgroundTint(getResources().getColor(R.color.red))
.setTextColor(getResources().getColor(R.color.white))
Expand All @@ -138,20 +178,34 @@ public void onClick(View view) {
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.txAdminRidePrice.requestFocus();
}else if(binding.txAdminRideArrivalTIme.getText().toString().length() < 3){
Snackbar.make(binding.txAdminRideArrivalTIme,"Please set Arrival Time!!", Snackbar.LENGTH_LONG)
.setBackgroundTint(getResources().getColor(R.color.red))
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.txAdminRideArrivalTIme.requestFocus();
}else if(binding.txAdminRideDepTime.getText().toString().length() < 3){
Snackbar.make(binding.txAdminRideDepTime,"Please set Departure Time!!", Snackbar.LENGTH_LONG)
.setBackgroundTint(getResources().getColor(R.color.red))
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.txAdminRideDepTime.requestFocus();
}else{
String carName = spfUserData.getSpfAgentRideDetails().getString("agentCarName", null);
String vehicalNumber = spfUserData.getSpfAgentRideDetails().getString("agentVehicalNumber", null);
String phoneNumber = spfUserData.getSpfAgentRideDetails().getString("agentPhoneNumber", null);
String journeyDate = spfUserData.getSpfAgentRideDetails().getString("agentDate", null);
String emptySeats = spfUserData.getSpfAgentRideDetails().getString("agentEmptySeats", null);
String totalJourney = spfUserData.getSpfAgentRideDetails().getString("agentTotalJourney", null);
String time = spfUserData.getSpfAgentRideDetails().getString("agentTime", null);
String ridePrice = binding.txAdminRidePrice.getText().toString();
String arrivalTime = binding.txAdminRideArrivalTIme.getText().toString();
String depTime = binding.txAdminRideDepTime.getText().toString();
String totalJourney = totalJourneyHours(arrivalTime, depTime);
String journeyLocs = showSelections();
spfUserData.setSpfAgentRideDetails(carName, vehicalNumber, phoneNumber, journeyDate, emptySeats, totalJourney, time,
selectedDistrictSource, selectedDistrictDestination, ridePrice, journeyLocs);
selectedDistrictSource, selectedDistrictDestination,arrivalTime, depTime, ridePrice, journeyLocs);
agentDetails = new AgentDetails(carName, vehicalNumber, phoneNumber, journeyDate, emptySeats, totalJourney, time,
selectedDistrictSource, selectedDistrictDestination,ridePrice, journeyLocs);
selectedDistrictSource, selectedDistrictDestination,arrivalTime, depTime,ridePrice, journeyLocs);
addDataIntoFirebaseDatabase();
}

Expand Down Expand Up @@ -206,4 +260,29 @@ public void onFailure(@NonNull Exception e) {
}
});
}

private String totalJourneyHours(String arrival, String dep){
Date date1, date2;
int days, hours, min;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("hh : mm");

try {
date1 = simpleDateFormat.parse(arrival);
date2 = simpleDateFormat.parse(dep);
} catch (ParseException e) {
throw new RuntimeException(e);
}

long difference = date2.getTime() - date1.getTime();
days = (int) (difference / (1000*60*60*24));
hours = (int) ((difference - (1000*60*60*24*days)) / (1000*60*60));
min = (int) (difference - (1000*60*60*24*days) - (1000*60*60*hours)) / (1000*60);
hours = (hours < 0 ? -hours : hours);
if(min < 0){
hours = 23 - hours;
min = 60 - Math.abs(min);
}
return hours +" : "+ min;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import android.app.DatePickerDialog;
import android.app.ProgressDialog;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
Expand All @@ -29,15 +26,17 @@
import com.itcraftsolution.raido.spf.SpfUserData;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;

public class AgentHomeFragment extends Fragment {

private FragmentAgentHomeBinding binding;
private String [] spTime = {"Hours ", "Minutes", "Days"};
private List<String> spTime = Arrays.asList("Hours ", "Minutes", "Days");
private String time;
private SpfUserData spfUserData;
private FirebaseAuth auth;
Expand Down Expand Up @@ -116,27 +115,28 @@ public void onClick(View view) {
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.edAdminSeats.requestFocus();
}else if(binding.edAdminHours.getText().toString().isEmpty() || Integer.parseInt(binding.edAdminSeats.getText().toString()) == 0){
Snackbar.make(binding.agentHomeMainLayout,"Please enter valid Journey Time", Snackbar.LENGTH_LONG)
.setBackgroundTint(getResources().getColor(R.color.red))
.setTextColor(getResources().getColor(R.color.white))
.show();
binding.edAdminHours.requestFocus();
}else{
}
// else if(binding.edAdminHours.getText().toString().isEmpty() || Integer.parseInt(binding.edAdminSeats.getText().toString()) == 0){
// Snackbar.make(binding.agentHomeMainLayout,"Please enter valid Journey Time", Snackbar.LENGTH_LONG)
// .setBackgroundTint(getResources().getColor(R.color.red))
// .setTextColor(getResources().getColor(R.color.white))
// .show();
// binding.edAdminHours.requestFocus();
// }
else{
String carName = binding.edAdminCarName.getText().toString();
String vehicleNumber = binding.edAdminVehicalNumber.getText().toString();
String phoneNumber = binding.edAdminNumber.getText().toString();
String date = binding.edAdminHomeDate.getText().toString();
String emptySeat = binding.edAdminSeats.getText().toString();
String totalJourney = binding.edAdminHours.getText().toString();
// binding.txResult.setText("car Name : " + carName +"\n" +
// "Vehical Number : " + vehicleNumber +"\n" +
// "Phone number : " + phoneNumber +"\n" +
// "date : " + date +"\n" +
// "Empty Seats : " + emptySeat +"\n" +
// "total Journey : " + totalJourney +"\n" +
// "time : " + time +"\n");
spfUserData.setSpfAgentRideDetails(carName, vehicleNumber, phoneNumber, date, emptySeat, totalJourney, time, null, null, null, null);
spfUserData.setSpfAgentRideDetails(carName, vehicleNumber, phoneNumber, date, emptySeat, null,time, null, null, null, null, null, null);
getParentFragmentManager().beginTransaction().replace(R.id.frMainContainer, new AgentDetailFragment()).addToBackStack(null).commit();

}
Expand All @@ -148,25 +148,25 @@ public void onClick(View view) {

return binding.getRoot();
}
private void spinnerTime(){
ArrayAdapter ad = new ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, spTime);
binding.spAdminTime.setAdapter(ad);
binding.spAdminTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
time = spTime[i];
}

@Override
public void onNothingSelected(AdapterView<?> adapterView) {

}
});

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
String currentDate = simpleDateFormat.format(new Date());
binding.edAdminHomeDate.setText(currentDate);
}
// private void spinnerTime(){
// ArrayAdapter<String> ad = new ArrayAdapter<String>(requireContext(), R.layout.spinner_layout, spTime);
// binding.spAdminTime.setAdapter(ad);
// binding.spAdminTime.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
// @Override
// public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
// time = spTime.get(i);
// }
//
// @Override
// public void onNothingSelected(AdapterView<?> adapterView) {
//
// }
// });
//
// SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
// String currentDate = simpleDateFormat.format(new Date());
// binding.edAdminHomeDate.setText(currentDate);
// }

private void loadProfileData(){
databaseReference.child("AgentLoginDetails").child(Objects.requireNonNull(auth.getCurrentUser()).getUid()).addValueEventListener(new ValueEventListener() {
Expand All @@ -191,8 +191,11 @@ public void onCancelled(@NonNull DatabaseError error) {
}

});
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
String currentDate = simpleDateFormat.format(new Date());
binding.edAdminHomeDate.setText(currentDate);

spinnerTime();
// spinnerTime();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import java.util.regex.Pattern;
Expand All @@ -77,7 +79,7 @@ public class LoginProfileFragment extends Fragment {
private FirebaseStorage firebaseStorage;
private StorageReference storageReference;
private ProgressDialog dialog;
private String spLoginUser[] = {"Car Rider", "Car Agent"};
private List<String> spLoginUser = Arrays.asList("Car Rider", "Car Agent");

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Expand Down Expand Up @@ -327,12 +329,12 @@ public void onFailure(@NonNull Exception e) {
}

private void spinnerProfile(){
ArrayAdapter adapter = new ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, spLoginUser);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(requireContext(), R.layout.spinner_layout, spLoginUser);
binding.spUserProfile.setAdapter(adapter);
binding.spUserProfile.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
userType = spLoginUser[i];
userType = spLoginUser.get(i);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.itcraftsolution.raido.Fragments;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
Expand All @@ -9,24 +10,44 @@
import android.view.View;
import android.view.ViewGroup;

import com.google.firebase.auth.FirebaseAuth;
import com.itcraftsolution.raido.Activity.AgentRideActivity;
import com.itcraftsolution.raido.Activity.UserRideActivity;
import com.itcraftsolution.raido.R;
import com.itcraftsolution.raido.databinding.FragmentSplashBinding;
import com.itcraftsolution.raido.spf.SpfUserData;

public class SplashFragment extends Fragment {

private FragmentSplashBinding binding;
private FirebaseAuth auth;
private SpfUserData spfUserData;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
binding = FragmentSplashBinding.inflate(getLayoutInflater());

auth = FirebaseAuth.getInstance();
spfUserData = new SpfUserData(requireContext());

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
getParentFragmentManager().beginTransaction().replace(R.id.frLoginContainer,
new LoginFragment()).addToBackStack(null).commit();
String userType = spfUserData.getSpfUserLoginDetails().getString("userType", null);
if (userType != null && auth.getCurrentUser() != null) {
if (userType.equals("Car Agent")) {
startActivity(new Intent(requireContext(), AgentRideActivity.class));
requireActivity().finishAffinity();
} else {
startActivity(new Intent(requireContext(), UserRideActivity.class));
requireActivity().finishAffinity();
}
} else {
getParentFragmentManager().beginTransaction().replace(R.id.frLoginContainer,
new LoginFragment()).addToBackStack(null).commit();
}
}
}, 1100);
return binding.getRoot();
Expand Down
Loading

0 comments on commit bfc68aa

Please sign in to comment.