Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-17 07:40:47 +01:00
commit 962af1ccc1
7 changed files with 53 additions and 48 deletions

View file

@ -3743,4 +3743,6 @@
<string name="poi_outpost">Пункт выдачи заказов</string> <string name="poi_outpost">Пункт выдачи заказов</string>
<string name="poi_barbecue_grill">Мангал: есть</string>
</resources> </resources>

View file

@ -3763,4 +3763,6 @@
<string name="poi_outpost">Shop\'s delivery point</string> <string name="poi_outpost">Shop\'s delivery point</string>
<string name="poi_barbecue_grill">Barbecue grill: yes</string>
</resources> </resources>

View file

@ -135,7 +135,7 @@ public class FavouritesDbHelper {
flatGroups.remove(g.name); flatGroups.remove(g.name);
favoriteGroups.remove(g); favoriteGroups.remove(g);
cachedFavoritePoints.removeAll(g.points); cachedFavoritePoints.removeAll(g.points);
context.getMapMarkersHelper().removeMarkersSyncGroup(g.name, true); context.getMapMarkersHelper().removeMarkersSyncGroup(g.name);
} }
} }
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
@ -352,7 +352,7 @@ public class FavouritesDbHelper {
if (remove) { if (remove) {
flatGroups.remove(group.name); flatGroups.remove(group.name);
saveCurrentPointsIntoFile(); saveCurrentPointsIntoFile();
context.getMapMarkersHelper().removeMarkersSyncGroup(group.name, true); context.getMapMarkersHelper().removeMarkersSyncGroup(group.name);
return true; return true;
} }
return false; return false;
@ -622,7 +622,7 @@ public class FavouritesDbHelper {
} }
if (!group.name.equals(newName)) { if (!group.name.equals(newName)) {
FavoriteGroup gr = flatGroups.remove(group.name); FavoriteGroup gr = flatGroups.remove(group.name);
markersHelper.removeMarkersSyncGroup(group.name, true); markersHelper.removeMarkersSyncGroup(group.name);
gr.name = newName; gr.name = newName;
FavoriteGroup renamedGroup = flatGroups.get(gr.name); FavoriteGroup renamedGroup = flatGroups.get(gr.name);
boolean existing = renamedGroup != null; boolean existing = renamedGroup != null;

View file

@ -554,7 +554,7 @@ public class GpxSelectionHelper {
if (show && !enabled) { if (show && !enabled) {
mapMarkersHelper.addMarkersSyncGroup(syncGroup); mapMarkersHelper.addMarkersSyncGroup(syncGroup);
} else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) { } else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) {
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true); mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath());
} }
} }
mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback); mapMarkersHelper.syncGroupAsync(syncGroup, enabled, callback);

View file

@ -28,7 +28,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
@ -57,8 +56,8 @@ public class MapMarkersHelper {
private ExecutorService executorService = Executors.newSingleThreadExecutor(); private ExecutorService executorService = Executors.newSingleThreadExecutor();
private List<MapMarker> mapMarkers = new LinkedList<>(); private List<MapMarker> mapMarkers = new ArrayList<>();
private List<MapMarker> mapMarkersHistory = new LinkedList<>(); private List<MapMarker> mapMarkersHistory = new ArrayList<>();
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>(); private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
private List<MapMarkerChangedListener> listeners = new ArrayList<>(); private List<MapMarkerChangedListener> listeners = new ArrayList<>();
@ -195,16 +194,6 @@ public class MapMarkersHelper {
public static int getColorId(int colorIndex) { public static int getColorId(int colorIndex) {
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0]; return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
} }
public static int getColorIndex(Context context, int color) {
int[] colors = getColors(context);
for (int i = 0; i < colors.length; i++) {
if (colors[i] == color) {
return i;
}
}
return -1;
}
} }
@Nullable @Nullable
@ -293,8 +282,8 @@ public class MapMarkersHelper {
} }
private void loadMarkers() { private void loadMarkers() {
mapMarkers = new LinkedList<>(); mapMarkers = new ArrayList<>();
mapMarkersHistory = new LinkedList<>(); mapMarkersHistory = new ArrayList<>();
List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers(); List<MapMarker> activeMarkers = markersDbHelper.getActiveMarkers();
addToMapMarkersList(activeMarkers); addToMapMarkersList(activeMarkers);
@ -310,13 +299,13 @@ public class MapMarkersHelper {
} }
private void removeFromMapMarkersList(List<MapMarker> markers) { private void removeFromMapMarkersList(List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers); List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.removeAll(markers); copyList.removeAll(markers);
mapMarkers = copyList; mapMarkers = copyList;
} }
private void removeFromMapMarkersList(MapMarker marker) { private void removeFromMapMarkersList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers); List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.remove(marker); copyList.remove(marker);
mapMarkers = copyList; mapMarkers = copyList;
} }
@ -326,7 +315,7 @@ public class MapMarkersHelper {
} }
private void addToMapMarkersList(int position, MapMarker marker) { private void addToMapMarkersList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers); List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.add(position, marker); copyList.add(position, marker);
mapMarkers = copyList; mapMarkers = copyList;
} }
@ -336,13 +325,13 @@ public class MapMarkersHelper {
} }
private void addToMapMarkersList(int position, List<MapMarker> markers) { private void addToMapMarkersList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkers); List<MapMarker> copyList = new ArrayList<>(mapMarkers);
copyList.addAll(position, markers); copyList.addAll(position, markers);
mapMarkers = copyList; mapMarkers = copyList;
} }
private void removeFromMapMarkersHistoryList(MapMarker marker) { private void removeFromMapMarkersHistoryList(MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory); List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.remove(marker); copyList.remove(marker);
mapMarkersHistory = copyList; mapMarkersHistory = copyList;
} }
@ -352,13 +341,13 @@ public class MapMarkersHelper {
} }
private void addToMapMarkersHistoryList(int position, MapMarker marker) { private void addToMapMarkersHistoryList(int position, MapMarker marker) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory); List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.add(position, marker); copyList.add(position, marker);
mapMarkersHistory = copyList; mapMarkersHistory = copyList;
} }
private void addToMapMarkersHistoryList(int position, List<MapMarker> markers) { private void addToMapMarkersHistoryList(int position, List<MapMarker> markers) {
List<MapMarker> copyList = new LinkedList<>(mapMarkersHistory); List<MapMarker> copyList = new ArrayList<>(mapMarkersHistory);
copyList.addAll(position, markers); copyList.addAll(position, markers);
mapMarkersHistory = copyList; mapMarkersHistory = copyList;
} }
@ -562,7 +551,7 @@ public class MapMarkersHelper {
return; return;
} }
List<WptPt> gpxPoints = new LinkedList<>(gpx.getPoints()); List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
int defColor = ContextCompat.getColor(ctx, R.color.marker_red); int defColor = ContextCompat.getColor(ctx, R.color.marker_red);
for (WptPt pt : gpxPoints) { for (WptPt pt : gpxPoints) {
group.setColor(pt.getColor(defColor)); group.setColor(pt.getColor(defColor));
@ -831,7 +820,7 @@ public class MapMarkersHelper {
} }
public void addSelectedMarkersToTop(@NonNull List<MapMarker> markers) { public void addSelectedMarkersToTop(@NonNull List<MapMarker> markers) {
List<MapMarker> markersToRemove = new LinkedList<>(); List<MapMarker> markersToRemove = new ArrayList<>();
for (MapMarker m : mapMarkers) { for (MapMarker m : mapMarkers) {
if (m.selected) { if (m.selected) {
if (!markers.contains(m)) { if (!markers.contains(m)) {
@ -891,7 +880,7 @@ public class MapMarkersHelper {
marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE; marker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
} }
addToMapMarkersHistoryList(mapMarkers); addToMapMarkersHistoryList(mapMarkers);
mapMarkers = new LinkedList<>(); mapMarkers = new ArrayList<>();
sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC); sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC);
updateGroups(); updateGroups();
refresh(); refresh();
@ -900,7 +889,7 @@ public class MapMarkersHelper {
public void removeMarkersHistory() { public void removeMarkersHistory() {
cancelAddressRequests(); cancelAddressRequests();
markersDbHelper.clearAllMarkersHistory(); markersDbHelper.clearAllMarkersHistory();
mapMarkersHistory = new LinkedList<>(); mapMarkersHistory = new ArrayList<>();
refresh(); refresh();
removeHistoryMarkersFromGroups(); removeHistoryMarkersFromGroups();
} }
@ -913,12 +902,10 @@ public class MapMarkersHelper {
} }
} }
public void removeMarkersSyncGroup(String id, boolean removeActiveMarkers) { public void removeMarkersSyncGroup(String id) {
if (id != null) { if (id != null) {
markersDbHelper.removeMarkersSyncGroup(id); markersDbHelper.removeMarkersSyncGroup(id);
if (removeActiveMarkers) { removeActiveMarkersFromSyncGroup(id);
removeActiveMarkersFromSyncGroup(id);
}
MapMarkersGroup group = getMapMarkerGroupByKey(id); MapMarkersGroup group = getMapMarkerGroupByKey(id);
if (group != null) { if (group != null) {
removeFromGroupsList(group); removeFromGroupsList(group);
@ -963,7 +950,7 @@ public class MapMarkersHelper {
public void removeActiveMarkersFromSyncGroup(String syncGroupId) { public void removeActiveMarkersFromSyncGroup(String syncGroupId) {
if (syncGroupId != null) { if (syncGroupId != null) {
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId); markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
List<MapMarker> copyList = new LinkedList<>(mapMarkers); List<MapMarker> copyList = new ArrayList<>(mapMarkers);
for (int i = 0; i < copyList.size(); i++) { for (int i = 0; i < copyList.size(); i++) {
MapMarker marker = copyList.get(i); MapMarker marker = copyList.get(i);
String groupKey = marker.groupKey; String groupKey = marker.groupKey;

View file

@ -189,7 +189,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
.setOnClickListener(new View.OnClickListener() { .setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true); markersHelper.removeMarkersSyncGroup(syncGroup.getId());
dismiss(); dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity()); MapActivity.launchMapActivityMoveToTop(getActivity());
} }

View file

@ -32,6 +32,7 @@ import java.util.List;
public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment { public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final String USED_ON_MAP_KEY = "used_on_map"; private static final String USED_ON_MAP_KEY = "used_on_map";
private static final int DEFAULT_VALUE = -1;
protected List<BaseBottomSheetItem> items = new ArrayList<>(); protected List<BaseBottomSheetItem> items = new ArrayList<>();
@ -75,7 +76,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
} }
int bottomDividerColorId = getBottomDividerColorId(); int bottomDividerColorId = getBottomDividerColorId();
if (bottomDividerColorId != -1) { if (bottomDividerColorId != DEFAULT_VALUE) {
mainView.findViewById(R.id.bottom_row_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId)); mainView.findViewById(R.id.bottom_row_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId));
} }
@ -89,10 +90,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
((TextView) mainView.findViewById(R.id.dismiss_button_text)).setText(getDismissButtonTextId()); ((TextView) mainView.findViewById(R.id.dismiss_button_text)).setText(getDismissButtonTextId());
int rightBottomButtonTextId = getRightBottomButtonTextId(); int rightBottomButtonTextId = getRightBottomButtonTextId();
if (rightBottomButtonTextId != -1) { if (rightBottomButtonTextId != DEFAULT_VALUE) {
View buttonsDivider = mainView.findViewById(R.id.bottom_buttons_divider); View buttonsDivider = mainView.findViewById(R.id.bottom_buttons_divider);
buttonsDivider.setVisibility(View.VISIBLE); buttonsDivider.setVisibility(View.VISIBLE);
if (bottomDividerColorId != -1) { if (bottomDividerColorId != DEFAULT_VALUE) {
buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId)); buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId));
} }
View rightButton = mainView.findViewById(R.id.right_bottom_button); View rightButton = mainView.findViewById(R.id.right_bottom_button);
@ -158,17 +159,15 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
final int screenHeight = AndroidUtils.getScreenHeight(activity); final int screenHeight = AndroidUtils.getScreenHeight(activity);
final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity); final int statusBarHeight = AndroidUtils.getStatusBarHeight(activity);
final int availableHeight = screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity) final int contentHeight = getContentHeight(screenHeight - statusBarHeight - AndroidUtils.getNavBarHeight(activity));
- AndroidUtils.dpToPx(getContext(), 1) // divider height
- getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height); // bottom row height
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {
final View viewToAdjust = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer; final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
if (viewToAdjust.getHeight() > availableHeight) { if (contentView.getHeight() > contentHeight) {
viewToAdjust.getLayoutParams().height = availableHeight; contentView.getLayoutParams().height = contentHeight;
viewToAdjust.requestLayout(); contentView.requestLayout();
} }
// 8dp is the shadow height // 8dp is the shadow height
@ -189,13 +188,28 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
}); });
} }
private int getContentHeight(int availableScreenHeight) {
int customHeight = getCustomHeight();
int maxHeight = availableScreenHeight
- AndroidUtils.dpToPx(getContext(), 1) // divider height
- getResources().getDimensionPixelSize(R.dimen.bottom_sheet_cancel_button_height);
if (customHeight != DEFAULT_VALUE && customHeight <= maxHeight) {
return customHeight;
}
return maxHeight;
}
protected int getCustomHeight() {
return DEFAULT_VALUE;
}
protected boolean useScrollableItemsContainer() { protected boolean useScrollableItemsContainer() {
return true; return true;
} }
@ColorRes @ColorRes
protected int getBottomDividerColorId() { protected int getBottomDividerColorId() {
return -1; return DEFAULT_VALUE;
} }
@StringRes @StringRes
@ -209,7 +223,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
@StringRes @StringRes
protected int getRightBottomButtonTextId() { protected int getRightBottomButtonTextId() {
return -1; return DEFAULT_VALUE;
} }
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {