Changeset View
Changeset View
Standalone View
Standalone View
Copy file pathapp/src/main/java/it/reyboz/bustorino/fragments/NearbyStopsFragment.kt
| Show First 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | override fun onCreate(savedInstanceState: Bundle?) { | ||||
| locationProvider = FusedNativeLocationProvider(requireContext()) | locationProvider = FusedNativeLocationProvider(requireContext()) | ||||
| } | } | ||||
| override fun onCreateView( | override fun onCreateView( | ||||
| inflater: LayoutInflater, container: ViewGroup?, | inflater: LayoutInflater, container: ViewGroup?, | ||||
| savedInstanceState: Bundle? | savedInstanceState: Bundle? | ||||
| ): View { | ): View { | ||||
| // Inflate the layout for this fragment | // Inflate the layout for this fragment | ||||
| if (getContext() == null) throw RuntimeException() | val context = requireContext() | ||||
| val root = inflater.inflate(R.layout.fragment_nearby_stops, container, false) | val root = inflater.inflate(R.layout.fragment_nearby_stops, container, false) | ||||
| gridRecyclerView = root.findViewById<RecyclerView>(R.id.stopGridRecyclerView) | gridRecyclerView = root.findViewById<RecyclerView>(R.id.stopGridRecyclerView) | ||||
| gridLayoutManager = AutoFitGridLayoutManager( | gridLayoutManager = AutoFitGridLayoutManager( | ||||
| requireContext().getApplicationContext(), | context.getApplicationContext(), | ||||
| utils.convertDipToPixels(getContext(), COLUMN_WIDTH_DP.toFloat()).toInt() | utils.convertDipToPixels(context, COLUMN_WIDTH_DP.toFloat()).toInt() | ||||
| ) | ) | ||||
| gridRecyclerView.setLayoutManager(gridLayoutManager) | gridRecyclerView.setLayoutManager(gridLayoutManager) | ||||
| gridRecyclerView.setHasFixedSize(false) | gridRecyclerView.setHasFixedSize(false) | ||||
| circlingProgressBar = root.findViewById<ProgressBar>(R.id.circularProgressBar) | circlingProgressBar = root.findViewById<ProgressBar>(R.id.circularProgressBar) | ||||
| flatProgressBar = root.findViewById(R.id.horizontalProgressBar) | flatProgressBar = root.findViewById(R.id.horizontalProgressBar) | ||||
| messageTextView = root.findViewById<TextView>(R.id.messageTextView) | messageTextView = root.findViewById<TextView>(R.id.messageTextView) | ||||
| titleTextView = root.findViewById<TextView>(R.id.titleTextView) | titleTextView = root.findViewById<TextView>(R.id.titleTextView) | ||||
| loadingTextView = root.findViewById<TextView>(R.id.positionLoadingTextView) | loadingTextView = root.findViewById<TextView>(R.id.positionLoadingTextView) | ||||
| ▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||||
| } | } | ||||
| viewModel.arrivalsDecoupled.observe(viewLifecycleOwner){ stoprouteList -> | viewModel.arrivalsDecoupled.observe(viewLifecycleOwner){ stoprouteList -> | ||||
| if (getContext() == null) { | if (getContext() == null) { | ||||
| Log.e(DEBUG_TAG, "Trying to show arrivals in Recycler but we're not attached") | Log.e(DEBUG_TAG, "Trying to show arrivals in Recycler but we're not attached") | ||||
| return@observe | return@observe | ||||
| } | } | ||||
| val context = requireContext() | |||||
| if (firstLocForArrivals) { | if (firstLocForArrivals) { | ||||
| arrivalsStopAdapter = ArrivalsStopAdapter(stoprouteList, mListener, context, lastPosition!!) | mListener?.let{ | ||||
| arrivalsStopAdapter = ArrivalsStopAdapter(stoprouteList, it, context, lastPosition!!) | |||||
| gridRecyclerView.setAdapter(arrivalsStopAdapter) | gridRecyclerView.setAdapter(arrivalsStopAdapter) | ||||
| firstLocForArrivals = false | firstLocForArrivals = false | ||||
| } | |||||
| } else { | } else { | ||||
| arrivalsStopAdapter!!.setRoutesPairListAndPosition(stoprouteList, lastPosition) | arrivalsStopAdapter!!.setRoutesPairListAndPosition(stoprouteList, lastPosition) | ||||
| } | } | ||||
| //arrivalsStopAdapter.notifyDataSetChanged(); | //arrivalsStopAdapter.notifyDataSetChanged(); | ||||
| showRecyclerHidingLoadMessage() | showRecyclerHidingLoadMessage() | ||||
| //if (mListener != null) mListener!!.readyGUIfor(FragmentKind.NEARBY_ARRIVALS) | //if (mListener != null) mListener!!.readyGUIfor(FragmentKind.NEARBY_ARRIVALS) | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | private fun prepareForFragmentType() { | ||||
| mListener?.readyGUIfor(FragmentKind.NEARBY_STOPS) | mListener?.readyGUIfor(FragmentKind.NEARBY_STOPS) | ||||
| } else if (fragment_type == FragType.ARRIVALS) { | } else if (fragment_type == FragType.ARRIVALS) { | ||||
| titleTextView!!.text = getString(R.string.nearby_arrivals_message) | titleTextView!!.text = getString(R.string.nearby_arrivals_message) | ||||
| switchButton!!.text = getString(R.string.show_stops) | switchButton!!.text = getString(R.string.show_stops) | ||||
| val arrivalsSorted = viewModel.arrivalsDecoupled.value | val arrivalsSorted = viewModel.arrivalsDecoupled.value | ||||
| arrivalsSorted?.let{ | arrivalsSorted?.let{ | ||||
| lastPosition?.let{pos -> | lastPosition?.let{pos -> | ||||
| arrivalsStopAdapter = ArrivalsStopAdapter(it,mListener,requireContext(), pos ) | arrivalsStopAdapter = ArrivalsStopAdapter(it,mListener!!,requireContext(), pos ) | ||||
| } | } | ||||
| } | } | ||||
| arrivalsStopAdapter?.let{ | arrivalsStopAdapter?.let{ | ||||
| gridRecyclerView.setAdapter(it) | gridRecyclerView.setAdapter(it) | ||||
| } | } | ||||
| mListener?.readyGUIfor(FragmentKind.NEARBY_ARRIVALS) | mListener?.readyGUIfor(FragmentKind.NEARBY_ARRIVALS) | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 119 Lines • Show Last 20 Lines | |||||