Merge branch 'master' of https://github.com/osmandapp/Osmand into custom_plugins

# Conflicts:
#	OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java
This commit is contained in:
Vitaliy 2020-03-26 16:40:03 +02:00
commit eb9e15cd6e
12 changed files with 116 additions and 30 deletions

View file

@ -127,14 +127,16 @@
</com.google.android.material.appbar.CollapsingToolbarLayout>
<ProgressBar
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"
android:minHeight="0dp"
android:layout_height="5dp"
android:visibility="gone"
android:indeterminate="true"
osmand:mpb_progressStyle="horizontal"
osmand:mpb_setBothDrawables="true"
osmand:mpb_useIntrinsicPadding="false"
tools:visibility="visible" />
</com.google.android.material.appbar.AppBarLayout>

View file

@ -31,6 +31,7 @@
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/import_complete_description" />

View file

@ -26,6 +26,7 @@
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description"
android:text="@string/import_duplicates_description"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" />
@ -135,14 +136,16 @@
</com.google.android.material.appbar.CollapsingToolbarLayout>
<ProgressBar
<me.zhanghai.android.materialprogressbar.MaterialProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
style="@style/Widget.MaterialProgressBar.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:indeterminate="true"
android:layout_height="5dp"
android:visibility="gone"
android:indeterminate="true"
osmand:mpb_progressStyle="horizontal"
osmand:mpb_setBothDrawables="true"
osmand:mpb_useIntrinsicPadding="false"
tools:visibility="visible" />
</com.google.android.material.appbar.AppBarLayout>

View file

@ -13,6 +13,7 @@
android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin"
android:paddingEnd="@dimen/content_padding"
android:lineSpacingMultiplier="@dimen/line_spacing_multiplier_description"
android:paddingBottom="@dimen/list_header_settings_top_margin"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"

View file

@ -14,4 +14,6 @@
<dimen name="context_img_card_width">280dp</dimen>
<dimen name="context_img_card_height">160dp</dimen>
<dimen name="line_spacing_multiplier_description">1.2</dimen>
</resources>

View file

@ -24,6 +24,7 @@
<string name="quick_action_terrain_hide">Hide terrain</string>
<string name="quick_action_show_hide_terrain">Show/hide terrain</string>
<string name="download_slope_maps">Slopes</string>
<string name="n_items_of_z">%1$s of %2$s</string>
<string name="recalculate_route_distance_promo">The route will be recalculated if the distance from the route to the current location is more than selected value.</string>
<string name="select_distance_route_will_recalc">Select the distance after which the route will be recalculated.</string>
<string name="recalculate_route_in_deviation">Recalculate route in case of deviation</string>

View file

@ -735,18 +735,35 @@ public class SettingsHelper {
}
private void renameProfile() {
List<ApplicationMode> values = ApplicationMode.allPossibleValues();
if (Algorithms.isEmpty(modeBean.userProfileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
if (appMode != null) {
modeBean.userProfileName = app.getString(appMode.getNameKeyResource());
}
}
int number = 0;
while (true) {
number++;
String key = modeBean.stringKey + "_" + number;
if (ApplicationMode.valueOfStringKey(key, null) == null) {
String name = modeBean.userProfileName + '_' + number;
if (ApplicationMode.valueOfStringKey(key, null) == null && isNameUnique(values, name)) {
modeBean.userProfileName = name;
modeBean.stringKey = key;
modeBean.userProfileName = modeBean.userProfileName + "_" + number;
break;
}
}
}
private boolean isNameUnique(List<ApplicationMode> values, String name) {
for (ApplicationMode mode : values) {
if (mode.getUserProfileName().equals(name)) {
return false;
}
}
return true;
}
@Override
public void apply() {
if (!appMode.isCustomProfile() && !shouldReplace) {

View file

@ -34,6 +34,7 @@ import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.util.Algorithms;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -190,19 +191,24 @@ public class QuickActionRegistry {
private List<QuickAction> parseActiveActionsList(String json) {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
List<QuickAction> quickActions = gson.fromJson(json, type);
List<QuickAction> rquickActions = new ArrayList<>();
if (quickActions != null) {
for (QuickAction qa : quickActions) {
if (qa != null) {
rquickActions.add(qa);
List<QuickAction> resQuickActions;
if (!Algorithms.isEmpty(json)) {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
List<QuickAction> quickActions = gson.fromJson(json, type);
resQuickActions = new ArrayList<>(quickActions.size());
if (quickActions != null) {
for (QuickAction qa : quickActions) {
if (qa != null) {
resQuickActions.add(qa);
}
}
}
} else {
resQuickActions = new ArrayList<>();
}
this.quickActions = rquickActions;
return rquickActions;
this.quickActions = resQuickActions;
return resQuickActions;
}
public List<QuickActionType> updateActionTypes() {

View file

@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ApplicationMode.ApplicationModeBean;
@ -20,15 +21,19 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.List;
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final Log LOG = PlatformUtil.getLog(DuplicatesSettingsAdapter.class.getName());
private static final int HEADER_TYPE = 0;
private static final int ITEM_TYPE = 1;
@ -81,7 +86,17 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
profileName = app.getString(appMode.getNameKeyResource());
}
itemHolder.title.setText(profileName);
String routingProfile = modeBean.routingProfile;
String routingProfile = "";
String routingProfileValue = modeBean.routingProfile;
if (!routingProfileValue.isEmpty()) {
try {
routingProfile = app.getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
} catch (IllegalArgumentException e) {
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
}
}
if (Algorithms.isEmpty(routingProfile)) {
itemHolder.subTitle.setVisibility(View.GONE);
} else {

View file

@ -14,7 +14,9 @@ import androidx.core.widget.CompoundButtonCompat;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode.ApplicationModeBean;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -23,11 +25,14 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms;
import net.osmand.view.ThreeStateCheckbox;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@ -41,6 +46,7 @@ import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED;
class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
private static final Log LOG = PlatformUtil.getLog(ExportImportSettingsAdapter.class.getName());
private OsmandApplication app;
private UiUtilities uiUtilities;
private List<? super Object> dataToOperate;
@ -91,7 +97,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes)));
final List<?> listItems = itemsMap.get(type);
subTextTv.setText(String.valueOf(listItems.size()));
subTextTv.setText(getSelectedItemsAmount(listItems));
if (dataToOperate.containsAll(listItems)) {
checkBox.setState(CHECKED);
@ -165,13 +171,24 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
switch (type) {
case PROFILE:
String profileName = ((ApplicationMode.ApplicationModeBean) currentItem).userProfileName;
ApplicationModeBean modeBean = (ApplicationModeBean) currentItem;
String profileName = modeBean.userProfileName;
if (Algorithms.isEmpty(profileName)) {
ApplicationMode appMode = ApplicationMode.valueOfStringKey(((ApplicationMode.ApplicationModeBean) currentItem).stringKey, null);
ApplicationMode appMode = ApplicationMode.valueOfStringKey(modeBean.stringKey, null);
profileName = app.getString(appMode.getNameKeyResource());
}
title.setText(profileName);
String routingProfile = (((ApplicationMode.ApplicationModeBean) currentItem).routingProfile);
String routingProfile = "";
String routingProfileValue = modeBean.routingProfile;
if (!routingProfileValue.isEmpty()) {
try {
routingProfile = app.getString(RoutingProfilesResources.valueOf(routingProfileValue.toUpperCase()).getStringRes());
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfile);
} catch (IllegalArgumentException e) {
routingProfile = Algorithms.capitalizeFirstLetterAndLowercase(routingProfileValue);
LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e);
}
}
if (Algorithms.isEmpty(routingProfile)) {
subText.setVisibility(View.GONE);
} else {
@ -181,8 +198,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
routingProfile));
subText.setVisibility(View.VISIBLE);
}
int profileIconRes = AndroidUtils.getDrawableId(app, ((ApplicationMode.ApplicationModeBean) currentItem).iconName);
ProfileIconColors iconColor = ((ApplicationMode.ApplicationModeBean) currentItem).iconColor;
int profileIconRes = AndroidUtils.getDrawableId(app, modeBean.iconName);
ProfileIconColors iconColor = modeBean.iconColor;
icon.setImageDrawable(uiUtilities.getIcon(profileIconRes, iconColor.getColor(nightMode)));
break;
case QUICK_ACTIONS:
@ -267,6 +284,16 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
return true;
}
private String getSelectedItemsAmount(List<?> listItems) {
int amount = 0;
for (Object item : listItems) {
if (dataToOperate.contains(item)) {
amount++;
}
}
return app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size()));
}
private int getGroupTitle(Type type) {
switch (type) {
case PROFILE:

View file

@ -172,8 +172,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
}
adapter = new ExportImportSettingsAdapter(app, nightMode, true);
Map<Type, List<?>> itemsMap = new HashMap<>();
if (settingsItems != null) {
adapter.updateSettingsList(getSettingsToOperate(settingsItems));
itemsMap = getSettingsToOperate(settingsItems);
adapter.updateSettingsList(itemsMap);
}
expandableList.setAdapter(adapter);
toolbarLayout.setTitle(getString(R.string.shared_string_import));
@ -186,6 +188,9 @@ public class ImportSettingsFragment extends BaseOsmAndFragment
} else {
toolbarLayout.setTitle(getString(R.string.shared_string_import));
}
if (itemsMap.size() == 1 && itemsMap.containsKey(Type.PROFILE)) {
expandableList.expandGroup(0);
}
}
@Override

View file

@ -1,5 +1,6 @@
package net.osmand.plus.settings;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,6 +14,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
@ -60,6 +62,10 @@ public class ImportedSettingsItemsAdapter extends
holder.icon.setPadding(0, 0, AndroidUtils.dpToPx(app, 16), 0);
holder.title.setTextColor(app.getResources().getColor(activeColorRes));
Typeface typeface = FontCache.getFont(app, app.getString(R.string.font_roboto_medium));
if (typeface != null) {
holder.title.setTypeface(typeface);
}
holder.divider.setVisibility(isLastItem ? View.VISIBLE : View.GONE);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override