Compare commits

...

6 Commits

Author SHA1 Message Date
Balazs Toldi
ecdd9da9c8
Fix issue where display name makes impossible to load saved things
This commit fixes an issue where the display name of a user makes it
impossible to load saved things. The problem is that the display name
was used in the url to load the saved things instead of the username.

Closes #179

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
2023-10-12 09:16:56 +02:00
Balazs Toldi
1c17e6b7d2
Fix some issues with the "goto User" and "goto Community" options
This commit allows the user to input the communities with their "!" prefix. Similarly, it also allows the "@" prefix for users when trying to navigate to them with their corresponding "go to" options.

Also fixes issues with these options in the Community and User pages.
2023-10-12 08:26:50 +02:00
Balazs Toldi
9f60eca225
Fix crash when trying to open the community lists in some cases.
In some cases the app crashed when trying to select a community. This commit attempts to fix this issue
2023-10-12 08:08:02 +02:00
Balazs Toldi
9deba8b10e
Fixing some sort type issues
This commit fixes issues where the sort type/time isn't loaded properly and the app resets back to NEW on the frontpage and Hot on Community pages.

Heads up: You might need to change the sort type in your settings if you see any issues.
2023-10-12 08:06:06 +02:00
Balazs Toldi
05948d74f4
Fix authentication when opening the app 2023-10-11 14:00:07 +02:00
Balazs Toldi
1007be50f8
Fix autherntiction on first logging in to Lemmy 0.19 2023-10-11 13:56:14 +02:00
10 changed files with 155 additions and 84 deletions

View File

@ -69,15 +69,15 @@ public class SortType {
} }
public enum Time { public enum Time {
HOUR("TopHour", "Top Hour"), HOUR("hour", "Hour"),
SIX_HOURS("TopSixHour", "Top Six Hours"), SIX_HOURS("SixHour", "Six Hours"),
TWELVE_HOURS("TopTwelveHour", "Top Twelve Hours"), TWELVE_HOURS("TwelveHour", "Twelve Hours"),
DAY("day", "Day"), DAY("day", "Day"),
WEEK("week", "Week"), WEEK("week", "Week"),
MONTH("month", "Month"), MONTH("month", "Month"),
THREE_MONTHS("TopThreeMonth", "Top Three Months"), THREE_MONTHS("ThreeMonths", "Three Months"),
SIX_MONTHS("TopSixMonth", "Top Six Months"), SIX_MONTHS("SixMonths", "Six Months"),
NINE_MONTHS("TopNineMonth", "Top Nine Months"), NINE_MONTHS("NineMonths", "Nine Months"),
YEAR("year", "Year"), YEAR("year", "Year"),
ALL("all", "All Time"); ALL("all", "All Time");
@ -88,5 +88,14 @@ public class SortType {
this.value = value; this.value = value;
this.fullName = fullName; this.fullName = fullName;
} }
public static Time fromValue(String value) {
for (Time time : values()) {
if (time.value.equalsIgnoreCase(value)) {
return time;
}
}
return null;
}
} }
} }

View File

@ -283,7 +283,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
PostFragment fragment = new PostFragment(); PostFragment fragment = new PostFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_USER);
bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountName); bundle.putString(PostFragment.EXTRA_USER_NAME, mAccountQualifiedName);
bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED); bundle.putString(PostFragment.EXTRA_USER_WHERE, PostPagingSource.USER_WHERE_SAVED);
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName); bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
@ -293,7 +293,7 @@ public class AccountSavedThingActivity extends BaseActivity implements ActivityT
} }
CommentsListingFragment fragment = new CommentsListingFragment(); CommentsListingFragment fragment = new CommentsListingFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountName); bundle.putString(CommentsListingFragment.EXTRA_USERNAME, mAccountQualifiedName);
bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken); bundle.putString(CommentsListingFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName); bundle.putString(CommentsListingFragment.EXTRA_ACCOUNT_NAME, mAccountName);
bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true); bundle.putBoolean(CommentsListingFragment.EXTRA_ARE_SAVED_COMMENTS, true);

View File

@ -106,6 +106,9 @@ public class LinkResolverActivity extends AppCompatActivity {
if (mAccessToken != null) { if (mAccessToken != null) {
String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null); String instance = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
mRetrofit.setBaseURL(instance); mRetrofit.setBaseURL(instance);
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
mRetrofit.setAccessToken(mAccessToken);
}
} }
Uri uri = getIntent().getData(); Uri uri = getIntent().getData();

View File

@ -8,7 +8,6 @@ import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Editable; import android.text.Editable;
import android.util.Log; import android.util.Log;
import android.util.Patterns;
import android.view.InflateException; import android.view.InflateException;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.Button; import android.widget.Button;
@ -180,6 +179,7 @@ public class LoginActivity extends BaseActivity {
try { try {
JSONObject responseJSON = new JSONObject(accountResponse); JSONObject responseJSON = new JSONObject(accountResponse);
String accessToken = responseJSON.getString("jwt"); String accessToken = responseJSON.getString("jwt");
mRetrofit.setAccessToken(null);
FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username, FetchMyInfo.fetchAccountInfo(mRetrofit.getRetrofit(), mRedditDataRoomDatabase, username,
accessToken, new FetchMyInfo.FetchMyInfoListener() { accessToken, new FetchMyInfo.FetchMyInfoListener() {
@ -189,13 +189,23 @@ public class LoginActivity extends BaseActivity {
@Override @Override
public void onFetchSiteInfoSuccess(SiteInfo siteInfo) { public void onFetchSiteInfoSuccess(SiteInfo siteInfo) {
boolean canDownvote = siteInfo.isEnable_downvotes(); boolean canDownvote = siteInfo.isEnable_downvotes();
ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name,display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance,canDownvote, mRedditDataRoomDatabase.accountDao(), ParseAndInsertNewAccount.parseAndInsertNewAccount(mExecutor, new Handler(), name, display_name, accessToken, profileImageUrl, bannerImageUrl, authCode, finalInstance, canDownvote, mRedditDataRoomDatabase.accountDao(),
() -> { () -> {
Intent resultIntent = new Intent(); Intent resultIntent = new Intent();
setResult(Activity.RESULT_OK, resultIntent); setResult(Activity.RESULT_OK, resultIntent);
finish(); finish();
}); });
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply(); mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.CAN_DOWNVOTE, canDownvote).apply();
String[] version = siteInfo.getVersion().split("\\.");
if (version.length > 0) {
Log.d("SwitchAccount", "Lemmy Version: " + version[0] + "." + version[1]);
int majorVersion = Integer.parseInt(version[0]);
int minorVersion = Integer.parseInt(version[1]);
if (majorVersion > 0 || (majorVersion == 0 && minorVersion >= 19)) {
mRetrofit.setAccessToken(accessToken);
mCurrentAccountSharedPreferences.edit().putBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true).apply();
}
}
} }
@Override @Override

View File

@ -336,11 +336,14 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
fragmentManager = getSupportFragmentManager(); fragmentManager = getSupportFragmentManager();
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null); mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
if (mCurrentAccountSharedPreferences.getBoolean(SharedPreferencesUtils.BEARER_TOKEN_AUTH, true)) {
mRetrofit.setAccessToken(mAccessToken);
}
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null); mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null); mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null); String instance = (mAccessToken == null) ? mSharedPreferences.getString(SharedPreferencesUtils.ANONYMOUS_ACCOUNT_INSTANCE, APIUtils.API_BASE_URI) : mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_INSTANCE, null);
if(instance != null) { if (instance != null) {
mRetrofit.setBaseURL(instance); mRetrofit.setBaseURL(instance);
} }
@ -1511,7 +1514,12 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
return true; return true;
} }
@ -1569,7 +1577,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@ -1590,7 +1602,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString()); String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent); startActivity(userIntent);
return true; return true;
} }
@ -1603,7 +1619,11 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, thingEditText.getText().toString()); String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent); startActivity(userIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {

View File

@ -1518,7 +1518,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
return true; return true;
} }
@ -1576,7 +1580,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@ -1597,7 +1605,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent); startActivity(userIntent);
return true; return true;
} }
@ -1610,7 +1622,11 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); String qualifiedName = thingEditText.getText().toString();
if (qualifiedName.startsWith("@")) {
qualifiedName = qualifiedName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, qualifiedName);
startActivity(userIntent); startActivity(userIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {

View File

@ -1514,7 +1514,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
return true; return true;
} }
@ -1572,7 +1576,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class);
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); String communityName = thingEditText.getText().toString();
if (communityName.startsWith("!")) {
communityName = communityName.substring(1);
}
subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_COMMUNITY_FULL_NAME_KEY, communityName);
startActivity(subredditIntent); startActivity(subredditIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
@ -1593,7 +1601,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
if (i == EditorInfo.IME_ACTION_DONE) { if (i == EditorInfo.IME_ACTION_DONE) {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); String userName = thingEditText.getText().toString();
if (userName.startsWith("@")) {
userName = userName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_QUALIFIED_USER_NAME_KEY, userName);
startActivity(userIntent); startActivity(userIntent);
return true; return true;
} }
@ -1606,7 +1618,11 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
-> { -> {
Utils.hideKeyboard(this); Utils.hideKeyboard(this);
Intent userIntent = new Intent(this, ViewUserDetailActivity.class); Intent userIntent = new Intent(this, ViewUserDetailActivity.class);
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); String userName = thingEditText.getText().toString();
if (userName.startsWith("@")) {
userName = userName.substring(1);
}
userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, userName);
startActivity(userIntent); startActivity(userIntent);
}) })
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {

View File

@ -158,7 +158,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
mFavoriteSubscribedSubredditData.size() + 3 : 1; mFavoriteSubscribedSubredditData.size() + 3 : 1;
} else { } else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ? offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
mFavoriteSubscribedSubredditData.size() + 2 : 1; mFavoriteSubscribedSubredditData.size() + 2 : 0;
} }
} else { } else {
offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ? offset = (mFavoriteSubscribedSubredditData != null && mFavoriteSubscribedSubredditData.size() > 0) ?
@ -301,7 +301,7 @@ public class SubscribedSubredditsRecyclerViewAdapter extends RecyclerView.Adapte
} }
if (itemClickListener != null) { if (itemClickListener != null) {
return mSubscribedSubredditData.size() > 0 ? mSubscribedSubredditData.size() + 1 : 0; return (hasClearSelectionRow) ? mSubscribedSubredditData.size() + 1 : mSubscribedSubredditData.size();
} }
return mSubscribedSubredditData.size(); return mSubscribedSubredditData.size();

View File

@ -536,17 +536,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
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()));
} }
sortType = newSortType(sort, sortTime);
boolean displaySubredditName = subredditName != null && (subredditName.equals("local") || subredditName.equals("all")); boolean displaySubredditName = subredditName != null && (subredditName.equals("local") || subredditName.equals("all"));
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
SortType.Type st = SortType.Type.fromValue(sort);
st = st == null ? SortType.Type.HOT : st;
if (sortTime != null) {
st = SortType.Type.fromValue(sortTime);
st = st == null ? SortType.Type.TOP_ALL : st;
sortType = new SortType(st);
} else {
sortType = new SortType(st);
}
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale, mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
@ -610,16 +605,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Time.ALL.name()); SortType.Time.ALL.name());
} }
sortType = newSortType(sort, sortTime);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
defaultPostLayout); defaultPostLayout);
SortType.Type st = SortType.Type.fromValue(sort);
st = st == null ? SortType.Type.HOT : st;
if (sortTime != null) {
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(st);
}
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale, mRedgifsRetrofit, mStreamableApiProvider, mCustomThemeWrapper, locale,
@ -677,17 +668,14 @@ 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()));
SortType.Type st = SortType.Type.fromValue(sort); String sortTime = null;
st = st == null ? SortType.Type.NEW : st;
if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) { if (sort.equalsIgnoreCase(SortType.Type.TOP.value)) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, 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()));
st = SortType.Type.fromValue(sortTime);
st = st == null ? SortType.Type.NEW : st;
sortType = new SortType(st);
} else {
sortType = new SortType(st);
} }
sortType = newSortType(sort, sortTime);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_USER_POST_BASE + username, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
@ -744,14 +732,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
subredditName = getArguments().getString(EXTRA_NAME); subredditName = getArguments().getString(EXTRA_NAME);
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name()); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", SortType.Type.HOT.name());
SortType.Type st = SortType.Type.fromValue(sort); String sortTime = null;
st = st == null ? SortType.Type.NEW : st;
if (sort.equals(SortType.Type.TOP.name())) { if (sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name()); sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", SortType.Time.ALL.name());
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(st);
} }
sortType = newSortType(sort, sortTime);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
@ -806,14 +791,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
nameOfUsage = multiRedditPath; nameOfUsage = multiRedditPath;
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Type.HOT.name()); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Type.HOT.name());
SortType.Type st = SortType.Type.fromValue(sort); String sortTime = null;
st = st == null ? SortType.Type.NEW : st;
if (sort.equals(SortType.Type.TOP.name())) { if (sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name()); sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, SortType.Time.ALL.name());
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(st);
} }
sortType = newSortType(sort, sortTime);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath, defaultPostLayout);
@ -866,14 +848,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
nameOfUsage = PostFilterUsage.NO_USAGE; nameOfUsage = PostFilterUsage.NO_USAGE;
subredditName = getArguments().getString(EXTRA_NAME); subredditName = getArguments().getString(EXTRA_NAME);
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.ACTIVE.name()); String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.ACTIVE.name());
SortType.Type st = SortType.Type.fromValue(sort); String sortTime = null;
st = st == null ? SortType.Type.NEW : st;
if (sort.equals(SortType.Type.TOP.name())) { if (sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name()); sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
sortType = new SortType(st, SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(st);
} }
sortType = newSortType(sort, sortTime);
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout); postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_FRONT_PAGE_POST, defaultPostLayout);
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit, mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit, mGfycatRetrofit,
@ -1389,25 +1368,25 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) { if (mSharedPreferences.getBoolean(SharedPreferencesUtils.SAVE_SORT_TYPE, true)) {
switch (postType) { switch (postType) {
case PostPagingSource.TYPE_FRONT_PAGE: case PostPagingSource.TYPE_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, sortType.getType().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_BEST_POST, sortType.getTime().name()).apply();
} }
break; break;
case PostPagingSource.TYPE_SUBREDDIT: case PostPagingSource.TYPE_SUBREDDIT:
mSortTypeSharedPreferences.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().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.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();
} }
break; break;
case PostPagingSource.TYPE_USER: case PostPagingSource.TYPE_USER:
mSortTypeSharedPreferences.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().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.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();
} }
break; break;
case PostPagingSource.TYPE_SEARCH: case PostPagingSource.TYPE_SEARCH:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}else { }else {
@ -1417,14 +1396,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
case PostPagingSource.TYPE_MULTI_REDDIT: case PostPagingSource.TYPE_MULTI_REDDIT:
case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT: case PostPagingSource.TYPE_ANONYMOUS_MULTIREDDIT:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath, mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getType().name()).apply(); sortType.getType().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath, mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
sortType.getTime().name()).apply(); sortType.getTime().name()).apply();
} }
break; break;
case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE: case PostPagingSource.TYPE_ANONYMOUS_FRONT_PAGE:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + "-", sortType.getType().value).apply();
if (sortType.getTime() != null) { if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply(); mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + "-", sortType.getTime().name()).apply();
} }
@ -2263,6 +2242,24 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return false; return false;
} }
public SortType newSortType(String sortTypeText, String sortTimeText) {
SortType.Type st = SortType.Type.fromValue(sortTypeText);
st = st == null ? SortType.Type.NEW : st;
SortType result;
if (sortTypeText.startsWith("Top")) {
sortTimeText = st.value.substring(3);
result = new SortType(st, SortType.Time.fromValue(sortTimeText));
} else if (sortTimeText != null) {
SortType.Time sortTime = SortType.Time.fromValue(sortTimeText);
SortType.Type sortType = SortType.Type.fromValue("Top" + sortTimeText);
result = new SortType(sortType != null ? sortType : st, sortTime);
} else {
result = new SortType(st);
}
return result;
}
private static abstract class LazyModeRunnable implements Runnable { private static abstract class LazyModeRunnable implements Runnable {
private int currentPosition = -1; private int currentPosition = -1;

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>TopHour</item> <item>hour</item>
<item>TopSixHour</item> <item>SixHour</item>
<item>TopTwelveHour</item> <item>TwelveHour</item>
<item>TopDay</item> <item>day</item>
<item>TopWeek</item> <item>week</item>
<item>TopMonth</item> <item>month</item>
<item>TopThreeMonths</item> <item>ThreeMonths</item>
<item>TopSixMonths</item> <item>SixMonths</item>
<item>TopNineMonths</item> <item>NineMonths</item>
<item>TopYear</item> <item>year</item>
<item>TopAll</item> <item>all</item>
</string-array> </string-array>
<string-array name="settings_default_search_result_tab"> <string-array name="settings_default_search_result_tab">