working set time.

This commit is contained in:
Anshu Sharma 2018-11-15 10:56:06 -05:00
parent d0719293f9
commit 08a88bd2ac
2 changed files with 39 additions and 19 deletions

View file

@ -130,26 +130,23 @@ public class ServiceProviderAvailabilities extends AppCompatActivity {
/** /**
* Parses the views of the UI to generate 2D int array and updates the database and user with * Parses the views of the UI to generate 2D int array and updates the database and user with
* the new 2D on click of the setTime button. * the new 2D on click of the setTime button.
* *
* @param view * @param view
*/ */
public void onSetTimes(View view){ public void onSetTimes(View view){
String mondayStratTime = ((Button)findViewById(R.id.MondayStart)).getText().toString(); int[] mondayTime = parseTime( ((Button)findViewById(R.id.MondayStart)).getText().toString(),((Button)findViewById(R.id.MondayEnd)).getText().toString() );
String mondayEndTime = ((Button)findViewById(R.id.MondayEnd)).getText().toString(); int[] tuesdayTime = parseTime( ((Button)findViewById(R.id.TuesdayStart)).getText().toString(),((Button)findViewById(R.id.TuesdayEnd)).getText().toString() );
String tuesdayStratTime = ((Button)findViewById(R.id.TuesdayStart)).getText().toString(); int[] wednesdayTime = parseTime( ((Button)findViewById(R.id.WednesdayStart)).getText().toString(),((Button)findViewById(R.id.WednesdayEnd)).getText().toString() );
String tuesdayEndTime = ((Button)findViewById(R.id.TuesdayEnd)).getText().toString(); int[] thursdayTime = parseTime( ((Button)findViewById(R.id.ThursdayStart)).getText().toString(),((Button)findViewById(R.id.ThursdayEnd)).getText().toString() );
String wednesdayStratTime = ((Button)findViewById(R.id.WednesdayStart)).getText().toString(); int[] fridayTime = parseTime( ((Button)findViewById(R.id.FridayStart)).getText().toString(), ((Button)findViewById(R.id.FridayEnd)).getText().toString() );
String wednesdayEndTime = ((Button)findViewById(R.id.WednesdayEnd)).getText().toString(); int[] saturdayTime = parseTime( ((Button)findViewById(R.id.SaturdayStart)).getText().toString(),((Button)findViewById(R.id.SaturdayEnd)).getText().toString() );
String thursdayStratTime = ((Button)findViewById(R.id.ThursdayStart)).getText().toString(); int[] sundayTime = parseTime( ((Button)findViewById(R.id.SundayStart)).getText().toString(),((Button)findViewById(R.id.SundayEnd)).getText().toString() );
String thursdayEndTime = ((Button)findViewById(R.id.ThursdayEnd)).getText().toString(); int[][] availabilities = {mondayTime,tuesdayTime,wednesdayTime,thursdayTime,fridayTime,saturdayTime,sundayTime};
String fridayStratTime = ((Button)findViewById(R.id.FridayStart)).getText().toString(); DBHelper dbHelper = new DBHelper(this);
String fridayEndTime = ((Button)findViewById(R.id.FridayEnd)).getText().toString(); ServiceProvider user = (ServiceProvider) dbHelper.findUserByUsername(username);
String saturdayStratTime = ((Button)findViewById(R.id.SaturdayStart)).getText().toString(); user.setAvailabilities(availabilities);
String saturdayEndTime = ((Button)findViewById(R.id.SaturdayEnd)).getText().toString(); dbHelper.updateAvailability(user);
String sundayStratTime = ((Button)findViewById(R.id.SundayStart)).getText().toString();
String sundayEndTime = ((Button)findViewById(R.id.SundayEnd)).getText().toString();
System.out.println(mondayEndTime);
} }
/** /**
@ -181,8 +178,22 @@ public class ServiceProviderAvailabilities extends AppCompatActivity {
return time; return time;
} }
private int[] parseTime(String time){ private int[] parseTime(String startTime, String endTime){
int[] apple = {1}; int[] times = new int[4];
return apple; if(startTime.equals("START")){
times[0]=0;
times[1]=0;
}else{
times[0] = Integer.parseInt(startTime.substring(0,2));
times[1] = Integer.parseInt(startTime.substring(3));
}
if(endTime.equals("END")){
times[2]=0;
times[3]=0;
}else{
times[2] = Integer.parseInt(endTime.substring(0,2));
times[3] = Integer.parseInt(endTime.substring(3));
}
return times;
} }
} }

View file

@ -12,6 +12,14 @@
android:paddingTop="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/background" android:background="@drawable/background"
tools:context=".ServiceProviderAvailabilities"> tools:context=".ServiceProviderAvailabilities">
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onSetTimes"
android:text="Button" />
<TableLayout <TableLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
@ -347,4 +355,5 @@
</TableRow> </TableRow>
</TableLayout> </TableLayout>
</LinearLayout> </LinearLayout>