Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/fragments/NearbyStopsFragment.java
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public class NearbyStopsFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor> { | ||||
private FragmentLocationListener fragmentLocationListener; | private FragmentLocationListener fragmentLocationListener; | ||||
private final String[] PROJECTION = {StopsTable.COL_ID,StopsTable.COL_LAT,StopsTable.COL_LONG, | private final String[] PROJECTION = {StopsTable.COL_ID,StopsTable.COL_LAT,StopsTable.COL_LONG, | ||||
StopsTable.COL_NAME,StopsTable.COL_TYPE,StopsTable.COL_LINES_STOPPING}; | StopsTable.COL_NAME,StopsTable.COL_TYPE,StopsTable.COL_LINES_STOPPING}; | ||||
private final static String DEBUG_TAG = "NearbyStopsFragment"; | private final static String DEBUG_TAG = "NearbyStopsFragment"; | ||||
private final static String FRAGMENT_TYPE_KEY = "FragmentType"; | private final static String FRAGMENT_TYPE_KEY = "FragmentType"; | ||||
public final static int TYPE_STOPS = 19, TYPE_ARRIVALS = 20; | public final static int TYPE_STOPS = 19, TYPE_ARRIVALS = 20; | ||||
private int fragment_type; | private int fragment_type; | ||||
public final static String FRAGMENT_TAG="NearbyStopsFrag"; | |||||
//data Bundle | //data Bundle | ||||
private final String BUNDLE_LOCATION = "location"; | private final String BUNDLE_LOCATION = "location"; | ||||
private final int LOADER_ID = 0; | private final int LOADER_ID = 0; | ||||
private RecyclerView gridRecyclerView; | private RecyclerView gridRecyclerView; | ||||
private SquareStopAdapter dataAdapter; | private SquareStopAdapter dataAdapter; | ||||
private AutoFitGridLayoutManager gridLayoutManager; | private AutoFitGridLayoutManager gridLayoutManager; | ||||
boolean canStartDBQuery = true; | boolean canStartDBQuery = true; | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | public void onCreate(Bundle savedInstanceState) { | ||||
globalSharedPref.registerOnSharedPreferenceChangeListener(preferenceChangeListener); | globalSharedPref.registerOnSharedPreferenceChangeListener(preferenceChangeListener); | ||||
} | } | ||||
@Override | @Override | ||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, | ||||
Bundle savedInstanceState) { | Bundle savedInstanceState) { | ||||
// Inflate the layout for this fragment | // Inflate the layout for this fragment | ||||
if (getContext() == null) throw new RuntimeException(); | |||||
View root = inflater.inflate(R.layout.fragment_nearby_stops, container, false); | View root = inflater.inflate(R.layout.fragment_nearby_stops, container, false); | ||||
gridRecyclerView = root.findViewById(R.id.stopGridRecyclerView); | gridRecyclerView = root.findViewById(R.id.stopGridRecyclerView); | ||||
gridLayoutManager = new AutoFitGridLayoutManager(getContext().getApplicationContext(), utils.convertDipToPixels(getContext(),COLUMN_WIDTH_DP)); | gridLayoutManager = new AutoFitGridLayoutManager(getContext().getApplicationContext(), Float.valueOf(utils.convertDipToPixels(getContext(),COLUMN_WIDTH_DP)).intValue()); | ||||
gridRecyclerView.setLayoutManager(gridLayoutManager); | gridRecyclerView.setLayoutManager(gridLayoutManager); | ||||
gridRecyclerView.setHasFixedSize(false); | gridRecyclerView.setHasFixedSize(false); | ||||
circlingProgressBar = root.findViewById(R.id.loadingBar); | circlingProgressBar = root.findViewById(R.id.loadingBar); | ||||
flatProgressBar = root.findViewById(R.id.horizontalProgressBar); | flatProgressBar = root.findViewById(R.id.horizontalProgressBar); | ||||
messageTextView = root.findViewById(R.id.messageTextView); | messageTextView = root.findViewById(R.id.messageTextView); | ||||
titleTextView = root.findViewById(R.id.titleTextView); | titleTextView = root.findViewById(R.id.titleTextView); | ||||
switchButton = root.findViewById(R.id.switchButton); | switchButton = root.findViewById(R.id.switchButton); | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | public void onAttach(Context context) { | ||||
/// TODO: RISOLVERE PROBLEMA: il context qui e' l'Activity non il Fragment | /// TODO: RISOLVERE PROBLEMA: il context qui e' l'Activity non il Fragment | ||||
if (context instanceof FragmentListenerMain) { | if (context instanceof FragmentListenerMain) { | ||||
mListener = (FragmentListenerMain) context; | mListener = (FragmentListenerMain) context; | ||||
} else { | } else { | ||||
throw new RuntimeException(context.toString() | throw new RuntimeException(context.toString() | ||||
+ " must implement OnFragmentInteractionListener"); | + " must implement OnFragmentInteractionListener"); | ||||
} | } | ||||
Log.d(DEBUG_TAG, "OnAttach called"); | Log.d(DEBUG_TAG, "OnAttach called"); | ||||
} | } | ||||
@Override | @Override | ||||
public void onPause() { | public void onPause() { | ||||
super.onPause(); | super.onPause(); | ||||
canStartDBQuery = false; | canStartDBQuery = false; | ||||
gridRecyclerView.setAdapter(null); | gridRecyclerView.setAdapter(null); | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | private void showStopsInRecycler(List<Stop> stops){ | ||||
dataAdapter.notifyDataSetChanged(); | dataAdapter.notifyDataSetChanged(); | ||||
//showRecyclerHidingLoadMessage(); | //showRecyclerHidingLoadMessage(); | ||||
if (gridRecyclerView.getVisibility() != View.VISIBLE) { | if (gridRecyclerView.getVisibility() != View.VISIBLE) { | ||||
circlingProgressBar.setVisibility(View.GONE); | circlingProgressBar.setVisibility(View.GONE); | ||||
gridRecyclerView.setVisibility(View.VISIBLE); | gridRecyclerView.setVisibility(View.VISIBLE); | ||||
} | } | ||||
messageTextView.setVisibility(View.GONE); | messageTextView.setVisibility(View.GONE); | ||||
if(mListener!=null) mListener.readyGUIfor(FragmentKind.NEARBY_STOPS); | |||||
} | } | ||||
private void showArrivalsInRecycler(List<Palina> palinas){ | private void showArrivalsInRecycler(List<Palina> palinas){ | ||||
Collections.sort(palinas,new StopSorterByDistance(lastReceivedLocation)); | Collections.sort(palinas,new StopSorterByDistance(lastReceivedLocation)); | ||||
final ArrayList<Pair<Stop,Route>> routesPairList = new ArrayList<>(10); | final ArrayList<Pair<Stop,Route>> routesPairList = new ArrayList<>(10); | ||||
//int maxNum = Math.min(MAX_STOPS, stopList.size()); | //int maxNum = Math.min(MAX_STOPS, stopList.size()); | ||||
for(Palina p: palinas){ | for(Palina p: palinas){ | ||||
Show All 10 Lines | private void showArrivalsInRecycler(List<Palina> palinas){ | ||||
firstLocForArrivals = false; | firstLocForArrivals = false; | ||||
} else { | } else { | ||||
arrivalsStopAdapter.setRoutesPairListAndPosition(routesPairList,lastReceivedLocation); | arrivalsStopAdapter.setRoutesPairListAndPosition(routesPairList,lastReceivedLocation); | ||||
} | } | ||||
//arrivalsStopAdapter.notifyDataSetChanged(); | //arrivalsStopAdapter.notifyDataSetChanged(); | ||||
showRecyclerHidingLoadMessage(); | showRecyclerHidingLoadMessage(); | ||||
if(mListener!=null) mListener.readyGUIfor(FragmentKind.NEARBY_ARRIVALS); | |||||
} | } | ||||
private void setNoStopsLayout(){ | private void setNoStopsLayout(){ | ||||
messageTextView.setVisibility(View.VISIBLE); | messageTextView.setVisibility(View.VISIBLE); | ||||
messageTextView.setText(R.string.no_stops_nearby); | messageTextView.setText(R.string.no_stops_nearby); | ||||
circlingProgressBar.setVisibility(View.GONE); | circlingProgressBar.setVisibility(View.GONE); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | class FragmentLocationListener implements AppLocationManager.LocationRequester{ | ||||
default: | default: | ||||
Log.e(DEBUG_TAG,"Location status not recognized"); | Log.e(DEBUG_TAG,"Location status not recognized"); | ||||
} | } | ||||
} | } | ||||
@Override | @Override | ||||
public LocationCriteria getLocationCriteria() { | public LocationCriteria getLocationCriteria() { | ||||
return new LocationCriteria(60,TIME_INTERVAL_REQUESTS); | return new LocationCriteria(120,TIME_INTERVAL_REQUESTS); | ||||
} | } | ||||
@Override | @Override | ||||
public long getLastUpdateTimeMillis() { | public long getLastUpdateTimeMillis() { | ||||
return lastUpdateTime; | return lastUpdateTime; | ||||
} | } | ||||
void resetUpdateTime(){ | void resetUpdateTime(){ | ||||
lastUpdateTime = -1; | lastUpdateTime = -1; | ||||
} | } | ||||
@Override | |||||
public void onLocationProviderAvailable() { | |||||
} | |||||
@Override | |||||
public void onLocationDisabled() { | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* Simple trick to get an automatic number of columns (from https://www.journaldev.com/13792/android-gridlayoutmanager-example) | * Simple trick to get an automatic number of columns (from https://www.journaldev.com/13792/android-gridlayoutmanager-example) | ||||
* | * | ||||
*/ | */ | ||||
class AutoFitGridLayoutManager extends GridLayoutManager { | class AutoFitGridLayoutManager extends GridLayoutManager { | ||||
Show All 33 Lines |
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