Sorting gilded posts in AccountPostsActivity is available. Refreshing in AccountPostsActivity is available.

This commit is contained in:
Alex Ning 2019-08-14 16:52:59 +08:00
parent 0a3d6520bc
commit 2dbb854bfc
11 changed files with 104 additions and 44 deletions

View File

@ -42,7 +42,7 @@
android:exported="false" />
<activity
android:name=".FilteredPostsActivity"
android:name=".FilteredThingActivity"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar" />
<activity

View File

@ -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() {
@ -151,11 +160,32 @@ public class AccountPostsActivity extends AppCompatActivity {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_account_posts_activity, mFragment).commit();
}
@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);
}
}
}

View File

@ -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);

View File

@ -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);
});

View File

@ -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 -> {

View File

@ -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";

View File

@ -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);
}
});

View File

@ -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()));
}

View File

@ -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();
});

View File

@ -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";

View File

@ -0,0 +1,23 @@
<?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_account_posts_activity"
android:orderInCategory="1"
android:title="@string/action_search"
android:icon="@drawable/ic_outline_sort_24px"
android:visible="false"
app:showAsAction="ifRoom" />
<item
android:id="@+id/action_refresh_account_posts_activity"
android:orderInCategory="2"
android:title="@string/action_refresh"
android:icon="@drawable/ic_refresh_white_24dp"
app:showAsAction="never" />
<item
android:id="@+id/action_lazy_mode_account_posts_activity"
android:orderInCategory="3"
android:title="@string/action_start_lazy_mode"
app:showAsAction="never" />
</menu>