Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MainScreenFragment.java
Show All 38 Lines | |||||
import com.google.android.material.floatingactionbutton.FloatingActionButton; | import com.google.android.material.floatingactionbutton.FloatingActionButton; | ||||
import com.google.zxing.integration.android.IntentIntegrator; | import com.google.zxing.integration.android.IntentIntegrator; | ||||
import java.util.Map; | import java.util.Map; | ||||
import it.reyboz.bustorino.R; | import it.reyboz.bustorino.R; | ||||
import it.reyboz.bustorino.backend.*; | import it.reyboz.bustorino.backend.*; | ||||
import it.reyboz.bustorino.middleware.AppLocationManager; | import it.reyboz.bustorino.middleware.AppLocationManager; | ||||
import it.reyboz.bustorino.middleware.AsyncDataDownload; | import it.reyboz.bustorino.middleware.AsyncArrivalsSearcher; | ||||
import it.reyboz.bustorino.middleware.AsyncStopsSearcher; | |||||
import it.reyboz.bustorino.util.LocationCriteria; | import it.reyboz.bustorino.util.LocationCriteria; | ||||
import it.reyboz.bustorino.util.Permissions; | import it.reyboz.bustorino.util.Permissions; | ||||
import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSIONS; | import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSIONS; | ||||
import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSION_GIVEN; | import static it.reyboz.bustorino.util.Permissions.LOCATION_PERMISSION_GIVEN; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | private final Runnable refreshStop = new Runnable() { | ||||
ArrivalsFragment fragment = (ArrivalsFragment) fragMan.findFragmentById(R.id.resultFrame); | ArrivalsFragment fragment = (ArrivalsFragment) fragMan.findFragmentById(R.id.resultFrame); | ||||
if (fragment == null){ | if (fragment == null){ | ||||
//we create a new fragment, which is WRONG | //we create a new fragment, which is WRONG | ||||
Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment"); | Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment"); | ||||
// AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | // AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | ||||
} else{ | } else{ | ||||
String stopName = fragment.getStopID(); | String stopName = fragment.getStopID(); | ||||
new AsyncDataDownload(fragmentHelper, fragment.getCurrentFetchersAsArray(), getContext()).execute(stopName); | new AsyncArrivalsSearcher(fragmentHelper, fragment.getCurrentFetchersAsArray(), getContext()).execute(stopName); | ||||
} | } | ||||
} else //we create a new fragment, which is WRONG | } else //we create a new fragment, which is WRONG | ||||
new AsyncDataDownload(fragmentHelper, arrivalsFetchers, getContext()).execute(); | new AsyncArrivalsSearcher(fragmentHelper, arrivalsFetchers, getContext()).execute(); | ||||
} | } | ||||
}; | }; | ||||
/// LOCATION STUFF /// | /// LOCATION STUFF /// | ||||
boolean pendingNearbyStopsRequest = false; | boolean pendingNearbyStopsRequest = false; | ||||
boolean locationPermissionGranted, locationPermissionAsked = false; | boolean locationPermissionGranted, locationPermissionAsked = false; | ||||
AppLocationManager locationManager; | AppLocationManager locationManager; | ||||
▲ Show 20 Lines • Show All 340 Lines • ▼ Show 20 Lines | public void onSearchClick(View v) { | ||||
if(getContext()!=null) { | if(getContext()!=null) { | ||||
if (query.length() < 1) { | if (query.length() < 1) { | ||||
Toast.makeText(getContext(), R.string.insert_bus_stop_name_error, Toast.LENGTH_SHORT).show(); | Toast.makeText(getContext(), R.string.insert_bus_stop_name_error, Toast.LENGTH_SHORT).show(); | ||||
} else if(query.length()< 3){ | } else if(query.length()< 3){ | ||||
Toast.makeText(getContext(), R.string.query_too_short, Toast.LENGTH_SHORT).show(); | Toast.makeText(getContext(), R.string.query_too_short, Toast.LENGTH_SHORT).show(); | ||||
} | } | ||||
else { | else { | ||||
fragmentHelper.stopLastRequestIfNeeded(true); | fragmentHelper.stopLastRequestIfNeeded(true); | ||||
new AsyncDataDownload(fragmentHelper, stopsFinderByNames, getContext()).execute(query); | new AsyncStopsSearcher(fragmentHelper, stopsFinderByNames).execute(query); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
public void onToggleKeyboardLayout(View v) { | public void onToggleKeyboardLayout(View v) { | ||||
if (searchMode == SEARCH_BY_NAME) { | if (searchMode == SEARCH_BY_NAME) { | ||||
▲ Show 20 Lines • Show All 177 Lines • ▼ Show 20 Lines | public void requestArrivalsForStopID(String ID) { | ||||
// we're still in UI thread, no need to mess with Progress | // we're still in UI thread, no need to mess with Progress | ||||
showToastMessage(R.string.insert_bus_stop_number_error, true); | showToastMessage(R.string.insert_bus_stop_number_error, true); | ||||
toggleSpinner(false); | toggleSpinner(false); | ||||
} else if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | } else if (framan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | ||||
ArrivalsFragment fragment = (ArrivalsFragment) framan.findFragmentById(R.id.resultFrame); | ArrivalsFragment fragment = (ArrivalsFragment) framan.findFragmentById(R.id.resultFrame); | ||||
if (fragment != null && fragment.getStopID() != null && fragment.getStopID().equals(ID)){ | if (fragment != null && fragment.getStopID() != null && fragment.getStopID().equals(ID)){ | ||||
// Run with previous fetchers | // Run with previous fetchers | ||||
//fragment.getCurrentFetchers().toArray() | //fragment.getCurrentFetchers().toArray() | ||||
new AsyncDataDownload(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper,fragment.getCurrentFetchersAsArray(), getContext()).execute(ID); | ||||
} else{ | } else{ | ||||
new AsyncDataDownload(fragmentHelper, arrivalsFetchers, getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper, arrivalsFetchers, getContext()).execute(ID); | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
new AsyncDataDownload(fragmentHelper,arrivalsFetchers, getContext()).execute(ID); | new AsyncArrivalsSearcher(fragmentHelper,arrivalsFetchers, getContext()).execute(ID); | ||||
Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID); | Log.d(DEBUG_TAG, "Started search for arrivals of stop " + ID); | ||||
} | } | ||||
} | } | ||||
/////////// LOCATION METHODS ////////// | /////////// LOCATION METHODS ////////// | ||||
/* | /* | ||||
private void startStopRequest(String provider) { | private void startStopRequest(String provider) { | ||||
Log.d(DEBUG_TAG, "Provider " + provider + " got enabled"); | Log.d(DEBUG_TAG, "Provider " + provider + " got enabled"); | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | class NearbyStopsRequester implements Runnable { | ||||
} else if(!haveProviders){ | } else if(!haveProviders){ | ||||
Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | Log.e(DEBUG_TAG, "NO PROVIDERS FOR POSITION"); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register