Search in sources :

Example 11 with SettingsItem

use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.

the class ActionButtonViewHolder method bindView.

public void bindView(@NonNull MapActivity mapActivity, @NonNull PrepareBackupResult backup, @Nullable BackupExportListener exportListener, boolean uploadItemsVisible, boolean nightMode) {
    OsmandApplication app = (OsmandApplication) itemView.getContext().getApplicationContext();
    BackupStatus status = BackupStatus.getBackupStatus(app, backup);
    NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
    if (settingsHelper.isBackupExporting()) {
        actionButton.setOnClickListener(v -> {
            settingsHelper.cancelImport();
            settingsHelper.cancelExport();
        });
        UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.shared_string_cancel);
    } else if (status == BackupStatus.MAKE_BACKUP || status == BackupStatus.CONFLICTS) {
        actionButton.setOnClickListener(v -> {
            try {
                BackupInfo info = backup.getBackupInfo();
                List<SettingsItem> items = info.itemsToUpload;
                if (!items.isEmpty() || !Algorithms.isEmpty(info.filteredFilesToDelete)) {
                    settingsHelper.exportSettings(BACKUP_ITEMS_KEY, items, info.itemsToDelete, exportListener);
                }
            } catch (IllegalStateException e) {
                log.error(e.getMessage(), e);
            }
        });
        UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.backup_now);
    } else if (status == BackupStatus.NO_INTERNET_CONNECTION || status == BackupStatus.ERROR) {
        actionButton.setOnClickListener(v -> app.getBackupHelper().prepareBackup());
        UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.retry);
    } else if (status == BackupStatus.SUBSCRIPTION_EXPIRED) {
        actionButton.setOnClickListener(v -> {
            if (Version.isInAppPurchaseSupported()) {
                OsmAndProPlanFragment.showInstance(mapActivity);
            } else {
                PromoCodeBottomSheet.showInstance(mapActivity.getSupportFragmentManager());
            }
        });
        UiUtilities.setupDialogButton(nightMode, actionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.renew_subscription);
    }
    AndroidUiHelper.updateVisibility(divider, uploadItemsVisible);
}
Also used : NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) Version(net.osmand.plus.Version) NonNull(androidx.annotation.NonNull) BACKUP_ITEMS_KEY(net.osmand.plus.backup.NetworkSettingsHelper.BACKUP_ITEMS_KEY) R(net.osmand.plus.R) AndroidUiHelper(net.osmand.plus.helpers.AndroidUiHelper) DialogButtonType(net.osmand.plus.utils.UiUtilities.DialogButtonType) BackupExportListener(net.osmand.plus.backup.NetworkSettingsHelper.BackupExportListener) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) OsmandApplication(net.osmand.plus.OsmandApplication) BackupInfo(net.osmand.plus.backup.BackupInfo) PrepareBackupResult(net.osmand.plus.backup.PrepareBackupResult) UiUtilities(net.osmand.plus.utils.UiUtilities) List(java.util.List) Nullable(androidx.annotation.Nullable) OsmAndProPlanFragment(net.osmand.plus.chooseplan.OsmAndProPlanFragment) View(android.view.View) Log(org.apache.commons.logging.Log) RecyclerView(androidx.recyclerview.widget.RecyclerView) PlatformUtil(net.osmand.PlatformUtil) Algorithms(net.osmand.util.Algorithms) MapActivity(net.osmand.plus.activities.MapActivity) NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) BackupInfo(net.osmand.plus.backup.BackupInfo) OsmandApplication(net.osmand.plus.OsmandApplication) List(java.util.List)

Example 12 with SettingsItem

use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.

the class BackupStatusAdapter method onImportFinished.

@Override
public void onImportFinished(boolean succeed, boolean needRestart, @NonNull List<SettingsItem> settingsItems) {
    for (SettingsItem settingsItem : settingsItems) {
        String fileName = BackupHelper.getItemFileName(settingsItem);
        Object item = getBackupItem(settingsItem.getType().name(), fileName);
        if (item != null) {
            notifyItemChanged(items.indexOf(item));
        }
    }
}
Also used : SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem)

Example 13 with SettingsItem

use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.

the class ConflictViewHolder method bindView.

public void bindView(@NonNull Pair<LocalFile, RemoteFile> pair, @Nullable BackupExportListener exportListener, @Nullable ImportListener importListener, boolean nightMode) {
    OsmandApplication app = getApplication();
    NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
    SettingsItem item = pair.first.item;
    String fileName = BackupHelper.getItemFileName(item);
    setupItemView(fileName, item, false);
    updateButtonsState(settingsHelper, fileName);
    localVersionButton.setOnClickListener(v -> {
        try {
            settingsHelper.exportSettings(fileName, exportListener, item);
        } catch (IllegalStateException e) {
            log.error(e.getMessage(), e);
        }
        updateButtonsState(settingsHelper, fileName);
    });
    serverButton.setOnClickListener(v -> {
        try {
            SettingsItem settingsItem = pair.second.item;
            settingsItem.setShouldReplace(true);
            settingsHelper.importSettings(fileName, Collections.singletonList(settingsItem), true, importListener);
        } catch (IllegalStateException e) {
            log.error(e.getMessage(), e);
        }
        updateButtonsState(settingsHelper, fileName);
    });
    AndroidUiHelper.updateVisibility(serverButton, true);
    AndroidUiHelper.updateVisibility(localVersionButton, true);
    UiUtilities.setupDialogButton(nightMode, localVersionButton, DialogButtonType.SECONDARY_ACTIVE, R.string.upload_local_version);
    UiUtilities.setupDialogButton(nightMode, serverButton, DialogButtonType.SECONDARY_ACTIVE, R.string.download_server_version);
}
Also used : NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) OsmandApplication(net.osmand.plus.OsmandApplication) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem)

Example 14 with SettingsItem

use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.

the class BackupInfo method createFilteredFilesToMerge.

private void createFilteredFilesToMerge(@NonNull OsmandApplication app) {
    List<Pair<LocalFile, RemoteFile>> files = new ArrayList<>();
    Set<SettingsItem> items = new HashSet<>();
    BackupHelper helper = app.getBackupHelper();
    for (Pair<LocalFile, RemoteFile> pair : filesToMerge) {
        SettingsItem item = pair.first.item;
        if (!items.contains(item)) {
            ExportSettingsType exportType = ExportSettingsType.getExportSettingsTypeForRemoteFile(pair.second);
            if (exportType != null && helper.getBackupTypePref(exportType).get()) {
                files.add(pair);
                items.add(item);
            }
        }
    }
    filteredFilesToMerge = files;
}
Also used : SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) ArrayList(java.util.ArrayList) Pair(android.util.Pair) HashSet(java.util.HashSet) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType)

Example 15 with SettingsItem

use of net.osmand.plus.settings.backend.backup.items.SettingsItem in project Osmand by osmandapp.

the class ExportBackupTask method getEstimatedItemsSize.

private long getEstimatedItemsSize() {
    long size = 0;
    BackupHelper backupHelper = helper.getApp().getBackupHelper();
    for (SettingsItem item : exporter.getItems()) {
        if (item instanceof FileSettingsItem) {
            List<File> filesToUpload = backupHelper.collectItemFilesForUpload((FileSettingsItem) item);
            for (File file : filesToUpload) {
                size += file.length() + APPROXIMATE_FILE_SIZE_BYTES;
            }
        } else {
            size += item.getEstimatedSize() + APPROXIMATE_FILE_SIZE_BYTES;
        }
    }
    Map<String, RemoteFile> remoteFilesMap = backupHelper.getBackup().getRemoteFiles(PrepareBackupResult.RemoteFilesType.UNIQUE);
    if (remoteFilesMap != null) {
        List<SettingsItem> itemsToDelete = exporter.getItemsToDelete();
        for (RemoteFile remoteFile : remoteFilesMap.values()) {
            for (SettingsItem item : itemsToDelete) {
                if (item.equals(remoteFile.item)) {
                    size += APPROXIMATE_FILE_SIZE_BYTES;
                }
            }
        }
        List<SettingsItem> oldItemsToDelete = exporter.getOldItemsToDelete();
        for (RemoteFile remoteFile : remoteFilesMap.values()) {
            for (SettingsItem item : oldItemsToDelete) {
                SettingsItem remoteFileItem = remoteFile.item;
                if (remoteFileItem != null && item.getType() == remoteFileItem.getType()) {
                    String itemFileName = item.getFileName();
                    if (itemFileName != null && itemFileName.startsWith("/")) {
                        itemFileName = itemFileName.substring(1);
                    }
                    if (Algorithms.stringsEqual(itemFileName, remoteFileItem.getFileName())) {
                        size += APPROXIMATE_FILE_SIZE_BYTES;
                    }
                }
            }
        }
    }
    return size;
}
Also used : FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) File(java.io.File)

Aggregations

SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)37 ArrayList (java.util.ArrayList)19 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)18 File (java.io.File)11 List (java.util.List)11 IOException (java.io.IOException)10 GpxSettingsItem (net.osmand.plus.settings.backend.backup.items.GpxSettingsItem)10 ProfileSettingsItem (net.osmand.plus.settings.backend.backup.items.ProfileSettingsItem)10 NonNull (androidx.annotation.NonNull)8 AvoidRoadsSettingsItem (net.osmand.plus.settings.backend.backup.items.AvoidRoadsSettingsItem)7 MapSourcesSettingsItem (net.osmand.plus.settings.backend.backup.items.MapSourcesSettingsItem)7 PoiUiFiltersSettingsItem (net.osmand.plus.settings.backend.backup.items.PoiUiFiltersSettingsItem)7 QuickActionsSettingsItem (net.osmand.plus.settings.backend.backup.items.QuickActionsSettingsItem)7 Nullable (androidx.annotation.Nullable)6 HashMap (java.util.HashMap)6 PluginSettingsItem (net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)6 HashSet (java.util.HashSet)5 FileInputStream (java.io.FileInputStream)4 FragmentActivity (androidx.fragment.app.FragmentActivity)3 Map (java.util.Map)3