From 0694c471c4ba39fa8235e1ecfcc4e8e40ad13ad2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 25 Mar 2020 18:06:43 +0800 Subject: Fix some bugs in CustomizeThemeActivity. --- .../Activity/CustomThemeListingActivity.java | 4 +- .../Activity/CustomizeThemeActivity.java | 140 ++++++++------------- .../CustomThemeListingRecyclerViewAdapter.java | 24 +++- .../Adapter/CustomizeThemeRecyclerViewAdapter.java | 40 +++++- .../AsyncTask/InsertCustomThemeAsyncTask.java | 25 +++- .../infinityforreddit/CustomTheme/CustomTheme.java | 133 ++++++++++---------- .../CustomTheme/CustomThemeDao.java | 9 ++ .../CustomTheme/CustomThemeSettingsItem.java | 23 +++- .../CustomTheme/CustomThemeWrapper.java | 14 ++- .../Settings/ThemePreferenceFragment.java | 2 +- .../Utils/SharedPreferencesUtils.java | 2 +- 11 files changed, 241 insertions(+), 175 deletions(-) (limited to 'app/src/main/java') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java index 791cd336..0e8376ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java @@ -56,14 +56,14 @@ public class CustomThemeListingActivity extends BaseActivity { getSupportActionBar().setDisplayHomeAsUpEnabled(true); CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(this, - CustomThemeWrapper.getPredifinedThemes(this)); + CustomThemeWrapper.getPredefinedThemes(this)); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(this)); customThemeViewModel = new ViewModelProvider(this, new CustomThemeViewModel.Factory(redditDataRoomDatabase)) .get(CustomThemeViewModel.class); - customThemeViewModel.getAllCustomThemes().observe(this, customThemes -> adapter.setUserThemes(customThemes)); + customThemeViewModel.getAllCustomThemes().observe(this, adapter::setUserThemes); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java index 468c55d9..7dde8fc6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomizeThemeActivity.java @@ -28,7 +28,6 @@ import ml.docilealligator.infinityforreddit.AsyncTask.GetCustomThemeAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertCustomThemeAsyncTask; import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeSettingsItem; -import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent; import ml.docilealligator.infinityforreddit.Infinity; @@ -43,7 +42,9 @@ 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_IS_PREDEFIINED_THEME = "EIPT"; private static final String CUSTOM_THEME_SETTINGS_ITEMS_STATE = "CTSIS"; + private static final String THEME_NAME_STATE = "TNS"; @BindView(R.id.appbar_layout_customize_theme_activity) AppBarLayout appBarLayout; @@ -68,10 +69,8 @@ public class CustomizeThemeActivity extends BaseActivity { @Inject CustomThemeWrapper customThemeWrapper; - public CustomThemeViewModel customThemeViewModel; - - private int themeType; private String themeName; + private boolean isPredefinedTheme; private ArrayList customThemeSettingsItems; private CustomizeThemeRecyclerViewAdapter adapter; @@ -89,81 +88,84 @@ public class CustomizeThemeActivity extends BaseActivity { setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); - adapter = new CustomizeThemeRecyclerViewAdapter(this); recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); if (savedInstanceState != null) { customThemeSettingsItems = savedInstanceState.getParcelableArrayList(CUSTOM_THEME_SETTINGS_ITEMS_STATE); + themeName = savedInstanceState.getString(THEME_NAME_STATE); } int androidVersion = Build.VERSION.SDK_INT; if (customThemeSettingsItems == null) { if (getIntent().hasExtra(EXTRA_THEME_TYPE)) { - themeType = getIntent().getIntExtra(EXTRA_THEME_TYPE, EXTRA_LIGHT_THEME); + int themeType = getIntent().getIntExtra(EXTRA_THEME_TYPE, EXTRA_LIGHT_THEME); new GetCustomThemeAsyncTask(redditDataRoomDatabase, themeType, customTheme -> { if (customTheme == null) { + isPredefinedTheme = true; switch (themeType) { case EXTRA_DARK_THEME: customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( CustomizeThemeActivity.this, - CustomThemeWrapper.getIndigoDark(CustomizeThemeActivity.this)); + CustomThemeWrapper.getIndigoDark(CustomizeThemeActivity.this), + androidVersion); + themeName = getString(R.string.theme_name_indigo_dark); break; case EXTRA_AMOLED_THEME: customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( CustomizeThemeActivity.this, - CustomThemeWrapper.getIndigoAmoled(CustomizeThemeActivity.this)); + CustomThemeWrapper.getIndigoAmoled(CustomizeThemeActivity.this), + androidVersion); + themeName = getString(R.string.theme_name_indigo_amoled); break; default: customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( CustomizeThemeActivity.this, - CustomThemeWrapper.getIndigo(CustomizeThemeActivity.this)); + CustomThemeWrapper.getIndigo(CustomizeThemeActivity.this), + androidVersion); + themeName = getString(R.string.theme_name_indigo); } } else { - customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem(CustomizeThemeActivity.this, customTheme); - } - - if (androidVersion < Build.VERSION_CODES.O) { - customThemeSettingsItems.get(customThemeSettingsItems.size() - 2).itemDetails = getString(R.string.theme_item_available_on_android_8); - } - if (androidVersion < Build.VERSION_CODES.M) { - customThemeSettingsItems.get(customThemeSettingsItems.size() - 3).itemDetails = getString(R.string.theme_item_available_on_android_6); + customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( + CustomizeThemeActivity.this, customTheme, androidVersion); + themeName = customTheme.name; } + setTitle(themeName); + adapter = new CustomizeThemeRecyclerViewAdapter(this, themeName, isPredefinedTheme); + recyclerView.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); }).execute(); - - switch (themeType) { - case EXTRA_DARK_THEME: - setTitle(getString(R.string.customize_dark_theme_fragment_title)); - break; - case EXTRA_AMOLED_THEME: - setTitle(getString(R.string.customize_amoled_theme_fragment_title)); - break; - default: - setTitle(getString(R.string.customize_light_theme_fragment_title)); - break; - } } else { + isPredefinedTheme = getIntent().getBooleanExtra(EXTRA_IS_PREDEFIINED_THEME, false); themeName = getIntent().getStringExtra(EXTRA_THEME_NAME); + adapter = new CustomizeThemeRecyclerViewAdapter(this, themeName, isPredefinedTheme); + recyclerView.setAdapter(adapter); setTitle(themeName); - new GetCustomThemeAsyncTask(redditDataRoomDatabase, themeName, - customTheme -> { - customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem(CustomizeThemeActivity.this, customTheme); - - if (androidVersion < Build.VERSION_CODES.O) { - customThemeSettingsItems.get(customThemeSettingsItems.size() - 2).itemDetails = getString(R.string.theme_item_available_on_android_8); - } - if (androidVersion < Build.VERSION_CODES.M) { - customThemeSettingsItems.get(customThemeSettingsItems.size() - 3).itemDetails = getString(R.string.theme_item_available_on_android_6); - } - - adapter.setCustomThemeSettingsItem(customThemeSettingsItems); - }).execute(); + if (isPredefinedTheme) { + customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( + CustomizeThemeActivity.this, + CustomThemeWrapper.getPredefinedCustomTheme(this, themeName), + androidVersion); + + setTitle(themeName); + adapter = new CustomizeThemeRecyclerViewAdapter(this, themeName, isPredefinedTheme); + recyclerView.setAdapter(adapter); + adapter.setCustomThemeSettingsItem(customThemeSettingsItems); + } else { + new GetCustomThemeAsyncTask(redditDataRoomDatabase, themeName, + customTheme -> { + customThemeSettingsItems = CustomThemeSettingsItem.convertCustomThemeToSettingsItem( + CustomizeThemeActivity.this, customTheme, androidVersion); + + adapter.setCustomThemeSettingsItem(customThemeSettingsItems); + }).execute(); + } } } else { + adapter = new CustomizeThemeRecyclerViewAdapter(this, themeName, isPredefinedTheme); + recyclerView.setAdapter(adapter); adapter.setCustomThemeSettingsItem(customThemeSettingsItems); } } @@ -182,52 +184,13 @@ public class CustomizeThemeActivity extends BaseActivity { finish(); return true; case R.id.action_save_customize_theme_activity: - if (themeName == null) { - switch (themeType) { - case CustomThemeSharedPreferencesUtils.DARK: - themeName = "Indigo Dark"; - break; - case CustomThemeSharedPreferencesUtils.AMOLED: - themeName = "Indigo Amoled"; - break; - default: - themeName = "Indigo"; - } - } - CustomTheme customTheme = CustomTheme.convertSettingsItemsToCustomTheme(customThemeSettingsItems, themeName); - - switch (themeType) { - case CustomThemeSharedPreferencesUtils.DARK: - customTheme.isLightTheme = false; - customTheme.isDarkTheme = true; - customTheme.isAmoledTheme = false; - new InsertCustomThemeAsyncTask(redditDataRoomDatabase, darkThemeSharedPreferences, customTheme, () -> { - Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); - EventBus.getDefault().post(new RecreateActivityEvent()); - finish(); - }).execute(); - break; - case CustomThemeSharedPreferencesUtils.AMOLED: - customTheme.isLightTheme = false; - customTheme.isDarkTheme = false; - customTheme.isAmoledTheme = true; - new InsertCustomThemeAsyncTask(redditDataRoomDatabase, amoledThemeSharedPreferences, customTheme, () -> { - Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); - EventBus.getDefault().post(new RecreateActivityEvent()); - finish(); - }).execute(); - break; - default: - customTheme.isLightTheme = true; - customTheme.isDarkTheme = false; - customTheme.isAmoledTheme = false; - new InsertCustomThemeAsyncTask(redditDataRoomDatabase, lightThemeSharedPreferences, customTheme, () -> { - Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); - EventBus.getDefault().post(new RecreateActivityEvent()); - finish(); - }).execute(); - } + new InsertCustomThemeAsyncTask(redditDataRoomDatabase, lightThemeSharedPreferences, + darkThemeSharedPreferences, amoledThemeSharedPreferences, customTheme, () -> { + Toast.makeText(CustomizeThemeActivity.this, R.string.saved, Toast.LENGTH_SHORT).show(); + EventBus.getDefault().post(new RecreateActivityEvent()); + finish(); + }).execute(); return true; } @@ -239,6 +202,7 @@ public class CustomizeThemeActivity extends BaseActivity { protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelableArrayList(CUSTOM_THEME_SETTINGS_ITEMS_STATE, customThemeSettingsItems); + outState.putString(THEME_NAME_STATE, themeName); } @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java index 81487a02..267c72cb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java @@ -6,6 +6,7 @@ import android.content.res.ColorStateList; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; @@ -56,11 +57,11 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< case VIEW_TYPE_PREDEFINED_THEME_DIVIDER: return new PreDefinedThemeDividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_theme_type_divider, parent, false)); case VIEW_TYPE_PREDEFINED_THEME: - return new PredefinedCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_custom_theme, parent, false)); + return new PredefinedCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_predefined_custom_theme, parent, false)); case VIEW_TYPE_USER_THEME_DIVIDER: return new UserThemeDividerViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_theme_type_divider, parent, false)); default: - return new UserCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_custom_theme, parent, false)); + return new UserCustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_user_custom_theme, parent, false)); } } @@ -73,12 +74,19 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< ((PredefinedCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> { Intent intent = new Intent(context, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); + intent.putExtra(CustomizeThemeActivity.EXTRA_IS_PREDEFIINED_THEME, true); context.startActivity(intent); }); } else if (holder instanceof UserCustomThemeViewHolder) { CustomTheme customTheme = userCustomThemes.get(position - predefinedCustomThemes.size() - 2); ((UserCustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary)); ((UserCustomThemeViewHolder) holder).nameTextView.setText(customTheme.name); + ((UserCustomThemeViewHolder) holder).deleteImageView.setOnClickListener(view -> { + + }); + ((UserCustomThemeViewHolder) holder).shareImageView.setOnClickListener(view -> { + + }); ((UserCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> { Intent intent = new Intent(context, CustomizeThemeActivity.class); intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name); @@ -103,9 +111,9 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< class PredefinedCustomThemeViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.color_primary_item_custom_theme) + @BindView(R.id.color_primary_item_predefined_custom_theme) View colorPrimaryView; - @BindView(R.id.name_text_view_item_custom_theme) + @BindView(R.id.name_text_view_item_predefined_custom_theme) TextView nameTextView; public PredefinedCustomThemeViewHolder(@NonNull View itemView) { @@ -116,10 +124,14 @@ public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter< class UserCustomThemeViewHolder extends RecyclerView.ViewHolder { - @BindView(R.id.color_primary_item_custom_theme) + @BindView(R.id.color_primary_item_user_custom_theme) View colorPrimaryView; - @BindView(R.id.name_text_view_item_custom_theme) + @BindView(R.id.name_text_view_item_user_custom_theme) TextView nameTextView; + @BindView(R.id.delete_image_view_item_user_custom_theme) + ImageView deleteImageView; + @BindView(R.id.share_image_view_item_user_custom_theme) + ImageView shareImageView; public UserCustomThemeViewHolder(@NonNull View itemView) { super(itemView); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomizeThemeRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomizeThemeRecyclerViewAdapter.java index 69fa7ee5..be2aae85 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomizeThemeRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomizeThemeRecyclerViewAdapter.java @@ -22,17 +22,25 @@ import ml.docilealligator.infinityforreddit.R; public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter { private static final int VIEW_TYPE_COLOR = 1; private static final int VIEW_TYPE_SWITCH = 2; + private static final int VIEW_TYPE_THEME_NAME = 3; private AppCompatActivity activity; private ArrayList customThemeSettingsItems; + private String themeName; + private boolean isPredefinedTheme; - public CustomizeThemeRecyclerViewAdapter(AppCompatActivity activity) { + public CustomizeThemeRecyclerViewAdapter(AppCompatActivity activity, String themeName, + boolean isPredefinedTheme) { this.activity = activity; customThemeSettingsItems = new ArrayList<>(); + this.themeName = themeName; + this.isPredefinedTheme = isPredefinedTheme; } @Override public int getItemViewType(int position) { - if (position < customThemeSettingsItems.size() - 3) { + if (position == 0) { + return VIEW_TYPE_THEME_NAME; + } else if (position > 3 && position < customThemeSettingsItems.size() - 3) { return VIEW_TYPE_COLOR; } @@ -44,6 +52,8 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter customThemeSettingsItem.isEnabled = ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.isChecked()); holder.itemView.setOnClickListener(view -> ((ThemeSwitchItemViewHolder) holder).themeItemSwitch.performClick()); + } else if (holder instanceof ThemeNameItemViewHolder) { + ((ThemeNameItemViewHolder) holder).themeNameTextView.setText(themeName); + holder.itemView.setOnClickListener(view -> { + + }); } } @Override public int getItemCount() { - return customThemeSettingsItems.size(); + return customThemeSettingsItems.size() + 1; } public void setCustomThemeSettingsItem(ArrayList customThemeSettingsItems) { @@ -111,4 +126,19 @@ public class CustomizeThemeRecyclerViewAdapter extends RecyclerView.Adapter{}); + } + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java index c8c29a03..5477ecbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java @@ -9,7 +9,9 @@ import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUt public class InsertCustomThemeAsyncTask extends AsyncTask { private RedditDataRoomDatabase redditDataRoomDatabase; - private SharedPreferences themeSharedPreferences; + private SharedPreferences lightThemeSharedPreferences; + private SharedPreferences darkThemeSharedPreferences; + private SharedPreferences amoledThemeSharedPreferences; private CustomTheme customTheme; private InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener; @@ -18,18 +20,33 @@ public class InsertCustomThemeAsyncTask extends AsyncTask { } public InsertCustomThemeAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase, - SharedPreferences themeSharedPreferences, CustomTheme customTheme, + SharedPreferences lightThemeSharedPreferences, + SharedPreferences darkThemeSharedPreferences, + SharedPreferences amoledThemeSharedPreferences, CustomTheme customTheme, InsertCustomThemeAsyncTaskListener insertCustomThemeAsyncTaskListener) { this.redditDataRoomDatabase = redditDataRoomDatabase; - this.themeSharedPreferences = themeSharedPreferences; + this.lightThemeSharedPreferences = lightThemeSharedPreferences; + this.darkThemeSharedPreferences = darkThemeSharedPreferences; + this.amoledThemeSharedPreferences = amoledThemeSharedPreferences; this.customTheme = customTheme; this.insertCustomThemeAsyncTaskListener = insertCustomThemeAsyncTaskListener; } @Override protected Void doInBackground(Void... voids) { + if (customTheme.isLightTheme) { + redditDataRoomDatabase.customThemeDao().unsetLightTheme(); + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences); + } + if (customTheme.isDarkTheme) { + redditDataRoomDatabase.customThemeDao().unsetDarkTheme(); + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences); + } + if (customTheme.isAmoledTheme) { + redditDataRoomDatabase.customThemeDao().unsetAmoledTheme(); + CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences); + } redditDataRoomDatabase.customThemeDao().insert(customTheme); - CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, themeSharedPreferences); return null; } 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 374030ac..65409086 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java @@ -161,71 +161,74 @@ public class CustomTheme { return customTheme; } - customTheme.colorPrimary = customThemeSettingsItems.get(0).colorValue; - customTheme.colorPrimaryDark = customThemeSettingsItems.get(1).colorValue; - customTheme.colorAccent = customThemeSettingsItems.get(2).colorValue; - customTheme.colorPrimaryLightTheme = customThemeSettingsItems.get(3).colorValue; - customTheme.primaryTextColor = customThemeSettingsItems.get(4).colorValue; - customTheme.secondaryTextColor = customThemeSettingsItems.get(5).colorValue; - customTheme.postTitleColor = customThemeSettingsItems.get(6).colorValue; - customTheme.postContentColor = customThemeSettingsItems.get(7).colorValue; - customTheme.commentColor = customThemeSettingsItems.get(8).colorValue; - customTheme.buttonTextColor = customThemeSettingsItems.get(9).colorValue; - customTheme.chipTextColor = customThemeSettingsItems.get(10).colorValue; - customTheme.backgroundColor = customThemeSettingsItems.get(11).colorValue; - customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(12).colorValue; - customTheme.commentBackgroundColor = customThemeSettingsItems.get(13).colorValue; - customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(14).colorValue; - customTheme.primaryIconColor = customThemeSettingsItems.get(15).colorValue; - customTheme.postIconAndInfoColor = customThemeSettingsItems.get(16).colorValue; - customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(17).colorValue; - customTheme.fabIconColor = customThemeSettingsItems.get(18).colorValue; - customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(19).colorValue; - customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(20).colorValue; - customTheme.circularProgressBarBackground = customThemeSettingsItems.get(21).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(22).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(23).colorValue; - customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(24).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(25).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(26).colorValue; - customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(27).colorValue; - customTheme.upvoted = customThemeSettingsItems.get(28).colorValue; - customTheme.downvoted = customThemeSettingsItems.get(29).colorValue; - customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(30).colorValue; - customTheme.postTypeTextColor = customThemeSettingsItems.get(31).colorValue; - customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(32).colorValue; - customTheme.spoilerTextColor = customThemeSettingsItems.get(33).colorValue; - customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(34).colorValue; - customTheme.nsfwTextColor = customThemeSettingsItems.get(35).colorValue; - customTheme.flairBackgroundColor = customThemeSettingsItems.get(36).colorValue; - customTheme.flairTextColor = customThemeSettingsItems.get(37).colorValue; - customTheme.archivedTint = customThemeSettingsItems.get(38).colorValue; - customTheme.lockedIconTint = customThemeSettingsItems.get(39).colorValue; - customTheme.crosspostIconTint = customThemeSettingsItems.get(40).colorValue; - customTheme.stickiedPostIconTint = customThemeSettingsItems.get(41).colorValue; - customTheme.subscribed = customThemeSettingsItems.get(42).colorValue; - customTheme.unsubscribed = customThemeSettingsItems.get(43).colorValue; - customTheme.username = customThemeSettingsItems.get(44).colorValue; - customTheme.subreddit = customThemeSettingsItems.get(45).colorValue; - customTheme.authorFlairTextColor = customThemeSettingsItems.get(46).colorValue; - customTheme.submitter = customThemeSettingsItems.get(47).colorValue; - customTheme.moderator = customThemeSettingsItems.get(48).colorValue; - customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(49).colorValue; - customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(50).colorValue; - customTheme.dividerColor = customThemeSettingsItems.get(51).colorValue; - customTheme.noPreviewLinkBackgroundColor = customThemeSettingsItems.get(52).colorValue; - customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(53).colorValue; - customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(54).colorValue; - customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(55).colorValue; - customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(56).colorValue; - customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(57).colorValue; - customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(58).colorValue; - customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(59).colorValue; - customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(60).colorValue; - customTheme.navBarColor = customThemeSettingsItems.get(61).colorValue; - customTheme.isLightStatusBar = customThemeSettingsItems.get(62).isEnabled; - customTheme.isLightNavBar = customThemeSettingsItems.get(63).isEnabled; - customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(64).isEnabled; + customTheme.isLightTheme = customThemeSettingsItems.get(0).isEnabled; + customTheme.isDarkTheme = customThemeSettingsItems.get(1).isEnabled; + customTheme.isAmoledTheme = customThemeSettingsItems.get(2).isEnabled; + customTheme.colorPrimary = customThemeSettingsItems.get(3).colorValue; + customTheme.colorPrimaryDark = customThemeSettingsItems.get(4).colorValue; + customTheme.colorAccent = customThemeSettingsItems.get(5).colorValue; + customTheme.colorPrimaryLightTheme = customThemeSettingsItems.get(6).colorValue; + customTheme.primaryTextColor = customThemeSettingsItems.get(7).colorValue; + customTheme.secondaryTextColor = customThemeSettingsItems.get(8).colorValue; + customTheme.postTitleColor = customThemeSettingsItems.get(9).colorValue; + customTheme.postContentColor = customThemeSettingsItems.get(10).colorValue; + customTheme.commentColor = customThemeSettingsItems.get(11).colorValue; + customTheme.buttonTextColor = customThemeSettingsItems.get(12).colorValue; + customTheme.chipTextColor = customThemeSettingsItems.get(13).colorValue; + customTheme.backgroundColor = customThemeSettingsItems.get(14).colorValue; + customTheme.cardViewBackgroundColor = customThemeSettingsItems.get(15).colorValue; + customTheme.commentBackgroundColor = customThemeSettingsItems.get(16).colorValue; + customTheme.bottomAppBarBackgroundColor = customThemeSettingsItems.get(17).colorValue; + customTheme.primaryIconColor = customThemeSettingsItems.get(18).colorValue; + customTheme.postIconAndInfoColor = customThemeSettingsItems.get(19).colorValue; + customTheme.commentIconAndInfoColor = customThemeSettingsItems.get(20).colorValue; + customTheme.fabIconColor = customThemeSettingsItems.get(21).colorValue; + customTheme.toolbarPrimaryTextAndIconColor = customThemeSettingsItems.get(22).colorValue; + customTheme.toolbarSecondaryTextColor = customThemeSettingsItems.get(23).colorValue; + customTheme.circularProgressBarBackground = customThemeSettingsItems.get(24).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTabBackground = customThemeSettingsItems.get(25).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTextColor = customThemeSettingsItems.get(26).colorValue; + customTheme.tabLayoutWithExpandedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(27).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTabBackground = customThemeSettingsItems.get(28).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTextColor = customThemeSettingsItems.get(29).colorValue; + customTheme.tabLayoutWithCollapsedCollapsingToolbarTabIndicator = customThemeSettingsItems.get(30).colorValue; + customTheme.upvoted = customThemeSettingsItems.get(31).colorValue; + customTheme.downvoted = customThemeSettingsItems.get(32).colorValue; + customTheme.postTypeBackgroundColor = customThemeSettingsItems.get(33).colorValue; + customTheme.postTypeTextColor = customThemeSettingsItems.get(34).colorValue; + customTheme.spoilerBackgroundColor = customThemeSettingsItems.get(35).colorValue; + customTheme.spoilerTextColor = customThemeSettingsItems.get(36).colorValue; + customTheme.nsfwBackgroundColor = customThemeSettingsItems.get(37).colorValue; + customTheme.nsfwTextColor = customThemeSettingsItems.get(38).colorValue; + customTheme.flairBackgroundColor = customThemeSettingsItems.get(39).colorValue; + customTheme.flairTextColor = customThemeSettingsItems.get(40).colorValue; + customTheme.archivedTint = customThemeSettingsItems.get(41).colorValue; + customTheme.lockedIconTint = customThemeSettingsItems.get(42).colorValue; + customTheme.crosspostIconTint = customThemeSettingsItems.get(43).colorValue; + customTheme.stickiedPostIconTint = customThemeSettingsItems.get(44).colorValue; + customTheme.subscribed = customThemeSettingsItems.get(45).colorValue; + customTheme.unsubscribed = customThemeSettingsItems.get(46).colorValue; + customTheme.username = customThemeSettingsItems.get(47).colorValue; + customTheme.subreddit = customThemeSettingsItems.get(48).colorValue; + customTheme.authorFlairTextColor = customThemeSettingsItems.get(49).colorValue; + customTheme.submitter = customThemeSettingsItems.get(50).colorValue; + customTheme.moderator = customThemeSettingsItems.get(51).colorValue; + customTheme.singleCommentThreadBackgroundColor = customThemeSettingsItems.get(52).colorValue; + customTheme.unreadMessageBackgroundColor = customThemeSettingsItems.get(53).colorValue; + customTheme.dividerColor = customThemeSettingsItems.get(54).colorValue; + customTheme.noPreviewLinkBackgroundColor = customThemeSettingsItems.get(55).colorValue; + customTheme.voteAndReplyUnavailableButtonColor = customThemeSettingsItems.get(56).colorValue; + customTheme.commentVerticalBarColor1 = customThemeSettingsItems.get(57).colorValue; + customTheme.commentVerticalBarColor2 = customThemeSettingsItems.get(58).colorValue; + customTheme.commentVerticalBarColor3 = customThemeSettingsItems.get(59).colorValue; + customTheme.commentVerticalBarColor4 = customThemeSettingsItems.get(60).colorValue; + customTheme.commentVerticalBarColor5 = customThemeSettingsItems.get(61).colorValue; + customTheme.commentVerticalBarColor6 = customThemeSettingsItems.get(62).colorValue; + customTheme.commentVerticalBarColor7 = customThemeSettingsItems.get(63).colorValue; + customTheme.navBarColor = customThemeSettingsItems.get(64).colorValue; + customTheme.isLightStatusBar = customThemeSettingsItems.get(65).isEnabled; + customTheme.isLightNavBar = customThemeSettingsItems.get(66).isEnabled; + customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface = customThemeSettingsItems.get(67).isEnabled; return customTheme; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java index 42102bcb..48ec7122 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java @@ -28,6 +28,15 @@ public interface CustomThemeDao { @Query("SELECT * FROM custom_themes WHERE name = :name COLLATE NOCASE LIMIT 1") CustomTheme getCustomTheme(String name); + @Query("UPDATE custom_themes SET is_light_theme = 0 WHERE is_light_theme = 1") + void unsetLightTheme(); + + @Query("UPDATE custom_themes SET is_dark_theme = 0 WHERE is_dark_theme = 1") + void unsetDarkTheme(); + + @Query("UPDATE custom_themes SET is_amoled_theme = 0 WHERE is_amoled_theme = 1") + void unsetAmoledTheme(); + @Query("DELETE FROM custom_themes WHERE name = :name") void deleteCustomTheme(String name); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeSettingsItem.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeSettingsItem.java index 97f5d10e..0dbf49de 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeSettingsItem.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeSettingsItem.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit.CustomTheme; import android.content.Context; +import android.os.Build; import android.os.Parcel; import android.os.Parcelable; @@ -44,13 +45,27 @@ public class CustomThemeSettingsItem implements Parcelable { } }; - public static ArrayList convertCustomThemeToSettingsItem(Context context, CustomTheme customTheme) { + public static ArrayList convertCustomThemeToSettingsItem(Context context, + CustomTheme customTheme, + int androidVersion) { ArrayList customThemeSettingsItems = new ArrayList<>(); if (customTheme == null) { return customThemeSettingsItems; } + customThemeSettingsItems.add(new CustomThemeSettingsItem( + context.getString(R.string.theme_item_is_light_theme), + customTheme.isLightTheme + )); + customThemeSettingsItems.add(new CustomThemeSettingsItem( + context.getString(R.string.theme_item_is_dark_theme), + customTheme.isDarkTheme + )); + customThemeSettingsItems.add(new CustomThemeSettingsItem( + context.getString(R.string.theme_item_is_amoled_theme), + customTheme.isAmoledTheme + )); customThemeSettingsItems.add(new CustomThemeSettingsItem( context.getString(R.string.theme_item_color_primary), context.getString(R.string.theme_item_color_primary_detail), @@ -308,6 +323,12 @@ public class CustomThemeSettingsItem implements Parcelable { customThemeSettingsItems.add(new CustomThemeSettingsItem( context.getString(R.string.theme_item_change_status_bar_icon_color_after_toolbar_collapsed_in_immersive_interface), customTheme.isChangeStatusBarIconColorAfterToolbarCollapsedInImmersiveInterface)); + if (androidVersion < Build.VERSION_CODES.O) { + customThemeSettingsItems.get(customThemeSettingsItems.size() - 2).itemDetails = context.getString(R.string.theme_item_available_on_android_8); + } + if (androidVersion < Build.VERSION_CODES.M) { + customThemeSettingsItems.get(customThemeSettingsItems.size() - 3).itemDetails = context.getString(R.string.theme_item_available_on_android_6); + } return customThemeSettingsItems; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java index 8244ce4f..b53fbab8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeWrapper.java @@ -377,7 +377,17 @@ public class CustomThemeWrapper { themeType == CustomThemeSharedPreferencesUtils.LIGHT); } - public static ArrayList getPredifinedThemes(Context context) { + public static CustomTheme getPredefinedCustomTheme(Context context, String name) { + if (name.equals(context.getString(R.string.theme_name_indigo_dark))) { + return getIndigoDark(context); + } else if (name.equals(context.getString(R.string.theme_name_indigo_amoled))) { + return getIndigoAmoled(context); + } else { + return getIndigo(context); + } + } + + public static ArrayList getPredefinedThemes(Context context) { ArrayList customThemes = new ArrayList<>(); customThemes.add(getIndigo(context)); customThemes.add(getIndigoDark(context)); @@ -534,7 +544,7 @@ public class CustomThemeWrapper { } public static CustomTheme getIndigoAmoled(Context context) { - CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_indigo_dark)); + CustomTheme customTheme = new CustomTheme(context.getString(R.string.theme_name_indigo_amoled)); customTheme.isLightTheme = false; customTheme.isDarkTheme = true; customTheme.isAmoledTheme = false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java index f96f6f21..aa41849c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java @@ -53,7 +53,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat { Preference customizeLightThemePreference = findPreference(SharedPreferencesUtils.CUSTOMIZE_LIGHT_THEME); Preference customizeDarkThemePreference = findPreference(SharedPreferencesUtils.CUSTOMIZE_DARK_THEME); Preference customizeAmoledThemePreference = findPreference(SharedPreferencesUtils.CUSTOMIZE_AMOLED_THEME); - Preference selectAndCustomizeThemePreference = findPreference(SharedPreferencesUtils.SELECT_AND_CUSTOMIZE_THEME); + Preference selectAndCustomizeThemePreference = findPreference(SharedPreferencesUtils.MANAGE_THEMES); boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q; if (themePreference != null && amoledDarkSwitch != null) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java index d9385249..08f55dfe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -80,5 +80,5 @@ public class SharedPreferencesUtils { public static final String CUSTOMIZE_LIGHT_THEME = "customize_light_theme"; public static final String CUSTOMIZE_DARK_THEME = "customize_dark_theme"; public static final String CUSTOMIZE_AMOLED_THEME = "customize_amoled_theme"; - public static final String SELECT_AND_CUSTOMIZE_THEME = "select_and_customize_theme"; + public static final String MANAGE_THEMES = "manage_themes"; } -- cgit v1.2.3