small fixes part 2
This commit is contained in:
parent
fd05f6dc9e
commit
cee05f8c8f
3 changed files with 17 additions and 24 deletions
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue