Search in sources :

Example 1 with ExportBackupTask

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

the class HeaderStatusViewHolder method bindView.

public void bindView(@NonNull BackupStatusAdapter adapter, @NonNull BackupStatus status, boolean nightMode) {
    OsmandApplication app = (OsmandApplication) itemView.getContext().getApplicationContext();
    NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
    ExportBackupTask exportTask = settingsHelper.getExportTask(BACKUP_ITEMS_KEY);
    if (exportTask != null) {
        title.setText(R.string.uploading);
        icon.setImageDrawable(getContentIcon(R.drawable.ic_action_cloud_upload));
        int progress = exportTask.getGeneralProgress();
        int maxProgress = (int) exportTask.getMaxProgress();
        int percentage = maxProgress != 0 ? BasicProgressAsyncTask.normalizeProgress(progress * 100 / maxProgress) : 0;
        String uploading = app.getString(R.string.local_openstreetmap_uploading);
        title.setText(app.getString(R.string.ltr_or_rtl_combine_via_space, uploading, percentage + "%"));
        progressBar.setMax(maxProgress);
        progressBar.setProgress(progress);
        AndroidUiHelper.updateVisibility(description, false);
        AndroidUiHelper.updateVisibility(progressBar, true);
    } else {
        description.setText(status.statusTitleRes);
        icon.setImageDrawable(getContentIcon(status.statusIconRes));
        String backupTime = MainSettingsFragment.getLastBackupTimeDescription(app);
        if (Algorithms.isEmpty(backupTime)) {
            title.setText(R.string.shared_string_never);
        } else {
            title.setText(backupTime);
        }
        AndroidUiHelper.updateVisibility(description, true);
        AndroidUiHelper.updateVisibility(progressBar, false);
    }
    itemView.setOnClickListener(v -> {
        adapter.toggleUploadItemsVisibility();
        adjustIndicator(app, itemView, adapter.isUploadItemsVisible(), nightMode);
    });
    adjustIndicator(app, itemView, adapter.isUploadItemsVisible(), nightMode);
    setupSelectableBackground(itemView.findViewById(R.id.header_container));
    AndroidUiHelper.updateVisibility(itemView.findViewById(R.id.explicit_indicator), status != BackupStatus.BACKUP_COMPLETE);
}
Also used : NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) OsmandApplication(net.osmand.plus.OsmandApplication) ExportBackupTask(net.osmand.plus.backup.ExportBackupTask)

Example 2 with ExportBackupTask

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

the class ItemViewHolder method setupItemView.

protected void setupItemView(@NonNull String exportKey, @NonNull SettingsItem item, boolean deleteItem) {
    OsmandApplication app = getApplication();
    String publicName = item.getPublicName(app);
    if (item instanceof FileSettingsItem) {
        FileSettingsItem settingsItem = (FileSettingsItem) item;
        if (settingsItem.getSubtype() == FileSubtype.VOICE) {
            publicName += " (" + app.getString(R.string.shared_string_recorded) + ")";
        } else if (settingsItem.getSubtype() == FileSubtype.TTS_VOICE) {
            publicName += " (" + app.getString(R.string.tts_title) + ")";
        }
    }
    title.setText(publicName);
    String fileName = BackupHelper.getItemFileName(item);
    String summary = app.getString(R.string.last_backup);
    UploadedFileInfo info = app.getBackupHelper().getDbHelper().getUploadedFileInfo(item.getType().name(), fileName);
    if (info != null) {
        String time = OsmAndFormatter.getFormattedPassedTime(app, info.getUploadTime(), app.getString(R.string.shared_string_never));
        description.setText(app.getString(R.string.ltr_or_rtl_combine_via_colon, summary, time));
    } else {
        description.setText(app.getString(R.string.ltr_or_rtl_combine_via_colon, summary, app.getString(R.string.shared_string_never)));
    }
    icon.setImageDrawable(getItemIcon(item));
    NetworkSettingsHelper settingsHelper = app.getNetworkSettingsHelper();
    ImportBackupTask importTask = settingsHelper.getImportTask(exportKey);
    ExportBackupTask exportTask = settingsHelper.getExportTask(exportKey);
    if (exportTask == null && importTask == null) {
        AndroidUiHelper.updateVisibility(secondIcon, deleteItem);
        AndroidUiHelper.updateVisibility(progressBar, false);
        secondIcon.setImageDrawable(getContentIcon(deleteItem ? R.drawable.ic_action_delete_dark : R.drawable.ic_action_cloud_done));
    } else {
        ItemProgressInfo progressInfo = null;
        if (exportTask != null) {
            progressInfo = exportTask.getItemProgressInfo(item.getType().name(), fileName);
        }
        if (importTask != null) {
            progressInfo = importTask.getItemProgressInfo(item.getType().name(), fileName);
        }
        setupProgress(progressInfo);
    }
    itemView.setTag(item);
}
Also used : NetworkSettingsHelper(net.osmand.plus.backup.NetworkSettingsHelper) ImportBackupTask(net.osmand.plus.backup.ImportBackupTask) OsmandApplication(net.osmand.plus.OsmandApplication) ItemProgressInfo(net.osmand.plus.backup.ExportBackupTask.ItemProgressInfo) FileSettingsItem(net.osmand.plus.settings.backend.backup.items.FileSettingsItem) UploadedFileInfo(net.osmand.plus.backup.BackupDbHelper.UploadedFileInfo) ExportBackupTask(net.osmand.plus.backup.ExportBackupTask)

Example 3 with ExportBackupTask

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

the class ConflictViewHolder method updateButtonsState.

private void updateButtonsState(@NonNull NetworkSettingsHelper helper, @NonNull String fileName) {
    ImportBackupTask importTask = helper.getImportTask(fileName);
    ExportBackupTask exportTask = helper.getExportTask(fileName);
    boolean enabled = exportTask == null && importTask == null;
    serverButton.setEnabled(enabled);
    localVersionButton.setEnabled(enabled);
}
Also used : ImportBackupTask(net.osmand.plus.backup.ImportBackupTask) ExportBackupTask(net.osmand.plus.backup.ExportBackupTask)

Aggregations

ExportBackupTask (net.osmand.plus.backup.ExportBackupTask)3 OsmandApplication (net.osmand.plus.OsmandApplication)2 ImportBackupTask (net.osmand.plus.backup.ImportBackupTask)2 NetworkSettingsHelper (net.osmand.plus.backup.NetworkSettingsHelper)2 UploadedFileInfo (net.osmand.plus.backup.BackupDbHelper.UploadedFileInfo)1 ItemProgressInfo (net.osmand.plus.backup.ExportBackupTask.ItemProgressInfo)1 FileSettingsItem (net.osmand.plus.settings.backend.backup.items.FileSettingsItem)1