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("