private void initRouteList(ClimbingArea selectedArea) { recList = (RecyclerView) findViewById(R.id.cardList); recList.setHasFixedSize(true); LinearLayoutManager llm = new LinearLayoutManager(this); llm.setOrientation(LinearLayoutManager.VERTICAL); recList.setLayoutManager(llm); recyclerViewAdapter = new RouteCardViewAdapter(this, selectedRoutes); recList.setAdapter(recyclerViewAdapter); recList.setItemAnimator(new SlideInUpAnimator()); recyclerViewAdapter.notifyItemRangeChanged(0, selectedRoutes.size()); }
@SuppressLint("NewApi") @Override public void onValueSelected(Entry e, Highlight h) { int selectedDifficulty = (int) e.getX(); clearSelectedRoutes(); for (ClimbingRoute route : selectedArea.getRoutes()) { if (Utils.trimUIAARank(route.getUIAARank()) == selectedDifficulty) selectedRoutes.add(route); } // recyclerViewAdapter.notifyItemRangeChanged(0, selectedRoutes.size()); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); recList.invalidate(); if (selectedRoutes.isEmpty()) onNothingSelected(); }
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // Replace the result Cursor displayed by the Cursor Adapter with // the new result set. // This handler is not synchonrized with the UI thread, so you // will need to synchronize it before modiyfing any UI elements // directly. switch (loader.getId()) { case URL_ROUTES_LOADER_ALL: while (data.moveToNext()) { int climbingRouteIdColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_ID); int climbingRouteNameColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_NAME); int climbingRouteLatitudeColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LATITUDE); int climbingRouteLongitudeColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LONGITUDE); int climbingRouteRankingColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_RANKING); int climbingRouteImageColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_IMAGE_URL); int climbingRouteDifficultyColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_UIAA); int climbingRouteFollowClimbColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_FOLLOW_CLIMB_ACCOMPLISHED); int climbingRouteLeadingClimbColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_LEADING_CLIMB_ACCOMPLISHED); int climbingRouteRouteAccomplishedColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_ROUTE_ACCOMPLISHED); int climbingRouteClimbingAreaColumnIndex = data.getColumnIndex(ClimbingDBHelper.COLUMN_ROUTES_CLIMBINGAREA_ID); int id = data.getInt(climbingRouteIdColumnIndex); String name = data.getString(climbingRouteNameColumnIndex); float latitude = data.getFloat(climbingRouteLatitudeColumnIndex); float longitude = data.getFloat(climbingRouteLongitudeColumnIndex); float ranking = data.getFloat(climbingRouteRankingColumnIndex); String difficulty = data.getString(climbingRouteDifficultyColumnIndex); String imageUrl = data.getString(climbingRouteImageColumnIndex); boolean followClimbAccomplished = data.getInt(climbingRouteFollowClimbColumnIndex) > 0; boolean leadClimbAccomplished = data.getInt(climbingRouteLeadingClimbColumnIndex) > 0; boolean routeAccomplished = data.getInt(climbingRouteRouteAccomplishedColumnIndex) > 0; int climbingArea = data.getInt(climbingRouteClimbingAreaColumnIndex); ClimbingRoute climbingRoute = new ClimbingRoute(); climbingRoute.setId(id); climbingRoute.setName(name); climbingRoute.setLatitude(latitude); climbingRoute.setLongitude(longitude); climbingRoute.setRanking(ranking); climbingRoute.setDrawableUrl(imageUrl); climbingRoute.setUIAARank(difficulty); climbingRoute.setFollowClimbAccomplished(followClimbAccomplished); climbingRoute.setLeadClimbAccomplished(leadClimbAccomplished); climbingRoute.setRouteAccomplished(routeAccomplished); Log.d(TAG, "Climbing Area loaded: " + climbingArea); selectedArea.getRoutes().add(climbingRoute); } break; default: } int size = selectedRoutes.size(); clearSelectedRoutes(); selectedRoutes.addAll(selectedArea.getRoutes()); recyclerViewAdapter.notifyItemRangeRemoved(0, size); setChartData(selectedArea); setShareIntent(selectedArea); // TextView sumRoutes = (TextView) findViewById(R.id.textView_sum_routes); // sumRoutes.setText(selectedArea.getRoutes().size() + ""); }
public void onNothingSelected() { clearSelectedRoutes(); selectedRoutes.addAll(selectedArea.getRoutes()); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); };
private void clearSelectedRoutes() { int size = selectedRoutes.size(); selectedRoutes.clear(); recyclerViewAdapter.notifyItemRangeRemoved(0, selectedArea.getRoutes().size()); }