diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-14 08:52:59 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-14 08:52:59 +0000 |
commit | 2dbb854bfcc6d409f611195ce2a43249a3cf8c2f (patch) | |
tree | db5f745fe7fec708ad6f20ea0bd94335f6ff73f2 /app/src/main/java/ml/docilealligator | |
parent | 0a3d6520bc0bd6844ad479b232d3ca11ee87fa21 (diff) | |
download | infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar.gz infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar.bz2 infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar.lz infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar.xz infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.tar.zst infinity-for-reddit-2dbb854bfcc6d409f611195ce2a43249a3cf8c2f.zip |
Sorting gilded posts in AccountPostsActivity is available. Refreshing in AccountPostsActivity is available.
Diffstat (limited to 'app/src/main/java/ml/docilealligator')
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java | 45 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java | 2 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java | 10 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java | 4 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java (renamed from app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java) | 4 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java | 44 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java | 2 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java | 10 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java | 2 |
9 files changed, 80 insertions, 43 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java index 9524fd47..991fdd33 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AccountPostsActivity.java @@ -4,6 +4,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.os.Bundle; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -22,7 +23,7 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -public class AccountPostsActivity extends AppCompatActivity { +public class AccountPostsActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { static final String EXTRA_USER_WHERE = "EUW"; @@ -40,6 +41,9 @@ public class AccountPostsActivity extends AppCompatActivity { private String mUserWhere; private Fragment mFragment; + private Menu mMenu; + + private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @@ -104,6 +108,9 @@ public class AccountPostsActivity extends AppCompatActivity { } else if(mUserWhere.equals(PostDataSource.USER_WHERE_HIDDEN)) { toolbar.setTitle(R.string.hidden); } else if(mUserWhere.equals(PostDataSource.USER_WHERE_GILDED)){ + if(mMenu != null) { + mMenu.findItem(R.id.action_sort_account_posts_activity).setVisible(true); + } toolbar.setTitle(R.string.gilded); } @@ -124,6 +131,8 @@ public class AccountPostsActivity extends AppCompatActivity { } else { getCurrentAccountAndBindView(); } + + userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); } private void getCurrentAccountAndBindView() { @@ -152,10 +161,31 @@ public class AccountPostsActivity extends AppCompatActivity { } @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.account_posts_activity, menu); + mMenu = menu; + if(mUserWhere != null && mUserWhere.equals(PostDataSource.USER_WHERE_GILDED)) { + menu.findItem(R.id.action_sort_account_posts_activity).setVisible(true); + } + return true; + } + + @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { - if(item.getItemId() == android.R.id.home) { - finish(); - return true; + switch (item.getItemId()) { + case R.id.action_sort_account_posts_activity: + userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag()); + return true; + case R.id.action_refresh_account_posts_activity: + if(mFragment != null) { + ((PostFragment) mFragment).refresh(); + } + return true; + case R.id.action_lazy_mode_account_posts_activity: + return true; + case android.R.id.home: + finish(); + return true; } return false; } @@ -170,4 +200,11 @@ public class AccountPostsActivity extends AppCompatActivity { outState.putString(ACCOUNT_NAME_STATE, mAccountName); outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); } + + @Override + public void userThingSortTypeSelected(String sortType) { + if(mFragment != null) { + ((PostFragment) mFragment).changeSortType(sortType); + } + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index 11ced525..7b054b03 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -26,7 +26,7 @@ interface AppComponent { void inject(RulesActivity rulesActivity); void inject(CommentsListingFragment commentsListingFragment); void inject(SubmitPostService submitPostService); - void inject(FilteredPostsActivity filteredPostsActivity); + void inject(FilteredThingActivity filteredPostsActivity); void inject(SearchResultActivity searchResultActivity); void inject(SearchSubredditsResultActivity searchSubredditsResultActivity); void inject(FollowedUsersListingFragment followedUsersListingFragment); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java index da2a7a02..b5ca248b 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentAndPostRecyclerViewAdapter.java @@ -310,11 +310,11 @@ class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVie ((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()); + Intent intent = new Intent(mActivity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, mSubredditNamePrefixed.substring(2)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, PostDataSource.TYPE_SUBREDDIT); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, PostDataSource.SORT_TYPE_HOT); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, mPost.getPostType()); mActivity.startActivity(intent); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java index 56e3e7e8..faffc24f 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentsListingFragment.java @@ -17,7 +17,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.fragment.app.Fragment; -import androidx.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -102,7 +102,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni mCommentRecyclerView.setAdapter(mAdapter); CommentViewModel.Factory factory = new CommentViewModel.Factory(mRetrofit, resources.getConfiguration().locale, username); - mCommentViewModel = ViewModelProviders.of(this, factory).get(CommentViewModel.class); + mCommentViewModel = new ViewModelProvider(this, factory).get(CommentViewModel.class); mCommentViewModel.getComments().observe(this, comments -> mAdapter.submitList(comments)); mCommentViewModel.getInitialLoadingState().observe(this, networkState -> { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java index 6de62689..caeb7ef0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java @@ -23,8 +23,8 @@ import javax.inject.Inject; import butterknife.BindView; import butterknife.ButterKnife; -public class FilteredPostsActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, - SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserPostsSortTypeSelectionCallback { +public class FilteredThingActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, + SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { static final String EXTRA_NAME = "ESN"; static final String EXTRA_QUERY = "EQ"; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index 7382fbaf..1a35b859 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -205,12 +205,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { - Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); - intent.putExtra(FilteredPostsActivity.EXTRA_QUERY, query); - intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); - intent.putExtra(FilteredPostsActivity.EXTRA_SORT_TYPE, sortType); - intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredThingActivity.EXTRA_QUERY, query); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter); startActivity(intent); } }); @@ -235,11 +235,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { - Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName); - intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); - intent.putExtra(FilteredPostsActivity.EXTRA_SORT_TYPE, sortType); - intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, subredditName); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter); startActivity(intent); } }); @@ -268,12 +268,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { - Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, username); - intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); - intent.putExtra(FilteredPostsActivity.EXTRA_SORT_TYPE, sortType); - intent.putExtra(FilteredPostsActivity.EXTRA_USER_WHERE, where); - intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, username); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType); + intent.putExtra(FilteredThingActivity.EXTRA_USER_WHERE, where); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter); startActivity(intent); } }); @@ -295,11 +295,11 @@ public class PostFragment extends Fragment implements FragmentCommunicator { @Override public void typeChipClicked(int filter) { - Intent intent = new Intent(activity, FilteredPostsActivity.class); - intent.putExtra(FilteredPostsActivity.EXTRA_NAME, activity.getString(R.string.best)); - intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType); - intent.putExtra(FilteredPostsActivity.EXTRA_SORT_TYPE, sortType); - intent.putExtra(FilteredPostsActivity.EXTRA_FILTER, filter); + Intent intent = new Intent(activity, FilteredThingActivity.class); + intent.putExtra(FilteredThingActivity.EXTRA_NAME, activity.getString(R.string.best)); + intent.putExtra(FilteredThingActivity.EXTRA_POST_TYPE, postType); + intent.putExtra(FilteredThingActivity.EXTRA_SORT_TYPE, sortType); + intent.putExtra(FilteredThingActivity.EXTRA_FILTER, filter); startActivity(intent); } }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 6f0cdc24..07b620ca 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -359,7 +359,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo ((DataViewHolder) holder).crosspostImageView.setVisibility(View.VISIBLE); } - if(!(mContext instanceof FilteredPostsActivity)) { + if(!(mContext instanceof FilteredThingActivity)) { ((DataViewHolder) holder).typeChip.setOnClickListener(view -> mCallback.typeChipClicked(post.getPostType())); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java index 83fb1464..dfbf297e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java @@ -24,7 +24,7 @@ import butterknife.ButterKnife; */ public class UserThingSortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment { - interface UserPostsSortTypeSelectionCallback { + interface UserThingSortTypeSelectionCallback { void userThingSortTypeSelected(String sortType); } @@ -56,28 +56,28 @@ public class UserThingSortTypeBottomSheetFragment extends RoundedBottomSheetDial newTypeTextView.setOnClickListener(view -> { if(activity != null) { - ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_NEW); + ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_NEW); } dismiss(); }); hotTypeTextView.setOnClickListener(view -> { if(activity != null) { - ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_HOT); + ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_HOT); } dismiss(); }); topTypeTextView.setOnClickListener(view -> { if(activity != null) { - ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_TOP); + ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_TOP); } dismiss(); }); controversialTypeTextView.setOnClickListener(view -> { if(activity != null) { - ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL); + ((UserThingSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL); } dismiss(); }); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index f510ce27..46cacbd0 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java @@ -48,7 +48,7 @@ import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import pl.droidsonroids.gif.GifImageView; import retrofit2.Retrofit; -public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserPostsSortTypeSelectionCallback { +public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { public static final String EXTRA_USER_NAME_KEY = "EUNK"; |