aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2019-08-05 09:18:30 +0000
committerAlex Ning <chineseperson5@gmail.com>2019-08-05 09:18:30 +0000
commit7761d3875673e65cfb6d0cb496a781a9ee8f2db3 (patch)
treebe6f2acbbe06acf8ce5d857faeb054bdc082c23a
parent199690355be9fb461ceddc346a9cc68a75940aa1 (diff)
downloadinfinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar.gz
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar.bz2
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar.lz
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar.xz
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.tar.zst
infinity-for-reddit-7761d3875673e65cfb6d0cb496a781a9ee8f2db3.zip
Sorting and refreshing in FilteredPostsActivity are available.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java89
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchPostSortTypeBottomSheetFragment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java1
-rw-r--r--app/src/main/res/layout/item_post.xml2
-rw-r--r--app/src/main/res/menu/filtered_posts_activity.xml17
7 files changed, 114 insertions, 13 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
index 3d3769d1..dcd2801a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java
@@ -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");
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java
index 4cddd4d9..eae90333 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java
@@ -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);
@@ -93,10 +127,39 @@ 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);
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 43db7760..79759c6c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -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();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchPostSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchPostSortTypeBottomSheetFragment.java
index 1bc862cc..f54cf5b4 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchPostSortTypeBottomSheetFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchPostSortTypeBottomSheetFragment.java
@@ -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;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
index 27ee7708..a06f0f6c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/SearchResultActivity.java
@@ -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();
diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml
index e3be0913..640f6c3f 100644
--- a/app/src/main/res/layout/item_post.xml
+++ b/app/src/main/res/layout/item_post.xml
@@ -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"
diff --git a/app/src/main/res/menu/filtered_posts_activity.xml b/app/src/main/res/menu/filtered_posts_activity.xml
new file mode 100644
index 00000000..ca53ec6c
--- /dev/null
+++ b/app/src/main/res/menu/filtered_posts_activity.xml
@@ -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> \ No newline at end of file