aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator
diff options
context:
space:
mode:
authorDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-07-11 02:45:00 +0000
committerDocile-Alligator <25734209+Docile-Alligator@users.noreply.github.com>2024-07-11 02:45:00 +0000
commit44aaaeac58e143525b80cd173ac50fd8fa798193 (patch)
treef08ba9245374be7c98ece459adc1255f5f70040a /app/src/main/java/ml/docilealligator
parent6e5eab371265c6959adc4d7ca4d3c0e60573d42b (diff)
downloadinfinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar.gz
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar.bz2
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar.lz
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar.xz
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.tar.zst
infinity-for-reddit-44aaaeac58e143525b80cd173ac50fd8fa798193.zip
Continue implementing online custom themes. Modifying online theme.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java49
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CustomThemeListingRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/apis/OnlineCustomThemeAPI.java8
3 files changed, 55 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);
}