diff options
Diffstat (limited to 'app/src')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java | 83 | ||||
-rw-r--r-- | app/src/main/res/values/arrays.xml | 6 | ||||
-rw-r--r-- | 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<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); 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 @@ <item>1</item> </string-array> + <string-array name="save_theme_options"> + <item>@string/save_locally</item> + <item>@string/save_online</item> + <item>@string/save_locally_and_online</item> + </string-array> + </resources> 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 @@ <string name="duplicate_theme_name_dialog_message">A theme in the database is also called %1$s. Do you want to change the name of this imported theme?</string> <string name="rename">Rename</string> <string name="override">Override</string> - <string name="override_online_theme_question">Override online theme?</string> - <string name="override_online_theme_message">You uploaded this theme so you can make changes.</string> - <string name="save_to_local">Save to local</string> - <string name="online_theme_modified">Online theme modified.</string> + <string name="save_theme_options_title">Save options</string> + <string name="save_theme_options_message">You uploaded this theme so you can make changes.</string> + <string name="save_locally">Save locally</string> + <string name="save_online">Save online</string> + <string name="save_locally_and_online">Save both locally and online</string> + <string name="theme_saved_locally">Theme saved locally</string> + <string name="theme_saved_online">Theme saved online</string> <string name="upload_theme_failed">Failed to upload this theme. Try again later.</string> <string name="color_picker">Color Picker</string> |