small fixes part 2

This commit is contained in:
Nazar 2019-10-25 14:24:24 +03:00
parent fd05f6dc9e
commit cee05f8c8f
3 changed files with 17 additions and 24 deletions

View file

@ -5,7 +5,6 @@ import android.annotation.SuppressLint;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
@ -67,7 +66,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
private Preference changeButton; private Preference changeButton;
private DataStorageMenuItem currentDataStorage; private DataStorageMenuItem currentDataStorage;
private String tmpManuallySpecifiedPath; private String tmpManuallySpecifiedPath;
private DataStorageHelper itemsHolder; private DataStorageHelper dataStorageHelper;
private boolean calculateTilesBtnPressed; private boolean calculateTilesBtnPressed;
private DataStorageHelper.RefreshMemoryUsedInfo calculateMemoryTask; private DataStorageHelper.RefreshMemoryUsedInfo calculateMemoryTask;
@ -75,14 +74,12 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
private OsmandApplication app; private OsmandApplication app;
private OsmandActionBarActivity activity; private OsmandActionBarActivity activity;
private OsmandSettings settings;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
app = getMyApplication(); app = getMyApplication();
activity = getMyActivity(); activity = getMyActivity();
settings = app.getSettings(); if (dataStorageHelper == null) {
if (itemsHolder == null) {
setRetainInstance(true); setRetainInstance(true);
refreshDataInfo(); refreshDataInfo();
} }
@ -94,12 +91,12 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
PreferenceScreen screen = getPreferenceScreen(); PreferenceScreen screen = getPreferenceScreen();
if (screen == null || itemsHolder == null) { if (screen == null || dataStorageHelper == null) {
return; return;
} }
menuItems = itemsHolder.getStorageItems(); menuItems = dataStorageHelper.getStorageItems();
memoryItems = itemsHolder.getMemoryInfoItems(); memoryItems = dataStorageHelper.getMemoryInfoItems();
dataStorageRadioButtonsGroup = new ArrayList<>(); dataStorageRadioButtonsGroup = new ArrayList<>();
for (DataStorageMenuItem item : menuItems) { for (DataStorageMenuItem item : menuItems) {
@ -111,7 +108,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
dataStorageRadioButtonsGroup.add(preference); dataStorageRadioButtonsGroup.add(preference);
} }
currentDataStorage = itemsHolder.getCurrentStorage(); currentDataStorage = dataStorageHelper.getCurrentStorage();
changeButton = new Preference(app); changeButton = new Preference(app);
changeButton.setKey(CHANGE_DIRECTORY_BUTTON); changeButton.setKey(CHANGE_DIRECTORY_BUTTON);
@ -159,7 +156,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
if (tmpManuallySpecifiedPath != null) { if (tmpManuallySpecifiedPath != null) {
DataStorageMenuItem manuallySpecified = null; DataStorageMenuItem manuallySpecified = null;
try { try {
manuallySpecified = (DataStorageMenuItem) itemsHolder.getManuallySpecified().clone(); manuallySpecified = (DataStorageMenuItem) dataStorageHelper.getManuallySpecified().clone();
manuallySpecified.setDirectory(tmpManuallySpecifiedPath); manuallySpecified.setDirectory(tmpManuallySpecifiedPath);
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
return false; return false;
@ -173,7 +170,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
//show necessary dialog //show necessary dialog
String key = preference.getKey(); String key = preference.getKey();
if (key != null) { if (key != null) {
DataStorageMenuItem newDataStorage = itemsHolder.getStorage(key); DataStorageMenuItem newDataStorage = dataStorageHelper.getStorage(key);
if (newDataStorage != null) { if (newDataStorage != null) {
if (!currentDataStorage.getKey().equals(newDataStorage.getKey())) { if (!currentDataStorage.getKey().equals(newDataStorage.getKey())) {
if (newDataStorage.getType() == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT if (newDataStorage.getType() == OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT
@ -215,7 +212,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
final View itemView = holder.itemView; final View itemView = holder.itemView;
if (preference instanceof CheckBoxPreference) { if (preference instanceof CheckBoxPreference) {
DataStorageMenuItem item = itemsHolder.getStorage(key); DataStorageMenuItem item = dataStorageHelper.getStorage(key);
if (item != null) { if (item != null) {
TextView tvTitle = itemView.findViewById(android.R.id.title); TextView tvTitle = itemView.findViewById(android.R.id.title);
TextView tvSummary = itemView.findViewById(R.id.summary); TextView tvSummary = itemView.findViewById(R.id.summary);
@ -266,7 +263,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
icon.setVisibility(View.INVISIBLE); icon.setVisibility(View.INVISIBLE);
title.setText(R.string.shared_string_change); title.setText(R.string.shared_string_change);
} else if(key.equals(OSMAND_USAGE)) { } else if(key.equals(OSMAND_USAGE)) {
long totalUsageBytes = itemsHolder.getTotalUsedBytes(); long totalUsageBytes = dataStorageHelper.getTotalUsedBytes();
TextView tvSummary = itemView.findViewById(R.id.summary); TextView tvSummary = itemView.findViewById(R.id.summary);
tvSummary.setText(DataStorageHelper.getFormattedMemoryInfo(totalUsageBytes, memoryUnitsFormats)); tvSummary.setText(DataStorageHelper.getFormattedMemoryInfo(totalUsageBytes, memoryUnitsFormats));
} else { } else {
@ -282,7 +279,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
@Override @Override
public void onClick(View v) { public void onClick(View v) {
calculateTilesBtnPressed = true; calculateTilesBtnPressed = true;
calculateTilesMemoryTask = itemsHolder.calculateTilesMemoryUsed(DataStorageFragment.this); calculateTilesMemoryTask = dataStorageHelper.calculateTilesMemoryUsed(DataStorageFragment.this);
updateAllSettings(); updateAllSettings();
} }
}); });
@ -329,7 +326,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
} }
private void showFolderSelectionDialog() { private void showFolderSelectionDialog() {
DataStorageMenuItem manuallySpecified = itemsHolder.getManuallySpecified(); DataStorageMenuItem manuallySpecified = dataStorageHelper.getManuallySpecified();
if (manuallySpecified != null) { if (manuallySpecified != null) {
SelectFolderBottomSheet.showInstance(getFragmentManager(), manuallySpecified.getKey(), SelectFolderBottomSheet.showInstance(getFragmentManager(), manuallySpecified.getKey(),
manuallySpecified.getDirectory(), DataStorageFragment.this, manuallySpecified.getDirectory(), DataStorageFragment.this,
@ -440,8 +437,8 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
private void refreshDataInfo() { private void refreshDataInfo() {
calculateTilesBtnPressed = false; calculateTilesBtnPressed = false;
itemsHolder = DataStorageHelper.refreshInfo(app); dataStorageHelper = new DataStorageHelper(app);
calculateMemoryTask = itemsHolder.calculateMemoryUsedInfo(this); calculateMemoryTask = dataStorageHelper.calculateMemoryUsedInfo(this);
} }
private String getSpaceDescription(String path) { private String getSpaceDescription(String path) {
@ -478,7 +475,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
public void onFinishUpdating(String taskKey) { public void onFinishUpdating(String taskKey) {
updateAllSettings(); updateAllSettings();
if (taskKey != null && taskKey.equals(TILES_MEMORY)) { if (taskKey != null && taskKey.equals(TILES_MEMORY)) {
app.getSettings().OSMAND_USAGE_SPACE.set(itemsHolder.getTotalUsedBytes()); app.getSettings().OSMAND_USAGE_SPACE.set(dataStorageHelper.getTotalUsedBytes());
} }
} }

View file

@ -47,14 +47,10 @@ public class DataStorageHelper {
private int currentStorageType; private int currentStorageType;
private String currentStoragePath; private String currentStoragePath;
private DataStorageHelper(OsmandApplication app) { public DataStorageHelper(OsmandApplication app) {
prepareData(app); prepareData(app);
} }
public static DataStorageHelper refreshInfo(OsmandApplication app) {
return new DataStorageHelper(app);
}
private void prepareData(OsmandApplication app) { private void prepareData(OsmandApplication app) {
if (app == null) { if (app == null) {

View file

@ -137,7 +137,7 @@ public class GlobalSettingsFragment extends BaseSettingsFragment implements Send
Preference externalStorageDir = (Preference) findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR); Preference externalStorageDir = (Preference) findPreference(OsmandSettings.EXTERNAL_STORAGE_DIR);
externalStorageDir.setIcon(getContentIcon(R.drawable.ic_action_folder)); externalStorageDir.setIcon(getContentIcon(R.drawable.ic_action_folder));
DataStorageHelper holder = DataStorageHelper.refreshInfo(app); DataStorageHelper holder = new DataStorageHelper(app);
DataStorageMenuItem currentStorage = holder.getCurrentStorage(); DataStorageMenuItem currentStorage = holder.getCurrentStorage();
long totalUsed = app.getSettings().OSMAND_USAGE_SPACE.get(); long totalUsed = app.getSettings().OSMAND_USAGE_SPACE.get();
if (totalUsed > 0) { if (totalUsed > 0) {