From cee05f8c8f8dbb115519c7689233c10509cd1dd9 Mon Sep 17 00:00:00 2001 From: Nazar Date: Fri, 25 Oct 2019 14:24:24 +0300 Subject: [PATCH] small fixes part 2 --- .../plus/settings/DataStorageFragment.java | 33 +++++++++---------- .../plus/settings/DataStorageHelper.java | 6 +--- .../plus/settings/GlobalSettingsFragment.java | 2 +- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java index f5946df6d7..2e357ac497 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java @@ -5,7 +5,6 @@ import android.annotation.SuppressLint; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; -import android.content.pm.PackageManager; import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; @@ -67,7 +66,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto private Preference changeButton; private DataStorageMenuItem currentDataStorage; private String tmpManuallySpecifiedPath; - private DataStorageHelper itemsHolder; + private DataStorageHelper dataStorageHelper; private boolean calculateTilesBtnPressed; private DataStorageHelper.RefreshMemoryUsedInfo calculateMemoryTask; @@ -75,14 +74,12 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto private OsmandApplication app; private OsmandActionBarActivity activity; - private OsmandSettings settings; @Override public void onCreate(Bundle savedInstanceState) { app = getMyApplication(); activity = getMyActivity(); - settings = app.getSettings(); - if (itemsHolder == null) { + if (dataStorageHelper == null) { setRetainInstance(true); refreshDataInfo(); } @@ -94,12 +91,12 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto PreferenceScreen screen = getPreferenceScreen(); - if (screen == null || itemsHolder == null) { + if (screen == null || dataStorageHelper == null) { return; } - menuItems = itemsHolder.getStorageItems(); - memoryItems = itemsHolder.getMemoryInfoItems(); + menuItems = dataStorageHelper.getStorageItems(); + memoryItems = dataStorageHelper.getMemoryInfoItems(); dataStorageRadioButtonsGroup = new ArrayList<>(); for (DataStorageMenuItem item : menuItems) { @@ -111,7 +108,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto dataStorageRadioButtonsGroup.add(preference); } - currentDataStorage = itemsHolder.getCurrentStorage(); + currentDataStorage = dataStorageHelper.getCurrentStorage(); changeButton = new Preference(app); changeButton.setKey(CHANGE_DIRECTORY_BUTTON); @@ -159,7 +156,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto if (tmpManuallySpecifiedPath != null) { DataStorageMenuItem manuallySpecified = null; try { - manuallySpecified = (DataStorageMenuItem) itemsHolder.getManuallySpecified().clone(); + manuallySpecified = (DataStorageMenuItem) dataStorageHelper.getManuallySpecified().clone(); manuallySpecified.setDirectory(tmpManuallySpecifiedPath); } catch (CloneNotSupportedException e) { return false; @@ -173,7 +170,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto //show necessary dialog String key = preference.getKey(); if (key != null) { - DataStorageMenuItem newDataStorage = itemsHolder.getStorage(key); + DataStorageMenuItem newDataStorage = dataStorageHelper.getStorage(key); if (newDataStorage != null) { if (!currentDataStorage.getKey().equals(newDataStorage.getKey())) { if (newDataStorage.getType() == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT @@ -215,7 +212,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto final View itemView = holder.itemView; if (preference instanceof CheckBoxPreference) { - DataStorageMenuItem item = itemsHolder.getStorage(key); + DataStorageMenuItem item = dataStorageHelper.getStorage(key); if (item != null) { TextView tvTitle = itemView.findViewById(android.R.id.title); TextView tvSummary = itemView.findViewById(R.id.summary); @@ -266,7 +263,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto icon.setVisibility(View.INVISIBLE); title.setText(R.string.shared_string_change); } else if(key.equals(OSMAND_USAGE)) { - long totalUsageBytes = itemsHolder.getTotalUsedBytes(); + long totalUsageBytes = dataStorageHelper.getTotalUsedBytes(); TextView tvSummary = itemView.findViewById(R.id.summary); tvSummary.setText(DataStorageHelper.getFormattedMemoryInfo(totalUsageBytes, memoryUnitsFormats)); } else { @@ -282,7 +279,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto @Override public void onClick(View v) { calculateTilesBtnPressed = true; - calculateTilesMemoryTask = itemsHolder.calculateTilesMemoryUsed(DataStorageFragment.this); + calculateTilesMemoryTask = dataStorageHelper.calculateTilesMemoryUsed(DataStorageFragment.this); updateAllSettings(); } }); @@ -329,7 +326,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto } private void showFolderSelectionDialog() { - DataStorageMenuItem manuallySpecified = itemsHolder.getManuallySpecified(); + DataStorageMenuItem manuallySpecified = dataStorageHelper.getManuallySpecified(); if (manuallySpecified != null) { SelectFolderBottomSheet.showInstance(getFragmentManager(), manuallySpecified.getKey(), manuallySpecified.getDirectory(), DataStorageFragment.this, @@ -440,8 +437,8 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto private void refreshDataInfo() { calculateTilesBtnPressed = false; - itemsHolder = DataStorageHelper.refreshInfo(app); - calculateMemoryTask = itemsHolder.calculateMemoryUsedInfo(this); + dataStorageHelper = new DataStorageHelper(app); + calculateMemoryTask = dataStorageHelper.calculateMemoryUsedInfo(this); } private String getSpaceDescription(String path) { @@ -478,7 +475,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto public void onFinishUpdating(String taskKey) { updateAllSettings(); if (taskKey != null && taskKey.equals(TILES_MEMORY)) { - app.getSettings().OSMAND_USAGE_SPACE.set(itemsHolder.getTotalUsedBytes()); + app.getSettings().OSMAND_USAGE_SPACE.set(dataStorageHelper.getTotalUsedBytes()); } } diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java index 994cc8eb0d..757f551fdc 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java @@ -47,14 +47,10 @@ public class DataStorageHelper { private int currentStorageType; private String currentStoragePath; - private DataStorageHelper(OsmandApplication app) { + public DataStorageHelper(OsmandApplication app) { prepareData(app); } - public static DataStorageHelper refreshInfo(OsmandApplication app) { - return new DataStorageHelper(app); - } - private void prepareData(OsmandApplication app) { if (app == null) { diff --git a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java index 561abc1146..1eb702376b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/GlobalSettingsFragment.java @@ -137,7 +137,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send Preference externalStorageDir = (Preference) findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR); externalStorageDir.setIcon(getContentIcon(R.drawable.ic_action_folder)); - DataStorageHelper holder = DataStorageHelper.refreshInfo(app); + DataStorageHelper holder = new DataStorageHelper(app); DataStorageMenuItem currentStorage = holder.getCurrentStorage(); long totalUsed = app.getSettings().OSMAND_USAGE_SPACE.get(); if (totalUsed > 0) {