aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/AndroidManifest.xml5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java37
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java99
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java16
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java1
-rw-r--r--app/src/main/res/layout/item_theme_type_divider.xml5
-rw-r--r--app/src/main/res/values/strings.xml5
-rw-r--r--app/src/main/res/xml/theme_preferences.xml9
9 files changed, 164 insertions, 16 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 233d5efc..dafb5596 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -21,7 +21,10 @@
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true"
tools:replace="android:label">
- <activity android:name=".Activity.CustomThemeListingActivity"></activity>
+ <activity android:name=".Activity.CustomThemeListingActivity"
+ android:label="@string/custom_theme_listing_activity_label"
+ android:parentActivityName=".Activity.MainActivity"
+ android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".Activity.CustomizeThemeActivity"
android:parentActivityName=".Activity.MainActivity"
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 8ba9a885..791cd336 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CustomThemeListingActivity.java
@@ -2,8 +2,12 @@ package ml.docilealligator.infinityforreddit.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.view.MenuItem;
+import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
+import androidx.lifecycle.ViewModelProvider;
+import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.AppBarLayout;
@@ -12,7 +16,11 @@ import javax.inject.Inject;
import javax.inject.Named;
import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Adapter.CustomThemeListingRecyclerViewAdapter;
+import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeViewModel;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@@ -31,11 +39,40 @@ public class CustomThemeListingActivity extends BaseActivity {
RedditDataRoomDatabase redditDataRoomDatabase;
@Inject
CustomThemeWrapper customThemeWrapper;
+ public CustomThemeViewModel customThemeViewModel;
@Override
protected void onCreate(Bundle savedInstanceState) {
+ ((Infinity) getApplication()).getAppComponent().inject(this);
+
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom_theme_listing);
+
+ ButterKnife.bind(this);
+
+ applyCustomTheme();
+
+ setSupportActionBar(toolbar);
+ getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+
+ CustomThemeListingRecyclerViewAdapter adapter = new CustomThemeListingRecyclerViewAdapter(this,
+ CustomThemeWrapper.getPredifinedThemes(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));
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ if (item.getItemId() == android.R.id.home) {
+ finish();
+ return true;
+ }
+ return false;
}
@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 9504317d..81487a02 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CustomThemeListingRecyclerViewAdapter.java
@@ -12,6 +12,7 @@ import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
+import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
@@ -20,49 +21,123 @@ import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme;
import ml.docilealligator.infinityforreddit.R;
public class CustomThemeListingRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+ private static final int VIEW_TYPE_PREDEFINED_THEME = 0;
+ private static final int VIEW_TYPE_USER_THME = 1;
+ private static final int VIEW_TYPE_PREDEFINED_THEME_DIVIDER = 2;
+ private static final int VIEW_TYPE_USER_THEME_DIVIDER = 3;
+
private Context context;
- private ArrayList<CustomTheme> customThemes;
+ private ArrayList<CustomTheme> predefinedCustomThemes;
+ private ArrayList<CustomTheme> userCustomThemes;
- public CustomThemeListingRecyclerViewAdapter(Context context) {
+ public CustomThemeListingRecyclerViewAdapter(Context context, ArrayList<CustomTheme> predefinedCustomThemes) {
this.context = context;
- customThemes = new ArrayList<>();
+ this.predefinedCustomThemes = predefinedCustomThemes;
+ userCustomThemes = new ArrayList<>();
+ }
+
+ @Override
+ public int getItemViewType(int position) {
+ if (position == 0) {
+ return VIEW_TYPE_PREDEFINED_THEME_DIVIDER;
+ } else if (position < 1 + predefinedCustomThemes.size()) {
+ return VIEW_TYPE_PREDEFINED_THEME;
+ } else if (position == 1 + predefinedCustomThemes.size()) {
+ return VIEW_TYPE_USER_THEME_DIVIDER;
+ } else {
+ return VIEW_TYPE_USER_THME;
+ }
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- return new CustomThemeViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_custom_theme, parent, false));
+ switch (viewType) {
+ 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));
+ 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));
+ }
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
- if (holder instanceof CustomThemeViewHolder) {
- CustomTheme customTheme = customThemes.get(position);
- ((CustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary));
- ((CustomThemeViewHolder) holder).nameTextView.setText(customTheme.name);
- ((CustomThemeViewHolder) holder).itemView.setOnClickListener(view -> {
+ if (holder instanceof PredefinedCustomThemeViewHolder) {
+ CustomTheme customTheme = predefinedCustomThemes.get(position - 1);
+ ((PredefinedCustomThemeViewHolder) holder).colorPrimaryView.setBackgroundTintList(ColorStateList.valueOf(customTheme.colorPrimary));
+ ((PredefinedCustomThemeViewHolder) holder).nameTextView.setText(customTheme.name);
+ ((PredefinedCustomThemeViewHolder) holder).itemView.setOnClickListener(view -> {
Intent intent = new Intent(context, CustomizeThemeActivity.class);
intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name);
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).itemView.setOnClickListener(view -> {
+ Intent intent = new Intent(context, CustomizeThemeActivity.class);
+ intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_NAME, customTheme.name);
+ context.startActivity(intent);
+ });
+ } else if (holder instanceof PreDefinedThemeDividerViewHolder) {
+ ((TextView) ((PreDefinedThemeDividerViewHolder) holder).itemView).setText(R.string.predefined_themes);
+ } else if (holder instanceof UserThemeDividerViewHolder) {
+ ((TextView) ((UserThemeDividerViewHolder) holder).itemView).setText(R.string.user_themes);
}
}
@Override
public int getItemCount() {
- return 0;
+ return predefinedCustomThemes.size() + userCustomThemes.size() + 2;
+ }
+
+ public void setUserThemes(List<CustomTheme> userThemes) {
+ userCustomThemes = (ArrayList<CustomTheme>) userThemes;
+ notifyDataSetChanged();
}
- class CustomThemeViewHolder extends RecyclerView.ViewHolder {
+ class PredefinedCustomThemeViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.color_primary_item_custom_theme)
View colorPrimaryView;
@BindView(R.id.name_text_view_item_custom_theme)
TextView nameTextView;
- public CustomThemeViewHolder(@NonNull View itemView) {
+ public PredefinedCustomThemeViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
}
+
+ class UserCustomThemeViewHolder extends RecyclerView.ViewHolder {
+
+ @BindView(R.id.color_primary_item_custom_theme)
+ View colorPrimaryView;
+ @BindView(R.id.name_text_view_item_custom_theme)
+ TextView nameTextView;
+
+ public UserCustomThemeViewHolder(@NonNull View itemView) {
+ super(itemView);
+ ButterKnife.bind(this, itemView);
+ }
+ }
+
+ class PreDefinedThemeDividerViewHolder extends RecyclerView.ViewHolder {
+
+ public PreDefinedThemeDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ }
+ }
+
+ class UserThemeDividerViewHolder extends RecyclerView.ViewHolder {
+
+ public UserThemeDividerViewHolder(@NonNull View itemView) {
+ super(itemView);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index 80c6c6c7..b7c2c947 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -7,6 +7,7 @@ import ml.docilealligator.infinityforreddit.Activity.AccountPostsActivity;
import ml.docilealligator.infinityforreddit.Activity.AccountSavedThingActivity;
import ml.docilealligator.infinityforreddit.Activity.CommentActivity;
import ml.docilealligator.infinityforreddit.Activity.CreateMultiRedditActivity;
+import ml.docilealligator.infinityforreddit.Activity.CustomThemeListingActivity;
import ml.docilealligator.infinityforreddit.Activity.CustomizeThemeActivity;
import ml.docilealligator.infinityforreddit.Activity.EditCommentActivity;
import ml.docilealligator.infinityforreddit.Activity.EditPostActivity;
@@ -143,4 +144,6 @@ public interface AppComponent {
void inject(ThemePreferenceFragment themePreferenceFragment);
void inject(CustomizeThemeActivity customizeThemeActivity);
+
+ void inject(CustomThemeListingActivity customThemeListingActivity);
}
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 58dbf619..f96f6f21 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/ThemePreferenceFragment.java
@@ -19,6 +19,7 @@ import org.greenrobot.eventbus.EventBus;
import javax.inject.Inject;
+import ml.docilealligator.infinityforreddit.Activity.CustomThemeListingActivity;
import ml.docilealligator.infinityforreddit.Activity.CustomizeThemeActivity;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
@@ -52,6 +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);
boolean systemDefault = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q;
if (themePreference != null && amoledDarkSwitch != null) {
@@ -112,7 +114,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
Intent intent = new Intent(activity, CustomizeThemeActivity.class);
intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_TYPE, CustomizeThemeActivity.EXTRA_LIGHT_THEME);
startActivity(intent);
- return false;
+ return true;
});
}
@@ -121,7 +123,7 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
Intent intent = new Intent(activity, CustomizeThemeActivity.class);
intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_TYPE, CustomizeThemeActivity.EXTRA_DARK_THEME);
startActivity(intent);
- return false;
+ return true;
});
}
@@ -130,7 +132,15 @@ public class ThemePreferenceFragment extends PreferenceFragmentCompat {
Intent intent = new Intent(activity, CustomizeThemeActivity.class);
intent.putExtra(CustomizeThemeActivity.EXTRA_THEME_TYPE, CustomizeThemeActivity.EXTRA_AMOLED_THEME);
startActivity(intent);
- return false;
+ return true;
+ });
+ }
+
+ if (selectAndCustomizeThemePreference != null) {
+ selectAndCustomizeThemePreference.setOnPreferenceClickListener(preference -> {
+ Intent intent = new Intent(activity, CustomThemeListingActivity.class);
+ startActivity(intent);
+ return true;
});
}
}
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 ef15d5e6..d9385249 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -80,4 +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";
}
diff --git a/app/src/main/res/layout/item_theme_type_divider.xml b/app/src/main/res/layout/item_theme_type_divider.xml
new file mode 100644
index 00000000..0933ae9c
--- /dev/null
+++ b/app/src/main/res/layout/item_theme_type_divider.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp" /> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fc88749c..b8d4e657 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -19,6 +19,7 @@
<string name="multi_reddit_listing_activity_label">Multireddit</string>
<string name="create_multi_reddit_activity_label">Create Multireddit</string>
<string name="subreddit_multiselection_activity_label">Select Subreddits</string>
+ <string name="custom_theme_listing_activity_label">Custom Themes</string>
<string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string>
@@ -361,6 +362,8 @@
<string name="settings_customize_light_theme_title">Light Theme</string>
<string name="settings_customize_dark_theme_title">Dark Theme</string>
<string name="settings_customize_amoled_theme_title">Amoled Theme</string>
+ <string name="settings_select_and_customize_theme_title">Select and Customize Themes</string>
+ <string name="settings_custom_theme_cannot_apply_to_settings_page_title">Custom themes cannot be applied to settings page.</string>
<string name="no_link_available">Cannot get the link</string>
@@ -598,6 +601,8 @@
<string name="theme_item_available_on_android_8">Only available for Android 8.0 or above.</string>
<string name="theme_item_available_on_android_6">Only available for Android 6.0 or above.</string>
+ <string name="predefined_themes">Predefined Themes</string>
+ <string name="user_themes">Your Themes</string>
<string name="theme_name_indigo">Indigo</string>
<string name="theme_name_indigo_dark">Indigo Dark</string>
<string name="theme_name_indigo_amoled">Indigo Amoled</string>
diff --git a/app/src/main/res/xml/theme_preferences.xml b/app/src/main/res/xml/theme_preferences.xml
index e7d9c13f..5bcc5ef3 100644
--- a/app/src/main/res/xml/theme_preferences.xml
+++ b/app/src/main/res/xml/theme_preferences.xml
@@ -33,4 +33,13 @@
app:icon="@drawable/ic_dark_theme_preference_24dp"
app:title="@string/settings_customize_amoled_theme_title" />
+ <Preference
+ app:key="select_and_customize_theme"
+ app:icon="@drawable/ic_edit_24dp"
+ app:title="@string/settings_select_and_customize_theme_title" />
+
+ <Preference
+ app:summary="@string/settings_custom_theme_cannot_apply_to_settings_page_title"
+ app:enabled="false" />
+
</PreferenceScreen> \ No newline at end of file