mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-30 03:24:44 +01:00
Basic search post functionality
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
3b91ee0280
commit
ad7083b423
@ -57,6 +57,15 @@ public class SortType {
|
|||||||
this.value = value;
|
this.value = value;
|
||||||
this.fullName = fullName;
|
this.fullName = fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Type fromValue(String value) {
|
||||||
|
for (Type type : values()) {
|
||||||
|
if (type.value.equals(value)) {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Time {
|
public enum Time {
|
||||||
|
@ -75,6 +75,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
public static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
public static final String EXTRA_RETURN_USER_ICON_URL = "ERUIU";
|
||||||
public static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
|
public static final String EXTRA_IS_MULTI_SELECTION = "EIMS";
|
||||||
public static final int SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE = 101;
|
public static final int SUICIDE_PREVENTION_ACTIVITY_REQUEST_CODE = 101;
|
||||||
|
public static final String EXTRA_COMMUNITY_FULL_NAME = "ECF";
|
||||||
|
|
||||||
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
private static final String SUBREDDIT_NAME_STATE = "SNS";
|
||||||
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
private static final String SUBREDDIT_IS_USER_STATE = "SIUS";
|
||||||
@ -82,6 +83,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
|
||||||
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1;
|
private static final int SUBREDDIT_SEARCH_REQUEST_CODE = 1;
|
||||||
private static final int USER_SEARCH_REQUEST_CODE = 2;
|
private static final int USER_SEARCH_REQUEST_CODE = 2;
|
||||||
|
private static final String COMMUNITY_QUALIFIED_NAME = "CQN";
|
||||||
|
|
||||||
@BindView(R.id.coordinator_layout_search_activity)
|
@BindView(R.id.coordinator_layout_search_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@ -125,6 +127,8 @@ public class SearchActivity extends BaseActivity {
|
|||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String query;
|
private String query;
|
||||||
private String subredditName;
|
private String subredditName;
|
||||||
|
|
||||||
|
private String communityQualifiedName;
|
||||||
private boolean subredditIsUser;
|
private boolean subredditIsUser;
|
||||||
private boolean searchOnlySubreddits;
|
private boolean searchOnlySubreddits;
|
||||||
private boolean searchOnlyUsers;
|
private boolean searchOnlyUsers;
|
||||||
@ -296,6 +300,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
if (intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
if (intent.hasExtra(EXTRA_SUBREDDIT_NAME)) {
|
||||||
subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
subredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
|
communityQualifiedName = intent.getStringExtra(EXTRA_COMMUNITY_FULL_NAME);
|
||||||
subredditNameTextView.setText(subredditName);
|
subredditNameTextView.setText(subredditName);
|
||||||
subredditIsUser = intent.getBooleanExtra(EXTRA_SUBREDDIT_IS_USER, false);
|
subredditIsUser = intent.getBooleanExtra(EXTRA_SUBREDDIT_IS_USER, false);
|
||||||
}
|
}
|
||||||
@ -364,6 +369,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, "u_" + subredditName);
|
||||||
} else {
|
} else {
|
||||||
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(SearchResultActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
|
intent.putExtra(SearchResultActivity.EXTRA_COMMUNITY_QUALIFIED_NAME, communityQualifiedName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@ -477,6 +483,7 @@ public class SearchActivity extends BaseActivity {
|
|||||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
outState.putString(SUBREDDIT_NAME_STATE, subredditName);
|
||||||
|
outState.putString(COMMUNITY_QUALIFIED_NAME, communityQualifiedName);
|
||||||
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
outState.putBoolean(SUBREDDIT_IS_USER_STATE, subredditIsUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
static final String EXTRA_SUBREDDIT_NAME = "ESN";
|
||||||
|
|
||||||
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
private static final String INSERT_SEARCH_QUERY_SUCCESS_STATE = "ISQSS";
|
||||||
|
public static final String EXTRA_COMMUNITY_QUALIFIED_NAME = "ECQN";
|
||||||
@BindView(R.id.coordinator_layout_search_result_activity)
|
@BindView(R.id.coordinator_layout_search_result_activity)
|
||||||
CoordinatorLayout coordinatorLayout;
|
CoordinatorLayout coordinatorLayout;
|
||||||
@BindView(R.id.appbar_layout_search_result_activity)
|
@BindView(R.id.appbar_layout_search_result_activity)
|
||||||
@ -132,8 +133,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
private Call<String> subredditAutocompleteCall;
|
private Call<String> subredditAutocompleteCall;
|
||||||
private String mAccessToken;
|
private String mAccessToken;
|
||||||
private String mAccountName;
|
private String mAccountName;
|
||||||
|
|
||||||
|
private String mAccountQualifiedName;
|
||||||
private String mQuery;
|
private String mQuery;
|
||||||
private String mSubredditName;
|
private String mSubredditName;
|
||||||
|
private String mCommunityQualifiedName;
|
||||||
private boolean mInsertSearchQuerySuccess;
|
private boolean mInsertSearchQuerySuccess;
|
||||||
private FragmentManager fragmentManager;
|
private FragmentManager fragmentManager;
|
||||||
private SectionsPagerAdapter sectionsPagerAdapter;
|
private SectionsPagerAdapter sectionsPagerAdapter;
|
||||||
@ -192,6 +196,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
String query = intent.getStringExtra(EXTRA_QUERY);
|
String query = intent.getStringExtra(EXTRA_QUERY);
|
||||||
|
|
||||||
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
mSubredditName = intent.getStringExtra(EXTRA_SUBREDDIT_NAME);
|
||||||
|
mCommunityQualifiedName = intent.getStringExtra(EXTRA_COMMUNITY_QUALIFIED_NAME);
|
||||||
|
|
||||||
if (query != null) {
|
if (query != null) {
|
||||||
mQuery = query;
|
mQuery = query;
|
||||||
@ -202,6 +207,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
|
|
||||||
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
mAccessToken = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCESS_TOKEN, null);
|
||||||
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
mAccountName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_NAME, null);
|
||||||
|
mAccountQualifiedName = mCurrentAccountSharedPreferences.getString(SharedPreferencesUtils.ACCOUNT_QUALIFIED_NAME, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE);
|
mInsertSearchQuerySuccess = savedInstanceState.getBoolean(INSERT_SEARCH_QUERY_SUCCESS_STATE);
|
||||||
@ -386,7 +392,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) {
|
if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) {
|
||||||
InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName,
|
InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountQualifiedName,
|
||||||
mQuery, () -> mInsertSearchQuerySuccess = true);
|
mQuery, () -> mInsertSearchQuerySuccess = true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -768,7 +774,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
|
|||||||
PostFragment mFragment = new PostFragment();
|
PostFragment mFragment = new PostFragment();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
|
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostPagingSource.TYPE_SEARCH);
|
||||||
bundle.putString(PostFragment.EXTRA_NAME, mSubredditName);
|
bundle.putString(PostFragment.EXTRA_NAME, mCommunityQualifiedName);
|
||||||
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
|
||||||
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
bundle.putString(PostFragment.EXTRA_TRENDING_SOURCE, getIntent().getStringExtra(EXTRA_TRENDING_SOURCE));
|
||||||
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken);
|
||||||
|
@ -1123,6 +1123,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
|
|||||||
} else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
|
} else if (itemId == R.id.action_search_view_subreddit_detail_activity) {
|
||||||
Intent intent = new Intent(this, SearchActivity.class);
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, subredditName);
|
||||||
|
intent.putExtra(SearchActivity.EXTRA_COMMUNITY_FULL_NAME, qualifiedName);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
} else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
|
} else if (itemId == R.id.action_refresh_view_subreddit_detail_activity) {
|
||||||
|
@ -1130,6 +1130,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
|
|||||||
} else if (itemId == R.id.action_search_view_user_detail_activity) {
|
} else if (itemId == R.id.action_search_view_user_detail_activity) {
|
||||||
Intent intent = new Intent(this, SearchActivity.class);
|
Intent intent = new Intent(this, SearchActivity.class);
|
||||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, username);
|
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, username);
|
||||||
|
intent.putExtra(SearchActivity.EXTRA_COMMUNITY_FULL_NAME, qualifiedName);
|
||||||
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true);
|
intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_IS_USER, true);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
@ -78,4 +78,18 @@ public interface LemmyAPI {
|
|||||||
@Query("saved_only") Boolean savedOnly,
|
@Query("saved_only") Boolean savedOnly,
|
||||||
@Query("auth") String auth
|
@Query("auth") String auth
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@GET("api/v3/search")
|
||||||
|
ListenableFuture<Response<String>> search(
|
||||||
|
@Query("q") String q,
|
||||||
|
@Query("community_id") Integer communityId,
|
||||||
|
@Query("community_name") String communityName,
|
||||||
|
@Query("creator_id") Integer creatorId,
|
||||||
|
@Query("type_") String type,
|
||||||
|
@Query("sort") String sort,
|
||||||
|
@Query("listing_type") String listingType,
|
||||||
|
@Query("page") Integer page,
|
||||||
|
@Query("limit") Integer limit,
|
||||||
|
@Query("auth") String auth
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -458,9 +458,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
|
|||||||
usage = PostFilterUsage.SEARCH_TYPE;
|
usage = PostFilterUsage.SEARCH_TYPE;
|
||||||
nameOfUsage = PostFilterUsage.NO_USAGE;
|
nameOfUsage = PostFilterUsage.NO_USAGE;
|
||||||
|
|
||||||
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.TOP.value);
|
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, SortType.Type.TOP_ALL.value);
|
||||||
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
|
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, SortType.Time.ALL.name());
|
||||||
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
|
sortType = new SortType(SortType.Type.fromValue(sort), SortType.Time.valueOf(sortTime));
|
||||||
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SEARCH_POST, defaultPostLayout);
|
||||||
|
|
||||||
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
mAdapter = new PostRecyclerViewAdapter(activity, this, mExecutor, mRetrofit.getRetrofit(), mGfycatRetrofit,
|
||||||
|
@ -174,9 +174,9 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return loadSubredditPosts(loadParams, api);
|
return loadSubredditPosts(loadParams, api);
|
||||||
case TYPE_USER:
|
case TYPE_USER:
|
||||||
return loadUserPosts(loadParams, api);
|
return loadUserPosts(loadParams, api);
|
||||||
/* case TYPE_SEARCH:
|
case TYPE_SEARCH:
|
||||||
return loadSearchPosts(loadParams, api);
|
return loadSearchPosts(loadParams, api);
|
||||||
case TYPE_MULTI_REDDIT:
|
/* case TYPE_MULTI_REDDIT:
|
||||||
return loadMultiRedditPosts(loadParams, api);
|
return loadMultiRedditPosts(loadParams, api);
|
||||||
default:
|
default:
|
||||||
return loadAnonymousHomePosts(loadParams, api);*/
|
return loadAnonymousHomePosts(loadParams, api);*/
|
||||||
@ -264,38 +264,23 @@ public class PostPagingSource extends ListenableFuturePagingSource<Integer, Post
|
|||||||
return Futures.catching(partialLoadResultFuture,
|
return Futures.catching(partialLoadResultFuture,
|
||||||
IOException.class, LoadResult.Error::new, executor);
|
IOException.class, LoadResult.Error::new, executor);
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
private ListenableFuture<LoadResult<String, Post>> loadSearchPosts(@NonNull LoadParams<String> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<Integer, Post>> loadSearchPosts(@NonNull LoadParams<Integer> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> searchPosts;
|
ListenableFuture<Response<String>> searchPosts;
|
||||||
if (subredditOrUserName == null) {
|
|
||||||
if (accessToken == null) {
|
|
||||||
searchPosts = api.searchPostsListenableFuture(query, loadParams.getKey(), sortType.getType(), sortType.getTime(),
|
|
||||||
trendingSource);
|
|
||||||
} else {
|
|
||||||
searchPosts = api.searchPostsOauthListenableFuture(query, loadParams.getKey(), sortType.getType(),
|
|
||||||
sortType.getTime(), trendingSource, APIUtils.getOAuthHeader(accessToken));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (accessToken == null) {
|
|
||||||
searchPosts = api.searchPostsInSpecificSubredditListenableFuture(subredditOrUserName, query,
|
|
||||||
sortType.getType(), sortType.getTime(), loadParams.getKey());
|
|
||||||
} else {
|
|
||||||
searchPosts = api.searchPostsInSpecificSubredditOauthListenableFuture(subredditOrUserName, query,
|
|
||||||
sortType.getType(), sortType.getTime(), loadParams.getKey(),
|
|
||||||
APIUtils.getOAuthHeader(accessToken));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> pageFuture = Futures.transform(searchPosts, this::transformData, executor);
|
searchPosts = api.search(query, null, subredditOrUserName, null, "Posts", sortType.getType().value, "All", loadParams.getKey(), 25, accessToken);
|
||||||
|
|
||||||
ListenableFuture<LoadResult<String, Post>> partialLoadResultFuture =
|
|
||||||
|
ListenableFuture<LoadResult<Integer, Post>> pageFuture = Futures.transform(searchPosts, this::transformData, executor);
|
||||||
|
|
||||||
|
ListenableFuture<LoadResult<Integer, Post>> partialLoadResultFuture =
|
||||||
Futures.catching(pageFuture, HttpException.class,
|
Futures.catching(pageFuture, HttpException.class,
|
||||||
LoadResult.Error::new, executor);
|
LoadResult.Error::new, executor);
|
||||||
|
|
||||||
return Futures.catching(partialLoadResultFuture,
|
return Futures.catching(partialLoadResultFuture,
|
||||||
IOException.class, LoadResult.Error::new, executor);
|
IOException.class, LoadResult.Error::new, executor);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
private ListenableFuture<LoadResult<String, Post>> loadMultiRedditPosts(@NonNull LoadParams<String> loadParams, LemmyAPI api) {
|
private ListenableFuture<LoadResult<String, Post>> loadMultiRedditPosts(@NonNull LoadParams<String> loadParams, LemmyAPI api) {
|
||||||
ListenableFuture<Response<String>> multiRedditPosts;
|
ListenableFuture<Response<String>> multiRedditPosts;
|
||||||
if (accessToken == null) {
|
if (accessToken == null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user