Sorting in SearchResultActivity is available. Switch DataSource instead of replacing fragments when changing sorting types. Minor bugs fixed.

This commit is contained in:
Alex Ning 2019-07-29 00:52:08 +08:00
parent 40fc423b33
commit 111ba8e5fc
32 changed files with 524 additions and 138 deletions

Binary file not shown.

View File

@ -2,10 +2,11 @@ package ml.docilealligator.infinityforreddit;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import SubredditDatabase.SubredditData; import SubredditDatabase.SubredditData;
import androidx.annotation.NonNull;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Response; import retrofit2.Response;
@ -56,10 +57,10 @@ class FetchSubredditData {
}); });
} }
static void fetchSubredditListingData(Retrofit retrofit, String query, String after, final FetchSubredditListingDataListener fetchSubredditListingDataListener) { static void fetchSubredditListingData(Retrofit retrofit, String query, String after, String sortType, final FetchSubredditListingDataListener fetchSubredditListingDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> subredditDataCall = api.searchSubreddits(query, after); Call<String> subredditDataCall = api.searchSubreddits(query, after, sortType);
subredditDataCall.enqueue(new Callback<String>() { subredditDataCall.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {

View File

@ -2,10 +2,11 @@ package ml.docilealligator.infinityforreddit;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull;
import java.util.ArrayList; import java.util.ArrayList;
import User.UserData; import User.UserData;
import androidx.annotation.NonNull;
import retrofit2.Call; import retrofit2.Call;
import retrofit2.Callback; import retrofit2.Callback;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -55,11 +56,11 @@ public class FetchUserData {
}); });
} }
public static void fetchUserListingData(Retrofit retrofit, String query, String after, public static void fetchUserListingData(Retrofit retrofit, String query, String after, String sortType,
FetchUserListingDataListener fetchUserListingDataListener) { FetchUserListingDataListener fetchUserListingDataListener) {
RedditAPI api = retrofit.create(RedditAPI.class); RedditAPI api = retrofit.create(RedditAPI.class);
Call<String> userInfo = api.searchUsers(query, after); Call<String> userInfo = api.searchUsers(query, after, sortType);
userInfo.enqueue(new Callback<String>() { userInfo.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {

View File

@ -114,7 +114,12 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
startActivityForResult(loginIntent, LOGIN_ACTIVITY_REQUEST_CODE); startActivityForResult(loginIntent, LOGIN_ACTIVITY_REQUEST_CODE);
} else { } else {
if (savedInstanceState == null) { if (savedInstanceState == null) {
replaceFragment(PostDataSource.SORT_TYPE_BEST); mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
} else { } else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit(); getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
@ -176,15 +181,6 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag())); fab.setOnClickListener(view -> postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()));
} }
private void replaceFragment(String sortType) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_FRONT_PAGE);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_content_main, mFragment).commit();
}
private void loadUserData() { private void loadUserData() {
if (!mFetchUserInfoSuccess) { if (!mFetchUserInfoSuccess) {
FetchMyInfo.fetchMyInfo(mOauthRetrofit, mAuthInfoSharedPreferences, new FetchMyInfo.FetchUserMyListener() { FetchMyInfo.fetchMyInfo(mOauthRetrofit, mAuthInfoSharedPreferences, new FetchMyInfo.FetchUserMyListener() {
@ -330,7 +326,7 @@ public class MainActivity extends AppCompatActivity implements SortTypeBottomShe
@Override @Override
public void sortTypeSelected(String sortType) { public void sortTypeSelected(String sortType) {
replaceFragment(sortType); ((PostFragment) mFragment).changeSortType(sortType);
} }
@Override @Override

View File

@ -31,6 +31,8 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
static final String SORT_TYPE_RISING = "rising"; static final String SORT_TYPE_RISING = "rising";
static final String SORT_TYPE_TOP = "top"; static final String SORT_TYPE_TOP = "top";
static final String SORT_TYPE_CONTROVERSIAL = "controversial"; static final String SORT_TYPE_CONTROVERSIAL = "controversial";
static final String SORT_TYPE_RELEVANCE = "relevance";
static final String SORT_TYPE_COMMENTS = "comments";
private Retrofit retrofit; private Retrofit retrofit;
private String accessToken; private String accessToken;
@ -459,7 +461,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
Call<String> getPost; Call<String> getPost;
if(subredditName == null) { if(subredditName == null) {
getPost = api.searchPosts(query, null, RedditUtils.getOAuthHeader(accessToken)); getPost = api.searchPosts(query, null, sortType, RedditUtils.getOAuthHeader(accessToken));
} else { } else {
getPost = api.searchPostsInSpecificSubreddit(subredditName, query, null, RedditUtils.getOAuthHeader(accessToken)); getPost = api.searchPostsInSpecificSubreddit(subredditName, query, null, RedditUtils.getOAuthHeader(accessToken));
} }
@ -467,6 +469,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
getPost.enqueue(new Callback<String>() { getPost.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
Log.i("initial", call.request().url().toString());
if(response.isSuccessful()) { if(response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1, ParsePost.parsePosts(response.body(), locale, -1,
new ParsePost.ParsePostsListingListener() { new ParsePost.ParsePostsListingListener() {
@ -507,7 +510,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
Call<String> getPost; Call<String> getPost;
if(subredditName == null) { if(subredditName == null) {
getPost = api.searchPosts(subredditName, params.key, RedditUtils.getOAuthHeader(accessToken)); getPost = api.searchPosts(query, params.key, sortType, RedditUtils.getOAuthHeader(accessToken));
} else { } else {
getPost = api.searchPostsInSpecificSubreddit(subredditName, query, params.key, RedditUtils.getOAuthHeader(accessToken)); getPost = api.searchPostsInSpecificSubreddit(subredditName, query, params.key, RedditUtils.getOAuthHeader(accessToken));
} }
@ -515,6 +518,7 @@ class PostDataSource extends PageKeyedDataSource<String, Post> {
getPost.enqueue(new Callback<String>() { getPost.enqueue(new Callback<String>() {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
Log.i("after", call.request().url().toString());
if(response.isSuccessful()) { if(response.isSuccessful()) {
ParsePost.parsePosts(response.body(), locale, -1, new ParsePost.ParsePostsListingListener() { ParsePost.parsePosts(response.body(), locale, -1, new ParsePost.ParsePostsListingListener() {
@Override @Override

View File

@ -90,4 +90,8 @@ class PostDataSourceFactory extends DataSource.Factory {
PostDataSource getPostDataSource() { PostDataSource getPostDataSource() {
return postDataSource; return postDataSource;
} }
void changeSortType(String sortType) {
this.sortType = sortType;
}
} }

View File

@ -287,6 +287,10 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
return rootView; return rootView;
} }
void changeSortType(String sortType) {
mPostViewModel.changeSortType(sortType);
}
@Override @Override
public void onAttach(@NonNull Context context) { public void onAttach(@NonNull Context context) {
super.onAttach(context); super.onAttach(context);

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.arch.core.util.Function; import androidx.arch.core.util.Function;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations; import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
@ -18,6 +19,7 @@ public class PostViewModel extends ViewModel {
private LiveData<NetworkState> paginationNetworkState; private LiveData<NetworkState> paginationNetworkState;
private LiveData<NetworkState> initialLoadingState; private LiveData<NetworkState> initialLoadingState;
private LiveData<PagedList<Post>> posts; private LiveData<PagedList<Post>> posts;
private MutableLiveData<String> sortTypeLiveData;
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType, public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, int postType, String sortType,
PostDataSource.OnPostFetchedCallback onPostFetchedCallback) { PostDataSource.OnPostFetchedCallback onPostFetchedCallback) {
@ -27,13 +29,20 @@ public class PostViewModel extends ViewModel {
(Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getInitialLoadStateLiveData); (Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getInitialLoadStateLiveData);
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
(Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getPaginationNetworkStateLiveData); (Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getPaginationNetworkStateLiveData);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setEnablePlaceholders(false) .setEnablePlaceholders(false)
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); posts = Transformations.switchMap(sortTypeLiveData, sort -> {
postDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
} }
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
@ -41,9 +50,12 @@ public class PostViewModel extends ViewModel {
postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, postType, sortType, onPostFetchedCallback); postDataSourceFactory = new PostDataSourceFactory(retrofit, accessToken, locale, subredditName, postType, sortType, onPostFetchedCallback);
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getInitialLoadStateLiveData()); (Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getInitialLoadStateLiveData);
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getPaginationNetworkStateLiveData()); (Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getPaginationNetworkStateLiveData);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -51,7 +63,10 @@ public class PostViewModel extends ViewModel {
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); posts = Transformations.switchMap(sortTypeLiveData, sort -> {
postDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
} }
public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType, public PostViewModel(Retrofit retrofit, String accessToken, Locale locale, String subredditName, int postType,
@ -61,7 +76,7 @@ public class PostViewModel extends ViewModel {
initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), initialLoadingState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getInitialLoadStateLiveData()); dataSource -> dataSource.getInitialLoadStateLiveData());
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getPaginationNetworkStateLiveData()); (Function<PostDataSource, LiveData<NetworkState>>) PostDataSource::getPaginationNetworkStateLiveData);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
@ -82,13 +97,19 @@ public class PostViewModel extends ViewModel {
paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(), paginationNetworkState = Transformations.switchMap(postDataSourceFactory.getPostDataSourceLiveData(),
dataSource -> dataSource.getPaginationNetworkStateLiveData()); dataSource -> dataSource.getPaginationNetworkStateLiveData());
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setEnablePlaceholders(false) .setEnablePlaceholders(false)
.setPageSize(25) .setPageSize(25)
.build(); .build();
posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); posts = Transformations.switchMap(sortTypeLiveData, sort -> {
postDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build();
});
} }
LiveData<PagedList<Post>> getPosts() { LiveData<PagedList<Post>> getPosts() {
@ -115,6 +136,10 @@ public class PostViewModel extends ViewModel {
postDataSourceFactory.getPostDataSource().retryLoadingMore(); postDataSourceFactory.getPostDataSource().retryLoadingMore();
} }
void changeSortType(String sortType) {
sortTypeLiveData.postValue(sortType);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory { public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit; private Retrofit retrofit;
private String accessToken; private String accessToken;

View File

@ -66,13 +66,13 @@ public interface RedditAPI {
Call<String> getInfo(@Path("subredditNamePrefixed") String subredditNamePrefixed, @Query("id") String id); Call<String> getInfo(@Path("subredditNamePrefixed") String subredditNamePrefixed, @Query("id") String id);
@GET("subreddits/search.json?raw_json=1&include_over_18=on") @GET("subreddits/search.json?raw_json=1&include_over_18=on")
Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after); Call<String> searchSubreddits(@Query("q") String subredditName, @Query("after") String after, @Query("sort") String sort);
@GET("search.json?raw_json=1&type=user&include_over_18=on") @GET("search.json?raw_json=1&type=user&include_over_18=on")
Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after); Call<String> searchUsers(@Query("q") String profileName, @Query("after") String after, @Query("sort") String sort);
@GET("search.json?raw_json=1&type=link&include_over_18=on") @GET("search.json?raw_json=1&type=link&include_over_18=on")
Call<String> searchPosts(@Query("q") String query, @Query("after") String after, Call<String> searchPosts(@Query("q") String query, @Query("after") String after, @Query("sort") String sort,
@HeaderMap Map<String, String> headers); @HeaderMap Map<String, String> headers);
@GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true&include_over_18=on") @GET("r/{subredditName}/search.json?raw_json=1&type=link&restrict_sr=true&include_over_18=on")

View File

@ -0,0 +1,77 @@
package ml.docilealligator.infinityforreddit;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* A simple {@link Fragment} subclass.
*/
public class SearchPostSortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
interface SearchSortTypeSelectionCallback {
void searchSortTypeSelected(String sortType);
}
static final String EXTRA_FRAGMENT_POSITION = "EFP";
@BindView(R.id.relevance_type_text_view_search_sort_type_bottom_sheet_fragment) TextView relevanceTypeTextView;
@BindView(R.id.hot_type_text_view_search_sort_type_bottom_sheet_fragment) TextView hotTypeTextView;
@BindView(R.id.top_type_text_view_search_sort_type_bottom_sheet_fragment) TextView topTypeTextView;
@BindView(R.id.new_type_text_view_search_sort_type_bottom_sheet_fragment) TextView newTypeTextView;
@BindView(R.id.comments_type_text_view_search_sort_type_bottom_sheet_fragment) TextView commentsTypeTextView;
public SearchPostSortTypeBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_search_post_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
Activity activity = getActivity();
relevanceTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE);
dismiss();
});
hotTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_HOT);
dismiss();
});
topTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_TOP);
dismiss();
});
newTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_NEW);
dismiss();
});
commentsTypeTextView.setOnClickListener(view -> {
((SearchSortTypeSelectionCallback) activity).searchSortTypeSelected(PostDataSource.SORT_TYPE_COMMENTS);
dismiss();
});
return rootView;
}
}

View File

@ -19,7 +19,8 @@ import com.google.android.material.tabs.TabLayout;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class SearchResultActivity extends AppCompatActivity { public class SearchResultActivity extends AppCompatActivity implements SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback,
SearchUserAndSubredditSortTypeBottomSheetFragment.SearchUserAndSubredditSortTypeSelectionCallback {
static final String EXTRA_QUERY = "QK"; static final String EXTRA_QUERY = "QK";
static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_SUBREDDIT_NAME = "ESN";
@ -32,6 +33,9 @@ public class SearchResultActivity extends AppCompatActivity {
private SectionsPagerAdapter sectionsPagerAdapter; private SectionsPagerAdapter sectionsPagerAdapter;
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -45,8 +49,16 @@ public class SearchResultActivity extends AppCompatActivity {
sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(sectionsPagerAdapter); viewPager.setAdapter(sectionsPagerAdapter);
viewPager.setOffscreenPageLimit(2); viewPager.setOffscreenPageLimit(2);
tabLayout.setupWithViewPager(viewPager); tabLayout.setupWithViewPager(viewPager);
searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(SearchPostSortTypeBottomSheetFragment.EXTRA_FRAGMENT_POSITION, viewPager.getCurrentItem());
searchPostSortTypeBottomSheetFragment.setArguments(bundle);
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();
// Get the intent, verify the action and get the query // Get the intent, verify the action and get the query
Intent intent = getIntent(); Intent intent = getIntent();
String query = intent.getExtras().getString(EXTRA_QUERY); String query = intent.getExtras().getString(EXTRA_QUERY);
@ -73,6 +85,21 @@ public class SearchResultActivity extends AppCompatActivity {
case android.R.id.home: case android.R.id.home:
onBackPressed(); onBackPressed();
return true; return true;
case R.id.action_sort_search_result_activity:
switch (viewPager.getCurrentItem()) {
case 0: {
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
break;
}
case 1:
case 2:
Bundle bundle = new Bundle();
bundle.putInt(SearchUserAndSubredditSortTypeBottomSheetFragment.EXTRA_FRAGMENT_POSITION, viewPager.getCurrentItem());
searchUserAndSubredditSortTypeBottomSheetFragment.setArguments(bundle);
searchUserAndSubredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchUserAndSubredditSortTypeBottomSheetFragment.getTag());
break;
}
return true;
case R.id.action_search_search_result_activity: case R.id.action_search_search_result_activity:
Intent intent = new Intent(this, SearchActivity.class); Intent intent = new Intent(this, SearchActivity.class);
finish(); finish();
@ -85,7 +112,18 @@ public class SearchResultActivity extends AppCompatActivity {
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@Override
public void searchSortTypeSelected(String sortType) {
sectionsPagerAdapter.changeSortType(sortType, 0);
}
@Override
public void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition) {
sectionsPagerAdapter.changeSortType(sortType, fragmentPosition);
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment; private PostFragment postFragment;
private SubredditListingFragment subredditListingFragment; private SubredditListingFragment subredditListingFragment;
private UserListingFragment userListingFragment; private UserListingFragment userListingFragment;
@ -102,7 +140,7 @@ public class SearchResultActivity extends AppCompatActivity {
PostFragment mFragment = new PostFragment(); PostFragment mFragment = new PostFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH); bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SEARCH);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST); bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_RELEVANCE);
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, mSubredditName); bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, mSubredditName);
bundle.putString(PostFragment.EXTRA_QUERY, mQuery); bundle.putString(PostFragment.EXTRA_QUERY, mQuery);
mFragment.setArguments(bundle); mFragment.setArguments(bundle);
@ -115,8 +153,7 @@ public class SearchResultActivity extends AppCompatActivity {
mFragment.setArguments(bundle); mFragment.setArguments(bundle);
return mFragment; return mFragment;
} }
default: default: {
{
UserListingFragment mFragment = new UserListingFragment(); UserListingFragment mFragment = new UserListingFragment();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(UserListingFragment.QUERY_KEY, mQuery); bundle.putString(UserListingFragment.QUERY_KEY, mQuery);
@ -162,6 +199,19 @@ public class SearchResultActivity extends AppCompatActivity {
return fragment; return fragment;
} }
void changeSortType(String sortType, int fragmentPosition) {
switch (fragmentPosition) {
case 0:
postFragment.changeSortType(sortType);
break;
case 1:
subredditListingFragment.changeSortType(sortType);
break;
case 2:
userListingFragment.changeSortType(sortType);
}
}
public void refresh() { public void refresh() {
if(postFragment != null) { if(postFragment != null) {
((FragmentCommunicator) postFragment).refresh(); ((FragmentCommunicator) postFragment).refresh();

View File

@ -0,0 +1,61 @@
package ml.docilealligator.infinityforreddit;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.fragment.app.Fragment;
import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment;
import butterknife.BindView;
import butterknife.ButterKnife;
/**
* A simple {@link Fragment} subclass.
*/
public class SearchUserAndSubredditSortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment {
interface SearchUserAndSubredditSortTypeSelectionCallback {
void searchUserAndSubredditSortTypeSelected(String sortType, int fragmentPosition);
}
static final String EXTRA_FRAGMENT_POSITION = "EFP";
@BindView(R.id.relevance_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment) TextView relevanceTypeTextView;
@BindView(R.id.activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment) TextView activityTypeTextView;
public SearchUserAndSubredditSortTypeBottomSheetFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_search_user_and_subreddit_sort_type_bottom_sheet, container, false);
ButterKnife.bind(this, rootView);
Activity activity = getActivity();
int position = getArguments().getInt(EXTRA_FRAGMENT_POSITION);
relevanceTypeTextView.setOnClickListener(view -> {
((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_RELEVANCE, position);
dismiss();
});
activityTypeTextView.setOnClickListener(view -> {
((SearchUserAndSubredditSortTypeSelectionCallback) activity).searchUserAndSubredditSortTypeSelected(PostDataSource.SORT_TYPE_HOT, position);
dismiss();
});
return rootView;
}
}

View File

@ -78,7 +78,7 @@ public class SortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragmen
}); });
controversialTypeTextView.setOnClickListener(view -> { controversialTypeTextView.setOnClickListener(view -> {
((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_BEST); ((SortTypeSelectionCallback) activity).sortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL);
dismiss(); dismiss();
}); });

View File

@ -1,11 +1,12 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.PageKeyedDataSource;
import java.util.ArrayList; import java.util.ArrayList;
import SubredditDatabase.SubredditData; import SubredditDatabase.SubredditData;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.PageKeyedDataSource;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class SubredditListingDataSource extends PageKeyedDataSource<String, SubredditData> { public class SubredditListingDataSource extends PageKeyedDataSource<String, SubredditData> {
@ -15,6 +16,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
} }
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback; private OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData; private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
@ -25,10 +27,11 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
private LoadParams<String> params; private LoadParams<String> params;
private LoadCallback<String, SubredditData> callback; private LoadCallback<String, SubredditData> callback;
SubredditListingDataSource(Retrofit retrofit, String query, SubredditListingDataSource(Retrofit retrofit, String query, String sortType,
OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) { OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback; this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback;
paginationNetworkStateLiveData = new MutableLiveData(); paginationNetworkStateLiveData = new MutableLiveData();
initialLoadStateLiveData = new MutableLiveData(); initialLoadStateLiveData = new MutableLiveData();
@ -49,7 +52,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
initialLoadStateLiveData.postValue(NetworkState.LOADING); initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchSubredditData.fetchSubredditListingData(retrofit, query, null, new FetchSubredditData.FetchSubredditListingDataListener() { FetchSubredditData.fetchSubredditListingData(retrofit, query, null, sortType, new FetchSubredditData.FetchSubredditListingDataListener() {
@Override @Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) { public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
if(subredditData.size() == 0) { if(subredditData.size() == 0) {
@ -83,7 +86,7 @@ public class SubredditListingDataSource extends PageKeyedDataSource<String, Subr
return; return;
} }
FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, new FetchSubredditData.FetchSubredditListingDataListener() { FetchSubredditData.fetchSubredditListingData(retrofit, query, params.key, sortType, new FetchSubredditData.FetchSubredditListingDataListener() {
@Override @Override
public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) { public void onFetchSubredditListingDataSuccess(ArrayList<SubredditData> subredditData, String after) {
callback.onResult(subredditData, after); callback.onResult(subredditData, after);

View File

@ -8,15 +8,17 @@ import retrofit2.Retrofit;
public class SubredditListingDataSourceFactory extends DataSource.Factory { public class SubredditListingDataSourceFactory extends DataSource.Factory {
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback; private SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback;
private SubredditListingDataSource subredditListingDataSource; private SubredditListingDataSource subredditListingDataSource;
private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData; private MutableLiveData<SubredditListingDataSource> subredditListingDataSourceMutableLiveData;
SubredditListingDataSourceFactory(Retrofit retrofit, String query, SubredditListingDataSourceFactory(Retrofit retrofit, String query, String sortType,
SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) { SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback; this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback;
subredditListingDataSourceMutableLiveData = new MutableLiveData<>(); subredditListingDataSourceMutableLiveData = new MutableLiveData<>();
} }
@ -25,7 +27,7 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
@Override @Override
public DataSource create() { public DataSource create() {
subredditListingDataSource = new SubredditListingDataSource(retrofit, subredditListingDataSource = new SubredditListingDataSource(retrofit,
query, onSubredditListingDataFetchedCallback); query, sortType, onSubredditListingDataFetchedCallback);
subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource); subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
return subredditListingDataSource; return subredditListingDataSource;
} }
@ -37,4 +39,8 @@ public class SubredditListingDataSourceFactory extends DataSource.Factory {
SubredditListingDataSource getSubredditListingDataSource() { SubredditListingDataSource getSubredditListingDataSource() {
return subredditListingDataSource; return subredditListingDataSource;
} }
void changeSortType(String sortType) {
this.sortType = sortType;
}
} }

View File

@ -10,6 +10,12 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
@ -17,11 +23,6 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase; import SubscribedSubredditDatabase.SubscribedSubredditRoomDatabase;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -79,7 +80,7 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mQuery = getArguments().getString(QUERY_KEY); mQuery = getArguments().getString(QUERY_KEY);
SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, mQuery, SubredditListingViewModel.Factory factory = new SubredditListingViewModel.Factory(mRetrofit, mQuery,
new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() { PostDataSource.SORT_TYPE_RELEVANCE, new SubredditListingDataSource.OnSubredditListingDataFetchedCallback() {
@Override @Override
public void hasSubreddit() { public void hasSubreddit() {
mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE); mFetchSubredditListingInfoLinearLayout.setVisibility(View.GONE);
@ -87,11 +88,8 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
@Override @Override
public void noSubreddit() { public void noSubreddit() {
mFetchSubredditListingInfoLinearLayout.setOnClickListener(new View.OnClickListener() { mFetchSubredditListingInfoLinearLayout.setOnClickListener(view -> {
@Override
public void onClick(View view) {
//Do nothing //Do nothing
}
}); });
showErrorView(R.string.no_subreddits); showErrorView(R.string.no_subreddits);
} }
@ -135,6 +133,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
} }
} }
void changeSortType(String sortType) {
mSubredditListingViewModel.changeSortType(sortType);
}
@Override @Override
public void refresh() { public void refresh() {
mSubredditListingViewModel.refresh(); mSubredditListingViewModel.refresh();

View File

@ -1,14 +1,16 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import SubredditDatabase.SubredditData;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.arch.core.util.Function; import androidx.arch.core.util.Function;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations; import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList; import androidx.paging.PagedList;
import SubredditDatabase.SubredditData;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class SubredditListingViewModel extends ViewModel { public class SubredditListingViewModel extends ViewModel {
@ -16,22 +18,30 @@ public class SubredditListingViewModel extends ViewModel {
private LiveData<NetworkState> paginationNetworkState; private LiveData<NetworkState> paginationNetworkState;
private LiveData<NetworkState> initialLoadingState; private LiveData<NetworkState> initialLoadingState;
private LiveData<PagedList<SubredditData>> subreddits; private LiveData<PagedList<SubredditData>> subreddits;
private MutableLiveData<String> sortTypeLiveData;
SubredditListingViewModel(Retrofit retrofit, String query, SubredditListingViewModel(Retrofit retrofit, String query, String sortType,
SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) { SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) {
subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, onSubredditListingDataFetchedCallback); subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType, onSubredditListingDataFetchedCallback);
initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(), initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
(Function<SubredditListingDataSource, LiveData<NetworkState>>) SubredditListingDataSource::getInitialLoadStateLiveData); (Function<SubredditListingDataSource, LiveData<NetworkState>>) SubredditListingDataSource::getInitialLoadStateLiveData);
paginationNetworkState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(), paginationNetworkState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
(Function<SubredditListingDataSource, LiveData<NetworkState>>) SubredditListingDataSource::getPaginationNetworkStateLiveData); (Function<SubredditListingDataSource, LiveData<NetworkState>>) SubredditListingDataSource::getPaginationNetworkStateLiveData);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setEnablePlaceholders(false) .setEnablePlaceholders(false)
.setPageSize(25) .setPageSize(25)
.build(); .build();
subreddits = (new LivePagedListBuilder(subredditListingDataSourceFactory, pagedListConfig)).build(); subreddits = Transformations.switchMap(sortTypeLiveData, sort -> {
subredditListingDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
return new LivePagedListBuilder(subredditListingDataSourceFactory, pagedListConfig).build();
});
} }
LiveData<PagedList<SubredditData>> getSubreddits() { LiveData<PagedList<SubredditData>> getSubreddits() {
@ -58,22 +68,28 @@ public class SubredditListingViewModel extends ViewModel {
subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore(); subredditListingDataSourceFactory.getSubredditListingDataSource().retryLoadingMore();
} }
void changeSortType(String sortType) {
sortTypeLiveData.postValue(sortType);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory { public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback; private SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback;
public Factory(Retrofit retrofit, String query, public Factory(Retrofit retrofit, String query, String sortType,
SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) { SubredditListingDataSource.OnSubredditListingDataFetchedCallback onSubredditListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback; this.onSubredditListingDataFetchedCallback = onSubredditListingDataFetchedCallback;
} }
@NonNull @NonNull
@Override @Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) new SubredditListingViewModel(retrofit, query, onSubredditListingDataFetchedCallback); return (T) new SubredditListingViewModel(retrofit, query, sortType, onSubredditListingDataFetchedCallback);
} }
} }
} }

View File

@ -1,11 +1,12 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.PageKeyedDataSource;
import java.util.ArrayList; import java.util.ArrayList;
import User.UserData; import User.UserData;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import androidx.paging.PageKeyedDataSource;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class UserListingDataSource extends PageKeyedDataSource<String, UserData> { public class UserListingDataSource extends PageKeyedDataSource<String, UserData> {
@ -13,8 +14,10 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
void hasUser(); void hasUser();
void noUser(); void noUser();
} }
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback; private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback;
private MutableLiveData<NetworkState> paginationNetworkStateLiveData; private MutableLiveData<NetworkState> paginationNetworkStateLiveData;
@ -25,10 +28,11 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
private PageKeyedDataSource.LoadParams<String> params; private PageKeyedDataSource.LoadParams<String> params;
private PageKeyedDataSource.LoadCallback<String, UserData> callback; private PageKeyedDataSource.LoadCallback<String, UserData> callback;
UserListingDataSource(Retrofit retrofit, String query, UserListingDataSource(Retrofit retrofit, String query, String sortType,
UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) { UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback; this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback;
paginationNetworkStateLiveData = new MutableLiveData(); paginationNetworkStateLiveData = new MutableLiveData();
initialLoadStateLiveData = new MutableLiveData(); initialLoadStateLiveData = new MutableLiveData();
@ -49,7 +53,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
initialLoadStateLiveData.postValue(NetworkState.LOADING); initialLoadStateLiveData.postValue(NetworkState.LOADING);
FetchUserData.fetchUserListingData(retrofit, query, null, new FetchUserData.FetchUserListingDataListener() { FetchUserData.fetchUserListingData(retrofit, query, null, sortType, new FetchUserData.FetchUserListingDataListener() {
@Override @Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
if(UserData.size() == 0) { if(UserData.size() == 0) {
@ -83,7 +87,7 @@ public class UserListingDataSource extends PageKeyedDataSource<String, UserData>
return; return;
} }
FetchUserData.fetchUserListingData(retrofit, query, params.key, new FetchUserData.FetchUserListingDataListener() { FetchUserData.fetchUserListingData(retrofit, query, params.key, sortType, new FetchUserData.FetchUserListingDataListener() {
@Override @Override
public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) { public void onFetchUserListingDataSuccess(ArrayList<UserData> UserData, String after) {
callback.onResult(UserData, after); callback.onResult(UserData, after);

View File

@ -8,15 +8,17 @@ import retrofit2.Retrofit;
public class UserListingDataSourceFactory extends DataSource.Factory { public class UserListingDataSourceFactory extends DataSource.Factory {
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback; private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback;
private UserListingDataSource userListingDataSource; private UserListingDataSource userListingDataSource;
private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData; private MutableLiveData<UserListingDataSource> userListingDataSourceMutableLiveData;
UserListingDataSourceFactory(Retrofit retrofit, String query, UserListingDataSourceFactory(Retrofit retrofit, String query, String sortType,
UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) { UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback; this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback;
userListingDataSourceMutableLiveData = new MutableLiveData<>(); userListingDataSourceMutableLiveData = new MutableLiveData<>();
} }
@ -25,7 +27,7 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
@Override @Override
public DataSource create() { public DataSource create() {
userListingDataSource = new UserListingDataSource(retrofit, userListingDataSource = new UserListingDataSource(retrofit,
query, onUserListingDataFetchedCallback); query, sortType, onUserListingDataFetchedCallback);
userListingDataSourceMutableLiveData.postValue(userListingDataSource); userListingDataSourceMutableLiveData.postValue(userListingDataSource);
return userListingDataSource; return userListingDataSource;
} }
@ -37,4 +39,8 @@ public class UserListingDataSourceFactory extends DataSource.Factory {
UserListingDataSource getUserListingDataSource() { UserListingDataSource getUserListingDataSource() {
return userListingDataSource; return userListingDataSource;
} }
void changeSortType(String sortType) {
this.sortType = sortType;
}
} }

View File

@ -1,7 +1,6 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -11,6 +10,12 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
@ -18,11 +23,6 @@ import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import SubscribedUserDatabase.SubscribedUserRoomDatabase; import SubscribedUserDatabase.SubscribedUserRoomDatabase;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import retrofit2.Retrofit; import retrofit2.Retrofit;
@ -85,11 +85,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mQuery = getArguments().getString(QUERY_KEY); mQuery = getArguments().getString(QUERY_KEY);
String accessToken = getActivity().getSharedPreferences(SharedPreferencesUtils.AUTH_CODE_FILE_KEY, Context.MODE_PRIVATE)
.getString(SharedPreferencesUtils.ACCESS_TOKEN_KEY, "");
UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery, UserListingViewModel.Factory factory = new UserListingViewModel.Factory(mRetrofit, mQuery,
new UserListingDataSource.OnUserListingDataFetchedCallback() { PostDataSource.SORT_TYPE_RELEVANCE, new UserListingDataSource.OnUserListingDataFetchedCallback() {
@Override @Override
public void hasUser() { public void hasUser() {
mFetchUserListingInfoLinearLayout.setVisibility(View.GONE); mFetchUserListingInfoLinearLayout.setVisibility(View.GONE);
@ -97,11 +94,8 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
@Override @Override
public void noUser() { public void noUser() {
mFetchUserListingInfoLinearLayout.setOnClickListener(new View.OnClickListener() { mFetchUserListingInfoLinearLayout.setOnClickListener(view -> {
@Override
public void onClick(View view) {
//Do nothing //Do nothing
}
}); });
showErrorView(R.string.no_users); showErrorView(R.string.no_users);
} }
@ -145,6 +139,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
} }
} }
void changeSortType(String sortType) {
mUserListingViewModel.changeSortType(sortType);
}
@Override @Override
public void refresh() { public void refresh() {
mUserListingViewModel.refresh(); mUserListingViewModel.refresh();

View File

@ -1,41 +1,51 @@
package ml.docilealligator.infinityforreddit; package ml.docilealligator.infinityforreddit;
import User.UserData;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.arch.core.util.Function; import androidx.arch.core.util.Function;
import androidx.lifecycle.LiveData; import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations; import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel; import androidx.lifecycle.ViewModel;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.paging.LivePagedListBuilder; import androidx.paging.LivePagedListBuilder;
import androidx.paging.PagedList; import androidx.paging.PagedList;
import User.UserData;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class UserListingViewModel extends ViewModel { public class UserListingViewModel extends ViewModel {
private UserListingDataSourceFactory UserListingDataSourceFactory; private UserListingDataSourceFactory UserListingDataSourceFactory;
private LiveData<NetworkState> paginationNetworkState; private LiveData<NetworkState> paginationNetworkState;
private LiveData<NetworkState> initialLoadingState; private LiveData<NetworkState> initialLoadingState;
private LiveData<PagedList<UserData>> Users; private LiveData<PagedList<UserData>> users;
private MutableLiveData<String> sortTypeLiveData;
UserListingViewModel(Retrofit retrofit, String query, UserListingViewModel(Retrofit retrofit, String query, String sortType,
UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) { UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) {
UserListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, onUserListingDataFetchedCallback); UserListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType, onUserListingDataFetchedCallback);
initialLoadingState = Transformations.switchMap(UserListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), initialLoadingState = Transformations.switchMap(UserListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
(Function<UserListingDataSource, LiveData<NetworkState>>) UserListingDataSource::getInitialLoadStateLiveData); (Function<UserListingDataSource, LiveData<NetworkState>>) UserListingDataSource::getInitialLoadStateLiveData);
paginationNetworkState = Transformations.switchMap(UserListingDataSourceFactory.getUserListingDataSourceMutableLiveData(), paginationNetworkState = Transformations.switchMap(UserListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
(Function<UserListingDataSource, LiveData<NetworkState>>) UserListingDataSource::getPaginationNetworkStateLiveData); (Function<UserListingDataSource, LiveData<NetworkState>>) UserListingDataSource::getPaginationNetworkStateLiveData);
sortTypeLiveData = new MutableLiveData<>();
sortTypeLiveData.postValue(sortType);
PagedList.Config pagedListConfig = PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()) (new PagedList.Config.Builder())
.setEnablePlaceholders(false) .setEnablePlaceholders(false)
.setPageSize(25) .setPageSize(25)
.build(); .build();
Users = (new LivePagedListBuilder(UserListingDataSourceFactory, pagedListConfig)).build(); users = Transformations.switchMap(sortTypeLiveData, sort -> {
UserListingDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
return (new LivePagedListBuilder(UserListingDataSourceFactory, pagedListConfig)).build();
});
} }
LiveData<PagedList<UserData>> getUsers() { LiveData<PagedList<UserData>> getUsers() {
return Users; return users;
} }
LiveData<NetworkState> getPaginationNetworkState() { LiveData<NetworkState> getPaginationNetworkState() {
@ -58,22 +68,28 @@ public class UserListingViewModel extends ViewModel {
UserListingDataSourceFactory.getUserListingDataSource().retryLoadingMore(); UserListingDataSourceFactory.getUserListingDataSource().retryLoadingMore();
} }
void changeSortType(String sortType) {
sortTypeLiveData.postValue(sortType);
}
public static class Factory extends ViewModelProvider.NewInstanceFactory { public static class Factory extends ViewModelProvider.NewInstanceFactory {
private Retrofit retrofit; private Retrofit retrofit;
private String query; private String query;
private String sortType;
private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback; private UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback;
public Factory(Retrofit retrofit, String query, public Factory(Retrofit retrofit, String query, String sortType,
UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) { UserListingDataSource.OnUserListingDataFetchedCallback onUserListingDataFetchedCallback) {
this.retrofit = retrofit; this.retrofit = retrofit;
this.query = query; this.query = query;
this.sortType = sortType;
this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback; this.onUserListingDataFetchedCallback = onUserListingDataFetchedCallback;
} }
@NonNull @NonNull
@Override @Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) { public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
return (T) new UserListingViewModel(retrofit, query, onUserListingDataFetchedCallback); return (T) new UserListingViewModel(retrofit, query, sortType, onUserListingDataFetchedCallback);
} }
} }
} }

View File

@ -253,7 +253,13 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
}); });
if(savedInstanceState == null) { if(savedInstanceState == null) {
replaceFragment(PostDataSource.SORT_TYPE_BEST); mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_BEST);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
} else { } else {
mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY); mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE_KEY);
if(mFragment == null) { if(mFragment == null) {
@ -330,16 +336,6 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
return false; return false;
} }
private void replaceFragment(String sortType) {
mFragment = new PostFragment();
Bundle bundle = new Bundle();
bundle.putString(PostFragment.EXTRA_SUBREDDIT_NAME, subredditName);
bundle.putInt(PostFragment.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType);
mFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_view_subreddit_detail_activity, mFragment).commit();
}
@Override @Override
protected void onSaveInstanceState(@NonNull Bundle outState) { protected void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
@ -353,7 +349,7 @@ public class ViewSubredditDetailActivity extends AppCompatActivity implements So
@Override @Override
public void sortTypeSelected(String sortType) { public void sortTypeSelected(String sortType) {
replaceFragment(sortType); ((PostFragment) mFragment).changeSortType(sortType);
} }
@Override @Override

View File

@ -1,18 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp">
<TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:paddingTop="24dp" android:paddingBottom="8dp"
android:paddingBottom="16dp" android:orientation="vertical">
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/bottom_sheet_post_type"
android:textSize="18sp" />
<LinearLayout <LinearLayout
android:id="@+id/text_type_linear_layout_post_type_bottom_sheet_fragment" android:id="@+id/text_type_linear_layout_post_type_bottom_sheet_fragment"
@ -30,7 +21,7 @@
android:layout_width="18dp" android:layout_width="18dp"
android:layout_height="18dp" android:layout_height="18dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp" android:layout_marginEnd="48dp"
android:src="@drawable/ic_outline_text_24px" android:src="@drawable/ic_outline_text_24px"
android:tint="@color/primaryTextColor" /> android:tint="@color/primaryTextColor" />
@ -38,7 +29,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/bottom_sheet_post_text" /> android:text="@string/bottom_sheet_post_text"
android:textColor="@color/primaryTextColor" />
</LinearLayout> </LinearLayout>
@ -58,7 +50,7 @@
android:layout_width="18dp" android:layout_width="18dp"
android:layout_height="18dp" android:layout_height="18dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp" android:layout_marginEnd="48dp"
android:src="@drawable/ic_link" android:src="@drawable/ic_link"
android:tint="@color/primaryTextColor" /> android:tint="@color/primaryTextColor" />
@ -66,7 +58,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/bottom_sheet_post_link" /> android:text="@string/bottom_sheet_post_link"
android:textColor="@color/primaryTextColor" />
</LinearLayout> </LinearLayout>
@ -86,7 +79,7 @@
android:layout_width="18dp" android:layout_width="18dp"
android:layout_height="18dp" android:layout_height="18dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_marginEnd="32dp" android:layout_marginEnd="48dp"
android:src="@drawable/ic_menu_gallery" android:src="@drawable/ic_menu_gallery"
android:tint="@color/primaryTextColor" /> android:tint="@color/primaryTextColor" />
@ -94,7 +87,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/bottom_sheet_post_image" /> android:text="@string/bottom_sheet_post_image"
android:textColor="@color/primaryTextColor" />
</LinearLayout> </LinearLayout>
@ -114,7 +108,7 @@
<ImageView <ImageView
android:layout_width="18dp" android:layout_width="18dp"
android:layout_height="18dp" android:layout_height="18dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="48dp"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:src="@drawable/ic_outline_video_label_24px" android:src="@drawable/ic_outline_video_label_24px"
android:tint="@color/primaryTextColor" /> android:tint="@color/primaryTextColor" />
@ -123,7 +117,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:text="@string/bottom_sheet_post_video" /> android:text="@string/bottom_sheet_post_video"
android:textColor="@color/primaryTextColor" />
</LinearLayout> </LinearLayout>

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp">
<TextView
android:id="@+id/relevance_type_text_view_search_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_relevance"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/hot_type_text_view_search_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_hot"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/top_type_text_view_search_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_top"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/new_type_text_view_search_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_new"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/comments_type_text_view_search_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_comments"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/relevance_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_relevance"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
<TextView
android:id="@+id/activity_type_text_view_search_user_and_subreddit_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/sort_activity"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" />
</LinearLayout>

View File

@ -4,22 +4,12 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="24dp"
android:paddingBottom="16dp"
android:paddingStart="32dp"
android:paddingEnd="32dp"
android:text="@string/sort"
android:textColor="@color/primaryTextColor"
android:textSize="18sp" />
<TextView <TextView
android:id="@+id/best_type_text_view_sort_type_bottom_sheet_fragment" android:id="@+id/best_type_text_view_sort_type_bottom_sheet_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_best" android:text="@string/sort_best"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -33,6 +23,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_hot" android:text="@string/sort_hot"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -46,6 +37,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_new" android:text="@string/sort_new"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -59,6 +51,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_random" android:text="@string/sort_random"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -72,6 +65,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_rising" android:text="@string/sort_rising"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -85,6 +79,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_top" android:text="@string/sort_top"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"
@ -98,6 +93,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/sort_controversial" android:text="@string/sort_controversial"
android:textColor="@color/primaryTextColor"
android:paddingTop="16dp" android:paddingTop="16dp"
android:paddingBottom="16dp" android:paddingBottom="16dp"
android:paddingStart="32dp" android:paddingStart="32dp"

View File

@ -2,15 +2,22 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android" <menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<item <item
android:id="@+id/action_search_search_result_activity" android:id="@+id/action_sort_search_result_activity"
android:orderInCategory="1" android:orderInCategory="1"
android:title="@string/action_search" android:title="@string/action_search"
android:icon="@drawable/ic_outline_sort_24px"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_search_search_result_activity"
android:orderInCategory="2"
android:title="@string/action_search"
android:icon="@drawable/ic_search_white_24dp" android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="ifRoom" /> app:showAsAction="ifRoom" />
<item <item
android:id="@+id/action_refresh_search_result_activity" android:id="@+id/action_refresh_search_result_activity"
android:orderInCategory="2" android:orderInCategory="3"
android:title="@string/action_refresh" android:title="@string/action_refresh"
app:showAsAction="never" /> app:showAsAction="never" />
</menu> </menu>

View File

@ -23,4 +23,8 @@
<color name="backgroundColor">#121212</color> <color name="backgroundColor">#121212</color>
<color name="backgroundColorPrimaryDark">#1565C0</color> <color name="backgroundColorPrimaryDark">#1565C0</color>
<color name="roundedBottomSheetPrimaryBackground">#242424</color>
<color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color>
</resources> </resources>

View File

@ -24,5 +24,7 @@
<color name="backgroundColorPrimaryDark">@color/colorPrimaryDark</color> <color name="backgroundColorPrimaryDark">@color/colorPrimaryDark</color>
<color name="roundedBottomSheetPrimaryBackground">#FFFFFF</color>
<color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color> <color name="roundedBottomSheetPrimaryNavigationBarColor">#000000</color>
</resources> </resources>

View File

@ -7,7 +7,6 @@
<dimen name="fab_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen>
<dimen name="app_bar_height">180dp</dimen> <dimen name="app_bar_height">180dp</dimen>
<dimen name="text_margin">16dp</dimen> <dimen name="text_margin">16dp</dimen>
<dimen name="roundedBottomSheetCornerRadiusTopPadding">0dp</dimen>
<dimen name="roundedBottomSheetCornerRadiusLeftPadding">0dp</dimen> <dimen name="roundedBottomSheetCornerRadiusLeftPadding">0dp</dimen>
<dimen name="roundedBottomSheetCornerRadiusRightPadding">0dp</dimen> <dimen name="roundedBottomSheetCornerRadiusRightPadding">0dp</dimen>
</resources> </resources>

View File

@ -142,7 +142,7 @@
<string name="sort_rising">Rising</string> <string name="sort_rising">Rising</string>
<string name="sort_top">Top</string> <string name="sort_top">Top</string>
<string name="sort_controversial">Controversial</string> <string name="sort_controversial">Controversial</string>
<string name="sort_relevance">Relevance</string>
<!-- TODO: Remove or change this placeholder text --> <string name="sort_comments">Comments</string>
<string name="hello_blank_fragment">Hello blank fragment</string> <string name="sort_activity">Activity</string>
</resources> </resources>