Skip to content

Commit

Permalink
Fixed exporter, added translations
Browse files Browse the repository at this point in the history
  • Loading branch information
dgudim committed Jan 14, 2024
1 parent 4c2d0e3 commit b23c2de
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

import static prototype.xd.scheduler.entities.settings_entries.SettingsEntryType.IMPORT_EXPORT_SETTINGS;
import static prototype.xd.scheduler.utilities.Logger.logException;
import static prototype.xd.scheduler.utilities.Static.ENTRIES_FILE;
import static prototype.xd.scheduler.utilities.Static.ENTRIES_FILE_BACKUP;
import static prototype.xd.scheduler.utilities.Static.GROUPS_FILE;
import static prototype.xd.scheduler.utilities.Static.GROUPS_FILE_BACKUP;
import static prototype.xd.scheduler.utilities.Static.SETTINGS_FILE;
import static prototype.xd.scheduler.utilities.Static.SETTINGS_FILE_BACKUP;
import static prototype.xd.scheduler.utilities.Utilities.displayToast;
import static prototype.xd.scheduler.utilities.Utilities.getFile;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.net.Uri;

import androidx.activity.result.ActivityResultLauncher;
Expand All @@ -19,13 +26,14 @@
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Map;

import prototype.xd.scheduler.R;
import prototype.xd.scheduler.databinding.ImportExportSettingsEntryBinding;
import prototype.xd.scheduler.utilities.DateManager;
import prototype.xd.scheduler.utilities.Static;
import prototype.xd.scheduler.utilities.Utilities;
import prototype.xd.scheduler.utilities.misc.ContextWrapper;
import prototype.xd.scheduler.utilities.misc.SettingsExporter;
import prototype.xd.scheduler.utilities.services.BackgroundSetterService;

public class ImportExportSettingsEntryConfig extends SettingsEntryConfig {
Expand Down Expand Up @@ -60,13 +68,20 @@ public int getRecyclerViewType() {
public static void notifyFileChosen(@NonNull ContextWrapper wrapper, @Nullable Uri uri) {
wrapper.uriToStream(uri, InputStream.class, stream -> {
File tempFile = getFile(Static.EXPORT_FILE);
// Copy from user's directory to internal
Files.copy(stream, tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);

// Extract everything
try (var zip = new ZipFile(tempFile)) {
zip.extractAll(wrapper.context.getExternalFilesDir(null).getPath());
}

SettingsExporter.importSettings();
// Load prefs
SharedPreferences.Editor editor = Static.clearAll();
Map<String, ?> prefs = Utilities.loadObjectWithBackup(SETTINGS_FILE, SETTINGS_FILE_BACKUP);
prefs.forEach((key, value) -> Static.putAnyEditor(editor, key, value));
// Overwrite immediately
editor.commit();

displayToast(wrapper.context, R.string.import_settings_successful);
try {
Expand All @@ -90,15 +105,22 @@ public static void notifySaveLocationChosen(@NonNull ContextWrapper wrapper, @Nu
File tempFile = getFile(Static.EXPORT_FILE);
Files.deleteIfExists(tempFile.toPath());
try (var zip = new ZipFile(tempFile)) {
zip.addFile(SettingsExporter.exportSettings());
// Add preferences
zip.addFile(Utilities.saveObjectWithBackup(SETTINGS_FILE, SETTINGS_FILE_BACKUP, Static.getAll()));
zip.addFile(getFile(GROUPS_FILE));
zip.addFile(getFile(GROUPS_FILE_BACKUP));
zip.addFile(getFile(ENTRIES_FILE));
zip.addFile(getFile(ENTRIES_FILE_BACKUP));

// Add all backgrounds
for (String bgName : DateManager.BG_NAMES_ROOT) {
File bgFile = getFile(bgName);
if (bgFile.exists()) {
zip.addFile(bgFile);
}
}

// Copy from internal temp file to target
Files.copy(tempFile.toPath(), stream);

displayToast(wrapper.context, R.string.export_settings_successful);
Expand Down

This file was deleted.

7 changes: 7 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@
<string name="global_events_show_hint">"Позиция надписи “Глобальный” "</string>
<string name="global_events_description">События, которые видны на всех днях</string>
<string name="event_created_message">Событие создано</string>
<string name="event_saved_message">Событие сохранено</string>
<string name="event_deleted_message">Событие удалено</string>
<string name="settings_effects_glow">Добавить свечение к прозрачности</string>
<string name="settings_effects_highlight_edges">Выделить внутренние края</string>
<string name="recurring">Повторяется</string>
<string name="action_view_calendar_events">Посмотреть события календаля</string>
<string name="title_all_calendar_events">Все события календаря</string>
<string name="title_all_calendar_events_description">Это все события из календаря</string>
<string name="title_edit_events_with_color">Настройки для определенных цветов</string>
<string name="title_edit_events_with_color_description">В календаре могут быть события разного цвета, здесь можно задать отдельные стили для каждого цвета.</string>
</resources>
7 changes: 7 additions & 0 deletions app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,14 @@
<string name="global_events_show_front">Перед подією</string>
<string name="global_events_show_hidden">Заховано</string>
<string name="event_created_message">Подія створена</string>
<string name="event_saved_message">Подія збережена</string>
<string name="event_deleted_message">Подія видалена</string>
<string name="settings_effects_glow">Додати свічення до прозорості</string>
<string name="settings_effects_highlight_edges">Виділити внутрішні краї</string>
<string name="recurring">Повторюється</string>
<string name="action_view_calendar_events">Подивитись події календалю</string>
<string name="title_all_calendar_events">Усі події календаря</string>
<string name="title_all_calendar_events_description">Це всі події з календаря</string>
<string name="title_edit_events_with_color">Налаштування для певних кольорів</string>
<string name="title_edit_events_with_color_description">У календарі можуть бути події різних кольорів, тут ви можете встановити окремі стилі для кожного кольору</string>
</resources>

0 comments on commit b23c2de

Please sign in to comment.