Skip to content

Commit

Permalink
Added some more rides information to the rides screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ischeinkman committed Aug 5, 2015
1 parent 785bcbe commit 5fbe187
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package org.ramonaza.officialramonapp.people.rides.ui.fragments;

import android.app.Fragment;
import android.database.sqlite.SQLiteDatabase;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import org.ramonaza.officialramonapp.R;
import org.ramonaza.officialramonapp.people.backend.ContactDatabaseContract;
import org.ramonaza.officialramonapp.people.backend.ContactDatabaseHandler;
import org.ramonaza.officialramonapp.people.backend.ContactDatabaseHelper;
import org.ramonaza.officialramonapp.people.backend.ContactInfoWrapper;
import org.ramonaza.officialramonapp.people.rides.backend.DriverInfoWrapper;
import org.ramonaza.officialramonapp.people.rides.backend.RidesDatabaseHandler;
Expand All @@ -21,6 +26,8 @@
*/
public class DisplayRidesFragment extends Fragment {

private TextView ridesDisplay;
private ProgressBar mBar;

/**
* Use this factory method to create a new instance of
Expand Down Expand Up @@ -49,25 +56,55 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView= inflater.inflate(R.layout.fragment_display_rides, container, false);
TextView ridesDisplay=(TextView)rootView.findViewById(R.id.RidesTextList);
ridesDisplay.setText(Html.fromHtml(createRidesList()));
ridesDisplay=(TextView)rootView.findViewById(R.id.RidesTextList);
mBar=(ProgressBar) rootView.findViewById(R.id.cProgressBar);
new CreateRidesText().execute();
return rootView;
}

private String createRidesList(){
RidesDatabaseHandler handler=new RidesDatabaseHandler(getActivity());
DriverInfoWrapper[] rides=handler.getDrivers(null, ContactDatabaseContract.DriverListTable.COLUMN_NAME+" ASC");
SQLiteDatabase db= new ContactDatabaseHelper(getActivity()).getWritableDatabase();
RidesDatabaseHandler rhandler=new RidesDatabaseHandler(db);
DriverInfoWrapper[] rides=rhandler.getDrivers(null, ContactDatabaseContract.DriverListTable.COLUMN_NAME+" ASC");
ContactDatabaseHandler chandler= new ContactDatabaseHandler(db);
String[] whereclause= new String[]{
String.format("%s = %d", ContactDatabaseContract.ContactListTable.COLUMN_PRESENT, 1),
String.format("not %s in (SELECT %s FROM %s)", ContactDatabaseContract.ContactListTable._ID,
ContactDatabaseContract.RidesListTable.COLUMN_ALEPH, ContactDatabaseContract.RidesListTable.TABLE_NAME)
};
ContactInfoWrapper[] driverless= chandler.getContacts(whereclause, null);
String ridesList="";
for(DriverInfoWrapper driver:rides){
ridesList+=String.format("<h1><b><u>%s</u></b></h1>",driver.getName());
ridesList+=String.format("<h1><b><u>%s</u></b></h1>",driver.getName(), driver.getFreeSpots());
for (ContactInfoWrapper alephInCar:driver.getAlephsInCar()){
ridesList+=String.format("-%s<br/>",alephInCar.getName());
}
ridesList+="<br/>";
ridesList+="<b>Free Spots: "+driver.getFreeSpots();
ridesList+="</b><br/><br/>";
}
if(driverless.length >0){
ridesList+="<h1><b><u>Driverless</u></b></h1>";
for(ContactInfoWrapper driverlessAleph: driverless) ridesList+=String.format("-%s<br/>",driverlessAleph.getName());
}
return ridesList;
}

private class CreateRidesText extends AsyncTask<Void, Void, String>{


@Override
protected String doInBackground(Void... params) {
return createRidesList();
}

@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
mBar.setVisibility(View.GONE);
ridesDisplay.setText(Html.fromHtml(s));
}
}

@Override
public void onDetach() {
super.onDetach();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ protected Void doInBackground(Integer... params) {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
String viewData="Name: "+mAleph.getName()+"\n"+
"Address: "+mAleph.getAddress()+"\n";
String viewData="Name: "+mAleph.getName()+"\n\n"+
"Address: "+mAleph.getAddress()+"\n\n"+
"School: "+mAleph.getSchool()+"\n\n";
for(DriverInfoWrapper driver: drivers){
viewData+="Currently in car: "+driver.getName()+"\n";
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/layout/fragment_display_rides.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
android:layout_height="match_parent"
tools:context="org.ramonaza.officialramonapp.people.rides.ui.fragments.DisplayRidesFragment">

<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/cProgressBar"/>


<ScrollView
android:layout_width="wrap_content"
Expand All @@ -13,7 +18,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/RidesTextList"
android:paddingLeft="10dp"
android:paddingTop="10dp"
Expand Down

0 comments on commit 5fbe187

Please # to comment.