aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java31
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java27
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java17
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllPostLayoutsAsyncTask.java57
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java58
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllThemesAsyncTask.java45
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java62
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java141
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java7
-rw-r--r--app/src/main/res/drawable-night/ic_info_preference_24dp.xml9
-rw-r--r--app/src/main/res/drawable/ic_info_preference_24dp.xml9
-rw-r--r--app/src/main/res/values/strings.xml14
-rw-r--r--app/src/main/res/xml/advanced_preferences.xml13
-rw-r--r--app/src/main/res/xml/theme_preferences.xml3
28 files changed, 504 insertions, 120 deletions
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 29b49d24..6ff51607 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
@@ -64,6 +64,9 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private boolean isInLazyMode = false;
private boolean mNullAccessToken = false;
@@ -281,7 +284,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
@Override
public void postLayoutSelected(int postLayout) {
if (mFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + mAccountName, postLayout).apply();
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
}
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 545bce1d..cd39817c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
@@ -72,6 +72,9 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private boolean isInLazyMode = false;
private boolean mNullAccessToken = false;
@@ -399,16 +402,16 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
if (mFragment != null) {
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
break;
case PostDataSource.TYPE_SUBREDDIT:
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + name, postLayout).apply();
break;
case PostDataSource.TYPE_USER:
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + name, postLayout).apply();
break;
case PostDataSource.TYPE_SEARCH:
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
}
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
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 1a38677a..0c1989c3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -161,6 +161,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private SectionsPagerAdapter sectionsPagerAdapter;
private AppBarLayout.LayoutParams params;
@@ -739,7 +745,6 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
return true;
case R.id.action_search_main_activity:
Intent intent = new Intent(this, SearchActivity.class);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent);
return true;
case R.id.action_refresh_main_activity:
@@ -999,7 +1004,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else {
switch (position) {
case 0:
- return "Best";
+ return "Home";
case 1:
return "Popular";
case 2:
@@ -1188,25 +1193,25 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
} else {
switch (viewPager.getCurrentItem()) {
case 0:
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
}
frontPagePostFragment.changeSortType(sortType);
break;
case 1:
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, sortType.getTime().name()).apply();
}
popularPostFragment.changeSortType(sortType);
break;
case 2:
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, sortType.getType().name()).apply();
if (sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_ALL_POST, sortType.getTime().name()).apply();
}
allPostFragment.changeSortType(sortType);
@@ -1261,12 +1266,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (mAccessToken == null) {
if (viewPager.getCurrentItem() == 0) {
if (popularPostFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply();
popularPostFragment.changePostLayout(postLayout);
}
} else {
if (allPostFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply();
allPostFragment.changePostLayout(postLayout);
}
}
@@ -1274,19 +1279,19 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
switch (viewPager.getCurrentItem()) {
case 0:
if (frontPagePostFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, postLayout).apply();
frontPagePostFragment.changePostLayout(postLayout);
}
break;
case 1:
if (popularPostFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, postLayout).apply();
popularPostFragment.changePostLayout(postLayout);
}
break;
case 2:
if (allPostFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, postLayout).apply();
allPostFragment.changePostLayout(postLayout);
}
}
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 e075d9a5..0160401a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchActivity.java
@@ -171,9 +171,9 @@ public class SearchActivity extends BaseActivity {
Intent intent = getIntent();
if (intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
- subredditName = intent.getExtras().getString(EXTRA_SUBREDDIT_NAME);
+ subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
subredditNameTextView.setText(subredditName);
- subredditIsUser = intent.getExtras().getBoolean(EXTRA_SUBREDDIT_IS_USER);
+ subredditIsUser = intent.getBooleanExtra(EXTRA_SUBREDDIT_IS_USER, false);
}
}
@@ -196,7 +196,7 @@ public class SearchActivity extends BaseActivity {
simpleSearchView.setIconsColor(toolbarPrimaryTextAndIconColorColor);
simpleSearchView.setTextColor(toolbarPrimaryTextAndIconColorColor);
simpleSearchView.setBackIconColor(toolbarPrimaryTextAndIconColorColor);
- simpleSearchView.setHintTextColor(mCustomThemeWrapper.getSecondaryTextColor());
+ simpleSearchView.setHintTextColor(mCustomThemeWrapper.getToolbarPrimaryTextAndIconColor());
searchInTextView.setTextColor(mCustomThemeWrapper.getColorAccent());
subredditNameTextView.setTextColor(mCustomThemeWrapper.getPrimaryTextColor());
}
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 359d408b..dc168e74 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -74,6 +74,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private boolean mNullAccessToken = false;
private String mAccessToken;
@@ -225,7 +231,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
return true;
case R.id.action_search_search_result_activity:
Intent intent = new Intent(this, SearchActivity.class);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
+ if (mSubredditName != null && !mSubredditName.equals("")) {
+ intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, mSubredditName);
+ }
intent.putExtra(SearchActivity.EXTRA_QUERY, mQuery);
finish();
startActivity(intent);
@@ -375,9 +383,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
void changeSortType(SortType sortType) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}
postFragment.changeSortType(sortType);
@@ -386,11 +394,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
void changeSortType(SortType sortType, int fragmentPosition) {
switch (fragmentPosition) {
case 1:
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, sortType.getType().name()).apply();
subredditListingFragment.changeSortType(sortType);
break;
case 2:
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, sortType.getType().name()).apply();
userListingFragment.changeSortType(sortType);
}
}
@@ -417,7 +425,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
void changePostLayout(int postLayout) {
if (postFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, postLayout).apply();
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
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 3cdd25ba..d6d32b67 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
@@ -74,6 +74,12 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private boolean mNullAccessToken = false;
private String mAccessToken;
@@ -209,7 +215,6 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
return true;
case R.id.action_search_view_multi_reddit_detail_activity:
Intent intent = new Intent(this, SearchActivity.class);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent);
return true;
case R.id.action_refresh_view_multi_reddit_detail_activity:
@@ -284,10 +289,10 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Override
public void sortTypeSelected(SortType sortType) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath,
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiPath,
sortType.getType().name()).apply();
if(sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath,
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE+ multiPath,
sortType.getTime().name()).apply();
}
@@ -305,7 +310,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
@Override
public void postLayoutSelected(int postLayout) {
if (mFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiPath, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiPath, postLayout).apply();
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
}
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 160a5b42..75a53c5c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -159,6 +159,9 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
private RequestManager mGlide;
private Locale mLocale;
@@ -562,7 +565,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mSwipeRefreshLayout.setRefreshing(true);
mGlide.clear(mFetchPostInfoImageView);
- String sortType = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase();
+ String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, SortType.Type.BEST.value).toLowerCase();
Call<String> postAndComments;
@@ -839,7 +842,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
}
private void fetchComments(boolean changeRefreshState) {
- String sortType = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT,
+ String sortType = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT,
SortType.Type.BEST.value).toLowerCase();
fetchComments(changeRefreshState, true, sortType);
}
@@ -1585,7 +1588,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
children.clear();
}
fetchComments(false, false, sortType.getType().value);
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT, sortType.getType().name()).apply();
}
public void lockSwipeRightToGoBack() {
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 daddd979..b34ce856 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -147,6 +147,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
public SubredditViewModel mSubredditViewModel;
private SectionsPagerAdapter sectionsPagerAdapter;
@@ -609,6 +615,12 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override
public void onPageSelected(int position) {
+ if (mAccessToken != null) {
+ if (showBottomAppBar) {
+ bottomNavigationView.performShow();
+ }
+ fab.show();
+ }
if (isInLazyMode) {
if (viewPager.getCurrentItem() == 0) {
sectionsPagerAdapter.resumeLazyMode();
@@ -656,8 +668,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
case R.id.action_search_view_subreddit_detail_activity:
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, false);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent);
return true;
case R.id.action_refresh_view_subreddit_detail_activity:
@@ -774,11 +784,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
@Override
public void postLayoutSelected(int postLayout) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
sectionsPagerAdapter.changePostLayout(postLayout);
}
- public void postScrollUp() {
+ public void contentScrollUp() {
if (mAccessToken != null) {
if (showBottomAppBar && !lockBottomAppBar) {
bottomNavigationView.performShow();
@@ -789,7 +799,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
}
}
- public void postScrollDown() {
+ public void contentScrollDown() {
if (mAccessToken != null) {
if (!(showBottomAppBar && lockBottomAppBar)) {
fab.hide();
@@ -825,7 +835,6 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public Fragment getItem(int position) {
if (position == 0) {
PostFragment fragment = new PostFragment();
- fragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
@@ -914,9 +923,9 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
public void changeSortType(SortType sortType) {
if (postFragment != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortType.getTime().name()).apply();
}
postFragment.changeSortType(sortType);
@@ -931,7 +940,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
void changePostLayout(int postLayout) {
if (postFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, postLayout).apply();
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
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 95ce79e1..c6bfec6a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -125,6 +125,12 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper mCustomThemeWrapper;
public UserViewModel userViewModel;
private SectionsPagerAdapter sectionsPagerAdapter;
@@ -577,7 +583,6 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
Intent intent = new Intent(this, SearchActivity.class);
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, username);
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true);
- intent.putExtra(SearchActivity.EXTRA_SEARCH_ONLY_SUBREDDITS, false);
startActivity(intent);
return true;
case R.id.action_refresh_view_user_detail_activity:
@@ -811,18 +816,18 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
public void changeSortType(SortType sortType) {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
}
postFragment.changeSortType(sortType);
}
} else {
if (commentsListingFragment != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, sortType.getType().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, sortType.getType().name()).apply();
if(sortType.getTime() != null) {
- mSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, sortType.getTime().name()).apply();
+ mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, sortType.getTime().name()).apply();
}
commentsListingFragment.changeSortType(sortType);
@@ -838,7 +843,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
void changePostLayout(int postLayout) {
if (postFragment != null) {
- mSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply();
+ mPostLayoutSharedPreferences.edit().putInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, postLayout).apply();
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java
index a9500914..18662781 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/SubscribedSubredditsRecyclerViewAdapter.java
@@ -158,6 +158,9 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
((SubredditViewHolder) viewHolder).favoriteImageView.setVisibility(View.GONE);
name = username;
iconUrl = userIconUrl;
+ if (itemClickListener != null) {
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
+ }
} else {
int offset;
if (itemClickListener != null) {
@@ -234,11 +237,13 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
});
}
});
+
+ if (itemClickListener != null) {
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
+ }
}
- if (itemClickListener != null) {
- viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
- } else {
+ if (itemClickListener == null) {
viewHolder.itemView.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, name);
@@ -332,7 +337,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
});
if (itemClickListener != null) {
- viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, true));
+ viewHolder.itemView.setOnClickListener(view -> itemClickListener.onClick(name, iconUrl, false));
} else {
viewHolder.itemView.setOnClickListener(view -> {
Intent intent = new Intent(mContext, ViewSubredditDetailActivity.class);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 70567266..fe483c3c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -16,6 +16,7 @@ import dagger.Provides;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Utils.CustomThemeSharedPreferencesUtils;
import ml.docilealligator.infinityforreddit.Utils.RedditUtils;
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
@@ -128,6 +129,18 @@ class AppModule {
}
@Provides
+ @Named("sort_type")
+ SharedPreferences provideSortTypeSharedPreferences() {
+ return mApplication.getSharedPreferences(SharedPreferencesUtils.SORT_TYPE_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
+ }
+
+ @Provides
+ @Named("post_layout")
+ SharedPreferences providePostLayoutSharedPreferences() {
+ return mApplication.getSharedPreferences(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
+ }
+
+ @Provides
@Singleton
CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences,
@Named("dark_theme") SharedPreferences darkThemeSharedPreferences,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllPostLayoutsAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllPostLayoutsAsyncTask.java
new file mode 100644
index 00000000..fb81d1e6
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllPostLayoutsAsyncTask.java
@@ -0,0 +1,57 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+public class DeleteAllPostLayoutsAsyncTask extends AsyncTask<Void, Void, Void> {
+
+ private SharedPreferences defaultSharedPreferences;
+ private SharedPreferences postLayoutSharedPreferences;
+ private DeleteAllPostLayoutsAsyncTaskListener deleteAllPostLayoutsAsyncTaskListener;
+
+ public interface DeleteAllPostLayoutsAsyncTaskListener {
+ void success();
+ }
+
+ public DeleteAllPostLayoutsAsyncTask(SharedPreferences defaultSharedPreferences,
+ SharedPreferences postLayoutSharedPreferences,
+ DeleteAllPostLayoutsAsyncTaskListener deleteAllPostLayoutsAsyncTaskListener) {
+ this.defaultSharedPreferences = defaultSharedPreferences;
+ this.postLayoutSharedPreferences = postLayoutSharedPreferences;
+ this.deleteAllPostLayoutsAsyncTaskListener = deleteAllPostLayoutsAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ Map<String,?> keys = defaultSharedPreferences.getAll();
+ SharedPreferences.Editor editor = defaultSharedPreferences.edit();
+
+ for(Map.Entry<String,?> entry : keys.entrySet()){
+ String key = entry.getKey();
+ if (key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SHARED_PREFERENCES_FILE)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_ALL_POST)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) {
+ editor.remove(key);
+ }
+ }
+ editor.apply();
+
+ postLayoutSharedPreferences.edit().clear().apply();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteAllPostLayoutsAsyncTaskListener.success();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java
new file mode 100644
index 00000000..153e0899
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllSortTypesAsyncTask.java
@@ -0,0 +1,58 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+
+import java.util.Map;
+
+import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
+
+public class DeleteAllSortTypesAsyncTask extends AsyncTask<Void, Void, Void> {
+ private SharedPreferences defaultSharedPreferences;
+ private SharedPreferences sortTypeSharedPreferences;
+ private DeleteAllSortTypesAsyncTaskListener deleteAllSortTypesAsyncTaskListener;
+
+ public interface DeleteAllSortTypesAsyncTaskListener {
+ void success();
+ }
+
+ public DeleteAllSortTypesAsyncTask(SharedPreferences defaultSharedPreferences,
+ SharedPreferences sortTypeSharedPreferences,
+ DeleteAllSortTypesAsyncTaskListener deleteAllSortTypesAsyncTaskListener) {
+ this.defaultSharedPreferences = defaultSharedPreferences;
+ this.sortTypeSharedPreferences = sortTypeSharedPreferences;
+ this.deleteAllSortTypesAsyncTaskListener = deleteAllSortTypesAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ Map<String,?> keys = defaultSharedPreferences.getAll();
+ SharedPreferences.Editor editor = defaultSharedPreferences.edit();
+
+ for(Map.Entry<String,?> entry : keys.entrySet()){
+ String key = entry.getKey();
+ if (key.startsWith(SharedPreferencesUtils.SORT_TYPE_BEST_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_BEST_POST)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_ALL_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_ALL_POST)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_POPULAR_POST)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST) || key.startsWith(SharedPreferencesUtils.SORT_TIME_SEARCH_POST)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE) || key.startsWith(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT) || key.startsWith(SharedPreferencesUtils.SORT_TIME_USER_COMMENT)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT) || key.startsWith(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER)
+ || key.startsWith(SharedPreferencesUtils.SORT_TYPE_POST_COMMENT)) {
+ editor.remove(key);
+ }
+ }
+ editor.apply();
+
+ sortTypeSharedPreferences.edit().clear().apply();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteAllSortTypesAsyncTaskListener.success();
+ }
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllThemesAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllThemesAsyncTask.java
new file mode 100644
index 00000000..0859fefd
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/DeleteAllThemesAsyncTask.java
@@ -0,0 +1,45 @@
+package ml.docilealligator.infinityforreddit.AsyncTask;
+
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+
+import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+
+public class DeleteAllThemesAsyncTask extends AsyncTask<Void, Void, Void> {
+ private RedditDataRoomDatabase redditDataRoomDatabase;
+ private SharedPreferences lightThemeSharedPreferences;
+ private SharedPreferences darkThemeSharedPreferences;
+ private SharedPreferences amoledThemeSharedPreferences;
+ private DeleteAllThemesAsyncTaskListener deleteAllThemesAsyncTaskListener;
+
+ public interface DeleteAllThemesAsyncTaskListener {
+ void success();
+ }
+
+ public DeleteAllThemesAsyncTask(RedditDataRoomDatabase redditDataRoomDatabase,
+ SharedPreferences lightThemeSharedPreferences,
+ SharedPreferences darkThemeSharedPreferences,
+ SharedPreferences amoledThemeSharedPreferences,
+ DeleteAllThemesAsyncTaskListener deleteAllThemesAsyncTaskListener) {
+ this.redditDataRoomDatabase = redditDataRoomDatabase;
+ this.lightThemeSharedPreferences = lightThemeSharedPreferences;
+ this.darkThemeSharedPreferences = darkThemeSharedPreferences;
+ this.amoledThemeSharedPreferences = amoledThemeSharedPreferences;
+ this.deleteAllThemesAsyncTaskListener = deleteAllThemesAsyncTaskListener;
+ }
+
+ @Override
+ protected Void doInBackground(Void... voids) {
+ redditDataRoomDatabase.customThemeDao().deleteAllCustomThemes();
+ lightThemeSharedPreferences.edit().clear().apply();
+ darkThemeSharedPreferences.edit().clear().apply();
+ amoledThemeSharedPreferences.edit().clear().apply();
+ return null;
+ }
+
+ @Override
+ protected void onPostExecute(Void aVoid) {
+ super.onPostExecute(aVoid);
+ deleteAllThemesAsyncTaskListener.success();
+ }
+}
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 f6443841..86a0f43b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AsyncTask/InsertCustomThemeAsyncTask.java
@@ -49,19 +49,19 @@ public class InsertCustomThemeAsyncTask extends AsyncTask<Void, Void, Void> {
if (customTheme.isLightTheme) {
redditDataRoomDatabase.customThemeDao().unsetLightTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, lightThemeSharedPreferences);
- } else if (previousTheme.isLightTheme) {
+ } else if (previousTheme != null && previousTheme.isLightTheme) {
lightThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isDarkTheme) {
redditDataRoomDatabase.customThemeDao().unsetDarkTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, darkThemeSharedPreferences);
- } else if (previousTheme.isDarkTheme) {
+ } else if (previousTheme != null && previousTheme.isDarkTheme) {
darkThemeSharedPreferences.edit().clear().apply();
}
if (customTheme.isAmoledTheme) {
redditDataRoomDatabase.customThemeDao().unsetAmoledTheme();
CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(customTheme, amoledThemeSharedPreferences);
- } else if (previousTheme.isAmoledTheme) {
+ } else if (previousTheme != null && previousTheme.isAmoledTheme) {
amoledThemeSharedPreferences.edit().clear().apply();
}
redditDataRoomDatabase.customThemeDao().insert(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 8741f8e5..68b4de13 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CustomTheme/CustomThemeDao.java
@@ -51,4 +51,7 @@ public interface CustomThemeDao {
@Query("UPDATE custom_themes SET name = :newName WHERE name = :oldName")
void updateName(String oldName, String newName);
+
+ @Query("DELETE FROM custom_themes")
+ void deleteAllCustomThemes();
}
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 5b1b8359..caf3a5cf 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -84,6 +84,12 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper customThemeWrapper;
private boolean mNullAccessToken = false;
private String mAccessToken;
@@ -165,10 +171,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
() -> mCommentViewModel.retryLoadingMore());
String username = getArguments().getString(EXTRA_USERNAME);
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_COMMENT, SortType.Type.NEW.value);
SortType sortType;
if(sort.equals(SortType.Type.CONTROVERSIAL.value) || sort.equals(SortType.Type.TOP.value)) {
- String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value);
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_COMMENT, SortType.Time.ALL.value);
sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()), SortType.Time.valueOf(sortTime.toUpperCase()));
} else {
sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
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 25a850bc..07ef965a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -114,6 +114,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
CustomThemeWrapper customThemeWrapper;
private RequestManager mGlide;
private AppCompatActivity activity;
@@ -303,9 +309,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
if (dy > 0) {
- ((ViewSubredditDetailActivity) activity).postScrollDown();
+ ((ViewSubredditDetailActivity) activity).contentScrollDown();
} else if (dy < 0) {
- ((ViewSubredditDetailActivity) activity).postScrollUp();
+ ((ViewSubredditDetailActivity) activity).contentScrollUp();
}
}
@@ -329,10 +335,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String subredditName = getArguments().getString(EXTRA_NAME);
String query = getArguments().getString(EXTRA_QUERY);
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name());
- String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.RELEVANCE.name());
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
SortType sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
@@ -373,24 +379,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
if(displaySubredditName) {
if(subredditName.equals("popular")) {
- sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, SortType.Type.HOT.name());
+ sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_POPULAR_POST, SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name());
+ sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_POPULAR_POST, SortType.Time.ALL.name());
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_POPULAR_POST, defaultPostLayout);
} else {
- sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.name());
+ sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_ALL_POST, SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name());
+ sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_ALL_POST, SortType.Time.ALL.name());
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_ALL_POST, defaultPostLayout);
}
} else {
- sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name());
+ sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name());
+ sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name());
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
}
if(sortTime != null) {
@@ -434,13 +440,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sortTime = null;
SortType sortType;
- sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
+ sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Type.HOT.name());
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
+ sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Time.ALL.name());
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
defaultPostLayout);
if(sortTime != null) {
@@ -487,15 +493,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mFetchPostInfoLinearLayout.setLayoutParams(params);
}
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name());
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name());
SortType sortType;
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name());
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(SortType.Type.valueOf(sort));
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
@@ -528,15 +534,15 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
filter, nsfw)).get(PostViewModel.class);
}
} else {
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
SortType sortType;
if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
- String sortTime = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
+ String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(SortType.Type.valueOf(sort));
}
- postLayout = mSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
+ postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mRedditDataRoomDatabase,
customThemeWrapper, accessToken, postType, postLayout, true,
@@ -804,27 +810,27 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (bundle != null) {
switch (postType) {
case PostDataSource.TYPE_SUBREDDIT:
- if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
+ if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_USER:
- if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) {
+ if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + bundle.getString(EXTRA_USER_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_MULTI_REDDIT:
- if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
+ if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + bundle.getString(EXTRA_NAME))) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_SEARCH:
- if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) {
+ if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST)) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
case PostDataSource.TYPE_FRONT_PAGE:
- if (!mSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) {
+ if (!mPostLayoutSharedPreferences.contains(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST)) {
changePostLayout(changeDefaultPostLayoutEvent.defaultPostLayout);
}
break;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
index 3e2aea9c..cb87a956 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
@@ -39,6 +39,7 @@ import io.noties.markwon.recycler.table.TableEntryPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity;
+import ml.docilealligator.infinityforreddit.Activity.ViewSubredditDetailActivity;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
@@ -134,6 +135,17 @@ public class SidebarFragment extends Fragment {
recyclerView.setLayoutManager(new LinearLayoutManager(activity));
recyclerView.setAdapter(markwonAdapter);
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+ if (dy > 0) {
+ ((ViewSubredditDetailActivity) activity).contentScrollDown();
+ } else if (dy < 0) {
+ ((ViewSubredditDetailActivity) activity).contentScrollUp();
+ }
+
+ }
+ });
mSubredditViewModel = new ViewModelProvider(this,
new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, subredditName))
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 1b0f3401..2625d1bb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
@@ -82,6 +82,9 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
CustomThemeWrapper customThemeWrapper;
private LinearLayoutManager mLinearLayoutManager;
private SubredditListingRecyclerViewAdapter mAdapter;
@@ -124,7 +127,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value);
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_SUBREDDIT, SortType.Type.RELEVANCE.value);
SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new SubredditListingRecyclerViewAdapter(mActivity, mOauthRetrofit, mRetrofit,
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 07430235..0cf3ea71 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
@@ -78,6 +78,9 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Named("default")
SharedPreferences mSharedPreferences;
@Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
CustomThemeWrapper customThemeWrapper;
private LinearLayoutManager mLinearLayoutManager;
private String mQuery;
@@ -119,7 +122,7 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mQuery = getArguments().getString(EXTRA_QUERY);
String accessToken = getArguments().getString(EXTRA_ACCESS_TOKEN);
String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
- String sort = mSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value);
+ String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_USER, SortType.Type.RELEVANCE.value);
SortType sortType = new SortType(SortType.Type.valueOf(sort.toUpperCase()));
mAdapter = new UserListingRecyclerViewAdapter(getActivity(), mOauthRetrofit, mRetrofit,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
index 5101e60c..de92c7fe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AdvancedPreferenceFragment.java
@@ -12,11 +12,19 @@ import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
+import com.google.android.material.dialog.MaterialAlertDialogBuilder;
+
+import org.greenrobot.eventbus.EventBus;
+
import javax.inject.Inject;
import javax.inject.Named;
+import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllPostLayoutsAsyncTask;
+import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllSortTypesAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllSubredditsAsyncTask;
+import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllThemesAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.DeleteAllUsersAsyncTask;
+import ml.docilealligator.infinityforreddit.Event.RecreateActivityEvent;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
@@ -32,6 +40,21 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat {
@Inject
@Named("default")
SharedPreferences mSharedPreferences;
+ @Inject
+ @Named("sort_type")
+ SharedPreferences mSortTypeSharedPreferences;
+ @Inject
+ @Named("post_layout")
+ SharedPreferences mPostLayoutSharedPreferences;
+ @Inject
+ @Named("light_theme")
+ SharedPreferences lightThemeSharedPreferences;
+ @Inject
+ @Named("dark_theme")
+ SharedPreferences darkThemeSharedPreferences;
+ @Inject
+ @Named("amoled_theme")
+ SharedPreferences amoledThemeSharedPreferences;
private Activity activity;
@Override
@@ -44,34 +67,96 @@ public class AdvancedPreferenceFragment extends PreferenceFragmentCompat {
Preference deleteUsersPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_USERS_DATA_IN_DATABASE);
Preference deleteSortTypePreference = findPreference(SharedPreferencesUtils.DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE);
Preference deletePostLaoutPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE);
-
- deleteSubredditsPreference.setOnPreferenceClickListener(preference -> {
- new DeleteAllSubredditsAsyncTask(mRedditDataRoomDatabase,
- () -> Toast.makeText(activity, R.string.delete_all_subreddits_success, Toast.LENGTH_SHORT).show()).execute();
- return true;
- });
-
- deleteUsersPreference.setOnPreferenceClickListener(preference -> {
- new DeleteAllUsersAsyncTask(mRedditDataRoomDatabase,
- () -> Toast.makeText(activity, R.string.delete_all_users_success, Toast.LENGTH_SHORT).show()).execute();
- return true;
- });
-
- deleteSortTypePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
-
- return false;
- }
- });
-
- deletePostLaoutPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
-
- return false;
- }
- });
+ Preference deleteAllThemesPreference = findPreference(SharedPreferencesUtils.DELETE_ALL_THEMES_IN_DATABASE);
+ Preference resetAllSettingsPreference = findPreference(SharedPreferencesUtils.RESET_ALL_SETTINGS);
+
+ if (deleteSubredditsPreference != null) {
+ deleteSubredditsPreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> new DeleteAllSubredditsAsyncTask(mRedditDataRoomDatabase,
+ () -> Toast.makeText(activity, R.string.delete_all_subreddits_success, Toast.LENGTH_SHORT).show()).execute())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
+
+ if (deleteUsersPreference != null) {
+ deleteUsersPreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> new DeleteAllUsersAsyncTask(mRedditDataRoomDatabase,
+ () -> Toast.makeText(activity, R.string.delete_all_users_success, Toast.LENGTH_SHORT).show()).execute())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
+
+ if (deleteSortTypePreference != null) {
+ deleteSortTypePreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> new DeleteAllSortTypesAsyncTask(mSharedPreferences, mSortTypeSharedPreferences, () -> {
+ Toast.makeText(activity, R.string.delete_all_sort_types_success, Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ }).execute())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
+
+ if (deletePostLaoutPreference != null) {
+ deletePostLaoutPreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> new DeleteAllPostLayoutsAsyncTask(mSharedPreferences, mPostLayoutSharedPreferences, () -> {
+ Toast.makeText(activity, R.string.delete_all_post_layouts_success, Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ }).execute())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
+
+ if (deleteAllThemesPreference != null) {
+ deleteAllThemesPreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> new DeleteAllThemesAsyncTask(mRedditDataRoomDatabase, lightThemeSharedPreferences,
+ darkThemeSharedPreferences, amoledThemeSharedPreferences, () -> {
+ Toast.makeText(activity, R.string.delete_all_themes_success, Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ }).execute())
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
+
+ if (resetAllSettingsPreference != null) {
+ resetAllSettingsPreference.setOnPreferenceClickListener(preference -> {
+ new MaterialAlertDialogBuilder(activity, R.style.MaterialAlertDialogTheme)
+ .setTitle(R.string.are_you_sure)
+ .setPositiveButton(R.string.yes, (dialogInterface, i)
+ -> {
+ mSharedPreferences.edit().clear().apply();
+ Toast.makeText(activity, R.string.reset_all_settings_success, Toast.LENGTH_SHORT).show();
+ EventBus.getDefault().post(new RecreateActivityEvent());
+ })
+ .setNegativeButton(R.string.no, null)
+ .show();
+ return true;
+ });
+ }
}
@Override
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 3675a26c..374a814a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/SharedPreferencesUtils.java
@@ -33,6 +33,8 @@ public class SharedPreferencesUtils {
public static final String IMMERSIVE_INTERFACE_KEY = "immersive_interface";
public static final String BOTTOM_APP_BAR_KEY = "bottom_app_bar";
public static final String VOTE_BUTTONS_ON_THE_RIGHT_KEY = "vote_buttons_on_the_right";
+
+ public static final String SORT_TYPE_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.sort_type";
public static final String SORT_TYPE_BEST_POST = "sort_type_best_post";
public static final String SORT_TIME_BEST_POST = "sort_time_best_post";
public static final String SORT_TYPE_ALL_POST = "sort_type_all_post";
@@ -52,6 +54,8 @@ public class SharedPreferencesUtils {
public static final String SORT_TYPE_SEARCH_SUBREDDIT = "sort_type_search_subreddit";
public static final String SORT_TYPE_SEARCH_USER = "sort_type_search_user";
public static final String SORT_TYPE_POST_COMMENT = "sort_type_post_comment";
+
+ public static final String POST_LAYOUT_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_layout";
public static final String POST_LAYOUT_FRONT_PAGE_POST = "post_layout_best_post";
public static final String POST_LAYOUT_POPULAR_POST = "post_layout_popular_post";
public static final String POST_LAYOUT_ALL_POST = "post_layout_all_post";
@@ -61,6 +65,7 @@ public class SharedPreferencesUtils {
public static final String POST_LAYOUT_SEARCH_POST = "post_layout_search_post";
public static final int POST_LAYOUT_CARD = 0;
public static final int POST_LAYOUT_COMPACT = 1;
+
public static final String PULL_NOTIFICATION_TIME = "pull_notification_time";
public static final String SHOW_ELAPSED_TIME_KEY = "show_elapsed_time";
public static final String DEFAULT_POST_LAYOUT_KEY = "default_post_layout";
@@ -87,4 +92,6 @@ public class SharedPreferencesUtils {
public static final String DELETE_ALL_USERS_DATA_IN_DATABASE= "delete_all_users_data_in_database";
public static final String DELETE_ALL_SORT_TYPE_DATA_IN_DATABASE= "delete_all_sort_type_data_in_database";
public static final String DELETE_ALL_POST_LAYOUT_DATA_IN_DATABASE= "delete_all_post_layout_data_in_database";
+ public static final String DELETE_ALL_THEMES_IN_DATABASE = "delete_all_themes_in_database";
+ public static final String RESET_ALL_SETTINGS = "reset_all_settings";
}
diff --git a/app/src/main/res/drawable-night/ic_info_preference_24dp.xml b/app/src/main/res/drawable-night/ic_info_preference_24dp.xml
new file mode 100644
index 00000000..10088cff
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_info_preference_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"
+ android:fillColor="#4DFFFFFF"/>
+</vector>
diff --git a/app/src/main/res/drawable/ic_info_preference_24dp.xml b/app/src/main/res/drawable/ic_info_preference_24dp.xml
new file mode 100644
index 00000000..88855dce
--- /dev/null
+++ b/app/src/main/res/drawable/ic_info_preference_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:pathData="M11,7h2v2h-2zM11,11h2v6h-2zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z"
+ android:fillColor="#42000000"/>
+</vector>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 67519d2f..7e024f40 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -367,12 +367,15 @@
<string name="settings_customize_dark_theme_title">Dark Theme</string>
<string name="settings_customize_amoled_theme_title">Amoled Theme</string>
<string name="settings_manage_themes_title">Manage Themes</string>
- <string name="settings_custom_theme_cannot_apply_to_settings_page_title">Custom themes cannot be applied to settings page (except toolbar, status bar and navigation bar).</string>
+ <string name="settings_custom_theme_cannot_apply_to_settings_page_summary">Custom themes cannot be applied to settings page (except toolbar, status bar and navigation bar).</string>
<string name="settings_advanced_master_title">Advanced</string>
<string name="settings_delete_all_subreddits_data_in_database_title">Delete All Subreddits in Database</string>
<string name="settings_delete_all_users_data_in_database_title">Delete All Users in Database</string>
- <string name="settings_delete_all_sort_type_data_in_database_title">Delete All Sort Type in Database</string>
- <string name="settings_delete_all_post_layout_data_in_database_title">Delete All Post Layout Data in Database</string>
+ <string name="settings_delete_all_sort_type_data_in_database_title">Delete All Sort Types in Database</string>
+ <string name="settings_delete_all_post_layout_data_in_database_title">Delete All Post Layouts in Database</string>
+ <string name="settings_delete_all_themes_in_database_title">Delete All Themes in Database</string>
+ <string name="settings_reset_all_settings_title">Reset All Settings</string>
+ <string name="settings_advanced_settings_summary">Clean the database and shared preferences</string>
<string name="no_link_available">Cannot get the link</string>
@@ -647,5 +650,10 @@
<string name="delete_all_subreddits_success">Delete all subreddits successful</string>
<string name="delete_all_users_success">Delete all users successful</string>
+ <string name="delete_all_sort_types_success">Delete all sort types successful</string>
+ <string name="delete_all_post_layouts_success">Delete all post layouts successful</string>
+ <string name="delete_all_themes_success">Delete all themes successful</string>
+ <string name="reset_all_settings_success">Reset all settings successful</string>
+
</resources>
diff --git a/app/src/main/res/xml/advanced_preferences.xml b/app/src/main/res/xml/advanced_preferences.xml
index f16e572d..432623d3 100644
--- a/app/src/main/res/xml/advanced_preferences.xml
+++ b/app/src/main/res/xml/advanced_preferences.xml
@@ -18,4 +18,17 @@
app:key="delete_all_post_layout_data_in_database"
app:title="@string/settings_delete_all_post_layout_data_in_database_title" />
+ <Preference
+ app:key="delete_all_themes_in_database"
+ app:title="@string/settings_delete_all_themes_in_database_title" />
+
+ <Preference
+ app:key="reset_all_settings"
+ app:title="@string/settings_reset_all_settings_title" />
+
+ <Preference
+ android:icon="@drawable/ic_info_preference_24dp"
+ app:summary="@string/settings_advanced_settings_summary"
+ app:enabled="false" />
+
</PreferenceScreen> \ No newline at end of file
diff --git a/app/src/main/res/xml/theme_preferences.xml b/app/src/main/res/xml/theme_preferences.xml
index f40ef592..a520fc49 100644
--- a/app/src/main/res/xml/theme_preferences.xml
+++ b/app/src/main/res/xml/theme_preferences.xml
@@ -42,7 +42,8 @@
app:title="@string/settings_manage_themes_title" />
<Preference
- app:summary="@string/settings_custom_theme_cannot_apply_to_settings_page_title"
+ android:icon="@drawable/ic_info_preference_24dp"
+ app:summary="@string/settings_custom_theme_cannot_apply_to_settings_page_summary"
app:enabled="false" />
</PreferenceScreen> \ No newline at end of file