diff options
author | Alex Ning <chineseperson5@gmail.com> | 2019-08-14 08:31:18 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2019-08-14 08:31:18 +0000 |
commit | 0a3d6520bc0bd6844ad479b232d3ca11ee87fa21 (patch) | |
tree | b0b8cee5d75b3a456df8d61c8b65bf4635fb736c /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 7cdf5d2e4c46da1830dd81c4929857e7496491e5 (diff) | |
download | infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar.gz infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar.bz2 infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar.lz infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar.xz infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.tar.zst infinity-for-reddit-0a3d6520bc0bd6844ad479b232d3ca11ee87fa21.zip |
Sorting users posts in ViewUserDetailActivity and FilteredPostsActivity is available.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
6 files changed, 140 insertions, 33 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java index e0f2bcf2..6de62689 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java @@ -24,13 +24,14 @@ import butterknife.BindView; import butterknife.ButterKnife; public class FilteredPostsActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, - SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback { + SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserPostsSortTypeSelectionCallback { static final String EXTRA_NAME = "ESN"; static final String EXTRA_QUERY = "EQ"; static final String EXTRA_FILTER = "EF"; static final String EXTRA_POST_TYPE = "EPT"; static final String EXTRA_SORT_TYPE = "EST"; + static final String EXTRA_USER_WHERE = "EUW"; private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; private static final String ACCESS_TOKEN_STATE = "ATS"; @@ -49,6 +50,7 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment; private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment; private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment; + private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; @Inject @@ -176,6 +178,8 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType case PostDataSource.TYPE_USER: String usernamePrefixed = "u/" + name; getSupportActionBar().setTitle(usernamePrefixed); + + userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); break; } @@ -205,6 +209,9 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType bundle.putString(PostFragment.EXTRA_SORT_TYPE, sortType); bundle.putInt(PostFragment.EXTRA_FILTER, filter); bundle.putString(PostFragment.EXTRA_ACCESS_TOKEN, mAccessToken); + if(postType == PostDataSource.TYPE_USER) { + bundle.putString(PostFragment.EXTRA_USER_WHERE, getIntent().getExtras().getString(EXTRA_USER_WHERE)); + } if(postType == PostDataSource.TYPE_SEARCH) { bundle.putString(PostFragment.EXTRA_QUERY, getIntent().getExtras().getString(EXTRA_QUERY)); } @@ -216,9 +223,6 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType @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; } @@ -242,6 +246,9 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType } else { subredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), subredditSortTypeBottomSheetFragment.getTag()); } + break; + case PostDataSource.TYPE_USER: + userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag()); } return true; case R.id.action_refresh_filtered_posts_activity: @@ -270,4 +277,9 @@ public class FilteredPostsActivity extends AppCompatActivity implements SortType public void sortTypeSelected(String sortType) { ((PostFragment)mFragment).changeSortType(sortType); } + + @Override + public void userThingSortTypeSelected(String sortType) { + ((PostFragment)mFragment).changeSortType(sortType); + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java index 625930e8..8e91314a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostDataSourceFactory.java @@ -98,10 +98,6 @@ class PostDataSourceFactory extends DataSource.Factory { return postDataSource; } - void changeAccessToken(String accessToken) { - this.accessToken = accessToken; - } - void changeSortType(String sortType) { this.sortType = sortType; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java index e9fb7bb2..7382fbaf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java @@ -272,6 +272,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator { 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); startActivity(intent); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java index f423fbec..70209249 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostViewModel.java @@ -100,6 +100,10 @@ public class PostViewModel extends ViewModel { accessTokenLiveData = new MutableLiveData<>(); accessTokenLiveData.postValue(accessToken); + sortTypeLiveData = new MutableLiveData<>(); + sortTypeLiveData.postValue(sortType); + + accessTokenAndSortTypeLiveData = new AccessTokenAndSortTypeLiveData(accessTokenLiveData, sortTypeLiveData); PagedList.Config pagedListConfig = (new PagedList.Config.Builder()) @@ -107,10 +111,8 @@ public class PostViewModel extends ViewModel { .setPageSize(25) .build(); - posts = (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); - - posts = Transformations.switchMap(accessTokenLiveData, newAccessToken -> { - postDataSourceFactory.changeAccessToken(accessTokenLiveData.getValue()); + posts = Transformations.switchMap(accessTokenAndSortTypeLiveData, sort -> { + postDataSourceFactory.changeAccessTokenAndSortType(accessTokenLiveData.getValue(), sortTypeLiveData.getValue()); return (new LivePagedListBuilder(postDataSourceFactory, pagedListConfig)).build(); }); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java new file mode 100644 index 00000000..83fb1464 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/UserThingSortTypeBottomSheetFragment.java @@ -0,0 +1,88 @@ +package ml.docilealligator.infinityforreddit; + + +import android.app.Activity; +import android.content.res.Configuration; +import android.os.Build; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; + +import com.deishelon.roundedbottomsheet.RoundedBottomSheetDialogFragment; + +import butterknife.BindView; +import butterknife.ButterKnife; + + +/** + * A simple {@link Fragment} subclass. + */ +public class UserThingSortTypeBottomSheetFragment extends RoundedBottomSheetDialogFragment { + + interface UserPostsSortTypeSelectionCallback { + void userThingSortTypeSelected(String sortType); + } + + static final String EXTRA_NO_BEST_TYPE = "ENBT"; + + @BindView(R.id.new_type_text_view_user_thing_sort_type_bottom_sheet_fragment) TextView newTypeTextView; + @BindView(R.id.hot_type_text_view_user_thing_sort_type_bottom_sheet_fragment) TextView hotTypeTextView; + @BindView(R.id.top_type_text_view_user_thing_sort_type_bottom_sheet_fragment) TextView topTypeTextView; + @BindView(R.id.controversial_type_text_view_user_thing_sort_type_bottom_sheet_fragment) TextView controversialTypeTextView; + + public UserThingSortTypeBottomSheetFragment() { + // Required empty public constructor + } + + + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_user_thing_sort_type_bottom_sheet, container, false); + + ButterKnife.bind(this, rootView); + + Activity activity = getActivity(); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O + && (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + + newTypeTextView.setOnClickListener(view -> { + if(activity != null) { + ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_NEW); + } + dismiss(); + }); + + hotTypeTextView.setOnClickListener(view -> { + if(activity != null) { + ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_HOT); + } + dismiss(); + }); + + topTypeTextView.setOnClickListener(view -> { + if(activity != null) { + ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_TOP); + } + dismiss(); + }); + + controversialTypeTextView.setOnClickListener(view -> { + if(activity != null) { + ((UserPostsSortTypeSelectionCallback) activity).userThingSortTypeSelected(PostDataSource.SORT_TYPE_CONTROVERSIAL); + } + dismiss(); + }); + + return rootView; + } + +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewUserDetailActivity.java index cd57a70a..f510ce27 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 { +public class ViewUserDetailActivity extends AppCompatActivity implements UserThingSortTypeBottomSheetFragment.UserPostsSortTypeSelectionCallback { public static final String EXTRA_USER_NAME_KEY = "EUNK"; @@ -58,26 +58,16 @@ public class ViewUserDetailActivity extends AppCompatActivity { private static final String ACCOUNT_NAME_STATE = "ANS"; private static final String IS_IN_LAZY_MODE_STATE = "IILMS"; - @BindView(R.id.coordinator_layout_view_user_detail_activity) - CoordinatorLayout coordinatorLayout; - @BindView(R.id.view_pager_view_user_detail_activity) - ViewPager viewPager; - @BindView(R.id.appbar_layout_view_user_detail) - AppBarLayout appBarLayout; - @BindView(R.id.tab_layout_view_user_detail_activity) - TabLayout tabLayout; - @BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity) - CollapsingToolbarLayout collapsingToolbarLayout; - @BindView(R.id.banner_image_view_view_user_detail_activity) - GifImageView bannerImageView; - @BindView(R.id.icon_gif_image_view_view_user_detail_activity) - GifImageView iconGifImageView; - @BindView(R.id.user_name_text_view_view_user_detail_activity) - TextView userNameTextView; - @BindView(R.id.subscribe_user_chip_view_user_detail_activity) - Chip subscribeUserChip; - @BindView(R.id.karma_text_view_view_user_detail_activity) - TextView karmaTextView; + @BindView(R.id.coordinator_layout_view_user_detail_activity) CoordinatorLayout coordinatorLayout; + @BindView(R.id.view_pager_view_user_detail_activity) ViewPager viewPager; + @BindView(R.id.appbar_layout_view_user_detail) AppBarLayout appBarLayout; + @BindView(R.id.tab_layout_view_user_detail_activity) TabLayout tabLayout; + @BindView(R.id.collapsing_toolbar_layout_view_user_detail_activity) CollapsingToolbarLayout collapsingToolbarLayout; + @BindView(R.id.banner_image_view_view_user_detail_activity) GifImageView bannerImageView; + @BindView(R.id.icon_gif_image_view_view_user_detail_activity) GifImageView iconGifImageView; + @BindView(R.id.user_name_text_view_view_user_detail_activity) TextView userNameTextView; + @BindView(R.id.subscribe_user_chip_view_user_detail_activity) Chip subscribeUserChip; + @BindView(R.id.karma_text_view_view_user_detail_activity) TextView karmaTextView; private SectionsPagerAdapter sectionsPagerAdapter; @@ -87,6 +77,8 @@ public class ViewUserDetailActivity extends AppCompatActivity { private Menu mMenu; private AppBarLayout.LayoutParams params; + private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; + private boolean mNullAccessToken = false; private String mAccessToken; private String mAccountName; @@ -347,6 +339,8 @@ public class ViewUserDetailActivity extends AppCompatActivity { karmaTextView.setText(karma); } }); + + userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); } private void getCurrentAccountAndInitializeViewPager() { @@ -431,6 +425,9 @@ public class ViewUserDetailActivity extends AppCompatActivity { case android.R.id.home: finish(); return true; + case R.id.action_sort_view_user_detail_activity: + userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag()); + return true; case R.id.action_search_view_user_detail_activity: Intent intent = new Intent(this, SearchActivity.class); intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, username); @@ -486,6 +483,11 @@ public class ViewUserDetailActivity extends AppCompatActivity { } } + @Override + public void userThingSortTypeSelected(String sortType) { + sectionsPagerAdapter.changeSortType(sortType); + } + private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> { interface InsertUserDataAsyncTaskListener { @@ -590,5 +592,11 @@ public class ViewUserDetailActivity extends AppCompatActivity { commentsListingFragment.refresh(); } } + + public void changeSortType(String sortType) { + if(postFragment != null) { + postFragment.changeSortType(sortType); + } + } } } |