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 @@ + + + + + + + + + + \ 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 @@ + + + + + + + + + + \ 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 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 7889f194c2..e0ad49319c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,9 +11,17 @@ Thx - Hardy --> + Calcutale + OsmAnd Usage + Tiles + Maps + %1$s TB + %1$s GB + %1$s MB + %1$s KB Move OsmAnd data files to the new destination?\n%1$s > %2$s %1$s • Used %2$s GB - Free %1$s • %2$s / %3$s GB + Free %1$s GB • Total %2$s GB Enter path to the folder Select folder Paste path to the folder with OsmAnd data 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 @@ + + + + + + + + + + + + + + menuItems; + private ArrayList memoryItems; private ArrayList 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) { @@ -173,6 +194,13 @@ public class DataStorageFragment extends BaseSettingsFragment { return false; } + @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); @@ -180,7 +208,11 @@ public class DataStorageFragment extends BaseSettingsFragment { 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,15 +254,59 @@ 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) { //selection set up for (CheckBoxPreference preference : dataStorageRadioButtonsGroup) { @@ -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 { protected WeakReference activity; diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageItemsHolder.java index 089bf5c448..8029cce071 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 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 menuItems = new ArrayList<>(); private DataStorageMenuItem currentDataStorage; private DataStorageMenuItem manuallySpecified; + private ArrayList 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; @@ -70,9 +82,9 @@ public class DataStorageItemsHolder { DataStorageMenuItem internalStorageItem = DataStorageMenuItem.builder() .buildKey(INTERNAL_STORAGE) - .buildTitle(getString(R.string.storage_directory_internal_app)) + .buildTitle(app.getString(R.string.storage_directory_internal_app)) .buildDirectory(path) - .buildDescription(getString(R.string.internal_app_storage_description)) + .buildDescription(app.getString(R.string.internal_app_storage_description)) .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_INTERNAL_FILE) .buildIconResId(iconId) .build(); @@ -85,7 +97,7 @@ public class DataStorageItemsHolder { DataStorageMenuItem sharedStorageItem = DataStorageMenuItem.builder() .buildKey(SHARED_STORAGE) - .buildTitle(getString(R.string.storage_directory_shared)) + .buildTitle(app.getString(R.string.storage_directory_shared)) .buildDirectory(path) .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_DEFAULT) .buildIconResId(iconId) @@ -104,7 +116,7 @@ public class DataStorageItemsHolder { iconId = getIconForStorageType(dir); DataStorageMenuItem externalStorageItem = DataStorageMenuItem.builder() .buildKey(EXTERNAL_STORAGE + i) - .buildTitle(getString(R.string.storage_directory_external) + " " + i) + .buildTitle(app.getString(R.string.storage_directory_external) + " " + i) .buildDirectory(path) .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_EXTERNAL_FILE) .buildIconResId(iconId) @@ -126,7 +138,7 @@ public class DataStorageItemsHolder { iconId = getIconForStorageType(dir); DataStorageMenuItem multiuserStorageItem = DataStorageMenuItem.builder() .buildKey(MULTIUSER_STORAGE + i) - .buildTitle(getString(R.string.storage_directory_multiuser) + " " + i) + .buildTitle(app.getString(R.string.storage_directory_multiuser) + " " + i) .buildDirectory(path) .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_OBB) .buildIconResId(iconId) @@ -140,7 +152,7 @@ public class DataStorageItemsHolder { //manually specified storage manuallySpecified = DataStorageMenuItem.builder() .buildKey(MANUALLY_SPECIFIED) - .buildTitle(getString(R.string.storage_directory_manual)) + .buildTitle(app.getString(R.string.storage_directory_manual)) .buildDirectory(currentStoragePath) .buildType(OsmandSettings.EXTERNAL_STORAGE_TYPE_SPECIFIED) .buildIconResId(R.drawable.ic_action_folder) @@ -150,10 +162,49 @@ public class DataStorageItemsHolder { if (currentDataStorage == null) { currentDataStorage = manuallySpecified; } + + initMemoryUsed(app); } - private String getString(int resId) { - return app.getString(resId); + private void initMemoryUsed(OsmandApplication app) { + mapsMemory = DataStorageMemoryItem.builder() + .buildKey(MAPS_MEMORY) + .buildExtensions(IndexConstants.BINARY_MAP_INDEX_EXT, IndexConstants.BINARY_MAP_INDEX_EXT_ZIP) + .buildDirectories( + 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()) + .build(); + memoryItems.add(mapsMemory); + + tracksMemory = DataStorageMemoryItem.builder() + .buildKey(TRACKS_MEMORY) +// .buildExtensions(".gpx", ".gpx.bz2") + .buildDirectories(app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath()) + .build(); + memoryItems.add(tracksMemory); + + notesMemory = DataStorageMemoryItem.builder() + .buildKey(NOTES_MEMORY) +// .buildExtensions("") + .buildDirectories(app.getAppPath(IndexConstants.AV_INDEX_DIR).getAbsolutePath()) + .build(); + memoryItems.add(notesMemory); + + tilesMemory = DataStorageMemoryItem.builder() + .buildKey(TILES_MEMORY) +// .buildExtensions("") + .buildDirectories(app.getAppPath(IndexConstants.TILES_INDEX_DIR).getAbsolutePath()) + .build(); + memoryItems.add(tilesMemory); + + otherMemory = DataStorageMemoryItem.builder() + .buildKey(OTHER_MEMORY) + .build(); + memoryItems.add(otherMemory); } public ArrayList getStorageItems() { @@ -197,4 +248,188 @@ public class DataStorageItemsHolder { public String getCurrentPath() { return currentStoragePath; } + + public ArrayList 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 { + 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()); + } + } + } + } + + 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()); + } + } + } + } + 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 CREATOR = new Parcelable.Creator() { + + @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..246da484bc --- /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 CREATOR = new Parcelable.Creator() { + + @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 buildKey(String key) { + this.key = key; + return this; + } + + public DataStorageMemoryItemBuilder buildExtensions(String ... extensions) { + this.extensions = extensions; + return this; + } + + public DataStorageMemoryItemBuilder buildDirectories(String ... directories) { + this.directories = directories; + return this; + } + + public DataStorageMemoryItemBuilder buildUsedMemoryBytes(long usedMemoryBytes) { + this.usedMemoryBytes = usedMemoryBytes; + return this; + } + + public DataStorageMemoryItem build() { + return new DataStorageMemoryItem(key, extensions, usedMemoryBytes, directories); + } + } + + public void addBytes(long bytes) { + this.usedMemoryBytes += bytes; + } +}