Search in sources :

Example 1 with BackupInfo

use of net.osmand.plus.backup.BackupInfo 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 2 with BackupInfo

use of net.osmand.plus.backup.BackupInfo in project Osmand by osmandapp.

the class RestoreSettingsFragment method collectAndReadSettings.

private void collectAndReadSettings() {
    BackupCollectListener collectListener = new BackupCollectListener() {

        @Nullable
        private SettingsItem getRestoreItem(@NonNull List<SettingsItem> items, @NonNull RemoteFile remoteFile) {
            for (SettingsItem item : items) {
                if (BackupHelper.applyItem(item, remoteFile.getType(), remoteFile.getName())) {
                    return item;
                }
            }
            return null;
        }

        @Override
        public void onBackupCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items, @NonNull List<RemoteFile> remoteFiles) {
            FragmentActivity activity = getActivity();
            if (AndroidUtils.isActivityNotDestroyed(activity)) {
                toolbarLayout.setTitle(getString(R.string.restore_from_osmand_cloud));
                description.setText(R.string.choose_what_to_restore);
                buttonsContainer.setVisibility(View.VISIBLE);
                progressBar.setVisibility(View.GONE);
                if (succeed) {
                    PrepareBackupResult backup = app.getBackupHelper().getBackup();
                    BackupInfo info = backup.getBackupInfo();
                    Set<SettingsItem> itemsForRestore = new HashSet<>();
                    if (info != null) {
                        for (RemoteFile remoteFile : info.filesToDownload) {
                            SettingsItem restoreItem = getRestoreItem(items, remoteFile);
                            if (restoreItem != null) {
                                itemsForRestore.add(restoreItem);
                            }
                        }
                    }
                    setSettingsItems(new ArrayList<>(itemsForRestore));
                    dataList = SettingsHelper.getSettingsToOperateByCategory(settingsItems, false, false);
                    adapter.updateSettingsItems(dataList, selectedItemsMap);
                }
            }
        }
    };
    try {
        settingsHelper.collectSettings(RESTORE_ITEMS_KEY, true, collectListener);
    } catch (IllegalStateException e) {
        LOG.error(e.getMessage(), e);
    }
}
Also used : BackupCollectListener(net.osmand.plus.backup.NetworkSettingsHelper.BackupCollectListener) BackupInfo(net.osmand.plus.backup.BackupInfo) FragmentActivity(androidx.fragment.app.FragmentActivity) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) NonNull(androidx.annotation.NonNull) PrepareBackupResult(net.osmand.plus.backup.PrepareBackupResult) ArrayList(java.util.ArrayList) List(java.util.List) RemoteFile(net.osmand.plus.backup.RemoteFile) HashSet(java.util.HashSet)

Aggregations

NonNull (androidx.annotation.NonNull)2 List (java.util.List)2 BackupInfo (net.osmand.plus.backup.BackupInfo)2 PrepareBackupResult (net.osmand.plus.backup.PrepareBackupResult)2 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)2 View (android.view.View)1 Nullable (androidx.annotation.Nullable)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 PlatformUtil (net.osmand.PlatformUtil)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 R (net.osmand.plus.R)1 Version (net.osmand.plus.Version)1 MapActivity (net.osmand.plus.activities.MapActivity)1 NetworkSettingsHelper (net.osmand.plus.backup.NetworkSettingsHelper)1 BACKUP_ITEMS_KEY (net.osmand.plus.backup.NetworkSettingsHelper.BACKUP_ITEMS_KEY)1 BackupCollectListener (net.osmand.plus.backup.NetworkSettingsHelper.BackupCollectListener)1 BackupExportListener (net.osmand.plus.backup.NetworkSettingsHelper.BackupExportListener)1