diff options
Diffstat (limited to '')
4 files changed, 60 insertions, 12 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 7b7a7acb..13f876c7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java @@ -242,13 +242,38 @@ public class CustomizeThemeActivity extends BaseActivity { return true; } CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName); - InsertCustomTheme.insertCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, lightThemeSharedPreferences, - darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, - false, () -> { - Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); - EventBus.getDefault().post(new RecreateActivityEvent()); - finish(); - }); + if (onlineCustomThemeMetadata != null && onlineCustomThemeMetadata.username.equals(accountName)) { + // This custom theme is uploaded by the current user + 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).uploadTheme( + customTheme.name, accountName, 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(); + 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(); + } + }); + }) + .setNeutralButton(R.string.save_to_local, ((dialog, which) -> saveThemeLocally(customTheme))) + .setNegativeButton(R.string.cancel, null) + .show(); + } else { + saveThemeLocally(customTheme); + } } return true; @@ -257,6 +282,16 @@ public class CustomizeThemeActivity extends BaseActivity { return false; } + private void saveThemeLocally(CustomTheme customTheme) { + InsertCustomTheme.insertCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, lightThemeSharedPreferences, + darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, + false, () -> { + Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new RecreateActivityEvent()); + finish(); + }); + } + @Override protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java index 4fbf3d8e..93fc08fc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java @@ -93,21 +93,21 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< ((UserCustomThemeViewHolder) holder).binding.shareImageViewItemUserCustomTheme.setOnClickListener(view -> { ((CustomThemeListingActivity) activity).shareTheme(customTheme); }); - ((UserCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> { + holder.itemView.setOnClickListener(view -> { CustomThemeOptionsBottomSheetFragment customThemeOptionsBottomSheetFragment = new CustomThemeOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putString(CustomThemeOptionsBottomSheetFragment.EXTRA_THEME_NAME, customTheme.name); customThemeOptionsBottomSheetFragment.setArguments(bundle); customThemeOptionsBottomSheetFragment.show(activity.getSupportFragmentManager(), customThemeOptionsBottomSheetFragment.getTag()); }); - ((UserCustomThemeViewHolder) holder).itemView.setOnLongClickListener(view -> { - ((UserCustomThemeViewHolder) holder).itemView.performClick(); + holder.itemView.setOnLongClickListener(view -> { + holder.itemView.performClick(); return true; }); } else if (holder instanceof PreDefinedThemeDividerViewHolder) { - ((TextView) ((PreDefinedThemeDividerViewHolder) holder).itemView).setText(R.string.predefined_themes); + ((TextView) holder.itemView).setText(R.string.predefined_themes); } else if (holder instanceof UserThemeDividerViewHolder) { - ((TextView) ((UserThemeDividerViewHolder) holder).itemView).setText(R.string.user_themes); + ((TextView) holder.itemView).setText(R.string.user_themes); } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/OnlineCustomThemeAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/OnlineCustomThemeAPI.java index e328a9b8..71e5095e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/apis/OnlineCustomThemeAPI.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/apis/OnlineCustomThemeAPI.java @@ -4,7 +4,10 @@ import com.google.common.util.concurrent.ListenableFuture; import retrofit2.Call; import retrofit2.Response; +import retrofit2.http.Field; +import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; +import retrofit2.http.POST; import retrofit2.http.Query; public interface OnlineCustomThemeAPI { @@ -13,4 +16,9 @@ public interface OnlineCustomThemeAPI { @GET("/themes/theme") Call<String> getCustomTheme(@Query("name") String themeName, @Query("username") String username); + + @FormUrlEncoded + @POST("/themes/upload") + Call<String> uploadTheme(@Field("name") String themeName, @Field("username") String username, + @Field("data") String customThemeJson, @Field("primary_color") String primaryColor); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cc3a44d7..6c91674c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -965,6 +965,11 @@ <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="upload_theme_failed">Failed to upload this theme. Try again later.</string> <string name="color_picker">Color Picker</string> <string name="invalid_color">Invalid Color</string> |