From 5fbe1876b4482bd592cf9394fa9fc308ce8e3285 Mon Sep 17 00:00:00 2001 From: Ilan Scheinkman Date: Tue, 4 Aug 2015 19:54:26 -0700 Subject: [PATCH] Added some more rides information to the rides screen --- .../ui/fragments/DisplayRidesFragment.java | 49 ++++++++++++++++--- .../ui/fragments/RidesAlephManipFragment.java | 5 +- .../res/layout/fragment_display_rides.xml | 6 ++- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/DisplayRidesFragment.java b/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/DisplayRidesFragment.java index 257fadb..252afb4 100644 --- a/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/DisplayRidesFragment.java +++ b/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/DisplayRidesFragment.java @@ -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; @@ -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 @@ -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("

%s

",driver.getName()); + ridesList+=String.format("

%s

",driver.getName(), driver.getFreeSpots()); for (ContactInfoWrapper alephInCar:driver.getAlephsInCar()){ ridesList+=String.format("-%s
",alephInCar.getName()); } - ridesList+="
"; + ridesList+="Free Spots: "+driver.getFreeSpots(); + ridesList+="

"; + } + if(driverless.length >0){ + ridesList+="

Driverless

"; + for(ContactInfoWrapper driverlessAleph: driverless) ridesList+=String.format("-%s
",driverlessAleph.getName()); } return ridesList; } + private class CreateRidesText extends AsyncTask{ + + + @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(); diff --git a/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/RidesAlephManipFragment.java b/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/RidesAlephManipFragment.java index 8ac8f75..2de9986 100644 --- a/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/RidesAlephManipFragment.java +++ b/app/src/main/java/org/ramonaza/officialramonapp/people/rides/ui/fragments/RidesAlephManipFragment.java @@ -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"; } diff --git a/app/src/main/res/layout/fragment_display_rides.xml b/app/src/main/res/layout/fragment_display_rides.xml index 8d8565f..927f74b 100644 --- a/app/src/main/res/layout/fragment_display_rides.xml +++ b/app/src/main/res/layout/fragment_display_rides.xml @@ -3,6 +3,11 @@ android:layout_height="match_parent" tools:context="org.ramonaza.officialramonapp.people.rides.ui.fragments.DisplayRidesFragment"> + +