Fix issue with default sort times

Previously, if the default sort type is set to "top of x time", most failed to load any posts.
This commit is contained in:
Balazs Toldi 2023-08-11 08:42:16 +02:00
parent 82414bba55
commit 3afd2601f0
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
2 changed files with 15 additions and 16 deletions

View File

@ -137,7 +137,6 @@ import eu.toldi.infinityforlemmy.post.PostPagingSource;
import eu.toldi.infinityforlemmy.post.PostViewModel; import eu.toldi.infinityforlemmy.post.PostViewModel;
import eu.toldi.infinityforlemmy.postfilter.PostFilter; import eu.toldi.infinityforlemmy.postfilter.PostFilter;
import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage; import eu.toldi.infinityforlemmy.postfilter.PostFilterUsage;
import eu.toldi.infinityforlemmy.utils.LemmyUtils;
import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils; import eu.toldi.infinityforlemmy.utils.SharedPreferencesUtils;
import eu.toldi.infinityforlemmy.utils.Utils; import eu.toldi.infinityforlemmy.utils.Utils;
import eu.toldi.infinityforlemmy.videoautoplay.ExoCreator; import eu.toldi.infinityforlemmy.videoautoplay.ExoCreator;
@ -530,7 +529,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName,
mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TYPE, SortType.Type.HOT.name())); mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TYPE, SortType.Type.HOT.name()));
if (sort.equals(sort.equals(SortType.Type.TOP.name()))) { if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName,
mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name())); mSharedPreferences.getString(SharedPreferencesUtils.SUBREDDIT_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
} }
@ -538,7 +537,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
if (sortTime != null) { if (sortTime != null) {
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); sortType = new SortType(SortType.Type.fromValue(sortTime));
} else { } else {
sortType = new SortType(SortType.Type.valueOf(sort)); sortType = new SortType(SortType.Type.valueOf(sort));
} }
@ -670,10 +669,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username,
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name())); mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TYPE, SortType.Type.NEW.name()));
if (sort.equals(SortType.Type.TOP.name())) { if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username,
mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name())); mSharedPreferences.getString(SharedPreferencesUtils.USER_DEFAULT_SORT_TIME, SortType.Time.ALL.name()));
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime)); sortType = new SortType(SortType.Type.fromValue(sortTime));
} else { } else {
sortType = new SortType(SortType.Type.valueOf(sort)); sortType = new SortType(SortType.Type.valueOf(sort));
} }

View File

@ -543,17 +543,17 @@
</string-array> </string-array>
<string-array name="settings_default_sort_time_values"> <string-array name="settings_default_sort_time_values">
<item>HOUR</item> <item>TopHour</item>
<item>6HOURS</item> <item>TopSixHour</item>
<item>12HOURS</item> <item>TopTwelveHour</item>
<item>DAY</item> <item>TopDay</item>
<item>WEEK</item> <item>TopWeek</item>
<item>MONTH</item> <item>TopMonth</item>
<item>3MONTHS</item> <item>TopThreeMonths</item>
<item>6MONTHS</item> <item>TopSixMonths</item>
<item>9MONTHS</item> <item>TopNineMonths</item>
<item>YEAR</item> <item>TopYear</item>
<item>ALL</item> <item>TopAll</item>
</string-array> </string-array>
<string-array name="settings_default_search_result_tab"> <string-array name="settings_default_search_result_tab">