Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MainScreenFragment.java
| Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
| private int searchMode; | private int searchMode; | ||||
| //private ImageButton addToFavorites; | //private ImageButton addToFavorites; | ||||
| private final ArrivalsFetcher[] arrivalsFetchers = new ArrivalsFetcher[]{new FiveTAPIFetcher(), new GTTJSONFetcher(), new FiveTScraperFetcher()}; | private final ArrivalsFetcher[] arrivalsFetchers = new ArrivalsFetcher[]{new FiveTAPIFetcher(), new GTTJSONFetcher(), new FiveTScraperFetcher()}; | ||||
| //// HIDDEN BUT IMPORTANT ELEMENTS //// | //// HIDDEN BUT IMPORTANT ELEMENTS //// | ||||
| FragmentManager fragMan; | FragmentManager fragMan; | ||||
| Handler mainHandler; | Handler mainHandler; | ||||
| private final Runnable refreshStop = new Runnable() { | private final Runnable refreshStop = new Runnable() { | ||||
| public void run() { | public void run() { | ||||
| if(getContext() == null) return; | |||||
| if (fragMan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | if (fragMan.findFragmentById(R.id.resultFrame) instanceof ArrivalsFragment) { | ||||
| 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 | ||||
| new AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | new AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | ||||
| } else{ | } else{ | ||||
| String stopName = fragment.getStopID(); | String stopName = fragment.getStopID(); | ||||
| Show All 19 Lines | private AppLocationManager.LocationRequester requester = new AppLocationManager.LocationRequester() { | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void onLocationStatusChanged(int status) { | public void onLocationStatusChanged(int status) { | ||||
| if(status == AppLocationManager.LOCATION_GPS_AVAILABLE && !isNearbyFragmentShown()){ | if(status == AppLocationManager.LOCATION_GPS_AVAILABLE && !isNearbyFragmentShown()){ | ||||
| //request Stops | //request Stops | ||||
| pendingNearbyStopsRequest = false; | pendingNearbyStopsRequest = false; | ||||
| if (getContext()!= null) | |||||
| mainHandler.post(new NearbyStopsRequester(getContext(), cr)); | mainHandler.post(new NearbyStopsRequester(getContext(), cr)); | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| public long getLastUpdateTimeMillis() { | public long getLastUpdateTimeMillis() { | ||||
| return 50; | return 50; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public LocationCriteria getLocationCriteria() { | public LocationCriteria getLocationCriteria() { | ||||
| return cr; | return cr; | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void onLocationProviderAvailable() { | public void onLocationProviderAvailable() { | ||||
| //Log.w(DEBUG_TAG, "pendingNearbyStopRequest: "+pendingNearbyStopsRequest); | //Log.w(DEBUG_TAG, "pendingNearbyStopRequest: "+pendingNearbyStopsRequest); | ||||
| if(!isNearbyFragmentShown()){ | if(!isNearbyFragmentShown() && getContext()!=null){ | ||||
| pendingNearbyStopsRequest = false; | pendingNearbyStopsRequest = false; | ||||
| mainHandler.post(new NearbyStopsRequester(getContext(), cr)); | mainHandler.post(new NearbyStopsRequester(getContext(), cr)); | ||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| public void onLocationDisabled() { | public void onLocationDisabled() { | ||||
| ▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | public void setSuppressArrivalsReload(boolean value){ | ||||
| ArrivalsFragment frag = (ArrivalsFragment) fragment; | ArrivalsFragment frag = (ArrivalsFragment) fragment; | ||||
| frag.setReloadOnResume(false); | frag.setReloadOnResume(false); | ||||
| } | } | ||||
| } | } | ||||
| */ | */ | ||||
| } | } | ||||
| /** | |||||
| * Cancel the reload of the arrival times | |||||
| * because we are going to pop the fragment | |||||
| */ | |||||
| public void cancelReloadArrivalsIfNeeded(){ | |||||
| if(getContext()==null) return; //we are not attached | |||||
| //Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame); | |||||
| fragmentHelper.stopLastRequestIfNeeded(); | |||||
| toggleSpinner(false); | |||||
| } | |||||
| @Override | @Override | ||||
| public void onAttach(@NonNull Context context) { | public void onAttach(@NonNull Context context) { | ||||
| super.onAttach(context); | super.onAttach(context); | ||||
| Log.d(DEBUG_TAG, "OnAttach called, setupOnAttach: "+setupOnAttached); | Log.d(DEBUG_TAG, "OnAttach called, setupOnAttach: "+setupOnAttached); | ||||
| mainHandler = new Handler(); | mainHandler = new Handler(); | ||||
| if (context instanceof CommonFragmentListener) { | if (context instanceof CommonFragmentListener) { | ||||
| mListener = (CommonFragmentListener) context; | mListener = (CommonFragmentListener) context; | ||||
| } else { | } else { | ||||
| throw new RuntimeException(context.toString() | throw new RuntimeException(context | ||||
| + " must implement CommonFragmentListener"); | + " must implement CommonFragmentListener"); | ||||
| } | } | ||||
| if (setupOnAttached) { | if (setupOnAttached) { | ||||
| if (pendingStopID==null) | if (pendingStopID==null) | ||||
| //We want the nearby bus stops! | //We want the nearby bus stops! | ||||
| mainHandler.post(new NearbyStopsRequester(context, cr)); | mainHandler.post(new NearbyStopsRequester(context, cr)); | ||||
| else{ | else{ | ||||
| ///TODO: if there is a stop displayed, we need to hold the update | ///TODO: if there is a stop displayed, we need to hold the update | ||||
| ▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
| public void onPause() { | public void onPause() { | ||||
| //mainHandler = null; | //mainHandler = null; | ||||
| locationManager.removeLocationRequestFor(requester); | locationManager.removeLocationRequestFor(requester); | ||||
| super.onPause(); | super.onPause(); | ||||
| fragmentHelper.setBlockAllActivities(true); | fragmentHelper.setBlockAllActivities(true); | ||||
| fragmentHelper.stopLastRequestIfNeeded(); | fragmentHelper.stopLastRequestIfNeeded(); | ||||
| } | } | ||||
| /* | /* | ||||
| GUI METHODS | GUI METHODS | ||||
| */ | */ | ||||
| /** | /** | ||||
| * QR scan button clicked | * QR scan button clicked | ||||
| * | * | ||||
| * @param v View QRButton clicked | * @param v View QRButton clicked | ||||
| */ | */ | ||||
| Show All 14 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
| public void onSearchClick(View v) { | public void onSearchClick(View v) { | ||||
| final StopsFinderByName[] stopsFinderByNames = new StopsFinderByName[]{new GTTStopsFetcher(), new FiveTStopsFetcher()}; | final StopsFinderByName[] stopsFinderByNames = new StopsFinderByName[]{new GTTStopsFetcher(), new FiveTStopsFetcher()}; | ||||
| if (searchMode == SEARCH_BY_ID) { | if (searchMode == SEARCH_BY_ID) { | ||||
| String busStopID = busStopSearchByIDEditText.getText().toString(); | String busStopID = busStopSearchByIDEditText.getText().toString(); | ||||
| requestArrivalsForStopID(busStopID); | requestArrivalsForStopID(busStopID); | ||||
| } else { // searchMode == SEARCH_BY_NAME | } else { // searchMode == SEARCH_BY_NAME | ||||
| String query = busStopSearchByNameEditText.getText().toString(); | String query = busStopSearchByNameEditText.getText().toString(); | ||||
| //new asyncWgetBusStopSuggestions(query, stopsDB, StopsFindersByNameRecursionHelper); | //new asyncWgetBusStopSuggestions(query, stopsDB, StopsFindersByNameRecursionHelper); | ||||
| if(getContext()!=null) | |||||
| new AsyncDataDownload(fragmentHelper, stopsFinderByNames, getContext()).execute(query); | new AsyncDataDownload(fragmentHelper, stopsFinderByNames, getContext()).execute(query); | ||||
| } | } | ||||
| } | } | ||||
| public void onToggleKeyboardLayout(View v) { | public void onToggleKeyboardLayout(View v) { | ||||
| if (searchMode == SEARCH_BY_NAME) { | if (searchMode == SEARCH_BY_NAME) { | ||||
| setSearchModeBusStopID(); | setSearchModeBusStopID(); | ||||
| if (busStopSearchByIDEditText.requestFocus()) { | if (busStopSearchByIDEditText.requestFocus()) { | ||||
| showKeyboard(); | showKeyboard(); | ||||
| } | } | ||||
| } else { // searchMode == SEARCH_BY_ID | } else { // searchMode == SEARCH_BY_ID | ||||
| ▲ Show 20 Lines • Show All 243 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