Search in sources :

Example 1 with BACKUP_ITEMS_KEY

use of net.osmand.plus.backup.NetworkSettingsHelper.BACKUP_ITEMS_KEY 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)

Aggregations

View (android.view.View)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 List (java.util.List)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 BackupInfo (net.osmand.plus.backup.BackupInfo)1 NetworkSettingsHelper (net.osmand.plus.backup.NetworkSettingsHelper)1 BACKUP_ITEMS_KEY (net.osmand.plus.backup.NetworkSettingsHelper.BACKUP_ITEMS_KEY)1 BackupExportListener (net.osmand.plus.backup.NetworkSettingsHelper.BackupExportListener)1 PrepareBackupResult (net.osmand.plus.backup.PrepareBackupResult)1 OsmAndProPlanFragment (net.osmand.plus.chooseplan.OsmAndProPlanFragment)1 AndroidUiHelper (net.osmand.plus.helpers.AndroidUiHelper)1 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)1 UiUtilities (net.osmand.plus.utils.UiUtilities)1 DialogButtonType (net.osmand.plus.utils.UiUtilities.DialogButtonType)1