Sorting and refreshing in FilteredPostsActivity are available.

This commit is contained in:
Alex Ning 2019-08-05 17:18:30 +08:00
parent 199690355b
commit 7761d38756
7 changed files with 114 additions and 13 deletions

View File

@ -305,6 +305,16 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie
String scoreWithVote = Integer.toString(mPost.getScore() + mPost.getVoteType());
((PostDetailViewHolder) holder).mScoreTextView.setText(scoreWithVote);
((PostDetailViewHolder) holder).mTypeChip.setOnClickListener(view -> {
Intent intent = new Intent(mActivity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2));
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT);
intent.putExtra(FilteredPostsActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT);
intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, mPost.getPostType());
mActivity.startActivity(intent);
});
switch (mPost.getPostType()) {
case Post.IMAGE_TYPE:
((PostDetailViewHolder) holder).mTypeChip.setText("IMAGE");

View File

@ -1,6 +1,7 @@
package ml.docilealligator.infinityforreddit;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import androidx.annotation.NonNull;
@ -11,7 +12,8 @@ import androidx.fragment.app.Fragment;
import butterknife.BindView;
import butterknife.ButterKnife;
public class FilteredPostsActivity extends AppCompatActivity {
public class FilteredPostsActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback,
SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback {
static final String EXTRA_NAME = "ESN";
static final String EXTRA_QUERY = "EQ";
@ -23,8 +25,16 @@ public class FilteredPostsActivity extends AppCompatActivity {
@BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar;
private String name;
private int postType;
private Fragment mFragment;
private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment;
private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment;
private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment;
private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -35,21 +45,45 @@ public class FilteredPostsActivity extends AppCompatActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String name = getIntent().getExtras().getString(EXTRA_NAME);
name = getIntent().getExtras().getString(EXTRA_NAME);
int filter = getIntent().getExtras().getInt(EXTRA_FILTER);
int postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE);
postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE);
String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE);
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
getSupportActionBar().setTitle(name);
bestSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Bundle bestBundle = new Bundle();
bestBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, false);
bestSortTypeBottomSheetFragment.setArguments(bestBundle);
break;
case PostDataSource.TYPE_SEARCH:
getSupportActionBar().setTitle(R.string.search);
searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
Bundle searchBundle = new Bundle();
searchPostSortTypeBottomSheetFragment.setArguments(searchBundle);
break;
case PostDataSource.TYPE_SUBREDDIT:
String subredditNamePrefixed = "r/" + name;
getSupportActionBar().setTitle(subredditNamePrefixed);
if(name.equals("popular") || name.equals("all")) {
getSupportActionBar().setTitle(name.substring(0, 1).toUpperCase() + name.substring(1));
popularAndAllSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Bundle popularBundle = new Bundle();
popularBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
popularAndAllSortTypeBottomSheetFragment.setArguments(popularBundle);
} else {
String subredditNamePrefixed = "r/" + name;
getSupportActionBar().setTitle(subredditNamePrefixed);
subredditSortTypeBottomSheetFragment = new SortTypeBottomSheetFragment();
Bundle bottomSheetBundle = new Bundle();
bottomSheetBundle.putBoolean(SortTypeBottomSheetFragment.EXTRA_NO_BEST_TYPE, true);
subredditSortTypeBottomSheetFragment.setArguments(bottomSheetBundle);
}
break;
case PostDataSource.TYPE_USER:
String usernamePrefixed = "u/" + name;
getSupportActionBar().setTitle(usernamePrefixed);
@ -92,11 +126,40 @@ public class FilteredPostsActivity extends AppCompatActivity {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.filtered_posts_activity, menu);
if(postType == PostDataSource.TYPE_USER) {
menu.findItem(R.id.action_sort_filtered_posts_activity).setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId() == android.R.id.home) {
finish();
return true;
switch (item.getItemId()) {
case android.R.id.home:
finish();
return true;
case R.id.action_sort_filtered_posts_activity:
switch (postType) {
case PostDataSource.TYPE_FRONT_PAGE:
bestSortTypeBottomSheetFragment.show(getSupportFragmentManager(), bestSortTypeBottomSheetFragment.getTag());
break;
case PostDataSource.TYPE_SEARCH:
searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag());
break;
case PostDataSource.TYPE_SUBREDDIT:
if(name.equals("popular") || name.equals("all")) {
popularAndAllSortTypeBottomSheetFragment.show(getSupportFragmentManager(), popularAndAllSortTypeBottomSheetFragment.getTag());
} else {
subredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), subredditSortTypeBottomSheetFragment.getTag());
}
}
return true;
case R.id.action_refresh_filtered_posts_activity:
((FragmentCommunicator) mFragment).refresh();
return true;
}
return false;
}
@ -108,4 +171,14 @@ public class FilteredPostsActivity extends AppCompatActivity {
getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment);
}
}
@Override
public void searchSortTypeSelected(String sortType) {
((PostFragment)mFragment).changeSortType(sortType);
}
@Override
public void sortTypeSelected(String sortType) {
((PostFragment)mFragment).changeSortType(sortType);
}
}

View File

@ -361,7 +361,9 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
((DataViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE);
}
((DataViewHolder) holder).typeChip.setOnClickListener(view -> callback.typeChipClicked(post.getPostType()));
if(!(mContext instanceof FilteredPostsActivity)) {
((DataViewHolder) holder).typeChip.setOnClickListener(view -> callback.typeChipClicked(post.getPostType()));
}
switch (post.getPostType()) {
case Post.IMAGE_TYPE:
@ -379,6 +381,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
break;
case Post.LINK_TYPE:
((DataViewHolder) holder).typeChip.setText(R.string.link);
((DataViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
String domain = Uri.parse(post.getUrl()).getHost();
((DataViewHolder) holder).linkTextView.setText(domain);
@ -430,6 +433,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
break;
case Post.NO_PREVIEW_LINK_TYPE:
((DataViewHolder) holder).typeChip.setText(R.string.link);
String noPreviewLinkUrl = post.getUrl();
((DataViewHolder) holder).linkTextView.setVisibility(View.VISIBLE);
String noPreviewLinkDomain = Uri.parse(noPreviewLinkUrl).getHost();

View File

@ -25,8 +25,6 @@ public class SearchPostSortTypeBottomSheetFragment extends RoundedBottomSheetDia
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;

View File

@ -54,7 +54,6 @@ public class SearchResultActivity extends AppCompatActivity implements SearchPos
searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putInt(SearchPostSortTypeBottomSheetFragment.EXTRA_FRAGMENT_POSITION, viewPager.getCurrentItem());
searchPostSortTypeBottomSheetFragment.setArguments(bundle);
searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment();

View File

@ -102,7 +102,7 @@
android:layout_height="24dp"
android:layout_toEndOf="@id/type_text_view_item_post"
android:layout_centerVertical="true"
android:visibility="gone"/>
android:visibility="gone" />
<TextView
android:id="@+id/gilded_number_text_view_item_post"

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_sort_filtered_posts_activity"
android:orderInCategory="1"
android:title="@string/action_sort"
android:icon="@drawable/ic_outline_sort_24px"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_refresh_filtered_posts_activity"
android:orderInCategory="2"
android:title="@string/action_refresh"
android:icon="@drawable/ic_search_white_24dp"
app:showAsAction="never" />
</menu>