From 7302edac089182e0c8d1564d2208c71662290e66 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:38:07 -0400 Subject: Different save options when saving the online theme. --- .../activities/CustomizeThemeActivity.java | 83 ++++++++++++++-------- app/src/main/res/values/arrays.xml | 6 ++ app/src/main/res/values/strings.xml | 11 +-- 3 files changed, 65 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java index 82a152b3..3601f109 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.activities; +import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; @@ -248,38 +249,29 @@ public class CustomizeThemeActivity extends BaseActivity { CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName); if (onlineCustomThemeMetadata != null && onlineCustomThemeMetadata.username.equals(accountName)) { // This custom theme is uploaded by the current user + final int[] option = {0}; new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) - .setTitle(R.string.override_online_theme_question) - .setMessage(R.string.override_online_theme_message) - .setPositiveButton(R.string.yes, (dialogInterface, i) -> { - onlineCustomThemesRetrofit.create(OnlineCustomThemeAPI.class).modifyTheme( - onlineCustomThemeMetadata.id, customTheme.name, - customTheme.getJSONModel(), - ('#' + Integer.toHexString(customTheme.colorPrimary)).toUpperCase() - ).enqueue(new Callback<>() { - @Override - public void onResponse(@NonNull Call call, @NonNull Response response) { - if (response.isSuccessful()) { - Toast.makeText(CustomizeThemeActivity.this, R.string.online_theme_modified, Toast.LENGTH_SHORT).show(); - Intent returnIntent = new Intent(); - returnIntent.putExtra(RETURN_EXTRA_INDEX_IN_THEME_LIST, getIntent().getIntExtra(EXTRA_INDEX_IN_THEME_LIST, -1)); - returnIntent.putExtra(RETURN_EXTRA_THEME_NAME, customTheme.name); - returnIntent.putExtra(RETURN_EXTRA_PRIMARY_COLOR, '#' + Integer.toHexString(customTheme.colorPrimary)); - setResult(RESULT_OK, returnIntent); - - finish(); - } else { - Toast.makeText(CustomizeThemeActivity.this, R.string.upload_theme_failed, Toast.LENGTH_SHORT).show(); - } - } - - @Override - public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { - Toast.makeText(CustomizeThemeActivity.this, R.string.upload_theme_failed, Toast.LENGTH_SHORT).show(); - } - }); + .setTitle(R.string.save_theme_options_title) + //.setMessage(R.string.save_theme_options_message) + .setSingleChoiceItems(R.array.save_theme_options, 0, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + option[0] = which; + } + }) + .setPositiveButton(R.string.ok, (dialogInterface, which) -> { + switch (option[0]) { + case 0: + saveThemeLocally(customTheme); + break; + case 1: + saveThemeOnline(customTheme); + break; + case 2: + saveThemeLocally(customTheme); + saveThemeOnline(customTheme); + } }) - .setNeutralButton(R.string.save_to_local, ((dialog, which) -> saveThemeLocally(customTheme))) .setNegativeButton(R.string.cancel, null) .show(); } else { @@ -297,12 +289,41 @@ public class CustomizeThemeActivity extends BaseActivity { InsertCustomTheme.insertCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, lightThemeSharedPreferences, darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, false, () -> { - Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); + Toast.makeText(CustomizeThemeActivity.this, R.string.theme_saved_locally, Toast.LENGTH_SHORT).show(); EventBus.getDefault().post(new RecreateActivityEvent()); finish(); }); } + private void saveThemeOnline(CustomTheme customTheme) { + onlineCustomThemesRetrofit.create(OnlineCustomThemeAPI.class).modifyTheme( + onlineCustomThemeMetadata.id, customTheme.name, + customTheme.getJSONModel(), + ('#' + Integer.toHexString(customTheme.colorPrimary)).toUpperCase() + ).enqueue(new Callback<>() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful()) { + Toast.makeText(CustomizeThemeActivity.this, R.string.theme_saved_online, Toast.LENGTH_SHORT).show(); + Intent returnIntent = new Intent(); + returnIntent.putExtra(RETURN_EXTRA_INDEX_IN_THEME_LIST, getIntent().getIntExtra(EXTRA_INDEX_IN_THEME_LIST, -1)); + returnIntent.putExtra(RETURN_EXTRA_THEME_NAME, customTheme.name); + returnIntent.putExtra(RETURN_EXTRA_PRIMARY_COLOR, '#' + Integer.toHexString(customTheme.colorPrimary)); + setResult(RESULT_OK, returnIntent); + + finish(); + } else { + Toast.makeText(CustomizeThemeActivity.this, R.string.upload_theme_failed, Toast.LENGTH_SHORT).show(); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable throwable) { + Toast.makeText(CustomizeThemeActivity.this, R.string.upload_theme_failed, Toast.LENGTH_SHORT).show(); + } + }); + } + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 93951ccb..adb1cb64 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -692,4 +692,10 @@ 1 + + @string/save_locally + @string/save_online + @string/save_locally_and_online + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6c91674c..898df6ed 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -965,10 +965,13 @@ A theme in the database is also called %1$s. Do you want to change the name of this imported theme? Rename Override - Override online theme? - You uploaded this theme so you can make changes. - Save to local - Online theme modified. + Save options + You uploaded this theme so you can make changes. + Save locally + Save online + Save both locally and online + Theme saved locally + Theme saved online Failed to upload this theme. Try again later. Color Picker -- cgit v1.2.3