From cc64d6c49eb87f9c6b35ca4439c279570c4982bc Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Sun, 7 Jul 2024 21:51:54 -0400 Subject: Continue implementing online custom themes. --- .../activities/CustomizeThemeActivity.java | 23 ++- ...nlineCustomThemeListingRecyclerViewAdapter.java | 2 + .../CustomThemeOptionsBottomSheetFragment.java | 6 + .../infinityforreddit/customtheme/CustomTheme.java | 208 ++++++++++++++++++++- 4 files changed, 232 insertions(+), 7 deletions(-) (limited to 'app/src/main/java/ml') 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 9b5921d4..88362d87 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CustomizeThemeActivity.java @@ -42,6 +42,7 @@ public class CustomizeThemeActivity extends BaseActivity { public static final int EXTRA_DARK_THEME = CustomThemeSharedPreferencesUtils.DARK; public static final int EXTRA_AMOLED_THEME = CustomThemeSharedPreferencesUtils.AMOLED; public static final String EXTRA_THEME_NAME = "ETN"; + public static final String EXTRA_CUSTOM_THEME = "ECT"; public static final String EXTRA_IS_PREDEFIINED_THEME = "EIPT"; public static final String EXTRA_CREATE_THEME = "ECT"; private static final String CUSTOM_THEME_SETTINGS_ITEMS_STATE = "CTSIS"; @@ -70,6 +71,7 @@ public class CustomizeThemeActivity extends BaseActivity { Executor mExecutor; private String themeName; + private CustomTheme customTheme; private boolean isPredefinedTheme; private ArrayList customThemeSettingsItems; private CustomizeThemeRecyclerViewAdapter adapter; @@ -142,6 +144,8 @@ public class CustomizeThemeActivity extends BaseActivity { } else { isPredefinedTheme = getIntent().getBooleanExtra(EXTRA_IS_PREDEFIINED_THEME, false); themeName = getIntent().getStringExtra(EXTRA_THEME_NAME); + customTheme = getIntent().getParcelableExtra(EXTRA_CUSTOM_THEME); + adapter = new CustomizeThemeRecyclerViewAdapter(this, customThemeWrapper, themeName); binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); if (isPredefinedTheme) { @@ -154,13 +158,20 @@ public class CustomizeThemeActivity extends BaseActivity { binding.recyclerViewCustomizeThemeActivity.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); } else { - GetCustomTheme.getCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, - themeName, customTheme -> { - customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( - CustomizeThemeActivity.this, customTheme, androidVersion); + if (customTheme != null) { + customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( + CustomizeThemeActivity.this, customTheme, androidVersion); - adapter.setCustomThemeSettingsItem(customThemeSettingsItems); - }); + adapter.setCustomThemeSettingsItem(customThemeSettingsItems); + } else { + GetCustomTheme.getCustomTheme(mExecutor, new Handler(), redditDataRoomDatabase, + themeName, customTheme -> { + customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( + CustomizeThemeActivity.this, customTheme, androidVersion); + + adapter.setCustomThemeSettingsItem(customThemeSettingsItems); + }); + } } } } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java index 840ca209..47b3a55c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/OnlineCustomThemeListingRecyclerViewAdapter.java @@ -67,6 +67,7 @@ public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapt ((OnlineCustomThemeViewHolder) holder).binding.addImageViewItemUserCustomTheme.setOnClickListener(view -> { Intent intent = new Intent(activity, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); + intent.putExtra(CustomizeThemeActivity.EXTRA_CUSTOM_THEME, customTheme); intent.putExtra(CustomizeThemeActivity.EXTRA_CREATE_THEME, true); activity.startActivity(intent); }); @@ -77,6 +78,7 @@ public class OnlineCustomThemeListingRecyclerViewAdapter extends PagingDataAdapt CustomThemeOptionsBottomSheetFragment customThemeOptionsBottomSheetFragment = new CustomThemeOptionsBottomSheetFragment(); Bundle bundle = new Bundle(); bundle.putString(CustomThemeOptionsBottomSheetFragment.EXTRA_THEME_NAME, customTheme.name); + bundle.putParcelable(CustomThemeOptionsBottomSheetFragment.EXTRA_CUSTOM_THEME, customTheme); customThemeOptionsBottomSheetFragment.setArguments(bundle); customThemeOptionsBottomSheetFragment.show(activity.getSupportFragmentManager(), customThemeOptionsBottomSheetFragment.getTag()); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java index fe446683..e497bdff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/CustomThemeOptionsBottomSheetFragment.java @@ -12,6 +12,7 @@ import androidx.fragment.app.Fragment; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.CustomizeThemeActivity; +import ml.docilealligator.infinityforreddit.customtheme.CustomTheme; import ml.docilealligator.infinityforreddit.customviews.LandscapeExpandedRoundedBottomSheetDialogFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentCustomThemeOptionsBottomSheetBinding; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -22,8 +23,10 @@ import ml.docilealligator.infinityforreddit.utils.Utils; public class CustomThemeOptionsBottomSheetFragment extends LandscapeExpandedRoundedBottomSheetDialogFragment { public static final String EXTRA_THEME_NAME = "ETN"; + public static final String EXTRA_CUSTOM_THEME = "ECT"; private String themeName; + private CustomTheme customTheme; private BaseActivity activity; public CustomThemeOptionsBottomSheetFragment() { @@ -42,11 +45,14 @@ public class CustomThemeOptionsBottomSheetFragment extends LandscapeExpandedRoun FragmentCustomThemeOptionsBottomSheetBinding binding = FragmentCustomThemeOptionsBottomSheetBinding.inflate(inflater, container, false); themeName = getArguments().getString(EXTRA_THEME_NAME); + customTheme = getArguments().getParcelable(EXTRA_CUSTOM_THEME); + binding.themeNameTextViewCustomThemeOptionsBottomSheetFragment.setText(themeName); binding.editThemeTextViewCustomThemeOptionsBottomSheetFragment.setOnClickListener(view -> { Intent intent = new Intent(activity, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, themeName); + intent.putExtra(CustomizeThemeActivity.EXTRA_CUSTOM_THEME, customTheme); startActivity(intent); dismiss(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java index a7268335..fb8110d3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/customtheme/CustomTheme.java @@ -1,6 +1,8 @@ package ml.docilealligator.infinityforreddit.customtheme; import android.graphics.Color; +import android.os.Parcel; +import android.os.Parcelable; import androidx.annotation.NonNull; import androidx.room.ColumnInfo; @@ -23,7 +25,7 @@ import java.util.ArrayList; import java.util.Map; @Entity(tableName = "custom_themes") -public class CustomTheme { +public class CustomTheme implements Parcelable { @PrimaryKey @NonNull @ColumnInfo(name = "name") @@ -213,6 +215,111 @@ public class CustomTheme { this.name = name; } + protected CustomTheme(Parcel in) { + name = in.readString(); + isLightTheme = in.readByte() != 0; + isDarkTheme = in.readByte() != 0; + isAmoledTheme = in.readByte() != 0; + colorPrimary = in.readInt(); + colorPrimaryDark = in.readInt(); + colorAccent = in.readInt(); + colorPrimaryLightTheme = in.readInt(); + primaryTextColor = in.readInt(); + secondaryTextColor = in.readInt(); + postTitleColor = in.readInt(); + postContentColor = in.readInt(); + readPostTitleColor = in.readInt(); + readPostContentColor = in.readInt(); + commentColor = in.readInt(); + buttonTextColor = in.readInt(); + backgroundColor = in.readInt(); + cardViewBackgroundColor = in.readInt(); + readPostCardViewBackgroundColor = in.readInt(); + filledCardViewBackgroundColor = in.readInt(); + readPostFilledCardViewBackgroundColor = in.readInt(); + commentBackgroundColor = in.readInt(); + bottomAppBarBackgroundColor = in.readInt(); + primaryIconColor = in.readInt(); + bottomAppBarIconColor = in.readInt(); + postIconAndInfoColor = in.readInt(); + commentIconAndInfoColor = in.readInt(); + toolbarPrimaryTextAndIconColor = in.readInt(); + toolbarSecondaryTextColor = in.readInt(); + circularProgressBarBackground = in.readInt(); + mediaIndicatorIconColor = in.readInt(); + mediaIndicatorBackgroundColor = in.readInt(); + tabLayoutWithExpandedCollapsingToolbarTabBackground = in.readInt(); + tabLayoutWithExpandedCollapsingToolbarTextColor = in.readInt(); + tabLayoutWithExpandedCollapsingToolbarTabIndicator = in.readInt(); + tabLayoutWithCollapsedCollapsingToolbarTabBackground = in.readInt(); + tabLayoutWithCollapsedCollapsingToolbarTextColor = in.readInt(); + tabLayoutWithCollapsedCollapsingToolbarTabIndicator = in.readInt(); + navBarColor = in.readInt(); + upvoted = in.readInt(); + downvoted = in.readInt(); + postTypeBackgroundColor = in.readInt(); + postTypeTextColor = in.readInt(); + spoilerBackgroundColor = in.readInt(); + spoilerTextColor = in.readInt(); + nsfwBackgroundColor = in.readInt(); + nsfwTextColor = in.readInt(); + flairBackgroundColor = in.readInt(); + flairTextColor = in.readInt(); + awardsBackgroundColor = in.readInt(); + awardsTextColor = in.readInt(); + archivedTint = in.readInt(); + lockedIconTint = in.readInt(); + crosspostIconTint = in.readInt(); + upvoteRatioIconTint = in.readInt(); + stickiedPostIconTint = in.readInt(); + noPreviewPostTypeIconTint = in.readInt(); + subscribed = in.readInt(); + unsubscribed = in.readInt(); + username = in.readInt(); + subreddit = in.readInt(); + authorFlairTextColor = in.readInt(); + submitter = in.readInt(); + moderator = in.readInt(); + currentUser = in.readInt(); + singleCommentThreadBackgroundColor = in.readInt(); + unreadMessageBackgroundColor = in.readInt(); + dividerColor = in.readInt(); + noPreviewPostTypeBackgroundColor = in.readInt(); + voteAndReplyUnavailableButtonColor = in.readInt(); + commentVerticalBarColor1 = in.readInt(); + commentVerticalBarColor2 = in.readInt(); + commentVerticalBarColor3 = in.readInt(); + commentVerticalBarColor4 = in.readInt(); + commentVerticalBarColor5 = in.readInt(); + commentVerticalBarColor6 = in.readInt(); + commentVerticalBarColor7 = in.readInt(); + fabIconColor = in.readInt(); + chipTextColor = in.readInt(); + linkColor = in.readInt(); + receivedMessageTextColor = in.readInt(); + sentMessageTextColor = in.readInt(); + receivedMessageBackgroundColor = in.readInt(); + sentMessageBackgroundColor = in.readInt(); + sendMessageIconColor = in.readInt(); + fullyCollapsedCommentBackgroundColor = in.readInt(); + awardedCommentBackgroundColor = in.readInt(); + isLightStatusBar = in.readByte() != 0; + isLightNavBar = in.readByte() != 0; + isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = in.readByte() != 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public CustomTheme createFromParcel(Parcel in) { + return new CustomTheme(in); + } + + @Override + public CustomTheme[] newArray(int size) { + return new CustomTheme[size]; + } + }; + public String getJSONModel() { Gson gson = getGsonBuilder().create(); return gson.toJson(this); @@ -330,6 +437,105 @@ public class CustomTheme { return customTheme; } + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(@NonNull Parcel dest, int flags) { + dest.writeString(name); + dest.writeByte((byte) (isLightTheme ? 1 : 0)); + dest.writeByte((byte) (isDarkTheme ? 1 : 0)); + dest.writeByte((byte) (isAmoledTheme ? 1 : 0)); + dest.writeInt(colorPrimary); + dest.writeInt(colorPrimaryDark); + dest.writeInt(colorAccent); + dest.writeInt(colorPrimaryLightTheme); + dest.writeInt(primaryTextColor); + dest.writeInt(secondaryTextColor); + dest.writeInt(postTitleColor); + dest.writeInt(postContentColor); + dest.writeInt(readPostTitleColor); + dest.writeInt(readPostContentColor); + dest.writeInt(commentColor); + dest.writeInt(buttonTextColor); + dest.writeInt(backgroundColor); + dest.writeInt(cardViewBackgroundColor); + dest.writeInt(readPostCardViewBackgroundColor); + dest.writeInt(filledCardViewBackgroundColor); + dest.writeInt(readPostFilledCardViewBackgroundColor); + dest.writeInt(commentBackgroundColor); + dest.writeInt(bottomAppBarBackgroundColor); + dest.writeInt(primaryIconColor); + dest.writeInt(bottomAppBarIconColor); + dest.writeInt(postIconAndInfoColor); + dest.writeInt(commentIconAndInfoColor); + dest.writeInt(toolbarPrimaryTextAndIconColor); + dest.writeInt(toolbarSecondaryTextColor); + dest.writeInt(circularProgressBarBackground); + dest.writeInt(mediaIndicatorIconColor); + dest.writeInt(mediaIndicatorBackgroundColor); + dest.writeInt(tabLayoutWithExpandedCollapsingToolbarTabBackground); + dest.writeInt(tabLayoutWithExpandedCollapsingToolbarTextColor); + dest.writeInt(tabLayoutWithExpandedCollapsingToolbarTabIndicator); + dest.writeInt(tabLayoutWithCollapsedCollapsingToolbarTabBackground); + dest.writeInt(tabLayoutWithCollapsedCollapsingToolbarTextColor); + dest.writeInt(tabLayoutWithCollapsedCollapsingToolbarTabIndicator); + dest.writeInt(navBarColor); + dest.writeInt(upvoted); + dest.writeInt(downvoted); + dest.writeInt(postTypeBackgroundColor); + dest.writeInt(postTypeTextColor); + dest.writeInt(spoilerBackgroundColor); + dest.writeInt(spoilerTextColor); + dest.writeInt(nsfwBackgroundColor); + dest.writeInt(nsfwTextColor); + dest.writeInt(flairBackgroundColor); + dest.writeInt(flairTextColor); + dest.writeInt(awardsBackgroundColor); + dest.writeInt(awardsTextColor); + dest.writeInt(archivedTint); + dest.writeInt(lockedIconTint); + dest.writeInt(crosspostIconTint); + dest.writeInt(upvoteRatioIconTint); + dest.writeInt(stickiedPostIconTint); + dest.writeInt(noPreviewPostTypeIconTint); + dest.writeInt(subscribed); + dest.writeInt(unsubscribed); + dest.writeInt(username); + dest.writeInt(subreddit); + dest.writeInt(authorFlairTextColor); + dest.writeInt(submitter); + dest.writeInt(moderator); + dest.writeInt(currentUser); + dest.writeInt(singleCommentThreadBackgroundColor); + dest.writeInt(unreadMessageBackgroundColor); + dest.writeInt(dividerColor); + dest.writeInt(noPreviewPostTypeBackgroundColor); + dest.writeInt(voteAndReplyUnavailableButtonColor); + dest.writeInt(commentVerticalBarColor1); + dest.writeInt(commentVerticalBarColor2); + dest.writeInt(commentVerticalBarColor3); + dest.writeInt(commentVerticalBarColor4); + dest.writeInt(commentVerticalBarColor5); + dest.writeInt(commentVerticalBarColor6); + dest.writeInt(commentVerticalBarColor7); + dest.writeInt(fabIconColor); + dest.writeInt(chipTextColor); + dest.writeInt(linkColor); + dest.writeInt(receivedMessageTextColor); + dest.writeInt(sentMessageTextColor); + dest.writeInt(receivedMessageBackgroundColor); + dest.writeInt(sentMessageBackgroundColor); + dest.writeInt(sendMessageIconColor); + dest.writeInt(fullyCollapsedCommentBackgroundColor); + dest.writeInt(awardedCommentBackgroundColor); + dest.writeByte((byte) (isLightStatusBar ? 1 : 0)); + dest.writeByte((byte) (isLightNavBar ? 1 : 0)); + dest.writeByte((byte) (isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface ? 1 : 0)); + } + private static class CustomThemeSerializer implements JsonSerializer { @Override public JsonElement serialize(CustomTheme src, Type typeofSrc, JsonSerializationContext context) { -- cgit v1.2.3