import custom profiles, ui fixes

This commit is contained in:
veliymolfar 2020-02-17 19:11:22 +02:00
parent c7f2de7f22
commit a19e6a3576
14 changed files with 276 additions and 234 deletions

View file

@ -6,26 +6,15 @@
android:orientation="vertical"
android:paddingBottom="20dp">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchItem"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:minHeight="48dp"
android:text="@string/shared_string_include_data"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/shared_string_include_data" />
<ExpandableListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@null"
android:headerDividersEnabled="false"
android:dividerHeight="0dp"
android:drawSelectorOnTop="false"
android:groupIndicator="@android:color/transparent"
android:visibility="gone"
tools:visibility="visible" />
</LinearLayout>

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="?attr/activity_background_basic"
android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:minHeight="@dimen/bottom_sheet_list_item_height"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding"
android:text="@string/export_profile_dialog_description"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
app:typeface="@string/font_roboto_regular" />
<include
android:id="@+id/topSwitchDivider"
layout="@layout/card_bottom_divider"
android:visibility="gone" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color">
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchItem"
android:layout_width="match_parent"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_height="wrap_content"
android:background="?attr/activity_background_basic"
android:minHeight="48dp"
android:text="@string/shared_string_include_data"
android:textSize="@dimen/default_list_text_size"
tools:text="@string/shared_string_include_data" />
</FrameLayout>
<include
android:id="@+id/bottomSwitchDivider"
layout="@layout/divider"
android:visibility="gone" />
</LinearLayout>

View file

@ -55,6 +55,7 @@
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:focusableInTouchMode="false"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"

View file

@ -66,6 +66,7 @@
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:focusableInTouchMode="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/content_padding"

View file

@ -601,6 +601,11 @@ public class ApplicationMode {
}
public String toJson() {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
return gson.toJson(toModeBean());
}
public ApplicationModeBean toModeBean(){
ApplicationModeBean mb = new ApplicationModeBean();
mb.stringKey = stringKey;
mb.userProfileName = getUserProfileName();
@ -612,8 +617,7 @@ public class ApplicationMode {
mb.locIcon = getLocationIcon();
mb.navIcon = getNavigationIcon();
mb.order = getOrder();
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
return gson.toJson(mb);
return mb;
}
public static void deleteCustomModes(List<ApplicationMode> modes, OsmandApplication app) {
@ -789,25 +793,25 @@ public class ApplicationMode {
}
}
static class ApplicationModeBean {
public static class ApplicationModeBean {
@Expose
String stringKey;
public String stringKey;
@Expose
String userProfileName;
public String userProfileName;
@Expose
String parent;
public String parent;
@Expose
String iconName = "map_world_globe_dark";
public String iconName = "map_world_globe_dark";
@Expose
ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
public ProfileIconColors iconColor = ProfileIconColors.DEFAULT;
@Expose
String routingProfile = null;
public String routingProfile = null;
@Expose
RouteService routeService = RouteService.OSMAND;
public RouteService routeService = RouteService.OSMAND;
@Expose
LocationIcon locIcon = null;
public LocationIcon locIcon = null;
@Expose
NavigationIcon navIcon = null;
public NavigationIcon navIcon = null;
@Expose
int order = -1;
}

View file

@ -111,10 +111,9 @@ public class SQLiteTileSource implements ITileSource {
db = ctx.getSQLiteAPI().getOrCreateDatabase(
ctx.getAppPath(TILES_INDEX_DIR).getAbsolutePath() + "/" + name + SQLITE_EXT, true);
db.execSQL("CREATE TABLE IF NOT EXIST tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))");
db.execSQL("CREATE TABLE tiles (x int, y int, z int, s int, image blob, time long, PRIMARY KEY (x,y,z,s))");
db.execSQL("CREATE INDEX IND on tiles (x,y,z,s)");
db.execSQL("CREATE TABLE IF NOT EXIST info(tilenumbering,minzoom,maxzoom)");
db.execSQL("CREATE TABLE IF NOT EXIST android_metadata (locale TEXT)");
db.execSQL("CREATE TABLE info(tilenumbering,minzoom,maxzoom)");
db.execSQL("INSERT INTO info (tilenumbering,minzoom,maxzoom) VALUES ('simple','" + minZoom + "','" + maxZoom + "');");
addInfoColumn(URL, urlTemplate);

View file

@ -436,24 +436,39 @@ public class SettingsHelper {
private ApplicationModeBuilder builder;
private ApplicationModeBean modeBean;
private Set<String> appModeBeanPrefsIds;
private OsmandApplication app;
public ProfileSettingsItem(@NonNull OsmandSettings settings, @NonNull ApplicationMode appMode) {
super(SettingsItemType.PROFILE, settings);
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationMode appMode) {
super(SettingsItemType.PROFILE, app.getSettings());
this.appMode = appMode;
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(settings.appModeBeanPrefsIds));
this.app = app;
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
public ProfileSettingsItem(@NonNull OsmandSettings settings, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.PROFILE, settings, json);
readFromJson(settings.getContext(), json);
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(settings.appModeBeanPrefsIds));
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull ApplicationModeBean modeBean) {
super(SettingsItemType.PROFILE, app.getSettings());
this.app = app;
this.modeBean = modeBean;
builder = ApplicationMode.fromModeBean(app, modeBean);
appMode = builder.getApplicationMode();
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
public ProfileSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
super(SettingsItemType.PROFILE, app.getSettings(), json);
this.app = app;
readFromJson(app.getSettings().getContext(), json);
appModeBeanPrefsIds = new HashSet<>(Arrays.asList(app.getSettings().appModeBeanPrefsIds));
}
public ApplicationMode getAppMode() {
return appMode;
}
public ApplicationModeBean getModeBean() {
return modeBean;
}
@NonNull
@Override
public String getName() {
@ -491,12 +506,6 @@ public class SettingsHelper {
@Override
public boolean exists() {
List<ApplicationMode> profiles = ApplicationMode.allPossibleValues();
for (ApplicationMode profile : profiles) {
if (appMode.toHumanString().equals(profile.toHumanString())) {
return true;
}
}
return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null;
}
@ -504,9 +513,12 @@ public class SettingsHelper {
public void apply() {
if (appMode.isCustomProfile()) {
if (!shouldReplace) {
appMode.setUserProfileName(COPY_PREFIX + appMode.getUserProfileName());
modeBean.stringKey = COPY_PREFIX + modeBean.stringKey;
modeBean.userProfileName = COPY_PREFIX + modeBean.userProfileName;
builder = ApplicationMode.fromModeBean(app, modeBean);
}
appMode = ApplicationMode.saveProfile(builder, getSettings().getContext());
ApplicationMode.changeProfileAvailability(appMode, true, app);
}
}
@ -716,6 +728,16 @@ public class SettingsHelper {
return file.exists();
}
private File renameFile(File file) {
String path = file.getAbsolutePath();
String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
File copyFile = new File(copyName);
if (file.exists()) {
renameFile(copyFile);
}
return copyFile;
}
@NonNull
@Override
SettingsItemReader getReader() {
@ -723,13 +745,14 @@ public class SettingsHelper {
@Override
public void readFromStream(@NonNull InputStream inputStream) throws IOException, IllegalArgumentException {
OutputStream output;
if (shouldReplace) {
if (shouldReplace || !file.exists()) {
output = new FileOutputStream(file);
} else {
String path = file.getAbsolutePath();
String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
File copyFile = new File(copyName);
output = new FileOutputStream(copyFile);
// String path = file.getAbsolutePath();
// String copyName = path.replaceAll(file.getName(), COPY_PREFIX + file.getName());
// File copyFile = new File(copyName);
// output = new FileOutputStream(copyFile);
output = new FileOutputStream(renameFile(file));
}
byte[] buffer = new byte[BUFFER];
int count;
@ -955,7 +978,8 @@ public class SettingsHelper {
if (!poiUIFilters.isEmpty() || !duplicates.isEmpty()) {
for (PoiUIFilter duplicate : duplicates) {
if (!shouldReplace) {
duplicate.setName(COPY_PREFIX + duplicate.getName());
renamePoiFilter(duplicate);
// duplicate.setName(COPY_PREFIX + duplicate.getName());
}
poiUIFilters.add(duplicate);
}
@ -966,6 +990,23 @@ public class SettingsHelper {
}
}
private void renamePoiFilter(PoiUIFilter poiUIFilter) {
poiUIFilter.setName(COPY_PREFIX + poiUIFilter.getName());
if (duplicateExists(poiUIFilter)) {
renamePoiFilter(poiUIFilter);
}
}
private boolean duplicateExists(PoiUIFilter poiUIFilter) {
List<PoiUIFilter> userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
for (PoiUIFilter filter : userPoiList) {
if (filter.getName().equals(poiUIFilter.getName())) {
return true;
}
}
return false;
}
public List<PoiUIFilter> getDuplicates() {
List<PoiUIFilter> duplicates = new ArrayList<>();
List<PoiUIFilter> userPoiList = app.getPoiFilters().getUserDefinedPoiFilters(false);
@ -1114,19 +1155,28 @@ public class SettingsHelper {
if (!mapSources.isEmpty() || !duplicates.isEmpty()) {
if (shouldReplace) {
for (ITileSource tileSource : duplicates) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
if (tileSource instanceof SQLiteTileSource) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName() + IndexConstants.SQLITE_EXT);
if (f != null && f.exists()) {
if (f.delete()) {
mapSources.add(tileSource);
}
}
} else if (tileSource instanceof TileSourceManager.TileSourceTemplate) {
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + tileSource.getName());
if (f != null && f.exists() && f.isDirectory()) {
if (f.delete()) {
mapSources.add(tileSource);
}
}
}
}
} else {
for (ITileSource tileSource : duplicates) {
tileSource.setName(COPY_PREFIX + tileSource.getName());
renameTileSource(tileSource);
mapSources.add(tileSource);
}
}
mapSources.addAll(duplicates);
for (ITileSource template : mapSources) {
if (template instanceof TileSourceManager.TileSourceTemplate) {
getSettings().installTileSource((TileSourceManager.TileSourceTemplate) template);
@ -1137,6 +1187,23 @@ public class SettingsHelper {
}
}
private void renameTileSource(ITileSource tileSource) {
tileSource.setName(COPY_PREFIX + tileSource.getName());
if (duplicateExists(tileSource)) {
renameTileSource(tileSource);
}
}
private boolean duplicateExists(ITileSource tileSource) {
LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
for (Map.Entry<String, String> entry : tileSourceEntries.entrySet()) {
if (entry.getValue().equals(tileSource.getName())) {
return true;
}
}
return false;
}
public List<ITileSource> getDuplicates() {
List<ITileSource> duplicates = new ArrayList<>();
final LinkedHashMap<String, String> tileSourceEntries = new LinkedHashMap<>(app.getSettings().getTileSourceEntries(true));
@ -1326,7 +1393,7 @@ public class SettingsHelper {
item = new GlobalSettingsItem(settings);
break;
case PROFILE:
item = new ProfileSettingsItem(settings, json);
item = new ProfileSettingsItem(app, json);
break;
case PLUGIN:
break;

View file

@ -22,6 +22,7 @@ import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.CompoundButton;
import android.widget.ImageView;
@ -487,4 +488,12 @@ public class UiUtilities {
public static Context getThemedContext(Context context, boolean nightMode, int lightStyle, int darkStyle) {
return new ContextThemeWrapper(context, nightMode ? darkStyle : lightStyle);
}
public static void setMargins(View v, int l, int t, int r, int b) {
if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
p.setMargins(l, t, r, b);
v.requestLayout();
}
}
}

View file

@ -192,7 +192,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
final View contentView = useScrollableItemsContainer() ? mainView.findViewById(R.id.scroll_view) : itemsContainer;
if (contentView.getHeight() > contentHeight) {
if (useScrollableItemsContainer()) {
if (useScrollableItemsContainer() || useExpandableList()) {
contentView.getLayoutParams().height = contentHeight;
} else {
contentView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
@ -231,6 +231,10 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
return true;
}
protected boolean useExpandableList() {
return false;
}
protected boolean hideButtonsContainer() {
return false;
}

View file

@ -399,9 +399,8 @@ public class ConfigureProfileFragment extends BaseSettingsFragment implements Co
} else if (EXPORT_PROFILE.equals(prefId)) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ExportImportProfileBottomSheet.showInstance(
ExportProfileBottomSheet.showInstance(
fragmentManager,
ExportImportProfileBottomSheet.State.EXPORT,
this,
getSelectedAppMode());
}

View file

@ -11,14 +11,17 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.map.ITileSource;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.SettingsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AdditionalDataWrapper;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.render.RenderingIcons;
@ -42,11 +45,19 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
this.importState = importState;
this.dataToOperate = new ArrayList<>();
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
if (!importState) {
for (AdditionalDataWrapper dataWrapper : dataList) {
dataToOperate.addAll(dataWrapper.getItems());
}
// if (!importState) {
// for (AdditionalDataWrapper dataWrapper : dataList) {
// dataToOperate.addAll(dataWrapper.getItems());
// }
// }
}
ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode) {
this.app = app;
this.nightMode = nightMode;
this.dataList = new ArrayList<>();
this.dataToOperate = new ArrayList<>();
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
}
@Override
@ -136,9 +147,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
switch (type) {
case PROFILE:
title.setText(((ApplicationMode) currentItem).toHumanString());
subText.setText(((ApplicationMode) currentItem).getDescription());
icon.setImageDrawable(app.getUIUtilities().getIcon(((ApplicationMode) currentItem).getIconRes(), profileColor));
title.setText(((ApplicationMode.ApplicationModeBean) currentItem).userProfileName);
subText.setText(((ApplicationMode.ApplicationModeBean) currentItem).routingProfile);
int profileIconRes = AndroidUtils.getDrawableId(app, ((ApplicationMode.ApplicationModeBean) currentItem).iconName);
ProfileIconColors iconColor = ((ApplicationMode.ApplicationModeBean) currentItem).iconColor;
icon.setImageDrawable(app.getUIUtilities().getIcon(profileIconRes, iconColor.getColor(nightMode)));
subText.setVisibility(View.VISIBLE);
icon.setVisibility(View.VISIBLE);
break;
@ -247,6 +260,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
notifyDataSetChanged();
}
public void clearSettingsList() {
this.dataList.clear();
notifyDataSetChanged();
}
public void selectAll(boolean selectAll) {
dataToOperate.clear();
if (selectAll) {

View file

@ -15,6 +15,7 @@ import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.LinearLayout.LayoutParams;
import android.widget.Toast;
import net.osmand.AndroidUtils;
@ -30,7 +31,6 @@ import net.osmand.plus.SettingsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.poi.PoiUIFilter;
@ -48,38 +48,17 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
private static final Log LOG = PlatformUtil.getLog(ExportImportProfileBottomSheet.class);
public static final String TAG = ExportImportProfileBottomSheet.class.getSimpleName();
private static final String STATE_KEY = "EXPORT_IMPORT_DIALOG_STATE_KEY";
public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
private static final Log LOG = PlatformUtil.getLog(ExportProfileBottomSheet.class);
public static final String TAG = ExportProfileBottomSheet.class.getSimpleName();
private static final String INCLUDE_ADDITIONAL_DATA_KEY = "INCLUDE_ADDITIONAL_DATA_KEY";
private boolean includeAdditionalData = false;
private boolean containsAdditionalData = false;
private OsmandApplication app;
private ApplicationMode profile;
private State state;
private List<AdditionalDataWrapper> dataList = new ArrayList<>();
private List<SettingsHelper.SettingsItem> settingsItems;
private ExpandableListView listView;
private ExportImportSettingsAdapter adapter;
private SettingsHelper.ProfileSettingsItem profileSettingsItem;
private File file;
@Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
@ -87,24 +66,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
super.onCreate(savedInstanceState);
app = requiredMyApplication();
Bundle bundle = getArguments();
if (bundle != null) {
this.state = (State) getArguments().getSerializable(STATE_KEY);
}
if (state == State.IMPORT) {
if (settingsItems == null) {
settingsItems = app.getSettingsHelper().getSettingsItems();
}
if (file == null) {
file = app.getSettingsHelper().getSettingsFile();
}
containsAdditionalData = checkAdditionalDataContains();
} else {
dataList = getAdditionalData();
// for (AdditionalDataWrapper dataWrapper : dataList) {
// dataToOperate.addAll(dataWrapper.getItems());
// }
}
}
@Override
@ -121,7 +83,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
LayoutInflater inflater = UiUtilities.getInflater(app, nightMode);
profile = state == State.IMPORT ? getAppModeFromSettingsItems() : getAppMode();
profile = getAppMode();
int profileColor = profile.getIconColorInfo().getColor(nightMode);
int colorNoAlpha = ContextCompat.getColor(context, profileColor);
@ -129,9 +91,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
Drawable backgroundIcon = UiUtilities.getColoredSelectableDrawable(context, colorNoAlpha, 0.3f);
Drawable[] layers = {new ColorDrawable(UiUtilities.getColorWithAlpha(colorNoAlpha, 0.10f)), backgroundIcon};
items.add(new TitleItem(state == State.EXPORT ?
getString(R.string.export_profile)
: getString(R.string.import_profile)));
items.add(new TitleItem(getString(R.string.export_profile)));
BaseBottomSheetItem profileItem = new BottomSheetItemWithCompoundButton.Builder()
.setChecked(true)
@ -145,40 +105,42 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
.create();
items.add(profileItem);
if (state == State.IMPORT && containsAdditionalData || state == State.EXPORT && !dataList.isEmpty()) {
BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder()
.setDescription(state == State.EXPORT ?
getString(R.string.export_profile_dialog_description)
: getString(R.string.import_profile_dialog_description))
.setLayoutId(R.layout.bottom_sheet_item_pref_info)
.create();
items.add(descriptionItem);
if (!dataList.isEmpty()) {
final View additionalDataView = inflater.inflate(R.layout.bottom_sheet_item_additional_data, null);
listView = additionalDataView.findViewById(R.id.list);
SwitchCompat switchItem = additionalDataView.findViewById(R.id.switchItem);
ExpandableListView listView = additionalDataView.findViewById(R.id.list);
adapter = new ExportImportSettingsAdapter(app, nightMode);
View listHeader = inflater.inflate(R.layout.item_header_export_expand_list, null);
final View topSwitchDivider = listHeader.findViewById(R.id.topSwitchDivider);
final View bottomSwitchDivider = listHeader.findViewById(R.id.bottomSwitchDivider);
final SwitchCompat switchItem = listHeader.findViewById(R.id.switchItem);
switchItem.setTextColor(getResources().getColor(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
switchItem.setChecked(includeAdditionalData);
switchItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
includeAdditionalData = !includeAdditionalData;
listView.setVisibility(includeAdditionalData ?
View.VISIBLE : View.GONE);
// if (includeAdditionalData && state == State.IMPORT) {
// updateDataToOperateFromSettingsItems();
// }
topSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
bottomSwitchDivider.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
if (includeAdditionalData) {
adapter.updateSettingsList(getAdditionalData());
adapter.selectAll(true);
} else {
adapter.selectAll(false);
adapter.clearSettingsList();
}
updateSwitch(switchItem);
setupHeightAndBackground(getView());
}
});
listView.setVisibility(includeAdditionalData ? View.VISIBLE : View.GONE);
adapter = new ExportImportSettingsAdapter(app, dataList, nightMode, false);
listView.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
@Override
public void onGroupExpand(int i) {
setupHeightAndBackground(getView());
}
});
updateSwitch(switchItem);
listView.addHeaderView(listHeader);
listView.setAdapter(adapter);
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(additionalDataView)
@ -187,19 +149,25 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
}
private void updateSwitch(View view) {
if (includeAdditionalData) {
UiUtilities.setMargins(view, 0, 0, 0, 0);
view.setPadding(AndroidUtils.dpToPx(app, 32), 0, AndroidUtils.dpToPx(app, 32), 0);
} else {
UiUtilities.setMargins(view, AndroidUtils.dpToPx(app, 16), 0, AndroidUtils.dpToPx(app, 16), 0);
view.setPadding(AndroidUtils.dpToPx(app, 16), 0, AndroidUtils.dpToPx(app, 16), 0);
}
}
@Override
protected int getRightBottomButtonTextId() {
return state == State.EXPORT ? R.string.shared_string_export : R.string.shared_string_import;
return R.string.shared_string_export;
}
@Override
protected void onRightBottomButtonClick() {
super.onRightBottomButtonClick();
if (state == State.EXPORT) {
prepareFile();
} else {
importSettings();
}
}
@Override
@ -212,14 +180,9 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return false;
}
private ApplicationMode getAppModeFromSettingsItems() {
for (SettingsHelper.SettingsItem item : settingsItems) {
if (item.getType().equals(SettingsHelper.SettingsItemType.PROFILE)) {
profileSettingsItem = ((SettingsHelper.ProfileSettingsItem) item);
return ((SettingsHelper.ProfileSettingsItem) item).getAppMode();
}
}
return getAppMode();
@Override
protected boolean useExpandableList() {
return true;
}
private List<AdditionalDataWrapper> getAdditionalData() {
@ -287,7 +250,7 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
private List<SettingsHelper.SettingsItem> prepareSettingsItemsForExport() {
List<SettingsHelper.SettingsItem> settingsItems = new ArrayList<>();
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app.getSettings(), profile));
settingsItems.add(new SettingsHelper.ProfileSettingsItem(app, profile));
if (includeAdditionalData) {
settingsItems.addAll(prepareAdditionalSettingsItems());
}
@ -323,39 +286,6 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return settingsItems;
}
private Boolean checkAdditionalDataContains() {
boolean containsData = false;
for (SettingsHelper.SettingsItem item : settingsItems) {
containsData = item.getType().equals(SettingsHelper.SettingsItemType.QUICK_ACTION)
|| item.getType().equals(SettingsHelper.SettingsItemType.POI_UI_FILTERS)
|| item.getType().equals(SettingsHelper.SettingsItemType.MAP_SOURCES)
|| item.getType().equals(SettingsHelper.SettingsItemType.FILE);
if (containsData) {
break;
}
}
return containsData;
}
private void importSettings() {
List<SettingsHelper.SettingsItem> list = new ArrayList<>();
list.add(profileSettingsItem);
if (includeAdditionalData) {
list.addAll(prepareAdditionalSettingsItems());
}
app.getSettingsHelper().importSettings(file, list, "", 1, new SettingsHelper.SettingsImportListener() {
@Override
public void onSettingsImportFinished(boolean succeed, boolean empty, @NonNull List<SettingsHelper.SettingsItem> items) {
if (succeed) {
app.showShortToastMessage(app.getString(R.string.file_imported_successfully, file.getName()));
} else if (empty) {
app.showShortToastMessage(app.getString(R.string.file_import_error, file.getName(), app.getString(R.string.shared_string_unexpected_error)));
}
}
});
dismiss();
}
private void prepareFile() {
if (app != null) {
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
@ -393,14 +323,10 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
State state,
Fragment target,
@NonNull ApplicationMode appMode) {
try {
Bundle bundle = new Bundle();
bundle.putSerializable(STATE_KEY, state);
ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
fragment.setArguments(bundle);
ExportProfileBottomSheet fragment = new ExportProfileBottomSheet();
fragment.setAppMode(appMode);
fragment.setTargetFragment(target, 0);
fragment.show(fragmentManager, TAG);
@ -409,39 +335,4 @@ public class ExportImportProfileBottomSheet extends BasePreferenceBottomSheet {
return false;
}
}
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
State state,
File file,
List<SettingsHelper.SettingsItem> items) {
try {
Bundle bundle = new Bundle();
bundle.putSerializable(STATE_KEY, state);
ExportImportProfileBottomSheet fragment = new ExportImportProfileBottomSheet();
fragment.setArguments(bundle);
fragment.setSettingsItems(items);
fragment.setFile(file);
fragment.show(fragmentManager, TAG);
return true;
} catch (RuntimeException e) {
return false;
}
}
public void setSettingsItems(List<SettingsHelper.SettingsItem> settingsItems) {
this.settingsItems = settingsItems;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public enum State {
EXPORT,
IMPORT
}
}

View file

@ -169,6 +169,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndDialogFragment implement
}
}
});
// if (getFragmentManager() != null) {
// ImportSettingsFragment fragment = (ImportSettingsFragment) getFragmentManager().findFragmentByTag(ImportSettingsFragment.TAG);
// fragment.dismiss();
// }
dismiss();
}

File diff suppressed because one or more lines are too long