From b7a4c7947a5a7bb29a1fbd0193136aee0be5c8a9 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 31 Dec 2019 11:34:25 +0200 Subject: [PATCH] Small code refactoring --- OsmAnd/res/values-ar/strings.xml | 2 +- OsmAnd/src/net/osmand/plus/activities/MapActivity.java | 9 --------- .../net/osmand/plus/settings/BaseSettingsFragment.java | 7 +++++++ .../osmand/plus/settings/ConfigureProfileFragment.java | 5 +---- .../net/osmand/plus/settings/MainSettingsFragment.java | 10 ++++------ .../plus/settings/ProfileAppearanceFragment.java | 4 ++-- 6 files changed, 15 insertions(+), 22 deletions(-) diff --git a/OsmAnd/res/values-ar/strings.xml b/OsmAnd/res/values-ar/strings.xml index 649d2941da..d7802ba7ce 100644 --- a/OsmAnd/res/values-ar/strings.xml +++ b/OsmAnd/res/values-ar/strings.xml @@ -3248,7 +3248,7 @@ حفظ التغييرات احفظ التغييرات في ملف التعريف أولاً حذف الملف الشخصي - هل تريد بالتأكيد حذف ملف التعريف \"٪ s\" + هل تريد بالتأكيد حذف ملف التعريف \"%s\" حدد ملف تعريف أساسي إسناد ملف التعريف المخصص الخاص بك إلى أحد ملفات تعريف التطبيق الافتراضية ، يحدد الإعداد الأساسي مثل الرؤية الافتراضية لعناصر واجهة المستخدم ووحدات السرعة والمسافة. وهذه هي ملفات تعريف التطبيق الافتراضية ، إلى جانب أمثلة لملفات تعريف مخصصة يمكن تمديدها إلى: حدد نوع الملاحة diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 590e04fb19..4d36ea9073 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -133,7 +133,6 @@ import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment.SettingsScreenType; import net.osmand.plus.settings.DataStorageFragment; -import net.osmand.plus.settings.MainSettingsFragment; import net.osmand.plus.settings.ProfileAppearanceFragment; import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; @@ -684,10 +683,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return; } } - MainSettingsFragment mainSettingsFragment = getMainSettingsFragment(); - if (mainSettingsFragment != null) { - mainSettingsFragment.close(); - } if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) { if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY && !isLandscapeLayout()) { mapContextMenu.openMenuHeaderOnly(); @@ -2420,10 +2415,6 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven return getFragment(QuickActionListFragment.TAG); } - public MainSettingsFragment getMainSettingsFragment() { - return getFragment(MainSettingsFragment.TAG); - } - T getFragment(String fragmentTag){ Fragment fragment = getSupportFragmentManager().findFragmentByTag(fragmentTag); return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (T) fragment : null; diff --git a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java index 596369d493..b911d14615 100644 --- a/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/BaseSettingsFragment.java @@ -772,4 +772,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl } return false; } + + void updateRouteInfoMenu() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapRouteInfoMenu().updateMenu(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java index 013d59a80e..d4163e2c65 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ConfigureProfileFragment.java @@ -135,10 +135,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment { TextView title = switchContainer.findViewById(R.id.switchButtonText); title.setText(isChecked ? R.string.shared_string_on : R.string.shared_string_off); - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } + updateRouteInfoMenu(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java index 00aecf503d..3f1e028cab 100644 --- a/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/MainSettingsFragment.java @@ -16,7 +16,6 @@ import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.profiles.ProfileDataObject; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment; import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener; @@ -200,10 +199,9 @@ public class MainSettingsFragment extends BaseSettingsFragment { return selectProfileListener; } - public void close() { - MapActivity mapActivity = getMapActivity(); - if (mapActivity != null) { - mapActivity.getMapRouteInfoMenu().updateMenu(); - } + @Override + public void onPause() { + updateRouteInfoMenu(); + super.onPause(); } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java index 172f4fc14e..f81ed304b6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/ProfileAppearanceFragment.java @@ -148,11 +148,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment { suffix++; newName = oldName.substring(0, i + 1) + divider + suffix; } - while (hasThatName(newName)); + while (hasProfileWithName(newName)); return newName; } - boolean hasThatName(String newName) { + private boolean hasProfileWithName(String newName) { for (ApplicationMode m : ApplicationMode.allPossibleValues()) { if (m.toHumanString(app).equals(newName)) { return true;