Fix displaying markers in landscape

This commit is contained in:
PavelRatushny 2017-10-27 16:05:05 +03:00
parent 44e15244fa
commit 7eb1f932cd
4 changed files with 74 additions and 14 deletions

View file

@ -107,11 +107,44 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="horizontal"> android:orientation="horizontal">
<android.support.v7.widget.RecyclerView <android.support.v4.widget.NestedScrollView
android:id="@+id/markers_recycler_view"
android:layout_weight="0.55" android:layout_weight="0.55"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="match_parent"/> android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/map_markers_layout"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_width="match_parent"
android:layout_height="8dp"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
osmand:cardUseCompatPadding="true"
osmand:cardCornerRadius="8dp">
<android.support.v7.widget.RecyclerView
android:nestedScrollingEnabled="false"
android:id="@+id/markers_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.v7.widget.CardView>
<View
android:layout_width="match_parent"
android:layout_height="8dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<LinearLayout <LinearLayout
android:layout_weight="0.45" android:layout_weight="0.45"

View file

@ -144,6 +144,11 @@
</android.support.design.widget.AppBarLayout> </android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/map_markers_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="72dp" android:paddingBottom="72dp"
@ -152,6 +157,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</FrameLayout>
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout

View file

@ -201,9 +201,18 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
changeKeyboardInBoxes(); changeKeyboardInBoxes();
final View mapMarkersLayout = mainView.findViewById(R.id.map_markers_layout);
RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view); RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.markers_recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new CoordinateInputAdapter(mapActivity, mapMarkers); adapter = new CoordinateInputAdapter(mapActivity, mapMarkers);
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
mapMarkersLayout.setVisibility(adapter.isEmpty() ? View.GONE : View.VISIBLE);
}
});
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -304,8 +313,9 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
@Override @Override
public void onDestroyView() { public void onDestroyView() {
if (getDialog() != null && getRetainInstance()) { Dialog dialog = getDialog();
getDialog().setDismissMessage(null); if (dialog != null && getRetainInstance()) {
dialog.setDismissMessage(null);
} }
super.onDestroyView(); super.onDestroyView();
} }

View file

@ -13,6 +13,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment; import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper; import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import java.util.List; import java.util.List;
@ -29,11 +30,13 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
private Float heading; private Float heading;
private boolean useCenter; private boolean useCenter;
private int screenOrientation; private int screenOrientation;
private boolean portrait;
public CoordinateInputAdapter (MapActivity mapActivity, List<MapMarker> mapMarkers) { public CoordinateInputAdapter (MapActivity mapActivity, List<MapMarker> mapMarkers) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent(); nightTheme = !mapActivity.getMyApplication().getSettings().isLightContent();
iconsCache = mapActivity.getMyApplication().getIconsCache(); iconsCache = mapActivity.getMyApplication().getIconsCache();
portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
this.mapMarkers = mapMarkers; this.mapMarkers = mapMarkers;
} }
@ -86,11 +89,14 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
} }
}); });
boolean singleItem = getItemCount() == 1;
boolean fistItem = position == 0; boolean fistItem = position == 0;
boolean lastItem = position == getItemCount() - 1; boolean lastItem = position == getItemCount() - 1;
if (portrait) {
holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE); holder.topDivider.setVisibility(fistItem ? View.VISIBLE : View.GONE);
holder.divider.setVisibility((getItemCount() > 1 && !lastItem) ? View.VISIBLE : View.GONE);
holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE); holder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
}
holder.divider.setVisibility((!singleItem && !lastItem) ? View.VISIBLE : View.GONE);
holder.title.setText(mapMarker.getName(mapActivity)); holder.title.setText(mapMarker.getName(mapActivity));
@ -105,6 +111,10 @@ public class CoordinateInputAdapter extends RecyclerView.Adapter<MapMarkerItemVi
return mapMarkers.size(); return mapMarkers.size();
} }
public boolean isEmpty() {
return getItemCount() == 0;
}
public MapMarker getItem(int position) { public MapMarker getItem(int position) {
return mapMarkers.get(position); return mapMarkers.get(position);
} }