diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-07-17 15:38:07 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-07-17 15:38:07 +0000 |
commit | 7302edac089182e0c8d1564d2208c71662290e66 (patch) | |
tree | 0db383b7e3fd81c5cace769775b6f2a29a56f42b /app/src/main/java | |
parent | 4edbfab34821d5cb2af30f7bb0a930cd0cfe7bc7 (diff) | |
download | infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar.gz infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar.bz2 infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar.lz infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar.xz infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.tar.zst infinity-for-reddit-7302edac089182e0c8d1564d2208c71662290e66.zip |
Different save options when saving the online theme.
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java | 83 |
1 files changed, 52 insertions, 31 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<String> call, @NonNull Response<String> 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<String> 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<String> call, @NonNull Response<String> 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<String> 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); |