Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/MainScreenFragment.java
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
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(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(); | Log.e("BusTO-RefreshStop", "Asking for refresh when there is no fragment"); | ||||
// AsyncDataDownload(fragmentHelper, arrivalsFetchers,getContext()).execute(); | |||||
} else{ | } else{ | ||||
String stopName = fragment.getStopID(); | String stopName = fragment.getStopID(); | ||||
new AsyncDataDownload(fragmentHelper, fragment.getCurrentFetchersAsArray(), getContext()).execute(stopName); | new AsyncDataDownload(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 AsyncDataDownload(fragmentHelper, arrivalsFetchers, getContext()).execute(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
}; | }; | ||||
private final ActivityResultLauncher<String[]> requestPermissionLauncher = | private final ActivityResultLauncher<String[]> requestPermissionLauncher = | ||||
registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { | registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { | ||||
@Override | @Override | ||||
public void onActivityResult(Map<String, Boolean> result) { | public void onActivityResult(Map<String, Boolean> result) { | ||||
if(result==null || result.get(Manifest.permission.ACCESS_COARSE_LOCATION) == null | if(result==null || result.get(Manifest.permission.ACCESS_COARSE_LOCATION) == null | ||||
||result.get(Manifest.permission.ACCESS_FINE_LOCATION) ) return; | ||result.get(Manifest.permission.ACCESS_FINE_LOCATION) ) return; | ||||
if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) == null || | |||||
result.get(Manifest.permission.ACCESS_FINE_LOCATION) == null) | |||||
return; | |||||
if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) && result.get(Manifest.permission.ACCESS_FINE_LOCATION)){ | if(result.get(Manifest.permission.ACCESS_COARSE_LOCATION) && result.get(Manifest.permission.ACCESS_FINE_LOCATION)){ | ||||
locationPermissionGranted = true; | locationPermissionGranted = true; | ||||
Log.w(DEBUG_TAG, "Starting position"); | Log.w(DEBUG_TAG, "Starting position"); | ||||
if (mListener!= null && getContext()!=null){ | if (mListener!= null && getContext()!=null){ | ||||
if (locationManager==null) | if (locationManager==null) | ||||
locationManager = AppLocationManager.getInstance(getContext()); | locationManager = AppLocationManager.getInstance(getContext()); | ||||
locationManager.addLocationRequestFor(requester); | locationManager.addLocationRequestFor(requester); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
/** | /** | ||||
* Cancel the reload of the arrival times | * Cancel the reload of the arrival times | ||||
* because we are going to pop the fragment | * because we are going to pop the fragment | ||||
*/ | */ | ||||
public void cancelReloadArrivalsIfNeeded(){ | public void cancelReloadArrivalsIfNeeded(){ | ||||
if(getContext()==null) return; //we are not attached | if(getContext()==null) return; //we are not attached | ||||
//Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame); | //Fragment fr = getChildFragmentManager().findFragmentById(R.id.resultFrame); | ||||
fragmentHelper.stopLastRequestIfNeeded(); | fragmentHelper.stopLastRequestIfNeeded(true); | ||||
toggleSpinner(false); | toggleSpinner(false); | ||||
} | } | ||||
@Override | @Override | ||||
public void onAttach(@NonNull Context context) { | public void onAttach(@NonNull Context context) { | ||||
super.onAttach(context); | super.onAttach(context); | ||||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
} | } | ||||
@Override | @Override | ||||
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(true); | ||||
} | } | ||||
/* | /* | ||||
GUI METHODS | GUI METHODS | ||||
*/ | */ | ||||
/** | /** | ||||
* QR scan button clicked | * QR scan button clicked | ||||
Show All 13 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
* OK this is pure shit | * OK this is pure shit | ||||
* | * | ||||
* @param v View clicked | * @param v View clicked | ||||
*/ | */ | ||||
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(); | ||||
fragmentHelper.stopLastRequestIfNeeded(true); | |||||
requestArrivalsForStopID(busStopID); | requestArrivalsForStopID(busStopID); | ||||
} else { // searchMode == SEARCH_BY_NAME | } else { // searchMode == SEARCH_BY_NAME | ||||
String query = busStopSearchByNameEditText.getText().toString(); | String query = busStopSearchByNameEditText.getText().toString(); | ||||
query = query.trim(); | query = query.trim(); | ||||
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); | |||||
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(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | public class MainScreenFragment extends BaseFragment implements FragmentListenerMain{ | ||||
private void prepareGUIForBusStops() { | private void prepareGUIForBusStops() { | ||||
swipeRefreshLayout.setEnabled(false); | swipeRefreshLayout.setEnabled(false); | ||||
swipeRefreshLayout.setVisibility(View.VISIBLE); | swipeRefreshLayout.setVisibility(View.VISIBLE); | ||||
//actionHelpMenuItem.setVisible(false); | //actionHelpMenuItem.setVisible(false); | ||||
} | } | ||||
void showNearbyStopsFragment(){ | void showNearbyStopsFragment(){ | ||||
swipeRefreshLayout.setVisibility(View.VISIBLE); | swipeRefreshLayout.setVisibility(View.VISIBLE); | ||||
NearbyStopsFragment fragment = NearbyStopsFragment.newInstance(NearbyStopsFragment.TYPE_STOPS); | final Fragment existingFrag = fragMan.findFragmentById(R.id.resultFrame); | ||||
Fragment oldFrag = fragMan.findFragmentById(R.id.resultFrame); | NearbyStopsFragment fragment; | ||||
if (!(existingFrag instanceof NearbyStopsFragment)){ | |||||
//there is no fragment showing | |||||
fragment = NearbyStopsFragment.newInstance(NearbyStopsFragment.TYPE_STOPS); | |||||
FragmentTransaction ft = fragMan.beginTransaction(); | FragmentTransaction ft = fragMan.beginTransaction(); | ||||
if (oldFrag != null) | //if (oldFrag != null) | ||||
ft.remove(oldFrag); | // ft.remove(oldFrag); | ||||
ft.add(R.id.resultFrame, fragment, NearbyStopsFragment.FRAGMENT_TAG); | |||||
ft.replace(R.id.resultFrame, fragment, NearbyStopsFragment.FRAGMENT_TAG); | |||||
ft.commit(); | ft.commit(); | ||||
} | } | ||||
} | |||||
@Override | @Override | ||||
public void showFloatingActionButton(boolean yes) { | public void showFloatingActionButton(boolean yes) { | ||||
mListener.showFloatingActionButton(yes); | mListener.showFloatingActionButton(yes); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 138 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