aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChumva <faiver.unknown@gmail.com>2019-10-17 10:54:51 +0300
committerChumva <faiver.unknown@gmail.com>2019-10-17 10:54:51 +0300
commit1c645c5cf9342fc6d0879570d83a974ff4294b45 (patch)
tree150c4d428827f3e3075626d9ead4529104be6858
parenta347acbd7c425822e100f6ad4748864cac917d27 (diff)
parentd58ca19f0cb14397f3229b055960fd04921981b8 (diff)
downloadOsmand-1c645c5cf9342fc6d0879570d83a974ff4294b45.tar.gz
Merge branch 'master' of ssh://github.com/osmandapp/Osmand into settings_improvements
-rw-r--r--OsmAnd/res/layout/data_storage_memory_used_item.xml47
-rw-r--r--OsmAnd/res/layout/divider_padding_half.xml25
-rw-r--r--OsmAnd/res/layout/preference_category_with_right_text.xml37
-rw-r--r--OsmAnd/res/values/strings.xml10
-rw-r--r--OsmAnd/res/xml/data_storage.xml38
-rw-r--r--OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java129
-rw-r--r--OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java325
-rw-r--r--OsmAnd/src/net/osmand/plus/settings/DataStorageMemoryItem.java122
-rw-r--r--OsmAnd/src/net/osmand/plus/settings/DataStorageMenuItem.java28
9 files changed, 691 insertions, 70 deletions
diff --git a/OsmAnd/res/layout/data_storage_memory_used_item.xml b/OsmAnd/res/layout/data_storage_memory_used_item.xml
new file mode 100644
index 0000000000..0653b8b681
--- /dev/null
+++ b/OsmAnd/res/layout/data_storage_memory_used_item.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:osmand="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:background="?attr/list_background_color"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/card_row_min_height"
+ android:orientation="horizontal">
+
+ <android.support.v7.widget.AppCompatImageView
+ android:id="@android:id/icon"
+ android:layout_width="@dimen/standard_icon_size"
+ android:layout_height="@dimen/standard_icon_size"
+ android:layout_gravity="center"
+ android:layout_marginLeft="@dimen/content_padding"
+ android:layout_marginRight="@dimen/content_padding"
+ android:src="@drawable/mm_storage_tank"
+ android:tint="?attr/default_icon_color"
+ tools:tint="?attr/default_icon_color" />
+
+ <net.osmand.plus.widgets.TextViewEx
+ android:id="@android:id/title"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1"
+ android:textColor="?android:textColorPrimary"
+ android:textSize="@dimen/default_desc_text_size"
+ android:paddingLeft="@dimen/content_padding"
+ osmand:typeface="@string/font_roboto_regular"
+ tools:text="Internal application memory" />
+
+ <net.osmand.plus.widgets.TextViewEx
+ android:id="@+id/memory"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:background="@null"
+ android:clickable="true"
+ android:focusable="true"
+ android:paddingLeft="@dimen/content_padding"
+ android:paddingRight="@dimen/content_padding"
+ android:textSize="@dimen/default_desc_text_size"
+ osmand:typeface="@string/font_roboto_regular"
+ tools:text="6.7 GB" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/OsmAnd/res/layout/divider_padding_half.xml b/OsmAnd/res/layout/divider_padding_half.xml
new file mode 100644
index 0000000000..55fec44417
--- /dev/null
+++ b/OsmAnd/res/layout/divider_padding_half.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:background="?attr/list_background_color">
+
+ <View
+ android:id="@+id/topSpace"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/content_padding_half" />
+
+ <View
+ android:id="@+id/divider"
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="?attr/dashboard_divider"
+ android:focusable="false" />
+
+ <View
+ android:id="@+id/bottomSpace"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/content_padding_half" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/OsmAnd/res/layout/preference_category_with_right_text.xml b/OsmAnd/res/layout/preference_category_with_right_text.xml
new file mode 100644
index 0000000000..3cafb66aed
--- /dev/null
+++ b/OsmAnd/res/layout/preference_category_with_right_text.xml
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:osmand="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="@dimen/card_row_min_height"
+ android:background="?attr/list_background_color"
+ android:gravity="center_vertical"
+ android:minHeight="@dimen/bottom_sheet_cancel_button_height_small"
+ android:orientation="horizontal">
+
+ <net.osmand.plus.widgets.TextViewEx
+ android:id="@android:id/title"
+ android:layout_width="0dp"
+ android:layout_weight="1"
+ android:layout_height="wrap_content"
+ android:textColor="@color/preference_category_title"
+ android:layout_gravity="center_vertical|start"
+ android:paddingLeft="@dimen/content_padding"
+ android:paddingRight="@dimen/content_padding"
+ android:textSize="@dimen/default_desc_text_size"
+ osmand:typeface="@string/font_roboto_medium"
+ tools:text="@string/plugin_settings" />
+
+ <net.osmand.plus.widgets.TextViewEx
+ android:id="@+id/summary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical|end"
+ android:paddingLeft="@dimen/content_padding"
+ android:paddingRight="@dimen/content_padding"
+ android:textColor="?android:textColorPrimary"
+ android:textSize="@dimen/default_desc_text_size"
+ osmand:typeface="@string/font_roboto_medium"
+ tools:text="summary" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index da85cfb513..4f72c5958f 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -11,13 +11,21 @@
Thx - Hardy
-->
+ <string name="shared_string_calculate">Calculate</string>
+ <string name="shared_string_osmand_usage">OsmAnd Usage</string>
+ <string name="shared_sting_tiles">Tiles</string>
+ <string name="shared_string_maps">Maps</string>
+ <string name="shared_string_memory_tb_desc">%1$s TB</string>
+ <string name="shared_string_memory_gb_desc">%1$s GB</string>
+ <string name="shared_string_memory_mb_desc">%1$s MB</string>
+ <string name="shared_string_memory_kb_desc">%1$s KB</string>
<string name="app_mode_utv">Side by Side</string>
<string name="rendering_attr_piste_difficulty_aerialway_name">Aerialway</string>
<string name="rendering_attr_piste_difficulty_connection_name">Connection</string>
<string name="avoid_in_routing_descr_">Avoid certain routes and road types</string>
<string name="change_data_storage_full_description">Move OsmAnd data files to the new destination?\n%1$s > %2$s</string>
<string name="data_storage_preference_summary">%1$s • Used %2$s GB</string>
- <string name="data_storage_space_description">Free %1$s • %2$s / %3$s GB</string>
+ <string name="data_storage_space_description">Free %1$s GB • Total %2$s GB</string>
<string name="enter_path_to_folder">Enter path to the folder</string>
<string name="shared_string_select_folder">Select folder</string>
<string name="paste_Osmand_data_folder_path">Paste path to the folder with OsmAnd data</string>
diff --git a/OsmAnd/res/xml/data_storage.xml b/OsmAnd/res/xml/data_storage.xml
index 527ab8e1a9..242418b0e0 100644
--- a/OsmAnd/res/xml/data_storage.xml
+++ b/OsmAnd/res/xml/data_storage.xml
@@ -2,6 +2,44 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="@string/application_dir">
+ <Preference
+ android:key="osmand_usage"
+ android:layout="@layout/preference_category_with_right_text"
+ android:title="@string/shared_string_osmand_usage" />
+
+ <Preference
+ android:key="maps_memory_used"
+ android:layout="@layout/data_storage_memory_used_item"
+ android:icon="@drawable/ic_map"
+ android:title="@string/shared_string_maps"/>
+
+ <Preference
+ android:key="tracks_memory_used"
+ android:layout="@layout/data_storage_memory_used_item"
+ android:icon="@drawable/ic_action_polygom_dark"
+ android:title="@string/shared_string_gpx_tracks"/>
+
+ <Preference
+ android:key="notes_memory_used"
+ android:layout="@layout/data_storage_memory_used_item"
+ android:icon="@drawable/ic_action_photo_dark"
+ android:title="@string/audionotes_plugin_name"/>
+
+ <Preference
+ android:key="tiles_memory_used"
+ android:layout="@layout/data_storage_memory_used_item"
+ android:icon="@drawable/ic_world_globe_dark"
+ android:title="@string/shared_sting_tiles"/>
+
+ <Preference
+ android:key="other_memory_used"
+ android:layout="@layout/data_storage_memory_used_item"
+ android:icon="@drawable/ic_action_folder"
+ android:title="@string/shared_string_other"/>
+
+ <Preference
+ android:layout="@layout/divider_padding_half" />
+
<PreferenceCategory
android:key="application_profiles"
android:layout="@layout/preference_category_with_descr"
diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java
index f4013e536c..b944501c53 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.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -46,39 +45,61 @@ import java.util.Locale;
import static net.osmand.plus.settings.DataStorageItemsHolder.INTERNAL_STORAGE;
import static net.osmand.plus.settings.DataStorageItemsHolder.MANUALLY_SPECIFIED;
+import static net.osmand.plus.settings.DataStorageItemsHolder.TILES_MEMORY;
import static net.osmand.plus.settings.bottomsheets.ChangeDataStorageBottomSheet.CHOSEN_DIRECTORY;
import static net.osmand.plus.settings.bottomsheets.ChangeDataStorageBottomSheet.MOVE_DATA;
import static net.osmand.plus.settings.bottomsheets.SelectFolderBottomSheet.PATH_CHANGED;
import static net.osmand.plus.settings.bottomsheets.SelectFolderBottomSheet.NEW_PATH;
-public class DataStorageFragment extends BaseSettingsFragment {
+public class DataStorageFragment extends BaseSettingsFragment implements DataStorageItemsHolder.UpdateMemoryInfoUIAdapter {
private final static String CHANGE_DIRECTORY_BUTTON = "change_directory";
+ private final static String OSMAND_USAGE = "osmand_usage";
+ private final static String CALCULATE_TILES_BTN_PRESSED = "calculate_tiles_btn_pressed";
+ private final static String ITEMS_HOLDER = "items_holder";
private ArrayList<DataStorageMenuItem> menuItems;
+ private ArrayList<DataStorageMemoryItem> memoryItems;
private ArrayList<CheckBoxPreference> dataStorageRadioButtonsGroup;
private Preference changeButton;
private DataStorageMenuItem currentDataStorage;
private String tmpManuallySpecifiedPath;
private DataStorageItemsHolder itemsHolder;
+ private boolean calculateTilesBtnPressed;
+
+ private DataStorageItemsHolder.RefreshMemoryUsedInfo calculateMemoryTask;
+ private DataStorageItemsHolder.RefreshMemoryUsedInfo calculateTilesMemoryTask;
private OsmandApplication app;
private OsmandActionBarActivity activity;
private OsmandSettings settings;
@Override
- protected void setupPreferences() {
+ public void onCreate(Bundle savedInstanceState) {
app = getMyApplication();
activity = getMyActivity();
+ settings = app.getSettings();
+ if (savedInstanceState != null) {
+ calculateTilesBtnPressed = savedInstanceState.getBoolean(CALCULATE_TILES_BTN_PRESSED);
+ itemsHolder = savedInstanceState.getParcelable(ITEMS_HOLDER);
+ }
+ if (itemsHolder == null) {
+ refreshDataInfo();
+ }
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ protected void setupPreferences() {
+
PreferenceScreen screen = getPreferenceScreen();
- if (screen == null || app == null || activity == null) {
+ if (screen == null || itemsHolder == null) {
return;
}
- settings = app.getSettings();
- itemsHolder = DataStorageItemsHolder.refreshInfo(app);
menuItems = itemsHolder.getStorageItems();
+ memoryItems = itemsHolder.getMemoryInfoItems();
dataStorageRadioButtonsGroup = new ArrayList<>();
for (DataStorageMenuItem item : menuItems) {
@@ -174,13 +195,24 @@ public class DataStorageFragment extends BaseSettingsFragment {
}
@Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(CALCULATE_TILES_BTN_PRESSED, calculateTilesBtnPressed);
+ outState.putParcelable(ITEMS_HOLDER, itemsHolder);
+ }
+
+ @Override
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
super.onBindPreferenceViewHolder(preference, holder);
String key = preference.getKey();
if (key == null) {
return;
}
- View itemView = holder.itemView;
+ int activeColorResId = isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
+ int activeColor = ContextCompat.getColor(app, activeColorResId);
+ int primaryTextColorResId = isNightMode() ? R.color.text_color_primary_dark : R.color.text_color_primary_light;
+ int primaryTextColor = ContextCompat.getColor(app, primaryTextColorResId);
+ final View itemView = holder.itemView;
if (preference instanceof CheckBoxPreference) {
DataStorageMenuItem item = itemsHolder.getStorage(key);
if (item != null) {
@@ -222,13 +254,57 @@ public class DataStorageFragment extends BaseSettingsFragment {
} else if (key.equals(CHANGE_DIRECTORY_BUTTON)) {
ImageView icon = itemView.findViewById(R.id.button_icon);
TextView title = itemView.findViewById(R.id.button_text);
- int colorResId = isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
- int color = ContextCompat.getColor(app, colorResId);
- Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, color, 0.3f);
+ Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, activeColor, 0.3f);
AndroidUtils.setBackground(itemView, drawable);
icon.setVisibility(View.INVISIBLE);
title.setText(R.string.shared_string_change);
+ } else if(key.equals(OSMAND_USAGE)) {
+ long totalUsageBytes = 0;
+ for (DataStorageMemoryItem mi : memoryItems) {
+ totalUsageBytes += mi.getUsedMemoryBytes();
+ }
+ TextView tvSummary = itemView.findViewById(R.id.summary);
+ tvSummary.setText(getFormattedMemoryUsedInfo(totalUsageBytes));
+ } else {
+ for (DataStorageMemoryItem mi : memoryItems) {
+ if (key.equals(mi.getKey())) {
+ TextView tvMemory = itemView.findViewById(R.id.memory);
+ String summary = "";
+ int color = 0;
+ if (mi.getKey().equals(TILES_MEMORY) && !calculateTilesBtnPressed) {
+ summary = getString(R.string.shared_string_calculate);
+ color = activeColor;
+ tvMemory.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ calculateTilesBtnPressed = true;
+ calculateTilesMemoryTask = itemsHolder.calculateTilesMemoryUsed(DataStorageFragment.this);
+ updateAllSettings();
+ }
+ });
+ } else {
+ tvMemory.setOnClickListener(null);
+ color = primaryTextColor;
+ summary = getFormattedMemoryUsedInfo(mi.getUsedMemoryBytes());
+ }
+ tvMemory.setTextColor(color);
+ tvMemory.setText(summary);
+ }
+ }
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ if (!activity.isChangingConfigurations()) {
+ if (calculateMemoryTask != null) {
+ calculateMemoryTask.cancel(true);
+ }
+ if (calculateTilesMemoryTask != null) {
+ calculateTilesMemoryTask.cancel(true);
+ }
}
+ super.onDestroy();
}
private void updateView(String key) {
@@ -348,8 +424,15 @@ public class DataStorageFragment extends BaseSettingsFragment {
Toast.makeText(activity, R.string.specified_directiory_not_writeable,
Toast.LENGTH_LONG).show();
}
+ refreshDataInfo();
updateAllSettings();
}
+
+ private void refreshDataInfo() {
+ calculateTilesBtnPressed = false;
+ itemsHolder = DataStorageItemsHolder.refreshInfo(app);
+ calculateMemoryTask = itemsHolder.calculateMemoryUsedInfo(this);
+ }
private String getSpaceDescription(String path) {
File dir = new File(path);
@@ -362,16 +445,40 @@ public class DataStorageFragment extends BaseSettingsFragment {
DecimalFormat formatter = new DecimalFormat("#.##");
return String.format(getString(R.string.data_storage_space_description),
formatter.format(AndroidUtils.getFreeSpaceGb(dir)),
- formatter.format(AndroidUtils.getUsedSpaceGb(dir)),
formatter.format(AndroidUtils.getTotalSpaceGb(dir)));
}
return "";
}
+
+ private String getFormattedMemoryUsedInfo(long bytes) {
+ int type = 1;
+ double used = (double) bytes / 1024;
+ while (used > 1024) {
+ ++type;
+ used = used / 1024;
+ }
+ String formattedUsed = new DecimalFormat("#.##").format(used);
+ if (type == 1) {
+ return String.format(getString(R.string.shared_string_memory_kb_desc), formattedUsed);
+ } else if (type == 2) {
+ return String.format(getString(R.string.shared_string_memory_mb_desc), formattedUsed);
+ } else if (type == 3){
+ return String.format(getString(R.string.shared_string_memory_gb_desc), formattedUsed);
+ } else if (type == 4){
+ return String.format(getString(R.string.shared_string_memory_tb_desc), formattedUsed);
+ }
+ return "";
+ }
protected void reloadData() {
new ReloadData(activity, getMyApplication()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null);
}
+ @Override
+ public void onMemoryInfoUpdate() {
+ updateAllSettings();
+ }
+
public static class MoveFilesToDifferentDirectory extends AsyncTask<Void, Void, Boolean> {
protected WeakReference<OsmandActionBarActivity> activity;
diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java
index 089bf5c448..6c1f4a8dc5 100644
--- a/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java
+++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java
@@ -1,7 +1,11 @@
package net.osmand.plus.settings;
+import android.os.AsyncTask;
import android.os.Build;
+import android.os.Parcel;
+import android.os.Parcelable;
+import net.osmand.IndexConstants;
import net.osmand.ValueHolder;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@@ -10,39 +14,49 @@ import net.osmand.plus.R;
import java.io.File;
import java.util.ArrayList;
-public class DataStorageItemsHolder {
+public class DataStorageItemsHolder implements Parcelable {
public final static String INTERNAL_STORAGE = "internal_storage";
public final static String EXTERNAL_STORAGE = "external_storage";
public final static String SHARED_STORAGE = "shared_storage";
public final static String MULTIUSER_STORAGE = "multiuser_storage";
public final static String MANUALLY_SPECIFIED = "manually_specified";
- private ArrayList<DataStorageMenuItem> menuItems;
+ public final static String MAPS_MEMORY = "maps_memory_used";
+ public final static String TRACKS_MEMORY = "tracks_memory_used";
+ public final static String NOTES_MEMORY = "notes_memory_used";
+ public final static String TILES_MEMORY = "tiles_memory_used";
+ public final static String OTHER_MEMORY = "other_memory_used";
+
+ private ArrayList<DataStorageMenuItem> menuItems = new ArrayList<>();
private DataStorageMenuItem currentDataStorage;
private DataStorageMenuItem manuallySpecified;
+ private ArrayList<DataStorageMemoryItem> memoryItems = new ArrayList<>();
+ private DataStorageMemoryItem mapsMemory;
+ private DataStorageMemoryItem tracksMemory;
+ private DataStorageMemoryItem notesMemory;
+ private DataStorageMemoryItem tilesMemory;
+ private DataStorageMemoryItem otherMemory;
+
private int currentStorageType;
private String currentStoragePath;
- private OsmandApplication app;
- private OsmandSettings settings;
-
private DataStorageItemsHolder(OsmandApplication app) {
- this.app = app;
- this.settings = app.getSettings();
- prepareData();
+ prepareData(app);
}
public static DataStorageItemsHolder refreshInfo(OsmandApplication app) {
return new DataStorageItemsHolder(app);
}
- private void prepareData() {
+ private void prepareData(OsmandApplication app) {
if (app == null) {
return;
}
+ OsmandSettings settings = app.getSettings();
+
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
currentStorageType = settings.getExternalStorageDirectoryTypeV19();
} else {
@@ -55,8 +69,6 @@ public class DataStorageItemsHolder {
}
currentStoragePath = settings.getExternalStorageDirectory().getAbsolutePath();
- menuItems = new ArrayList<>();
-
String path;
File dir;
int iconId;
@@ -69,13 +81,13 @@ public class DataStorageItemsHolder {
iconId = R.drawable.ic_action_phone;
DataStorageMenuItem internalStorageItem = DataStorageMenuItem.builder()
- .buildKey(INTERNAL_STORAGE)
- .buildTitle(getString(R.string.storage_directory_internal_app))
- .buildDirectory(path)
- .buildDescription(getString(R.string.internal_app_storage_description))
- .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE)
- .buildIconResId(iconId)
- .build();
+ .setKey(INTERNAL_STORAGE)
+ .setTitle(app.getString(R.string.storage_directory_internal_app))
+ .setDirectory(path)
+ .setDescription(app.getString(R.string.internal_app_storage_description))
+ .setType(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE)
+ .setIconResId(iconId)
+ .createItem();
addItem(internalStorageItem);
//shared_storage
@@ -84,12 +96,12 @@ public class DataStorageItemsHolder {
iconId = R.drawable.ic_action_phone;
DataStorageMenuItem sharedStorageItem = DataStorageMenuItem.builder()
- .buildKey(SHARED_STORAGE)
- .buildTitle(getString(R.string.storage_directory_shared))
- .buildDirectory(path)
- .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT)
- .buildIconResId(iconId)
- .build();
+ .setKey(SHARED_STORAGE)
+ .setTitle(app.getString(R.string.storage_directory_shared))
+ .setDirectory(path)
+ .setType(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT)
+ .setIconResId(iconId)
+ .createItem();
addItem(sharedStorageItem);
//external storage
@@ -103,12 +115,12 @@ public class DataStorageItemsHolder {
path = dir.getAbsolutePath();
iconId = getIconForStorageType(dir);
DataStorageMenuItem externalStorageItem = DataStorageMenuItem.builder()
- .buildKey(EXTERNAL_STORAGE + i)
- .buildTitle(getString(R.string.storage_directory_external) + " " + i)
- .buildDirectory(path)
- .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE)
- .buildIconResId(iconId)
- .build();
+ .setKey(EXTERNAL_STORAGE + i)
+ .setTitle(app.getString(R.string.storage_directory_external) + " " + i)
+ .setDirectory(path)
+ .setType(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE)
+ .setIconResId(iconId)
+ .createItem();
addItem(externalStorageItem);
}
}
@@ -125,12 +137,12 @@ public class DataStorageItemsHolder {
path = dir.getAbsolutePath();
iconId = getIconForStorageType(dir);
DataStorageMenuItem multiuserStorageItem = DataStorageMenuItem.builder()
- .buildKey(MULTIUSER_STORAGE + i)
- .buildTitle(getString(R.string.storage_directory_multiuser) + " " + i)
- .buildDirectory(path)
- .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB)
- .buildIconResId(iconId)
- .build();
+ .setKey(MULTIUSER_STORAGE + i)
+ .setTitle(app.getString(R.string.storage_directory_multiuser) + " " + i)
+ .setDirectory(path)
+ .setType(OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB)
+ .setIconResId(iconId)
+ .createItem();
addItem(multiuserStorageItem);
}
}
@@ -139,21 +151,60 @@ public class DataStorageItemsHolder {
//manually specified storage
manuallySpecified = DataStorageMenuItem.builder()
- .buildKey(MANUALLY_SPECIFIED)
- .buildTitle(getString(R.string.storage_directory_manual))
- .buildDirectory(currentStoragePath)
- .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED)
- .buildIconResId(R.drawable.ic_action_folder)
- .build();
+ .setKey(MANUALLY_SPECIFIED)
+ .setTitle(app.getString(R.string.storage_directory_manual))
+ .setDirectory(currentStoragePath)
+ .setType(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED)
+ .setIconResId(R.drawable.ic_action_folder)
+ .createItem();
menuItems.add(manuallySpecified);
if (currentDataStorage == null) {
currentDataStorage = manuallySpecified;
}
+
+ initMemoryUsed(app);
}
- private String getString(int resId) {
- return app.getString(resId);
+ private void initMemoryUsed(OsmandApplication app) {
+ mapsMemory = DataStorageMemoryItem.builder()
+ .setKey(MAPS_MEMORY)
+ .setExtensions(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_MAP_INDEX_EXT_ZIP)
+ .setDirectories(
+ app.getAppPath(IndexConstants.MAPS_PATH).getAbsolutePath(),
+ app.getAppPath(IndexConstants.ROADS_INDEX_DIR).getAbsolutePath(),
+ app.getAppPath(IndexConstants.SRTM_INDEX_DIR).getAbsolutePath(),
+ app.getAppPath(IndexConstants.WIKI_INDEX_DIR).getAbsolutePath(),
+ app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR).getAbsolutePath(),
+ app.getAppPath(IndexConstants.BACKUP_INDEX_DIR).getAbsolutePath())
+ .createItem();
+ memoryItems.add(mapsMemory);
+
+ tracksMemory = DataStorageMemoryItem.builder()
+ .setKey(TRACKS_MEMORY)
+// .setExtensions(".gpx", ".gpx.bz2")
+ .setDirectories(app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath())
+ .createItem();
+ memoryItems.add(tracksMemory);
+
+ notesMemory = DataStorageMemoryItem.builder()
+ .setKey(NOTES_MEMORY)
+// .setExtensions("")
+ .setDirectories(app.getAppPath(IndexConstants.AV_INDEX_DIR).getAbsolutePath())
+ .createItem();
+ memoryItems.add(notesMemory);
+
+ tilesMemory = DataStorageMemoryItem.builder()
+ .setKey(TILES_MEMORY)
+// .setExtensions("")
+ .setDirectories(app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath())
+ .createItem();
+ memoryItems.add(tilesMemory);
+
+ otherMemory = DataStorageMemoryItem.builder()
+ .setKey(OTHER_MEMORY)
+ .createItem();
+ memoryItems.add(otherMemory);
}
public ArrayList<DataStorageMenuItem> getStorageItems() {
@@ -197,4 +248,190 @@ public class DataStorageItemsHolder {
public String getCurrentPath() {
return currentStoragePath;
}
+
+ public ArrayList<DataStorageMemoryItem> getMemoryInfoItems() {
+ return memoryItems;
+ }
+
+ public RefreshMemoryUsedInfo calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener) {
+ File rootDir = new File(currentStoragePath);
+ RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir, tilesMemory.getDirectories());
+ task.execute(mapsMemory, tracksMemory, notesMemory);
+ return task;
+ }
+
+ public RefreshMemoryUsedInfo calculateTilesMemoryUsed(UpdateMemoryInfoUIAdapter listener) {
+ File rootDir = new File(tilesMemory.getDirectories()[0]);
+ RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir);
+ task.execute(tilesMemory);
+ return task;
+ }
+
+ public static class RefreshMemoryUsedInfo extends AsyncTask<DataStorageMemoryItem, Void, Void> {
+ private UpdateMemoryInfoUIAdapter listener;
+ private File rootDir;
+ private DataStorageMemoryItem otherMemory;
+ private String[] directoriesToAvoid;
+
+ public RefreshMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener, DataStorageMemoryItem otherMemory, File rootDir, String... directoriesToAvoid) {
+ this.listener = listener;
+ this.otherMemory = otherMemory;
+ this.rootDir = rootDir;
+ this.directoriesToAvoid = directoriesToAvoid;
+ }
+
+ @Override
+ protected Void doInBackground(DataStorageMemoryItem... items) {
+ if (items.length == 1) {
+ DataStorageMemoryItem item = items[0];
+ item.addBytes(getDirectorySize(rootDir, item.getExtensions()));
+ } else {
+ calculateMultiTypes(items);
+ }
+ return null;
+ }
+
+ private void calculateMultiTypes(DataStorageMemoryItem[] items) {
+ File[] files = rootDir.listFiles();
+
+ for (File f : files) {
+ boolean matched = false;
+ if (f.isDirectory()) {
+ boolean avoid = false;
+ for (String directoryToAvoid : directoriesToAvoid) {
+ if (f.getAbsolutePath().equals(directoryToAvoid)) {
+ avoid = true;
+ break;
+ }
+ }
+ if (!avoid) {
+ for (DataStorageMemoryItem item : items) {
+ String[] directories = item.getDirectories();
+ if (directories != null) {
+ for (String directory : directories) {
+ if (f.getAbsolutePath().equals(directory)) {
+ item.addBytes(getDirectorySize(f, item.getExtensions()));
+ matched = true;
+ break;
+ }
+ }
+ }
+ }
+ if (!matched) {
+ otherMemory.addBytes(getDirectorySize(f, null));
+ }
+ }
+ } else if (f.isFile()) {
+ for (DataStorageMemoryItem item : items) {
+ String[] extensions = item.getExtensions();
+ if (extensions != null) {
+ for (String extension : extensions) {
+ if (f.getAbsolutePath().endsWith(extension)) {
+ item.addBytes(f.length());
+ matched = true;
+ break;
+ }
+ }
+ }
+ }
+ if (!matched) {
+ otherMemory.addBytes(f.length());
+ }
+ publishProgress();
+ }
+ }
+ }
+
+ private long getDirectorySize(File dir, String[] extensions) {
+ long bytes = 0;
+ if (dir.isDirectory()) {
+ File[] files = dir.listFiles();
+ for (File file : files) {
+ if (isCancelled()) {
+ break;
+ }
+ if (file.isDirectory()) {
+ bytes += getDirectorySize(file, extensions);
+ } else if (file.isFile()) {
+ //check file extension
+ boolean matched = false;
+ if (extensions != null) {
+ for (String extension : extensions) {
+ if (file.getName().endsWith(extension)) {
+ matched = true;
+ break;
+ }
+ }
+ } else {
+ matched = true;
+ }
+ if (matched) {
+ bytes += file.length();
+ } else {
+ otherMemory.addBytes(file.length());
+ }
+ publishProgress();
+ }
+ }
+ }
+ return bytes;
+ }
+
+ @Override
+ protected void onProgressUpdate(Void... values) {
+ super.onProgressUpdate(values);
+ if (listener != null) {
+ listener.onMemoryInfoUpdate();
+ }
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ if (listener != null) {
+ listener.onMemoryInfoUpdate();
+ }
+ }
+ }
+
+ public interface UpdateMemoryInfoUIAdapter {
+
+ void onMemoryInfoUpdate();
+
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ private DataStorageItemsHolder(Parcel in) {
+ menuItems = in.readArrayList(DataStorageMenuItem.class.getClassLoader());
+ currentDataStorage = in.readParcelable(DataStorageMenuItem.class.getClassLoader());
+ memoryItems = in.readArrayList(DataStorageMemoryItem.class.getClassLoader());
+ currentStorageType = in.readInt();
+ currentStoragePath = in.readString();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeArray(menuItems.toArray());
+ dest.writeParcelable(currentDataStorage, flags);
+ dest.writeArray(memoryItems.toArray());
+ dest.writeInt(currentStorageType);
+ dest.writeString(currentStoragePath);
+ }
+
+ public static final Parcelable.Creator<DataStorageItemsHolder> CREATOR = new Parcelable.Creator<DataStorageItemsHolder>() {
+
+ @Override
+ public DataStorageItemsHolder createFromParcel(Parcel source) {
+ return new DataStorageItemsHolder(source);
+ }
+
+ @Override
+ public DataStorageItemsHolder[] newArray(int size) {
+ return new DataStorageItemsHolder[size];
+ }
+ };
} \ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageMemoryItem.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageMemoryItem.java
new file mode 100644
index 0000000000..a13d87fab2
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageMemoryItem.java
@@ -0,0 +1,122 @@
+package net.osmand.plus.settings;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+public class DataStorageMemoryItem implements Parcelable {
+ private String key;
+ private String[] extensions;
+ private String[] directories;
+ private long usedMemoryBytes;
+
+ private DataStorageMemoryItem(String key, String[] extensions, long usedMemoryBytes, String[] directories) {
+ this.key = key;
+ this.extensions = extensions;
+ this.usedMemoryBytes = usedMemoryBytes;
+ this.directories = directories;
+ }
+
+ private DataStorageMemoryItem(Parcel in) {
+ key = in.readString();
+ in.readStringArray(extensions);
+ in.readStringArray(directories);
+ usedMemoryBytes = in.readLong();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public long getUsedMemoryBytes() {
+ return usedMemoryBytes;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public void setUsedMemoryBytes(long usedMemoryBytes) {
+ this.usedMemoryBytes = usedMemoryBytes;
+ }
+
+ public static DataStorageMemoryItemBuilder builder() {
+ return new DataStorageMemoryItemBuilder();
+ }
+
+ public String[] getExtensions() {
+ return extensions;
+ }
+
+ public void setExtensions(String[] extensions) {
+ this.extensions = extensions;
+ }
+
+ public String[] getDirectories() {
+ return directories;
+ }
+
+ public void setDirectories(String[] directories) {
+ this.directories = directories;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(key);
+ dest.writeStringArray(extensions);
+ dest.writeStringArray(directories);
+ dest.writeLong(usedMemoryBytes);
+ }
+
+ public static final Parcelable.Creator<DataStorageMemoryItem> CREATOR = new Parcelable.Creator<DataStorageMemoryItem>() {
+
+ @Override
+ public DataStorageMemoryItem createFromParcel(Parcel source) {
+ return new DataStorageMemoryItem(source);
+ }
+
+ @Override
+ public DataStorageMemoryItem[] newArray(int size) {
+ return new DataStorageMemoryItem[size];
+ }
+ };
+
+ public static class DataStorageMemoryItemBuilder {
+ private String key;
+ private String[] extensions;
+ private String[] directories;
+ private long usedMemoryBytes;
+
+ public DataStorageMemoryItemBuilder setKey(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public DataStorageMemoryItemBuilder setExtensions(String ... extensions) {
+ this.extensions = extensions;
+ return this;
+ }
+
+ public DataStorageMemoryItemBuilder setDirectories(String ... directories) {
+ this.directories = directories;
+ return this;
+ }
+
+ public DataStorageMemoryItemBuilder setUsedMemoryBytes(long usedMemoryBytes) {
+ this.usedMemoryBytes = usedMemoryBytes;
+ return this;
+ }
+
+ public DataStorageMemoryItem createItem() {
+ return new DataStorageMemoryItem(key, extensions, usedMemoryBytes, directories);
+ }
+ }
+
+ public void addBytes(long bytes) {
+ this.usedMemoryBytes += bytes;
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageMenuItem.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageMenuItem.java
index 548150089d..cd49cfd21d 100644
--- a/OsmAnd/src/net/osmand/plus/settings/DataStorageMenuItem.java
+++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageMenuItem.java
@@ -120,37 +120,37 @@ public class DataStorageMenuItem implements Parcelable, Cloneable {
@IdRes
private int iconResId;
- public DataStorageMenuItemBuilder buildKey(String key) {
+ public DataStorageMenuItemBuilder setKey(String key) {
this.key = key;
return this;
}
- public DataStorageMenuItemBuilder buildType(int type) {
+ public DataStorageMenuItemBuilder setType(int type) {
this.type = type;
return this;
}
- public DataStorageMenuItemBuilder buildTitle(String title) {
+ public DataStorageMenuItemBuilder setTitle(String title) {
this.title = title;
return this;
}
- public DataStorageMenuItemBuilder buildDescription(String description) {
+ public DataStorageMenuItemBuilder setDescription(String description) {
this.description = description;
return this;
}
- public DataStorageMenuItemBuilder buildDirectory(String directory) {
+ public DataStorageMenuItemBuilder setDirectory(String directory) {
this.directory = directory;
return this;
}
- public DataStorageMenuItemBuilder buildIconResId(int iconResId) {
+ public DataStorageMenuItemBuilder setIconResId(int iconResId) {
this.iconResId = iconResId;
return this;
}
- public DataStorageMenuItem build() {
+ public DataStorageMenuItem createItem() {
return new DataStorageMenuItem(key, type, title, description, directory, iconResId);
}
}
@@ -158,12 +158,12 @@ public class DataStorageMenuItem implements Parcelable, Cloneable {
@Override
public Object clone() throws CloneNotSupportedException {
return DataStorageMenuItem.builder()
- .buildKey(this.key)
- .buildTitle(this.title)
- .buildDescription(this.description)
- .buildDirectory(this.directory)
- .buildType(this.type)
- .buildIconResId(this.iconResId)
- .build();
+ .setKey(this.key)
+ .setTitle(this.title)
+ .setDescription(this.description)
+ .setDirectory(this.directory)
+ .setType(this.type)
+ .setIconResId(this.iconResId)
+ .createItem();
}
} \ No newline at end of file