Add action for import button and change fab visibility

This commit is contained in:
PavelRatushny 2017-11-10 12:08:52 +02:00
parent c356d103d1
commit 9324fe9904

View file

@ -53,13 +53,14 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
private Paint textPaint = new Paint(); private Paint textPaint = new Paint();
private Snackbar snackbar; private Snackbar snackbar;
private boolean compassUpdateAllowed = true; private boolean compassUpdateAllowed = true;
private View mainView;
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent(); final boolean night = !mapActivity.getMyApplication().getSettings().isLightContent();
final View mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false); mainView = inflater.inflate(R.layout.fragment_map_markers_groups, container, false);
Fragment addMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(AddMarkersGroupBottomSheetDialogFragment.TAG); Fragment addMarkersGroupFragment = getChildFragmentManager().findFragmentByTag(AddMarkersGroupBottomSheetDialogFragment.TAG);
if (addMarkersGroupFragment != null) { if (addMarkersGroupFragment != null) {
@ -235,8 +236,30 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
} }
} }
}); });
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
changeFabVisibilityIfNeeded();
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
changeFabVisibilityIfNeeded();
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
changeFabVisibilityIfNeeded();
}
});
final View emptyView = mainView.findViewById(R.id.empty_view); final View emptyView = mainView.findViewById(R.id.empty_view);
mainView.findViewById(R.id.import_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openAddGroupMenu();
}
});
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view); ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day); emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_group_night : R.drawable.ic_empty_state_marker_group_day);
recyclerView.setEmptyView(emptyView); recyclerView.setEmptyView(emptyView);
@ -251,6 +274,10 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
return mainView; return mainView;
} }
private void changeFabVisibilityIfNeeded() {
mainView.findViewById(R.id.add_group_fab).setVisibility(adapter.getItemCount() > 0 ? View.VISIBLE : View.GONE);
}
private void openAddGroupMenu() { private void openAddGroupMenu() {
AddMarkersGroupBottomSheetDialogFragment fragment = new AddMarkersGroupBottomSheetDialogFragment(); AddMarkersGroupBottomSheetDialogFragment fragment = new AddMarkersGroupBottomSheetDialogFragment();
fragment.setListener(createAddMarkersGroupFragmentListener()); fragment.setListener(createAddMarkersGroupFragmentListener());