Added toasts
This commit is contained in:
parent
2ebda7ab71
commit
6e1c5915ca
1 changed files with 32 additions and 4 deletions
|
@ -7,6 +7,7 @@ import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TimePicker;
|
import android.widget.TimePicker;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
|
@ -142,10 +143,22 @@ public class ServiceProviderAvailabilities extends AppCompatActivity {
|
||||||
int[] saturdayTime = parseTime( ((Button)findViewById(R.id.SaturdayStart)).getText().toString(),((Button)findViewById(R.id.SaturdayEnd)).getText().toString() );
|
int[] saturdayTime = parseTime( ((Button)findViewById(R.id.SaturdayStart)).getText().toString(),((Button)findViewById(R.id.SaturdayEnd)).getText().toString() );
|
||||||
int[] sundayTime = parseTime( ((Button)findViewById(R.id.SundayStart)).getText().toString(),((Button)findViewById(R.id.SundayEnd)).getText().toString() );
|
int[] sundayTime = parseTime( ((Button)findViewById(R.id.SundayStart)).getText().toString(),((Button)findViewById(R.id.SundayEnd)).getText().toString() );
|
||||||
int[][] availabilities = {mondayTime,tuesdayTime,wednesdayTime,thursdayTime,fridayTime,saturdayTime,sundayTime};
|
int[][] availabilities = {mondayTime,tuesdayTime,wednesdayTime,thursdayTime,fridayTime,saturdayTime,sundayTime};
|
||||||
|
boolean validation = true;
|
||||||
|
for(int[] times: availabilities){
|
||||||
|
if(!validateTime(times)){
|
||||||
|
validation = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(validation){
|
||||||
DBHelper dbHelper = new DBHelper(this);
|
DBHelper dbHelper = new DBHelper(this);
|
||||||
ServiceProvider user = (ServiceProvider) dbHelper.findUserByUsername(username);
|
ServiceProvider user = (ServiceProvider) dbHelper.findUserByUsername(username);
|
||||||
user.setAvailabilities(availabilities);
|
user.setAvailabilities(availabilities);
|
||||||
dbHelper.updateAvailability(user);
|
dbHelper.updateAvailability(user);
|
||||||
|
Toast.makeText(this, "New Availabilities have been set.", Toast.LENGTH_LONG).show();
|
||||||
|
} else{
|
||||||
|
Toast.makeText(this, "All end times must be later then start times.", Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -196,4 +209,19 @@ public class ServiceProviderAvailabilities extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
return times;
|
return times;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean validateTime(int[] time){
|
||||||
|
if(time[0]==0&&time[1]==0&&time[2]==0&&time[3]==0){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(time[2]>time[0]){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
if(time[2]==time[0]&&time[3]>time[1]){
|
||||||
|
return true;
|
||||||
|
}else{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue