From 2dbb854bfcc6d409f611195ce2a43249a3cf8c2f Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 14 Aug 2019 16:52:59 +0800 Subject: Sorting gilded posts in AccountPostsActivity is available. Refreshing in AccountPostsActivity is available. --- app/src/main/AndroidManifest.xml | 2 +- .../infinityforreddit/AccountPostsActivity.java | 45 +++- .../infinityforreddit/AppComponent.java | 2 +- .../CommentAndPostRecyclerViewAdapter.java | 10 +- .../infinityforreddit/CommentsListingFragment.java | 4 +- .../infinityforreddit/FilteredPostsActivity.java | 285 --------------------- .../infinityforreddit/FilteredThingActivity.java | 285 +++++++++++++++++++++ .../infinityforreddit/PostFragment.java | 44 ++-- .../infinityforreddit/PostRecyclerViewAdapter.java | 2 +- .../UserThingSortTypeBottomSheetFragment.java | 10 +- .../infinityforreddit/ViewUserDetailActivity.java | 2 +- app/src/main/res/menu/account_posts_activity.xml | 23 ++ 12 files changed, 387 insertions(+), 327 deletions(-) delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java create mode 100644 app/src/main/res/menu/account_posts_activity.xml (limited to 'app/src/main') diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fad66b16..353588df 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -42,7 +42,7 @@ android:exported="false" /> { - 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/FilteredPostsActivity.java deleted file mode 100644 index 6de62689..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredPostsActivity.java +++ /dev/null @@ -1,285 +0,0 @@ -package ml.docilealligator.infinityforreddit; - -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; -import android.view.Window; -import android.view.WindowManager; - -import androidx.annotation.NonNull; -import androidx.appcompat.app.AppCompatActivity; -import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.Fragment; - -import com.google.android.material.appbar.AppBarLayout; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; - -public class FilteredPostsActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, - 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"; - private static final String FRAGMENT_OUT_STATE = "FOS"; - - @BindView(R.id.appbar_layout_filtered_posts_activity) AppBarLayout appBarLayout; - @BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar; - - private boolean mNullAccessToken = false; - private String mAccessToken; - private String name; - private int postType; - - private Fragment mFragment; - - private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment; - private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment; - private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment; - private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; - private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; - - @Inject - RedditDataRoomDatabase mRedditDataRoomDatabase; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_filtered_posts); - - ButterKnife.bind(this); - - ((Infinity) getApplication()).getAppComponent().inject(this); - - Resources resources = getResources(); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 - && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT - || resources.getBoolean(R.bool.isTablet))) { - Window window = getWindow(); - window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - - boolean lightNavBar = false; - if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { - lightNavBar = true; - } - boolean finalLightNavBar = lightNavBar; - - View decorView = window.getDecorView(); - if(finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { - @Override - void onStateChanged(AppBarLayout appBarLayout, State state) { - if (state == State.COLLAPSED) { - if(finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - } else if (state == State.EXPANDED) { - if(finalLightNavBar) { - decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); - } - } - } - }); - - int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (statusBarResourceId > 0) { - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); - params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); - toolbar.setLayoutParams(params); - } - } - - setSupportActionBar(toolbar); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - - name = getIntent().getExtras().getString(EXTRA_NAME); - postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE); - int filter = getIntent().getExtras().getInt(EXTRA_FILTER); - String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE); - - if(savedInstanceState != null) { - mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); - mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); - if(!mNullAccessToken && mAccessToken == null) { - getCurrentAccountAndBindView(filter, sortType); - } else { - mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); - bindView(filter, sortType, false); - } - } else { - getCurrentAccountAndBindView(filter, sortType); - } - } - - private void getCurrentAccountAndBindView(int filter, String sortType) { - new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { - if(account == null) { - mNullAccessToken = true; - } else { - mAccessToken = account.getAccessToken(); - } - bindView(filter, sortType, true); - }).execute(); - } - - private void bindView(int filter, String sortType, boolean initializeFragment) { - 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: - 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); - - userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); - break; - } - - switch (filter) { - case Post.TEXT_TYPE: - toolbar.setSubtitle(R.string.text); - break; - case Post.LINK_TYPE: - case Post.NO_PREVIEW_LINK_TYPE: - toolbar.setSubtitle(R.string.link); - break; - case Post.IMAGE_TYPE: - toolbar.setSubtitle(R.string.image); - break; - case Post.VIDEO_TYPE: - toolbar.setSubtitle(R.string.video); - break; - case Post.GIF_VIDEO_TYPE: - toolbar.setSubtitle(R.string.gif); - } - - if(initializeFragment) { - mFragment = new PostFragment(); - Bundle bundle = new Bundle(); - bundle.putString(PostFragment.EXTRA_NAME, name); - bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType); - 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)); - } - mFragment.setArguments(bundle); - getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); - } - } - - @Override - public boolean onCreateOptionsMenu(Menu menu) { - getMenuInflater().inflate(R.menu.filtered_posts_activity, menu); - return true; - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - 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()); - } - break; - case PostDataSource.TYPE_USER: - userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag()); - } - return true; - case R.id.action_refresh_filtered_posts_activity: - ((FragmentCommunicator) mFragment).refresh(); - return true; - } - return false; - } - - @Override - protected void onSaveInstanceState(@NonNull Bundle outState) { - super.onSaveInstanceState(outState); - if (mFragment != null) { - getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); - } - outState.putString(ACCESS_TOKEN_STATE, mAccessToken); - outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); - } - - @Override - public void searchSortTypeSelected(String sortType) { - ((PostFragment)mFragment).changeSortType(sortType); - } - - @Override - 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/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java new file mode 100644 index 00000000..caeb7ef0 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FilteredThingActivity.java @@ -0,0 +1,285 @@ +package ml.docilealligator.infinityforreddit; + +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; +import android.view.Window; +import android.view.WindowManager; + +import androidx.annotation.NonNull; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.fragment.app.Fragment; + +import com.google.android.material.appbar.AppBarLayout; + +import javax.inject.Inject; + +import butterknife.BindView; +import butterknife.ButterKnife; + +public class FilteredThingActivity extends AppCompatActivity implements SortTypeBottomSheetFragment.SortTypeSelectionCallback, + SearchPostSortTypeBottomSheetFragment.SearchSortTypeSelectionCallback, UserThingSortTypeBottomSheetFragment.UserThingSortTypeSelectionCallback { + + 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"; + private static final String FRAGMENT_OUT_STATE = "FOS"; + + @BindView(R.id.appbar_layout_filtered_posts_activity) AppBarLayout appBarLayout; + @BindView(R.id.toolbar_filtered_posts_activity) Toolbar toolbar; + + private boolean mNullAccessToken = false; + private String mAccessToken; + private String name; + private int postType; + + private Fragment mFragment; + + private SortTypeBottomSheetFragment bestSortTypeBottomSheetFragment; + private SortTypeBottomSheetFragment popularAndAllSortTypeBottomSheetFragment; + private SortTypeBottomSheetFragment subredditSortTypeBottomSheetFragment; + private UserThingSortTypeBottomSheetFragment userThingSortTypeBottomSheetFragment; + private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; + + @Inject + RedditDataRoomDatabase mRedditDataRoomDatabase; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_filtered_posts); + + ButterKnife.bind(this); + + ((Infinity) getApplication()).getAppComponent().inject(this); + + Resources resources = getResources(); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 + && (resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT + || resources.getBoolean(R.bool.isTablet))) { + Window window = getWindow(); + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + + boolean lightNavBar = false; + if((resources.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) != Configuration.UI_MODE_NIGHT_YES) { + lightNavBar = true; + } + boolean finalLightNavBar = lightNavBar; + + View decorView = window.getDecorView(); + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + appBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() { + @Override + void onStateChanged(AppBarLayout appBarLayout, State state) { + if (state == State.COLLAPSED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } else if (state == State.EXPANDED) { + if(finalLightNavBar) { + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR); + } + } + } + }); + + int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); + if (statusBarResourceId > 0) { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) toolbar.getLayoutParams(); + params.topMargin = getResources().getDimensionPixelSize(statusBarResourceId); + toolbar.setLayoutParams(params); + } + } + + setSupportActionBar(toolbar); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + name = getIntent().getExtras().getString(EXTRA_NAME); + postType = getIntent().getExtras().getInt(EXTRA_POST_TYPE); + int filter = getIntent().getExtras().getInt(EXTRA_FILTER); + String sortType = getIntent().getExtras().getString(EXTRA_SORT_TYPE); + + if(savedInstanceState != null) { + mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); + mAccessToken = savedInstanceState.getString(ACCESS_TOKEN_STATE); + if(!mNullAccessToken && mAccessToken == null) { + getCurrentAccountAndBindView(filter, sortType); + } else { + mFragment = getSupportFragmentManager().getFragment(savedInstanceState, FRAGMENT_OUT_STATE); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); + bindView(filter, sortType, false); + } + } else { + getCurrentAccountAndBindView(filter, sortType); + } + } + + private void getCurrentAccountAndBindView(int filter, String sortType) { + new GetCurrentAccountAsyncTask(mRedditDataRoomDatabase.accountDao(), account -> { + if(account == null) { + mNullAccessToken = true; + } else { + mAccessToken = account.getAccessToken(); + } + bindView(filter, sortType, true); + }).execute(); + } + + private void bindView(int filter, String sortType, boolean initializeFragment) { + 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: + 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); + + userThingSortTypeBottomSheetFragment = new UserThingSortTypeBottomSheetFragment(); + break; + } + + switch (filter) { + case Post.TEXT_TYPE: + toolbar.setSubtitle(R.string.text); + break; + case Post.LINK_TYPE: + case Post.NO_PREVIEW_LINK_TYPE: + toolbar.setSubtitle(R.string.link); + break; + case Post.IMAGE_TYPE: + toolbar.setSubtitle(R.string.image); + break; + case Post.VIDEO_TYPE: + toolbar.setSubtitle(R.string.video); + break; + case Post.GIF_VIDEO_TYPE: + toolbar.setSubtitle(R.string.gif); + } + + if(initializeFragment) { + mFragment = new PostFragment(); + Bundle bundle = new Bundle(); + bundle.putString(PostFragment.EXTRA_NAME, name); + bundle.putInt(PostFragment.EXTRA_POST_TYPE, postType); + 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)); + } + mFragment.setArguments(bundle); + getSupportFragmentManager().beginTransaction().replace(R.id.frame_layout_filtered_posts_activity, mFragment).commit(); + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.filtered_posts_activity, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(@NonNull MenuItem item) { + 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()); + } + break; + case PostDataSource.TYPE_USER: + userThingSortTypeBottomSheetFragment.show(getSupportFragmentManager(), userThingSortTypeBottomSheetFragment.getTag()); + } + return true; + case R.id.action_refresh_filtered_posts_activity: + ((FragmentCommunicator) mFragment).refresh(); + return true; + } + return false; + } + + @Override + protected void onSaveInstanceState(@NonNull Bundle outState) { + super.onSaveInstanceState(outState); + if (mFragment != null) { + getSupportFragmentManager().putFragment(outState, FRAGMENT_OUT_STATE, mFragment); + } + outState.putString(ACCESS_TOKEN_STATE, mAccessToken); + outState.putBoolean(NULL_ACCESS_TOKEN_STATE, mNullAccessToken); + } + + @Override + public void searchSortTypeSelected(String sortType) { + ((PostFragment)mFragment).changeSortType(sortType); + } + + @Override + 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/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 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"; diff --git a/app/src/main/res/menu/account_posts_activity.xml b/app/src/main/res/menu/account_posts_activity.xml new file mode 100644 index 00000000..cf39a53d --- /dev/null +++ b/app/src/main/res/menu/account_posts_activity.xml @@ -0,0 +1,23 @@ + + + + + + + \ No newline at end of file -- cgit v1.2.3