mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-29 04:17:12 +01:00
Preparing to add trending search support.
This commit is contained in:
parent
cac9503eb5
commit
08cf438bb0
@ -62,6 +62,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
|
||||
public static final String EXTRA_NAME = "ESN";
|
||||
public static final String EXTRA_QUERY = "EQ";
|
||||
public static final String EXTRA_TRENDING_SOURCE = "ETS";
|
||||
public static final String EXTRA_FILTER = "EF";
|
||||
public static final String EXTRA_CONTAIN_FLAIR = "ECF";
|
||||
public static final String EXTRA_POST_TYPE = "EPT";
|
||||
@ -312,6 +313,7 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
bundle.putString(PostFragment.EXTRA_NAME, name);
|
||||
bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getStringExtra(EXTRA_QUERY));
|
||||
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
||||
}
|
||||
mFragment.setArguments(bundle);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit();
|
||||
|
@ -85,7 +85,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface,
|
||||
FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, RandomBottomSheetFragment.RandomOptionSelectionCallback,
|
||||
PostTypeBottomSheetFragment.PostTypeSelectionCallback, RecyclerViewContentScrollingInterface {
|
||||
static final String EXTRA_QUERY = "QK";
|
||||
|
||||
static final String EXTRA_QUERY = "EQ";
|
||||
static final String EXTRA_TRENDING_SOURCE = "ETS";
|
||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||
|
||||
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
||||
@ -764,6 +766,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
|
||||
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
|
||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||
bundle.putString(PostFragment.EXTRA_ACCOUNT_NAME, mAccountName);
|
||||
mFragment.setArguments(bundle);
|
||||
|
File diff suppressed because one or more lines are too long
@ -136,6 +136,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
public static final String EXTRA_USER_NAME = "EUN";
|
||||
public static final String EXTRA_USER_WHERE = "EUW";
|
||||
public static final String EXTRA_QUERY = "EQ";
|
||||
public static final String EXTRA_TRENDING_SOURCE = "ETS";
|
||||
public static final String EXTRA_POST_TYPE = "EPT";
|
||||
public static final String EXTRA_FILTER = "EF";
|
||||
public static final String EXTRA_ACCESS_TOKEN = "EAT";
|
||||
@ -221,6 +222,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
private String subredditName;
|
||||
private String username;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private String where;
|
||||
private String multiRedditPath;
|
||||
private String concatenatedSubredditNames;
|
||||
@ -423,6 +425,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
subredditName = getArguments().getString(EXTRA_NAME);
|
||||
query = getArguments().getString(EXTRA_QUERY);
|
||||
trendingSource = getArguments().getString(EXTRA_TRENDING_SOURCE);
|
||||
if (savedInstanceState == null) {
|
||||
postFragmentId += query.hashCode();
|
||||
}
|
||||
@ -450,6 +453,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter);
|
||||
startActivity(intent);
|
||||
@ -460,6 +464,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_CONTAIN_FLAIR, flair);
|
||||
startActivity(intent);
|
||||
@ -470,6 +475,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, Post.NSFW_TYPE);
|
||||
startActivity(intent);
|
||||
@ -1096,8 +1102,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
new Handler(), accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
new Handler(), accessToken == null ? mRetrofit : mOauthRetrofit, accessToken,
|
||||
@ -1132,8 +1138,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
mPostViewModel = new ViewModelProvider(PostFragment.this, new PostViewModel.Factory(mExecutor,
|
||||
new Handler(), mRetrofit, null,
|
||||
accountName, mSharedPreferences,
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, postType, sortType,
|
||||
postFilter, readPosts)).get(PostViewModel.class);
|
||||
mPostFeedScrolledPositionSharedPreferences, subredditName, query, trendingSource,
|
||||
postType, sortType, postFilter, readPosts)).get(PostViewModel.class);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
mPostViewModel = new ViewModelProvider(this, new PostViewModel.Factory(mExecutor,
|
||||
new Handler(), mRetrofit, null,
|
||||
@ -1509,6 +1515,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
||||
Intent intent = new Intent(activity, FilteredPostsActivity.class);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_TRENDING_SOURCE, trendingSource);
|
||||
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
|
||||
startActivity(intent);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT) {
|
||||
|
@ -48,6 +48,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String subredditOrUserName;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
@ -151,8 +152,8 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
|
||||
PostDataSource(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String subredditOrUserName, String query, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
String subredditOrUserName, String query, String trendingSource, int postType,
|
||||
SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
@ -162,6 +163,7 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.subredditOrUserName = subredditOrUserName;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
paginationNetworkStateLiveData = new MutableLiveData<>();
|
||||
initialLoadStateLiveData = new MutableLiveData<>();
|
||||
hasPostLiveData = new MutableLiveData<>();
|
||||
@ -639,16 +641,17 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
if (subredditOrUserName == null) {
|
||||
if (accessToken == null) {
|
||||
if (sortType.getTime() != null) {
|
||||
getPost = api.searchPosts(query, lastItem, sortType.getType().value, sortType.getTime().value);
|
||||
getPost = api.searchPosts(query, lastItem, sortType.getType().value, sortType.getTime().value,
|
||||
trendingSource);
|
||||
} else {
|
||||
getPost = api.searchPosts(query, lastItem, sortType.getType().value);
|
||||
getPost = api.searchPosts(query, lastItem, sortType.getType().value, trendingSource);
|
||||
}
|
||||
} else {
|
||||
if(sortType.getTime() != null) {
|
||||
getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
|
||||
sortType.getTime().value, APIUtils.getOAuthHeader(accessToken));
|
||||
sortType.getTime().value, trendingSource, APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value,
|
||||
getPost = api.searchPostsOauth(query, lastItem, sortType.getType().value, trendingSource,
|
||||
APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
}
|
||||
@ -732,16 +735,18 @@ public class PostDataSource extends PageKeyedDataSource<String, Post> {
|
||||
if (subredditOrUserName == null) {
|
||||
if (accessToken == null) {
|
||||
if (sortType.getTime() != null) {
|
||||
getPost = api.searchPosts(query, after, sortType.getType().value, sortType.getTime().value);
|
||||
getPost = api.searchPosts(query, after, sortType.getType().value, sortType.getTime().value,
|
||||
trendingSource);
|
||||
} else {
|
||||
getPost = api.searchPosts(query, after, sortType.getType().value);
|
||||
getPost = api.searchPosts(query, after, sortType.getType().value, trendingSource);
|
||||
}
|
||||
} else {
|
||||
if (sortType.getTime() != null) {
|
||||
getPost = api.searchPostsOauth(query, after, sortType.getType().value,
|
||||
sortType.getTime().value, APIUtils.getOAuthHeader(accessToken));
|
||||
sortType.getTime().value, trendingSource, APIUtils.getOAuthHeader(accessToken));
|
||||
} else {
|
||||
getPost = api.searchPostsOauth(query, after, sortType.getType().value, APIUtils.getOAuthHeader(accessToken));
|
||||
getPost = api.searchPostsOauth(query, after, sortType.getType().value, trendingSource,
|
||||
APIUtils.getOAuthHeader(accessToken));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
@ -26,6 +26,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
@ -94,8 +95,8 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
|
||||
PostDataSourceFactory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, String query, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
String name, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
@ -105,6 +106,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
postDataSourceLiveData = new MutableLiveData<>();
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
@ -121,7 +123,7 @@ class PostDataSourceFactory extends DataSource.Factory {
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
postDataSource = new PostDataSource(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query,
|
||||
sharedPreferences, postFeedScrolledPositionSharedPreferences, name, query, trendingSource,
|
||||
postType, sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
Log.i("asdasfd", "s5 " + (postFilter == null));
|
||||
|
@ -137,9 +137,10 @@ public class PostViewModel extends ViewModel {
|
||||
|
||||
public PostViewModel(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences cache, String subredditName,
|
||||
String query, int postType, SortType sortType, PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
postDataSourceFactory = new PostDataSourceFactory(executor, handler, retrofit, accessToken, accountName,
|
||||
sharedPreferences, cache, subredditName, query, postType, sortType, postFilter,
|
||||
sharedPreferences, cache, subredditName, query, trendingSource, postType, sortType, postFilter,
|
||||
readPostList);
|
||||
|
||||
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
|
||||
@ -211,6 +212,7 @@ public class PostViewModel extends ViewModel {
|
||||
private SharedPreferences postFeedScrolledPositionSharedPreferences;
|
||||
private String name;
|
||||
private String query;
|
||||
private String trendingSource;
|
||||
private int postType;
|
||||
private SortType sortType;
|
||||
private PostFilter postFilter;
|
||||
@ -272,8 +274,8 @@ public class PostViewModel extends ViewModel {
|
||||
|
||||
public Factory(Executor executor, Handler handler, Retrofit retrofit, String accessToken, String accountName,
|
||||
SharedPreferences sharedPreferences, SharedPreferences postFeedScrolledPositionSharedPreferences,
|
||||
String name, String query, int postType, SortType sortType, PostFilter postFilter,
|
||||
List<ReadPost> readPostList) {
|
||||
String name, String query, String trendingSource, int postType, SortType sortType,
|
||||
PostFilter postFilter, List<ReadPost> readPostList) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
this.retrofit = retrofit;
|
||||
@ -283,6 +285,7 @@ public class PostViewModel extends ViewModel {
|
||||
this.postFeedScrolledPositionSharedPreferences = postFeedScrolledPositionSharedPreferences;
|
||||
this.name = name;
|
||||
this.query = query;
|
||||
this.trendingSource = trendingSource;
|
||||
this.postType = postType;
|
||||
this.sortType = sortType;
|
||||
this.postFilter = postFilter;
|
||||
@ -310,7 +313,7 @@ public class PostViewModel extends ViewModel {
|
||||
postFeedScrolledPositionSharedPreferences, postType, sortType, postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SEARCH) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
postFeedScrolledPositionSharedPreferences, name, query, postType, sortType,
|
||||
postFeedScrolledPositionSharedPreferences, name, query, trendingSource, postType, sortType,
|
||||
postFilter, readPostList);
|
||||
} else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
|
||||
return (T) new PostViewModel(executor, handler, retrofit, accessToken, accountName, sharedPreferences,
|
||||
|
Loading…
Reference in New Issue
Block a user