Remove visibility methods from view holder

This commit is contained in:
PavelRatushny 2017-09-15 10:27:44 +03:00
parent 8eb57b6712
commit a1d94e8d20
4 changed files with 16 additions and 36 deletions

View file

@ -99,7 +99,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) { public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) { if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
if (!iconHidden && isCurrentlyActive) { if (!iconHidden && isCurrentlyActive) {
((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.GONE); ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
iconHidden = true; iconHidden = true;
} }
View itemView = viewHolder.itemView; View itemView = viewHolder.itemView;
@ -135,7 +135,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
@Override @Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof MapMarkerItemViewHolder) { if (viewHolder instanceof MapMarkerItemViewHolder) {
((MapMarkerItemViewHolder) viewHolder).setOptionsButtonVisibility(View.VISIBLE); ((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
iconHidden = false; iconHidden = false;
} }
super.clearView(recyclerView, viewHolder); super.clearView(recyclerView, viewHolder);

View file

@ -21,7 +21,7 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
final TextView point; final TextView point;
final View rightPointSpace; final View rightPointSpace;
final TextView description; final TextView description;
final ImageButton optionsBtn; public final ImageButton optionsBtn;
final View divider; final View divider;
final View bottomShadow; final View bottomShadow;
@ -42,25 +42,4 @@ public class MapMarkerItemViewHolder extends RecyclerView.ViewHolder {
divider = view.findViewById(R.id.divider); divider = view.findViewById(R.id.divider);
bottomShadow = view.findViewById(R.id.bottom_shadow); bottomShadow = view.findViewById(R.id.bottom_shadow);
} }
public void setOptionsButtonVisibility(int visibility) {
optionsBtn.setVisibility(visibility);
}
public void setIconDirectionVisibility(int visibility) {
iconDirection.setVisibility(visibility);
}
public void setBottomShadowVisibility(int visibility) {
bottomShadow.setVisibility(visibility);
}
public void setPointSpaceVisibility(int visibility) {
leftPointSpace.setVisibility(visibility);
rightPointSpace.setVisibility(visibility);
}
public void setDividerVisibility(int visibility) {
divider.setVisibility(visibility);
}
} }

View file

@ -93,7 +93,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
int markerColor = MapMarker.getColorId(marker.colorIndex); int markerColor = MapMarker.getColorId(marker.colorIndex);
LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude()); LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
if (showDirectionEnabled && pos < 2) { if (showDirectionEnabled && pos < 2) {
holder.setIconDirectionVisibility(View.GONE); holder.iconDirection.setVisibility(View.GONE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor)); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor));
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.markers_top_bar_background)); holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.markers_top_bar_background));
@ -107,7 +107,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
drawableResToUpdate = R.drawable.ic_arrow_marker_diretion; drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
markerImageViewToUpdate = holder.icon; markerImageViewToUpdate = holder.icon;
} else { } else {
holder.setIconDirectionVisibility(View.VISIBLE); holder.iconDirection.setVisibility(View.VISIBLE);
holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, markerColor)); holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag_dark, markerColor));
holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light)); holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.bg_color_dark : R.color.bg_color_light));
@ -122,11 +122,11 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
markerImageViewToUpdate = holder.iconDirection; markerImageViewToUpdate = holder.iconDirection;
} }
if (pos == getItemCount() - 1) { if (pos == getItemCount() - 1) {
holder.setBottomShadowVisibility(View.VISIBLE); holder.bottomShadow.setVisibility(View.VISIBLE);
holder.setDividerVisibility(View.GONE); holder.divider.setVisibility(View.GONE);
} else { } else {
holder.setBottomShadowVisibility(View.GONE); holder.bottomShadow.setVisibility(View.GONE);
holder.setDividerVisibility(View.VISIBLE); holder.divider.setVisibility(View.VISIBLE);
} }
holder.iconReorder.setOnTouchListener(new View.OnTouchListener() { holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

View file

@ -133,14 +133,15 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
} }
}); });
itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE); itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
itemViewHolder.setIconDirectionVisibility(View.GONE); itemViewHolder.iconDirection.setVisibility(View.GONE);
itemViewHolder.setPointSpaceVisibility(View.GONE); itemViewHolder.leftPointSpace.setVisibility(View.GONE);
itemViewHolder.rightPointSpace.setVisibility(View.GONE);
if (position == getItemCount() - 1) { if (position == getItemCount() - 1) {
((MapMarkerItemViewHolder) holder).setBottomShadowVisibility(View.VISIBLE); itemViewHolder.bottomShadow.setVisibility(View.VISIBLE);
((MapMarkerItemViewHolder) holder).setDividerVisibility(View.GONE); itemViewHolder.divider.setVisibility(View.GONE);
} else { } else {
((MapMarkerItemViewHolder) holder).setBottomShadowVisibility(View.GONE); itemViewHolder.bottomShadow.setVisibility(View.GONE);
((MapMarkerItemViewHolder) holder).setDividerVisibility(View.VISIBLE); itemViewHolder.divider.setVisibility(View.VISIBLE);
} }
} else if (holder instanceof MapMarkerDateViewHolder) { } else if (holder instanceof MapMarkerDateViewHolder) {
final MapMarkerDateViewHolder dateViewHolder = (MapMarkerDateViewHolder) holder; final MapMarkerDateViewHolder dateViewHolder = (MapMarkerDateViewHolder) holder;