copy of copy profiles, action, filters

This commit is contained in:
veliymolfar 2020-02-18 13:10:04 +02:00
parent a19e6a3576
commit 6b93e03a99
7 changed files with 48 additions and 28 deletions

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -11,7 +11,6 @@
android:id="@+id/toolbar_layout" android:id="@+id/toolbar_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="?attr/colorPrimary" android:background="?attr/colorPrimary"
android:orientation="vertical"> android:orientation="vertical">
@ -40,7 +39,6 @@
android:id="@+id/description" android:id="@+id/description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_layout"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:paddingStart="@dimen/content_padding" android:paddingStart="@dimen/content_padding"
android:paddingTop="@dimen/list_header_settings_top_margin" android:paddingTop="@dimen/list_header_settings_top_margin"
@ -55,15 +53,13 @@
android:id="@+id/description_divider" android:id="@+id/description_divider"
layout="@layout/card_bottom_divider" layout="@layout/card_bottom_divider"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"/>
android:layout_below="@+id/description" />
<ExpandableListView <ExpandableListView
android:id="@+id/list" android:id="@+id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="0dp"
android:layout_below="@+id/description_divider" android:layout_weight="1"
android:layout_marginBottom="@dimen/dialog_button_ex_height"
android:divider="@null" android:divider="@null"
android:dividerHeight="0dp" android:dividerHeight="0dp"
android:drawSelectorOnTop="false" android:drawSelectorOnTop="false"
@ -74,7 +70,6 @@
android:id="@+id/buttons_container" android:id="@+id/buttons_container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_ex_height" android:layout_height="@dimen/dialog_button_ex_height"
android:layout_alignParentBottom="true"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:gravity="center" android:gravity="center"
android:orientation="horizontal" android:orientation="horizontal"
@ -140,4 +135,4 @@
</LinearLayout> </LinearLayout>
</RelativeLayout> </LinearLayout>

View file

@ -47,14 +47,17 @@
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium" /> osmand:typeface="@string/font_roboto_medium" />
<include layout="@layout/list_item_divider" /> <include
android:id="@+id/description_divider"
layout="@layout/card_bottom_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/list" android:id="@+id/list"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_weight="1" android:layout_weight="1" />
android:background="?attr/list_background_color" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -93,6 +93,7 @@ public class SettingsHelper {
public static final String SETTINGS_VERSION_KEY = "settings_version"; public static final String SETTINGS_VERSION_KEY = "settings_version";
private static final String COPY_PREFIX = "copy_"; private static final String COPY_PREFIX = "copy_";
private static final String COPY_SUFFIX = "_copy";
private static final Log LOG = PlatformUtil.getLog(SettingsHelper.class); private static final Log LOG = PlatformUtil.getLog(SettingsHelper.class);
private static final int BUFFER = 1024; private static final int BUFFER = 1024;
@ -509,12 +510,19 @@ public class SettingsHelper {
return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null; return builder != null && ApplicationMode.valueOfStringKey(getName(), null) != null;
} }
private void renameProfile() {
modeBean.stringKey = COPY_PREFIX + modeBean.stringKey;
modeBean.userProfileName = COPY_PREFIX + modeBean.userProfileName;
if (ApplicationMode.valueOfStringKey(modeBean.stringKey, null) != null) {
renameProfile();
}
}
@Override @Override
public void apply() { public void apply() {
if (appMode.isCustomProfile()) { if (appMode.isCustomProfile()) {
if (!shouldReplace) { if (!shouldReplace && exists()) {
modeBean.stringKey = COPY_PREFIX + modeBean.stringKey; renameProfile();
modeBean.userProfileName = COPY_PREFIX + modeBean.userProfileName;
builder = ApplicationMode.fromModeBean(app, modeBean); builder = ApplicationMode.fromModeBean(app, modeBean);
} }
appMode = ApplicationMode.saveProfile(builder, getSettings().getContext()); appMode = ApplicationMode.saveProfile(builder, getSettings().getContext());
@ -748,10 +756,6 @@ public class SettingsHelper {
if (shouldReplace || !file.exists()) { if (shouldReplace || !file.exists()) {
output = new FileOutputStream(file); output = new FileOutputStream(file);
} else { } else {
// 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)); output = new FileOutputStream(renameFile(file));
} }
byte[] buffer = new byte[BUFFER]; byte[] buffer = new byte[BUFFER];
@ -805,6 +809,24 @@ public class SettingsHelper {
return quickActions; return quickActions;
} }
private void renameAction(QuickAction quickAction) {
quickAction.setName(COPY_PREFIX + quickAction.getName(app));
if (duplicateExists(quickAction)) {
renameAction(quickAction);
}
}
private boolean duplicateExists(QuickAction quickAction) {
QuickActionFactory factory = new QuickActionFactory();
List<QuickAction> savedActions = factory.parseActiveActionsList(getSettings().QUICK_ACTION_LIST.get());
for (QuickAction action : savedActions) {
if (action.getName(app).equals(quickAction.getName(app))) {
return true;
}
}
return false;
}
@Override @Override
public void apply() { public void apply() {
if (!quickActions.isEmpty() || !duplicates.isEmpty()) { if (!quickActions.isEmpty() || !duplicates.isEmpty()) {
@ -822,7 +844,7 @@ public class SettingsHelper {
} }
} else { } else {
for (QuickAction action : duplicates) { for (QuickAction action : duplicates) {
action.setName(COPY_PREFIX + action.getName(app)); renameAction(action);
} }
} }
newActions.addAll(duplicates); newActions.addAll(duplicates);
@ -979,7 +1001,6 @@ public class SettingsHelper {
for (PoiUIFilter duplicate : duplicates) { for (PoiUIFilter duplicate : duplicates) {
if (!shouldReplace) { if (!shouldReplace) {
renamePoiFilter(duplicate); renamePoiFilter(duplicate);
// duplicate.setName(COPY_PREFIX + duplicate.getName());
} }
poiUIFilters.add(duplicate); poiUIFilters.add(duplicate);
} }
@ -992,6 +1013,7 @@ public class SettingsHelper {
private void renamePoiFilter(PoiUIFilter poiUIFilter) { private void renamePoiFilter(PoiUIFilter poiUIFilter) {
poiUIFilter.setName(COPY_PREFIX + poiUIFilter.getName()); poiUIFilter.setName(COPY_PREFIX + poiUIFilter.getName());
poiUIFilter.setFilterId(poiUIFilter.getFilterId() + COPY_SUFFIX);
if (duplicateExists(poiUIFilter)) { if (duplicateExists(poiUIFilter)) {
renamePoiFilter(poiUIFilter); renamePoiFilter(poiUIFilter);
} }

View file

@ -726,6 +726,10 @@ public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter>
return filterId; return filterId;
} }
public void setFilterId(String filterId) {
this.filterId = filterId;
}
public Map<String, PoiType> getPoiAdditionals() { public Map<String, PoiType> getPoiAdditionals() {
return poiAdditionals; return poiAdditionals;
} }

View file

@ -97,7 +97,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
((ItemViewHolder) holder).icon.setImageResource(View.VISIBLE); ((ItemViewHolder) holder).icon.setImageResource(View.VISIBLE);
} else { } else {
((ItemViewHolder) holder).icon.setImageResource(R.drawable.ic_action_info_dark); ((ItemViewHolder) holder).icon.setImageResource(R.drawable.ic_action_info_dark);
((ItemViewHolder) holder).icon.setVisibility(View.GONE); ((ItemViewHolder) holder).icon.setVisibility(View.INVISIBLE);
} }
((ItemViewHolder) holder).divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE); ((ItemViewHolder) holder).divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
} }

View file

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

File diff suppressed because one or more lines are too long