Skip to content

Commit

Permalink
Merge pull request #26 from virresh/sessions
Browse files Browse the repository at this point in the history
Sessions nearly sorted
  • Loading branch information
virresh authored Nov 1, 2019
2 parents f31b6b4 + f32d4b0 commit 24c8e68
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.RadioButton;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.mobilecomputing.sahayak.JavaClasses.Proposal;
import com.mobilecomputing.sahayak.JavaClasses.Session;
import com.mobilecomputing.sahayak.JavaClasses.SessionLab;
import com.mobilecomputing.sahayak.R;

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

import cn.pedant.SweetAlert.SweetAlertDialog;

Expand All @@ -42,10 +43,15 @@ public proposalShowFragment() {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final int[] numberOfChecks = {0};
final ArrayList<Date> checkedTimes = new ArrayList<Date>();
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_proposal_show, container, false);
final Button b = (Button) v.findViewById(R.id.submitButton);
final Proposal mProposal = (Proposal) getArguments().getSerializable("PROPOSAL_INFO");

LinearLayout sessionsLayout= (LinearLayout) v.findViewById(R.id.sessionsList);

TextView mProposal_skill = (TextView) v.findViewById(R.id.proposal_skill);
mProposal_skill.setText(mProposal.getSkill());

Expand All @@ -56,72 +62,54 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
mProposal_description.setText("Category: " + mProposal.getCategory());
//mProposal_description.setText("Description: " + mProposal.getDescription());

final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(mProposal.getStartDate());
int sh = startCalendar.HOUR_OF_DAY;
int sm = startCalendar.MINUTE;
if(sm<30){
sm=0;
}
else{
sm=1;
}

String tmp[] = {"00", "30"};
final CheckBox rb1 = (CheckBox) v.findViewById(R.id.radioButton);
String xyz = "";
int quanta = 15;
int running_sum = 0;
while(running_sum<mProposal.getDuration()){
final Date start = startCalendar.getTime();
startCalendar.add(Calendar.MINUTE, quanta);
running_sum+=quanta;
Date end = startCalendar.getTime();

final CheckBox sessionCheckBox = new CheckBox(getContext());
sessionCheckBox.setText(dateFormat.format(start)+" - "+dateFormat.format(end));
sessionsLayout.addView(sessionCheckBox);

sessionCheckBox.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
numberOfChecks[0] +=1;
checkedTimes.add(start);
}
else if(!isChecked){
numberOfChecks[0] -=1;
checkedTimes.remove(start);
}
if(numberOfChecks[0]<=0){
b.setEnabled(false);
}
else if(numberOfChecks[0]>0){
b.setEnabled(true);
}
}
});

// TODO: Use proper variable names so that purpose of code is clear
if (sm == 1) {
xyz = "";
if (sh < 10) {
xyz = "0";
}
xyz += sh + "" + tmp[sm] + "-";
if (sh + 1 < 10) {
xyz += "0";
}
xyz += (sh + 1) + "" + tmp[sm - 1];
rb1.setText(xyz);
} else {
xyz = "";
if (sh < 10) {
xyz = "0";
}
xyz += sh + "" + tmp[sm] + "-" + sh + "" + tmp[sm + 1];
rb1.setText(xyz);
}

final CheckBox rb2 = (CheckBox) v.findViewById(R.id.radioButton2);
if (sm == 1) {
xyz = "";
if (sh + 1 < 10) {
xyz += "0" + (sh + 1) + "" + tmp[sm - 1] + "-0" + (sh + 1) + tmp[sm];
} else {
xyz += (sh + 1) + "" + tmp[sm - 1] + "-" + (sh + 1) + tmp[sm];
}

rb2.setText(xyz);
} else {
xyz = "";
if (sh < 10) {
xyz = "0";
}
xyz += sh + "" + tmp[sm + 1] + "-";
if (sh + 1 < 10) {
xyz += "0";
}
xyz += (sh + 1) + "" + tmp[sm];
rb2.setText(xyz);
}

final Button b = (Button) v.findViewById(R.id.submitButton);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
SessionLab sl = SessionLab.get(view.getContext());
Session newSession = new Session(sl.getSessions().size(), mProposal);
sl.AddSession(newSession);

for(int i=0; i<checkedTimes.size(); i++){
Session newSession = new Session(sl.getSessions().size(), mProposal);
newSession.setInteractionDate(checkedTimes.get(i));
sl.AddSession(newSession);
}
//Toast.makeText(view.getContext(), "Session for " + newSession.getSkill() + " requested successfully!", Toast.LENGTH_SHORT).show();
new SweetAlertDialog(getContext(), SweetAlertDialog.SUCCESS_TYPE)
.setTitleText("Session requested successfully!")
Expand All @@ -136,34 +124,7 @@ public void onClick(SweetAlertDialog sweetAlertDialog) {
}
});

rb1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(rb1.isChecked() || rb2.isChecked())
{
b.setEnabled(true);
}
else
{
b.setEnabled(false);
}
}
});

rb2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(rb1.isChecked() || rb2.isChecked())
{
b.setEnabled(true);
}
else
{
b.setEnabled(false);
}
}
});

//submit only if at least one session is checked
return v;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

public class Session implements Serializable {
Expand Down Expand Up @@ -78,8 +77,8 @@ public Session(int ID, Proposal p){
// Initialise session from a proposal
this.setID(ID);
this.setTeacher(p.getMentorName());
this.setInteractionDate(Calendar.getInstance().getTime());
this.setSkill(p.getSkill());
this.setDuration(15);
}

}
26 changes: 9 additions & 17 deletions app/src/main/res/layout/fragment_proposal_show.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Fragments.proposalShowFragment">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/proposal_skill"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -40,22 +42,11 @@
android:text="Enter Time Slot"
/>
<LinearLayout
android:id="@+id/sessionsList"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="horizontal"
android:orientation="vertical"
android:padding="15dp">
<CheckBox
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />

<CheckBox
android:id="@+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="RadioButton" />
</LinearLayout>

<Button
Expand All @@ -69,4 +60,5 @@
android:text="Submit"
android:textAllCaps="false"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</ScrollView>

0 comments on commit 24c8e68

Please sign in to comment.