From f3f9642a0e200b62f3010b013e6107d039ae8e90 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Thu, 5 Mar 2020 17:43:27 +0800 Subject: Add a custom theme table in database. --- .../Activity/AccountPostsActivity.java | 2 + .../Activity/AccountSavedThingActivity.java | 1 + .../infinityforreddit/Activity/BaseActivity.java | 16 ++- .../Activity/CommentActivity.java | 1 + .../Activity/CreateMultiRedditActivity.java | 1 + .../Activity/EditCommentActivity.java | 1 + .../Activity/EditPostActivity.java | 1 + .../Activity/FilteredThingActivity.java | 2 + .../Activity/LinkResolverActivity.java | 2 + .../infinityforreddit/Activity/LoginActivity.java | 1 + .../infinityforreddit/Activity/MainActivity.java | 1 + .../Activity/MultiRedditListingActivity.java | 1 + .../Activity/PostImageActivity.java | 1 + .../Activity/PostLinkActivity.java | 1 + .../Activity/PostTextActivity.java | 1 + .../Activity/PostVideoActivity.java | 1 + .../infinityforreddit/Activity/RulesActivity.java | 1 + .../infinityforreddit/Activity/SearchActivity.java | 2 + .../Activity/SearchResultActivity.java | 2 + .../Activity/SearchSubredditsResultActivity.java | 2 + .../Activity/SettingsActivity.java | 2 + .../Activity/SubredditMultiselectionActivity.java | 1 + .../Activity/SubredditSelectionActivity.java | 1 + .../Activity/SubscribedThingListingActivity.java | 1 + .../Activity/ViewGIFActivity.java | 5 +- .../Activity/ViewImageActivity.java | 2 + .../Activity/ViewMessageActivity.java | 1 + .../Activity/ViewMultiRedditDetailActivity.java | 1 + .../Activity/ViewPostDetailActivity.java | 1 + .../Activity/ViewSidebarActivity.java | 1 + .../Activity/ViewSubredditDetailActivity.java | 1 + .../Activity/ViewUserDetailActivity.java | 1 + .../Activity/ViewVideoActivity.java | 2 + .../infinityforreddit/AppModule.java | 10 ++ .../infinityforreddit/CustomTheme/CustomTheme.java | 116 +++++++++++++++++++++ .../CustomTheme/CustomThemeDao.java | 24 +++++ .../CustomTheme/CustomThemeRepository.java | 19 ++++ .../CustomTheme/CustomThemeViewModel.java | 36 +++++++ .../Fragment/CommentsListingFragment.java | 2 +- .../Fragment/FollowedUsersListingFragment.java | 1 + .../infinityforreddit/Fragment/PostFragment.java | 1 + .../Fragment/SubredditListingFragment.java | 2 +- .../SubscribedSubredditsListingFragment.java | 2 +- .../Fragment/UserListingFragment.java | 2 +- .../MultiReddit/MultiRedditRepository.java | 28 +---- .../MultiReddit/MultiRedditViewModel.java | 4 - .../infinityforreddit/PullNotificationWorker.java | 1 + .../infinityforreddit/RedditDataRoomDatabase.java | 44 +++++++- .../GesturesAndButtonsPreferenceFragment.java | 2 + .../Settings/MainPreferenceFragment.java | 2 + .../Settings/NotificationPreferenceFragment.java | 2 + .../Utils/SharedPreferencesUtils.java | 52 +++++++++ 52 files changed, 371 insertions(+), 40 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeRepository.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeViewModel.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java index 2c7416a0..822a47ec 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java @@ -20,6 +20,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -56,6 +57,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean isInLazyMode = false; private boolean mNullAccessToken = false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java index 238ed3ce..0b10698a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java @@ -65,6 +65,7 @@ public class AccountSavedThingActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private SectionsPagerAdapter sectionsPagerAdapter; private Menu mMenu; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java index 863322ce..9200e80a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java @@ -50,8 +50,7 @@ public abstract class BaseActivity extends AppCompatActivity { case 0: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_NO); getTheme().applyStyle(R.style.Theme_Purple, true); - lightStatusbar = !transparentStatusBarAfterToolbarCollapsed; - changeStatusBarIconColor = false; + changeStatusBarIconColor = immersiveInterface; break; case 1: AppCompatDelegate.setDefaultNightMode(MODE_NIGHT_YES); @@ -70,8 +69,7 @@ public abstract class BaseActivity extends AppCompatActivity { } if((getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { getTheme().applyStyle(R.style.Theme_Purple, true); - lightStatusbar = !transparentStatusBarAfterToolbarCollapsed; - changeStatusBarIconColor = false; + changeStatusBarIconColor = immersiveInterface; } else { if(mSharedPreferences.getBoolean(SharedPreferencesUtils.AMOLED_DARK_KEY, false)) { getTheme().applyStyle(R.style.Theme_Default_AmoledDark, true); @@ -172,4 +170,14 @@ public abstract class BaseActivity extends AppCompatActivity { public void setTransparentStatusBarAfterToolbarCollapsed(boolean transparentStatusBarAfterToolbarCollapsed) { this.transparentStatusBarAfterToolbarCollapsed = transparentStatusBarAfterToolbarCollapsed; } + + @Override + protected void onApplyThemeResource(Resources.Theme theme, int resid, boolean first) { + super.onApplyThemeResource(theme, resid, first); + } + + @Override + public Resources.Theme getTheme() { + return super.getTheme(); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java index 73cde34e..fd422e9e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentActivity.java @@ -89,6 +89,7 @@ public class CommentActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java index dcd3a734..61593cd9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CreateMultiRedditActivity.java @@ -66,6 +66,7 @@ public class CreateMultiRedditActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java index 657a0fc4..b71dd151 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditCommentActivity.java @@ -63,6 +63,7 @@ public class EditCommentActivity extends BaseActivity { @Named("oauth") Retrofit mOauthRetrofit; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String mFullName; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java index a93a8b48..fa0a3d74 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/EditPostActivity.java @@ -62,6 +62,7 @@ public class EditPostActivity extends BaseActivity { @Named("oauth") Retrofit mOauthRetrofit; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String mFullName; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java index f2747ff8..66a9b154 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java @@ -20,6 +20,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -64,6 +65,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean isInLazyMode = false; private boolean mNullAccessToken = false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 0a2553de..b112ee47 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import java.util.List; import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; @@ -44,6 +45,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/{0,1}"; @Inject + @Named("default") SharedPreferences mSharedPreferences; public static Uri getRedditUriByPath(String path) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java index 89e19a2b..212dbd0f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LoginActivity.java @@ -59,6 +59,7 @@ public class LoginActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String authCode; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java index af05d808..b9c74256 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java @@ -152,6 +152,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private SectionsPagerAdapter sectionsPagerAdapter; private AppBarLayout.LayoutParams params; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java index 4667ce9d..8080794e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MultiRedditListingActivity.java @@ -70,6 +70,7 @@ public class MultiRedditListingActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; @Inject @Named("oauth") diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java index 69150291..949b5428 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostImageActivity.java @@ -122,6 +122,7 @@ public class PostImageActivity extends BaseActivity implements FlairBottomSheetF @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java index 0f9b54fc..dd9fee91 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostLinkActivity.java @@ -99,6 +99,7 @@ public class PostLinkActivity extends BaseActivity implements FlairBottomSheetFr @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java index 988454e2..c310b3c3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostTextActivity.java @@ -99,6 +99,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java index 33ce3006..d73f9704 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/PostVideoActivity.java @@ -127,6 +127,7 @@ public class PostVideoActivity extends BaseActivity implements FlairBottomSheetF @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java index 57b15c4c..826debd6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/RulesActivity.java @@ -62,6 +62,7 @@ public class RulesActivity extends BaseActivity { @Named("no_oauth") Retrofit mRetrofit; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String mSubredditName; private RulesRecyclerViewAdapter mAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java index 580b7d49..58716b61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java @@ -22,6 +22,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -53,6 +54,7 @@ public class SearchActivity extends BaseActivity { @BindView(R.id.subreddit_name_text_view_search_activity) TextView subredditNameTextView; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String query; private String subredditName; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java index ab2fad08..f21c6515 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java @@ -25,6 +25,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -66,6 +67,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java index 0b8a6b1e..ba1ba5c9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java @@ -19,6 +19,7 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -48,6 +49,7 @@ public class SearchSubredditsResultActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java index adaef84d..81b16bef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SettingsActivity.java @@ -14,6 +14,7 @@ import androidx.preference.PreferenceFragmentCompat; import com.google.android.material.appbar.AppBarLayout; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -34,6 +35,7 @@ public class SettingsActivity extends BaseActivity implements Toolbar toolbar; @Inject + @Named("default") SharedPreferences mSharedPreferences; @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java index 2bf4e5dd..3be8274c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java @@ -74,6 +74,7 @@ public class SubredditMultiselectionActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java index 4abb5a42..ee9efb95 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java @@ -65,6 +65,7 @@ public class SubredditSelectionActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java index 506d47bf..d7da38ef 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java @@ -65,6 +65,7 @@ public class SubscribedThingListingActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java index 5c641cff..72cef5a5 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewGIFActivity.java @@ -47,6 +47,7 @@ import com.github.pwittchen.swipe.library.rx2.Swipe; import java.io.File; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -74,6 +75,7 @@ public class ViewGIFActivity extends AppCompatActivity { @BindView(R.id.load_image_error_linear_layout_view_gif_activity) LinearLayout mLoadErrorLinearLayout; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean isActionBarHidden = false; private boolean isDownloading = false; @@ -406,7 +408,8 @@ public class ViewGIFActivity extends AppCompatActivity { @Override public void saveFailed() { - + Toast.makeText(ViewGIFActivity.this, + R.string.cannot_save_gif, Toast.LENGTH_SHORT).show(); } }).execute(); } else { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java index c58d0736..0697c5e1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewImageActivity.java @@ -52,6 +52,7 @@ import com.github.pwittchen.swipe.library.rx2.Swipe; import java.io.File; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -78,6 +79,7 @@ public class ViewImageActivity extends AppCompatActivity { @BindView(R.id.load_image_error_linear_layout_view_image_activity) LinearLayout mLoadErrorLinearLayout; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean isActionBarHidden = false; private boolean isDownloading = false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java index 0468038a..c765f863 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java @@ -79,6 +79,7 @@ public class ViewMessageActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java index cfe2af6f..2cd68c10 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java @@ -68,6 +68,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java index 9d77c73b..230e6a2a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java @@ -154,6 +154,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private RequestManager mGlide; private Locale mLocale; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java index 35076de2..4955689b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java @@ -70,6 +70,7 @@ public class ViewSidebarActivity extends BaseActivity { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private String subredditName; private SubredditViewModel mSubredditViewModel; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java index b9640612..6d3b3cbe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java @@ -132,6 +132,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java index a71b2c71..e15d805b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java @@ -122,6 +122,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private SectionsPagerAdapter sectionsPagerAdapter; private SubscribedUserDao subscribedUserDao; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 935538e7..7e873010 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -54,6 +54,7 @@ import com.google.android.exoplayer2.util.Util; import java.io.File; import javax.inject.Inject; +import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; @@ -91,6 +92,7 @@ public class ViewVideoActivity extends AppCompatActivity { private float touchY = -1.0f; @Inject + @Named("default") SharedPreferences mSharedPreferences; @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index a8619df8..c64fac50 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.app.Application; +import android.content.Context; import android.content.SharedPreferences; import androidx.preference.PreferenceManager; @@ -13,6 +14,7 @@ import javax.inject.Singleton; import dagger.Module; import dagger.Provides; import ml.docilealligator.infinityforreddit.Utils.RedditUtils; +import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import okhttp3.ConnectionPool; import okhttp3.OkHttpClient; import retrofit2.Retrofit; @@ -97,8 +99,16 @@ class AppModule { } @Provides + @Named("default") @Singleton SharedPreferences provideSharedPreferences() { return PreferenceManager.getDefaultSharedPreferences(mApplication); } + + @Provides + @Named("theme") + @Singleton + SharedPreferences provideThemeSharedPreferences() { + return mApplication.getSharedPreferences(SharedPreferencesUtils.THEME_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java new file mode 100644 index 00000000..799e530d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomTheme.java @@ -0,0 +1,116 @@ +package ml.docilealligator.infinityforreddit.CustomTheme; + +import androidx.annotation.NonNull; +import androidx.room.ColumnInfo; +import androidx.room.Entity; +import androidx.room.PrimaryKey; + +@Entity(tableName = "custom_themes") +public class CustomTheme { + @PrimaryKey + @NonNull + @ColumnInfo(name = "name") + public String name; + @ColumnInfo(name = "color_primary") + public int colorPrimary; + @ColumnInfo(name = "color_primary_dark") + public int colorPrimaryDark; + @ColumnInfo(name = "color_accent") + public int colorAccent; + @ColumnInfo(name = "color_primary_light_theme") + public int colorPrimaryLightTheme; + @ColumnInfo(name = "primary_text_color") + public int primaryTextColor; + @ColumnInfo(name = "secondary_text_color") + public int secondaryTextColor; + @ColumnInfo(name = "background_color") + public int backgroundColor; + @ColumnInfo(name = "rounded_bottom_sheet_primary_background") + public int roundedBottomSheetPrimaryBackground; + @ColumnInfo(name = "card_view_background_color") + public int cardViewBackgroundColor; + @ColumnInfo(name = "toolbar_primary_text_and_icon_color") + public int toolbarPrimaryTextAndIconColor; + @ColumnInfo(name = "toolbar_and_tab_background_color") + public int toolbarAndTabBackgroundColor; + @ColumnInfo(name = "circular_progress_bar_background") + public int circularProgressBarBackground; + @ColumnInfo(name = "tab_layout_with_expanded_collapsing_toolbar_tab_background") + public int tabLayoutWithExpandedCollapsingToolbarTabBackground; + @ColumnInfo(name = "tab_layout_with_expanded_collapsing_toolbar_text_color") + public int tabLayoutWithExpandedCollapsingToolbarTextColor; + @ColumnInfo(name = "tab_layout_with_expanded_collapsing_toolbar_tab_indicator") + public int tabLayoutWithExpandedCollapsingToolbarTabIndicator; + @ColumnInfo(name = "tab_layout_with_collapsed_collapsing_toolbar_tab_background") + public int tabLayoutWithCollapsedCollapsingToolbarTabBackground; + @ColumnInfo(name = "tab_layout_with_collapsed_collapsing_toolbar_text_color") + public int tabLayoutWithCollapsedCollapsingToolbarTextColor; + @ColumnInfo(name = "tab_layout_with_collapsed_collapsing_toolbar_tab_indicator") + public int tabLayoutWithCollapsedCollapsingToolbarTabIndicator; + @ColumnInfo(name = "nav_bar_color") + public int navBarColor; + @ColumnInfo(name = "upvoted") + public int upvoted; + @ColumnInfo(name = "downvoted") + public int downvoted; + @ColumnInfo(name = "post_type") + public int postType; + @ColumnInfo(name = "spoiler_color") + public int spoilerColor; + @ColumnInfo(name = "nsfw_color") + public int nsfwColor; + @ColumnInfo(name = "flair_color") + public int flairColor; + @ColumnInfo(name = "archived_tint") + public int archivedTint; + @ColumnInfo(name = "locked_icon_tint") + public int lockedIconTint; + @ColumnInfo(name = "crosspost") + public int crosspost; + @ColumnInfo(name = "stickied_post") + public int stickiedPost; + @ColumnInfo(name = "subscribed") + public int subscribed; + @ColumnInfo(name = "unsubscribed") + public int unsubscribed; + @ColumnInfo(name = "username") + public int username; + @ColumnInfo(name = "subreddit") + public int subreddit; + @ColumnInfo(name = "author_flair_text_color") + public int authorFlairTextColor; + @ColumnInfo(name = "submitter") + public int submitter; + @ColumnInfo(name = "moderator") + public int moderator; + @ColumnInfo(name = "notification_icon_color") + public int notificationIconColor; + @ColumnInfo(name = "single_comment_thread_background_color") + public int singleCommentThreadBackgroundColor; + @ColumnInfo(name = "unread_message_background_color") + public int unreadMessageBackgroundColor; + @ColumnInfo(name = "divider_color") + public int dividerColor; + @ColumnInfo(name = "no_preview_link_background_color") + public int noPreviewLinkBackgroundColor; + @ColumnInfo(name = "vote_and_reply_unavailable_vote_button_color") + public int voteAndReplyUnavailableVoteButtonColor; + @ColumnInfo(name = "comment_vertical_bar_color_1") + public int commentVerticalBarColor1; + @ColumnInfo(name = "comment_vertical_bar_color_2") + public int commentVerticalBarColor2; + @ColumnInfo(name = "comment_vertical_bar_color_3") + public int commentVerticalBarColor3; + @ColumnInfo(name = "comment_vertical_bar_color_4") + public int commentVerticalBarColor4; + @ColumnInfo(name = "comment_vertical_bar_color_5") + public int commentVerticalBarColor5; + @ColumnInfo(name = "comment_vertical_bar_color_6") + public int commentVerticalBarColor6; + @ColumnInfo(name = "comment_vertical_bar_color_7") + public int commentVerticalBarColor7; + + public CustomTheme(@NonNull String name) { + this.name = name; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java new file mode 100644 index 00000000..f1afb3c4 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java @@ -0,0 +1,24 @@ +package ml.docilealligator.infinityforreddit.CustomTheme; + +import androidx.lifecycle.LiveData; +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.OnConflictStrategy; +import androidx.room.Query; + +import java.util.List; + +@Dao +public interface CustomThemeDao { + @Insert(onConflict = OnConflictStrategy.REPLACE) + void insert(CustomTheme customTheme); + + @Query("SELECT * FROM custom_themes") + LiveData> getAllCustomThemes(); + + @Query("SELECT * FROM custom_themes WHERE name = :name AND username = :username COLLATE NOCASE LIMIT 1") + CustomTheme getCustomTheme(String name, String username); + + @Query("DELETE FROM custom_themes WHERE name = :name AND username = :username") + void deleteCustomTheme(String name, String username); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeRepository.java new file mode 100644 index 00000000..e2c0b692 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeRepository.java @@ -0,0 +1,19 @@ +package ml.docilealligator.infinityforreddit.CustomTheme; + +import androidx.lifecycle.LiveData; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class CustomThemeRepository { + private LiveData> mAllCustomThemes; + + CustomThemeRepository(RedditDataRoomDatabase redditDataRoomDatabase) { + mAllCustomThemes = redditDataRoomDatabase.customThemeDao().getAllCustomThemes(); + } + + LiveData> getAllCustomThemes() { + return mAllCustomThemes; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeViewModel.java new file mode 100644 index 00000000..44a43f23 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeViewModel.java @@ -0,0 +1,36 @@ +package ml.docilealligator.infinityforreddit.CustomTheme; + +import androidx.annotation.NonNull; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.ViewModel; +import androidx.lifecycle.ViewModelProvider; + +import java.util.List; + +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; + +public class CustomThemeViewModel extends ViewModel { + private LiveData> mAllCustomThemes; + + public CustomThemeViewModel(RedditDataRoomDatabase redditDataRoomDatabase) { + mAllCustomThemes = new CustomThemeRepository(redditDataRoomDatabase).getAllCustomThemes(); + } + + public LiveData> getAllCustomThemes() { + return mAllCustomThemes; + } + + public static class Factory extends ViewModelProvider.NewInstanceFactory { + private RedditDataRoomDatabase mRedditDataRoomDatabase; + + public Factory(RedditDataRoomDatabase redditDataRoomDatabase) { + mRedditDataRoomDatabase = redditDataRoomDatabase; + } + + @NonNull + @Override + public T create(@NonNull Class modelClass) { + return (T) new CustomThemeViewModel(mRedditDataRoomDatabase); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java index ee3cc947..8cb75d6a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java @@ -4,7 +4,6 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; @@ -81,6 +80,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private boolean mNullAccessToken = false; private String mAccessToken; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java index 2bd84344..9dad2c5e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java @@ -60,6 +60,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo @Named("oauth") Retrofit mOauthRetrofit; @Inject + @Named("default") SharedPreferences mSharedPreferences; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java index 2605ffa0..7b07c9dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java @@ -112,6 +112,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private RequestManager mGlide; private AppCompatActivity activity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java index 9e16db19..c6a413dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java @@ -5,7 +5,6 @@ import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; @@ -79,6 +78,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private LinearLayoutManager mLinearLayoutManager; private SubredditListingRecyclerViewAdapter mAdapter; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java index a0d2af6c..852590b7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java @@ -4,7 +4,6 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; @@ -66,6 +65,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra @Named("oauth") Retrofit mOauthRetrofit; @Inject + @Named("default") SharedPreferences mSharedPreferences; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java index 726e8c14..4167c483 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java @@ -4,7 +4,6 @@ package ml.docilealligator.infinityforreddit.Fragment; import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; @@ -75,6 +74,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private LinearLayoutManager mLinearLayoutManager; private String mQuery; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditRepository.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditRepository.java index b725caa2..860cdd43 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditRepository.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditRepository.java @@ -1,7 +1,5 @@ package ml.docilealligator.infinityforreddit.MultiReddit; -import android.os.AsyncTask; - import androidx.lifecycle.LiveData; import java.util.List; @@ -9,14 +7,13 @@ import java.util.List; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; public class MultiRedditRepository { - private MultiRedditDao mMultiRedditDao; private LiveData> mAllMultiReddits; private LiveData> mAllFavoriteMultiReddits; MultiRedditRepository(RedditDataRoomDatabase redditDataRoomDatabase, String accountName) { - mMultiRedditDao = redditDataRoomDatabase.multiRedditDao(); - mAllMultiReddits = mMultiRedditDao.getAllMultiReddits(accountName); - mAllFavoriteMultiReddits = mMultiRedditDao.getAllFavoriteMultiReddits(accountName); + MultiRedditDao multiRedditDao = redditDataRoomDatabase.multiRedditDao(); + mAllMultiReddits = multiRedditDao.getAllMultiReddits(accountName); + mAllFavoriteMultiReddits = multiRedditDao.getAllFavoriteMultiReddits(accountName); } LiveData> getAllMultiReddits() { @@ -26,23 +23,4 @@ public class MultiRedditRepository { LiveData> getAllFavoriteMultiReddits() { return mAllFavoriteMultiReddits; } - - public void insert(MultiReddit MultiReddit) { - new MultiRedditRepository.insertAsyncTask(mMultiRedditDao).execute(); - } - - private static class insertAsyncTask extends AsyncTask { - - private MultiRedditDao mAsyncTaskDao; - - insertAsyncTask(MultiRedditDao dao) { - mAsyncTaskDao = dao; - } - - @Override - protected Void doInBackground(final MultiReddit... params) { - mAsyncTaskDao.insert(params[0]); - return null; - } - } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditViewModel.java index bb9dcf76..14f42bee 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/MultiReddit/MultiRedditViewModel.java @@ -32,10 +32,6 @@ public class MultiRedditViewModel extends AndroidViewModel { return mAllFavoriteMultiReddits; } - public void insert(MultiReddit MultiReddit) { - mMultiRedditRepository.insert(MultiReddit); - } - public static class Factory extends ViewModelProvider.NewInstanceFactory { private Application mApplication; private RedditDataRoomDatabase mRedditDataRoomDatabase; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java index 716c4f0b..31da44dc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PullNotificationWorker.java @@ -45,6 +45,7 @@ public class PullNotificationWorker extends Worker { @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject + @Named("default") SharedPreferences mSharedPreferences; private Context context; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java index 4a55da1f..a0d6edb0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/RedditDataRoomDatabase.java @@ -11,6 +11,8 @@ import androidx.sqlite.db.SupportSQLiteDatabase; import ml.docilealligator.infinityforreddit.Account.Account; import ml.docilealligator.infinityforreddit.Account.AccountDao; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomTheme; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeDao; import ml.docilealligator.infinityforreddit.MultiReddit.MultiReddit; import ml.docilealligator.infinityforreddit.MultiReddit.MultiRedditDao; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditDao; @@ -23,7 +25,7 @@ import ml.docilealligator.infinityforreddit.User.UserDao; import ml.docilealligator.infinityforreddit.User.UserData; @Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, - SubscribedUserData.class, MultiReddit.class}, version = 5) + SubscribedUserData.class, MultiReddit.class, CustomTheme.class}, version = 6) public abstract class RedditDataRoomDatabase extends RoomDatabase { private static RedditDataRoomDatabase INSTANCE; @@ -33,7 +35,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { if (INSTANCE == null) { INSTANCE = Room.databaseBuilder(context.getApplicationContext(), RedditDataRoomDatabase.class, "reddit_data") - .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5) + .addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, + MIGRATION_5_6) .build(); } } @@ -53,6 +56,8 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { public abstract MultiRedditDao multiRedditDao(); + public abstract CustomThemeDao customThemeDao(); + private static final Migration MIGRATION_1_2 = new Migration(1, 2) { @Override public void migrate(SupportSQLiteDatabase database) { @@ -106,4 +111,39 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase { + " ADD COLUMN sidebar_description TEXT"); } }; + + private static final Migration MIGRATION_5_6 = new Migration(5, 6) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("CREATE TABLE custom_themes" + + "(name TEXT NOT NULL PRIMARY KEY, color_primary INTEGER NOT NULL," + + "color_primary_dark INTEGER NOT NULL, color_accent INTEGER NOT NULL," + + "color_primary_light_theme INTEGER NOT NULL, primary_text_color INTEGER NOT NULL," + + "secondary_text_color INTEGER NOT NULL, background_color INTEGER NOT NULL," + + "rounded_bottom_sheet_primary_background INTEGER NOT NULL," + + "card_view_background_color INTEGER NOT NULL, toolbar_primary_text_and_icon_color INTEGER NOT NULL," + + "toolbar_and_tab_background_color INTEGER NOT NULL, circular_progress_bar_background INTEGER NOT NULL," + + "tab_layout_with_expanded_collapsing_toolbar_tab_background INTEGER NOT NULL," + + "tab_layout_with_expanded_collapsing_toolbar_text_color INTEGER NOT NULL," + + "tab_layout_with_expanded_collapsing_toolbar_tab_indicator INTEGER NOT NULL," + + "tab_layout_with_collapsed_collapsing_toolbar_tab_background INTEGER NOT NULL," + + "tab_layout_with_collapsed_collapsing_toolbar_text_color INTEGER NOT NULL," + + "tab_layout_with_collapsed_collapsing_toolbar_tab_indicator INTEGER NOT NULL," + + "nav_bar_color INTEGER NOT NULL, upvoted INTEGER NOT NULL, downvoted INTEGER NOT NULL," + + "post_type INTEGER NOT NULL, spoiler_color INTEGER NOT NULL, nsfw_color INTEGER NOT NULL," + + "flair_color INTEGER NOT NULL, archived_tint INTEGER NOT NULL, locked_icon_tint INTEGER NOT NULL," + + "crosspost INTEGER NOT NULL, stickied_post INTEGER NOT NULL, subscribed INTEGER NOT NULL," + + "unsubscribed INTEGER NOT NULL, username INTEGER NOT NULL, subreddit INTEGER NOT NULL," + + "author_flair_text_color INTEGER NOT NULL, submitter INTEGER NOT NULL," + + "moderator INTEGER NOT NULL, notification_icon_color INTEGER NOT NULL," + + "single_comment_thread_background_color INTEGER NOT NULL," + + "unread_message_background_color INTEGER NOT NULL, divider_color INTEGER NOT NULL," + + "no_preview_link_background_color INTEGER NOT NULL," + + "vote_and_reply_unavailable_vote_button_color INTEGER NOT NULL," + + "comment_vertical_bar_color_1 INTEGER NOT NULL, comment_vertical_bar_color_2 INTEGER NOT NULL," + + "comment_vertical_bar_color_3 INTEGER NOT NULL, comment_vertical_bar_color_4 INTEGER NOT NULL," + + "comment_vertical_bar_color_5 INTEGER NOT NULL, comment_vertical_bar_color_6 INTEGER NOT NULL," + + "comment_vertical_bar_color_7 INTEGER NOT NULL)"); + } + }; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/GesturesAndButtonsPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/GesturesAndButtonsPreferenceFragment.java index 255e8d23..ec170cc8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/GesturesAndButtonsPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/GesturesAndButtonsPreferenceFragment.java @@ -14,6 +14,7 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.Event.ChangeLockBottomAppBarEvent; import ml.docilealligator.infinityforreddit.Infinity; @@ -26,6 +27,7 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class GesturesAndButtonsPreferenceFragment extends PreferenceFragmentCompat { @Inject + @Named("default") SharedPreferences sharedPreferences; private Activity activity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java index 5733c32e..1aea7212 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/MainPreferenceFragment.java @@ -14,6 +14,7 @@ import androidx.preference.SwitchPreference; import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWBlurEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; @@ -29,6 +30,7 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class MainPreferenceFragment extends PreferenceFragmentCompat { @Inject + @Named("default") SharedPreferences sharedPreferences; private Activity activity; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java index 36b0326e..f6644468 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/NotificationPreferenceFragment.java @@ -20,6 +20,7 @@ import androidx.work.WorkManager; import java.util.concurrent.TimeUnit; import javax.inject.Inject; +import javax.inject.Named; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.PullNotificationWorker; @@ -32,6 +33,7 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; public class NotificationPreferenceFragment extends PreferenceFragmentCompat { @Inject + @Named("default") SharedPreferences sharedPreferences; private boolean enableNotification; private long notificationInterval; 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 0ff474bd..6d0ba6c6 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java @@ -77,4 +77,56 @@ public class SharedPreferencesUtils { public static final String LOCK_BOTTOM_APP_BAR = "lock_bottom_app_bar"; public static final String SHOW_COMMENT_DIVIDER = "show_comment_divider"; public static final String SHOW_ABSOLUTE_NUMBER_OF_VOTES = "show_absolute_number_of_votes"; + + //Theme + public static final String THEME_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.theme"; + public static final String COLOR_PRIMARY = "colorPrimary"; + public static final String COLOR_PRIMARY_DARK = "colorPrimaryDark"; + public static final String COLOR_ACCENT = "colorAccent"; + public static final String COLOR_PRIMARY_LIGHT_THEME = "colorPrimaryLightTheme"; + public static final String PRIMARY_TEXT_COLOR = "primaryTextColor"; + public static final String SECONDARY_TEXT_COLOR = "secondaryTextColor"; + public static final String BACKGROUND_COLOR = "backgroundColor"; + public static final String ROUNDED_BOTTOM_SHEET_PRIMARY_BACKGROUND = "roundedBottomSheetPrimaryBackground"; + public static final String CARD_VIEW_BACKGROUND_COLOR = "cardViewBackgroundColor"; + public static final String TOOLBAR_PRIMARY_TEXT_AND_ICON_COLOR = "toolbarPrimaryTextAndIconColor"; + public static final String TOOLBAR_AND_TAB_BACKGROUND_COLOR = "toolbarAndTabBackgroundColor"; + public static final String CIRCULAR_PROGRESS_BAR_BACKGROUND = "circularProgressBarBackground"; + public static final String TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_BACKGROUND = "tabLayoutWithExpandedCollapsingToolbarTabBackground"; + public static final String TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TEXT_COLOR = "tabLayoutWithExpandedCollapsingToolbarTextColor"; + public static final String TAB_LAYOUT_WITH_EXPANDED_COLLAPSING_TOOLBAR_TAB_INDICATOR = "tabLayoutWithExpandedCollapsingToolbarTabIndicator"; + public static final String TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_BACKGROUND = "tabLayoutWithCollapsedCollapsingToolbarTabBackground"; + public static final String TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TEXT_COLOR = "tabLayoutWithCollapsedCollapsingToolbarTextColor"; + public static final String TAB_LAYOUT_WITH_COLLAPSED_COLLAPSING_TOOLBAR_TAB_INDICATOR = "tabLayoutWithCollapsedCollapsingToolbarTabIndicator"; + public static final String NAV_BAR_COLOR = "navBarColor"; + public static final String UPVOTED = "upvoted"; + public static final String DOWNVOTED = "downvoted"; + public static final String POST_TYPE = "postType"; + public static final String SPOILER_COLOR = "spoilerColor"; + public static final String NSFW_COLOR = "nsfwColor"; + public static final String FLAIR_COLOR = "flairColor"; + public static final String ARCHIVED_TINT = "archivedTint"; + public static final String LOCKED_ICON_TINT = "lockedIconTint"; + public static final String CROSSPOST = "crosspost"; + public static final String STICKIED_POST = "stickiedPost"; + public static final String SUBSCRIBED = "subscribed"; + public static final String UNSUBSCRIBED = "unsubscribed"; + public static final String USERNAME = "username"; + public static final String SUBREDDIT = "subreddit"; + public static final String AUTHOR_FLAIR_TEXT_COLOR = "authorFlairTextColor"; + public static final String SUBMITTER = "submitter"; + public static final String MODERATOR = "moderator"; + public static final String NOTIFICATION_ICON_COLOR = "notificationIconColor"; + public static final String SINGLE_COMMENT_THREAD_BACKGROUND = "singleCommentThreadBackgroundColor"; + public static final String UNREAD_MESSAGE_BACKGROUND_COLOR = "unreadMessageBackgroundColor"; + public static final String DIVIDER_COLOR = "dividerColor"; + public static final String NO_PREVIEW_LINK_BACKGROUND_COLOR = "noPreviewLinkBackgroundColor"; + public static final String VOTE_AND_REPLY_UNAVAILABLE_VOTE_BUTTON_COLOR = "voteAndReplyUnavailableVoteButtonColor"; + public static final String COMMENT_VERTICAL_BAR_COLOR_1 = "commentVerticalBarColor1"; + public static final String COMMENT_VERTICAL_BAR_COLOR_2 = "commentVerticalBarColor2"; + public static final String COMMENT_VERTICAL_BAR_COLOR_3 = "commentVerticalBarColor3"; + public static final String COMMENT_VERTICAL_BAR_COLOR_4 = "commentVerticalBarColor4"; + public static final String COMMENT_VERTICAL_BAR_COLOR_5 = "commentVerticalBarColor5"; + public static final String COMMENT_VERTICAL_BAR_COLOR_6 = "commentVerticalBarColor6"; + public static final String COMMENT_VERTICAL_BAR_COLOR_7 = "commentVerticalBarColor7"; } -- cgit v1.2.3