diff options
Diffstat (limited to 'app/src')
10 files changed, 372 insertions, 92 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java index b1fe0162..63260d1a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FragmentCommunicator.java @@ -48,5 +48,5 @@ public interface FragmentCommunicator { default void filterPosts() { - }; + } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragmentContentScrollingInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragmentContentScrollingInterface.java new file mode 100644 index 00000000..75d5271d --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragmentContentScrollingInterface.java @@ -0,0 +1,7 @@ +package ml.docilealligator.infinityforreddit; + +public interface PostFragmentContentScrollingInterface { + void contentScrollUp(); + + void contentScrollDown(); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java index 38a1da5d..e0ae0de2 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FilteredPostsActivity.java @@ -34,6 +34,7 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.PostFilter; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; @@ -55,7 +56,8 @@ import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; public class FilteredPostsActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, - MarkPostAsReadInterface, FilteredThingFABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback { + MarkPostAsReadInterface, FilteredThingFABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, + PostFragmentContentScrollingInterface { public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_QUERY = "EQ"; @@ -549,10 +551,12 @@ public class FilteredPostsActivity extends BaseActivity implements SortTypeSelec } } + @Override public void contentScrollUp() { fab.show(); } + @Override public void contentScrollDown() { fab.hide(); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java index fe9da437..f3df425a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java @@ -68,6 +68,7 @@ import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; import ml.docilealligator.infinityforreddit.FetchMyInfo; import ml.docilealligator.infinityforreddit.FetchSubscribedThing; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; import ml.docilealligator.infinityforreddit.PullNotificationWorker; @@ -115,7 +116,7 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; public class MainActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, - RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface { + RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface, PostFragmentContentScrollingInterface { static final String EXTRA_MESSSAGE_FULLNAME = "ENF"; static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; @@ -1106,7 +1107,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb sectionsPagerAdapter.changePostLayout(postLayout); } - public void postScrollUp() { + @Override + public void contentScrollUp() { if (mAccessToken != null) { if (showBottomAppBar && !mLockBottomAppBar) { bottomAppBar.performShow(); @@ -1117,7 +1119,8 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb } } - public void postScrollDown() { + @Override + public void contentScrollDown() { if (mAccessToken != null) { if (!(showBottomAppBar && mLockBottomAppBar)) { fab.hide(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java index a3ca8889..7a3a4305 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SearchResultActivity.java @@ -1,5 +1,6 @@ package ml.docilealligator.infinityforreddit.activities; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; @@ -10,6 +11,8 @@ import android.view.MenuItem; import android.view.View; import android.view.Window; import android.view.WindowManager; +import android.view.inputmethod.InputMethodManager; +import android.widget.EditText; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -22,6 +25,8 @@ import androidx.viewpager2.adapter.FragmentStateAdapter; import androidx.viewpager2.widget.ViewPager2; import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.dialog.MaterialAlertDialogBuilder; +import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayoutMediator; import com.r0adkll.slidr.Slidr; @@ -36,8 +41,18 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; import ml.docilealligator.infinityforreddit.ActivityToolbarInterface; +import ml.docilealligator.infinityforreddit.FragmentCommunicator; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; +import ml.docilealligator.infinityforreddit.SortType; +import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.asynctasks.GetCurrentAccountAsyncTask; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.FABMoreOptionsBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostLayoutBottomSheetFragment; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.PostTypeBottomSheetFragment; +import ml.docilealligator.infinityforreddit.bottomsheetfragments.RandomBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchPostSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SearchUserAndSubredditSortTypeBottomSheetFragment; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SortTimeBottomSheetFragment; @@ -47,19 +62,15 @@ import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.fragments.PostFragment; import ml.docilealligator.infinityforreddit.fragments.SubredditListingFragment; import ml.docilealligator.infinityforreddit.fragments.UserListingFragment; -import ml.docilealligator.infinityforreddit.FragmentCommunicator; -import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.post.PostDataSource; -import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.recentsearchquery.InsertRecentSearchQuery; -import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; -import ml.docilealligator.infinityforreddit.SortType; -import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback, - PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface { + PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, + FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, + PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostFragmentContentScrollingInterface { static final String EXTRA_QUERY = "QK"; static final String EXTRA_SUBREDDIT_NAME = "ESN"; @@ -77,6 +88,8 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect TabLayout tabLayout; @BindView(R.id.view_pager_search_result_activity) ViewPager2 viewPager2; + @BindView(R.id.fab_search_result_activity) + FloatingActionButton fab; @Inject RedditDataRoomDatabase mRedditDataRoomDatabase; @Inject @@ -89,6 +102,12 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect @Named("post_layout") SharedPreferences mPostLayoutSharedPreferences; @Inject + @Named("bottom_app_bar") + SharedPreferences bottomAppBarSharedPreference; + @Inject + @Named("nsfw_and_spoiler") + SharedPreferences mNsfwAndSpoilerSharedPreferences; + @Inject CustomThemeWrapper mCustomThemeWrapper; private boolean mNullAccessToken = false; private String mAccessToken; @@ -98,10 +117,6 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect private boolean mInsertSearchQuerySuccess; private FragmentManager fragmentManager; private SectionsPagerAdapter sectionsPagerAdapter; - private SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment; - private SortTimeBottomSheetFragment sortTimeBottomSheetFragment; - private SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment; - private PostLayoutBottomSheetFragment postLayoutBottomSheetFragment; private SlidrInterface mSlidrInterface; @Override @@ -138,6 +153,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); } adjustToolbar(toolbar); + + int navBarHeight = getNavBarHeight(); + if (navBarHeight > 0) { + CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) fab.getLayoutParams(); + params.bottomMargin += navBarHeight; + fab.setLayoutParams(params); + } } } @@ -168,19 +190,9 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect if (!mNullAccessToken && mAccessToken == null) { getCurrentAccountAndInitializeViewPager(); } else { - initializeViewPager(); + bindView(); } } - - searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment(); - Bundle bundle = new Bundle(); - searchPostSortTypeBottomSheetFragment.setArguments(bundle); - - sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); - - searchUserAndSubredditSortTypeBottomSheetFragment = new SearchUserAndSubredditSortTypeBottomSheetFragment(); - - postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); } @Override @@ -206,6 +218,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyTabLayoutTheme(tabLayout); + applyFABTheme(fab); } private void getCurrentAccountAndInitializeViewPager() { @@ -216,11 +229,11 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect mAccessToken = account.getAccessToken(); mAccountName = account.getUsername(); } - initializeViewPager(); + bindView(); }).execute(); } - private void initializeViewPager() { + private void bindView() { sectionsPagerAdapter = new SectionsPagerAdapter(this); viewPager2.setAdapter(sectionsPagerAdapter); viewPager2.setOffscreenPageLimit(3); @@ -251,12 +264,130 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect }).attach(); fixViewPager2Sensitivity(viewPager2); + int fabOption = bottomAppBarSharedPreference.getInt(SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB, SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SUBMIT_POSTS); + switch (fabOption) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: + fab.setImageResource(R.drawable.ic_refresh_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: + fab.setImageResource(R.drawable.ic_sort_toolbar_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: + fab.setImageResource(R.drawable.ic_post_layout_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: + fab.setImageResource(R.drawable.ic_search_black_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + fab.setImageResource(R.drawable.ic_subreddit_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER: + fab.setImageResource(R.drawable.ic_user_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM: + fab.setImageResource(R.drawable.ic_random_24dp); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: + if (mAccessToken == null) { + fab.setImageResource(R.drawable.ic_filter_24dp); + } else { + fab.setImageResource(R.drawable.ic_hide_read_posts_24dp); + } + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + fab.setImageResource(R.drawable.ic_filter_24dp); + break; + default: + if (mAccessToken == null) { + fab.setImageResource(R.drawable.ic_filter_24dp); + } else { + fab.setImageResource(R.drawable.ic_add_day_night_24dp); + } + break; + } + fab.setOnClickListener(view -> { + switch (fabOption) { + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_REFRESH: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_SORT_TYPE: { + SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment(); + searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag()); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_CHANGE_POST_LAYOUT: { + PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_SEARCH: { + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, mSubredditName); + startActivity(intent); + break; + } + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_SUBREDDIT: + goToSubreddit(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_GO_TO_USER: + goToUser(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_RANDOM: + random(); + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_HIDE_READ_POSTS: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.hideReadPosts(); + } + break; + case SharedPreferencesUtils.OTHER_ACTIVITIES_BOTTOM_APP_BAR_FAB_FILTER_POSTS: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; + default: + PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); + postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); + break; + } + }); + fab.setOnLongClickListener(view -> { + FABMoreOptionsBottomSheetFragment fabMoreOptionsBottomSheetFragment = new FABMoreOptionsBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(FABMoreOptionsBottomSheetFragment.EXTRA_ANONYMOUS_MODE, mAccessToken == null); + fabMoreOptionsBottomSheetFragment.setArguments(bundle); + fabMoreOptionsBottomSheetFragment.show(getSupportFragmentManager(), fabMoreOptionsBottomSheetFragment.getTag()); + return true; + }); + if (mAccountName != null && mSharedPreferences.getBoolean(SharedPreferencesUtils.ENABLE_SEARCH_HISTORY, true) && !mInsertSearchQuerySuccess && mQuery != null) { InsertRecentSearchQuery.insertRecentSearchQueryListener(mRedditDataRoomDatabase, mAccountName, mQuery, () -> mInsertSearchQuerySuccess = true); } } + private void displaySortTypeBottomSheetFragment() { + switch (viewPager2.getCurrentItem()) { + case 0: { + SearchPostSortTypeBottomSheetFragment searchPostSortTypeBottomSheetFragment = new SearchPostSortTypeBottomSheetFragment(); + searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag()); + break; + } + case 1: + case 2: + SearchUserAndSubredditSortTypeBottomSheetFragment searchUserAndSubredditSortTypeBottomSheetFragment + = new SearchUserAndSubredditSortTypeBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putInt(SearchUserAndSubredditSortTypeBottomSheetFragment.EXTRA_FRAGMENT_POSITION, viewPager2.getCurrentItem()); + searchUserAndSubredditSortTypeBottomSheetFragment.setArguments(bundle); + searchUserAndSubredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchUserAndSubredditSortTypeBottomSheetFragment.getTag()); + break; + } + } + @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.search_result_activity, menu); @@ -271,19 +402,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect onBackPressed(); return true; case R.id.action_sort_search_result_activity: - switch (viewPager2.getCurrentItem()) { - case 0: { - searchPostSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchPostSortTypeBottomSheetFragment.getTag()); - break; - } - case 1: - case 2: - Bundle bundle = new Bundle(); - bundle.putInt(SearchUserAndSubredditSortTypeBottomSheetFragment.EXTRA_FRAGMENT_POSITION, viewPager2.getCurrentItem()); - searchUserAndSubredditSortTypeBottomSheetFragment.setArguments(bundle); - searchUserAndSubredditSortTypeBottomSheetFragment.show(getSupportFragmentManager(), searchUserAndSubredditSortTypeBottomSheetFragment.getTag()); - break; - } + displaySortTypeBottomSheetFragment(); return true; case R.id.action_search_search_result_activity: Intent intent = new Intent(this, SearchActivity.class); @@ -300,6 +419,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } return true; case R.id.action_change_post_layout_search_result_activity: + PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); return true; } @@ -333,6 +453,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect public void sortTypeSelected(String sortType) { Bundle bundle = new Bundle(); bundle.putString(SortTimeBottomSheetFragment.EXTRA_SORT_TYPE, sortType); + SortTimeBottomSheetFragment sortTimeBottomSheetFragment = new SortTimeBottomSheetFragment(); sortTimeBottomSheetFragment.setArguments(bundle); sortTimeBottomSheetFragment.show(getSupportFragmentManager(), sortTimeBottomSheetFragment.getTag()); } @@ -379,6 +500,153 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } } + @Override + public void fabOptionSelected(int option) { + switch (option) { + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SUBMIT_POST: + PostTypeBottomSheetFragment postTypeBottomSheetFragment = new PostTypeBottomSheetFragment(); + postTypeBottomSheetFragment.show(getSupportFragmentManager(), postTypeBottomSheetFragment.getTag()); + break; + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_REFRESH: + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.refresh(); + } + break; + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_SORT_TYPE: + displaySortTypeBottomSheetFragment(); + break; + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_CHANGE_POST_LAYOUT: + PostLayoutBottomSheetFragment postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); + postLayoutBottomSheetFragment.show(getSupportFragmentManager(), postLayoutBottomSheetFragment.getTag()); + break; + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_SEARCH: + Intent intent = new Intent(this, SearchActivity.class); + intent.putExtra(SearchActivity.EXTRA_SUBREDDIT_NAME, mSubredditName); + startActivity(intent); + break; + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_SUBREDDIT: { + goToSubreddit(); + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_OPTION_GO_TO_USER: { + goToUser(); + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_RANDOM: { + random(); + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_HIDE_READ_POSTS: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.hideReadPosts(); + } + break; + } + case FABMoreOptionsBottomSheetFragment.FAB_FILTER_POSTS: { + if (sectionsPagerAdapter != null) { + sectionsPagerAdapter.filterPosts(); + } + break; + } + } + } + + private void goToSubreddit() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_subreddit) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent subredditIntent = new Intent(this, ViewSubredditDetailActivity.class); + subredditIntent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, thingEditText.getText().toString()); + startActivity(subredditIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void goToUser() { + EditText thingEditText = (EditText) getLayoutInflater().inflate(R.layout.dialog_go_to_thing_edit_text, null); + thingEditText.requestFocus(); + InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + if (imm != null) { + imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); + } + new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme) + .setTitle(R.string.go_to_user) + .setView(thingEditText) + .setPositiveButton(R.string.ok, (dialogInterface, i) + -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + Intent userIntent = new Intent(this, ViewUserDetailActivity.class); + userIntent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, thingEditText.getText().toString()); + startActivity(userIntent); + }) + .setNegativeButton(R.string.cancel, null) + .setOnDismissListener(dialogInterface -> { + if (imm != null) { + imm.hideSoftInputFromWindow(thingEditText.getWindowToken(), 0); + } + }) + .show(); + } + + private void random() { + RandomBottomSheetFragment randomBottomSheetFragment = new RandomBottomSheetFragment(); + Bundle bundle = new Bundle(); + bundle.putBoolean(RandomBottomSheetFragment.EXTRA_IS_NSFW, mNsfwAndSpoilerSharedPreferences.getBoolean((mAccountName == null ? "" : mAccountName) + SharedPreferencesUtils.NSFW_BASE, false)); + randomBottomSheetFragment.setArguments(bundle); + randomBottomSheetFragment.show(getSupportFragmentManager(), randomBottomSheetFragment.getTag()); + } + + @Override + public void postTypeSelected(int postType) { + Intent intent; + switch (postType) { + case PostTypeBottomSheetFragment.TYPE_TEXT: + intent = new Intent(this, PostTextActivity.class); + startActivity(intent); + break; + case PostTypeBottomSheetFragment.TYPE_LINK: + intent = new Intent(this, PostLinkActivity.class); + startActivity(intent); + break; + case PostTypeBottomSheetFragment.TYPE_IMAGE: + intent = new Intent(this, PostImageActivity.class); + startActivity(intent); + break; + case PostTypeBottomSheetFragment.TYPE_VIDEO: + intent = new Intent(this, PostVideoActivity.class); + startActivity(intent); + } + } + + @Override + public void contentScrollUp() { + fab.show(); + } + + @Override + public void contentScrollDown() { + fab.hide(); + } + private class SectionsPagerAdapter extends FragmentStateAdapter { public SectionsPagerAdapter(FragmentActivity fa) { @@ -505,6 +773,20 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect } } + void filterPosts() { + Fragment fragment = fragmentManager.findFragmentByTag("f0"); + if (fragment instanceof PostFragment) { + ((PostFragment) fragment).filterPosts(); + } + } + + void hideReadPosts() { + Fragment fragment = fragmentManager.findFragmentByTag("f0"); + if (fragment instanceof PostFragment) { + ((PostFragment) fragment).hideReadPosts(); + } + } + @Override public int getItemCount() { return 3; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java index 4852c32d..66ca1a1d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewSubredditDetailActivity.java @@ -66,6 +66,7 @@ import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; @@ -102,7 +103,7 @@ import retrofit2.Retrofit; public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, - RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface { + RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface, PostFragmentContentScrollingInterface { public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -1053,6 +1054,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp sectionsPagerAdapter.changePostLayout(postLayout); } + @Override public void contentScrollUp() { if (mAccessToken != null) { if (showBottomAppBar && !lockBottomAppBar) { @@ -1064,6 +1066,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp } } + @Override public void contentScrollDown() { if (mAccessToken != null) { if (!(showBottomAppBar && lockBottomAppBar)) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java index 9c77e0a9..9da8b670 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewUserDetailActivity.java @@ -70,6 +70,7 @@ import ml.docilealligator.infinityforreddit.DeleteThing; import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; @@ -108,7 +109,7 @@ import retrofit2.Retrofit; public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback, PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback, - RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface { + RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface, PostFragmentContentScrollingInterface { public static final String EXTRA_USER_NAME_KEY = "EUNK"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; @@ -1198,6 +1199,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele startActivity(intent); } + @Override public void contentScrollUp() { if (mAccessToken != null) { if (showBottomAppBar && !lockBottomAppBar) { @@ -1209,6 +1211,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele } } + @Override public void contentScrollDown() { if (mAccessToken != null) { if (!(showBottomAppBar && lockBottomAppBar)) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java index 3dccf361..13cc45cf 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/bottomsheetfragments/FABMoreOptionsBottomSheetFragment.java @@ -17,6 +17,7 @@ import ml.docilealligator.infinityforreddit.R; public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogFragment { + public static final String EXTRA_ANONYMOUS_MODE = "EAM"; public static final int FAB_OPTION_SUBMIT_POST = 0; public static final int FAB_OPTION_REFRESH = 1; public static final int FAB_OPTION_CHANGE_SORT_TYPE = 2; @@ -62,10 +63,20 @@ public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogF ButterKnife.bind(this, rootView); - submitPostTextView.setOnClickListener(view -> { - activity.fabOptionSelected(FAB_OPTION_SUBMIT_POST); - dismiss(); - }); + if (getArguments() != null && getArguments().getBoolean(EXTRA_ANONYMOUS_MODE, false)) { + submitPostTextView.setVisibility(View.GONE); + hideReadPostsTextView.setVisibility(View.GONE); + } else { + submitPostTextView.setOnClickListener(view -> { + activity.fabOptionSelected(FAB_OPTION_SUBMIT_POST); + dismiss(); + }); + + hideReadPostsTextView.setOnClickListener(view -> { + activity.fabOptionSelected(FAB_HIDE_READ_POSTS); + dismiss(); + }); + } refreshTextView.setOnClickListener(view -> { activity.fabOptionSelected(FAB_OPTION_REFRESH); @@ -102,11 +113,6 @@ public class FABMoreOptionsBottomSheetFragment extends RoundedBottomSheetDialogF dismiss(); }); - hideReadPostsTextView.setOnClickListener(view -> { - activity.fabOptionSelected(FAB_HIDE_READ_POSTS); - dismiss(); - }); - filterPostsTextView.setOnClickListener(view -> { activity.fabOptionSelected(FAB_FILTER_POSTS); dismiss(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java index 832de6c0..60d7f907 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java @@ -67,14 +67,12 @@ import ml.docilealligator.infinityforreddit.FragmentCommunicator; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.NetworkState; import ml.docilealligator.infinityforreddit.PostFilter; +import ml.docilealligator.infinityforreddit.PostFragmentContentScrollingInterface; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.SortType; import ml.docilealligator.infinityforreddit.activities.BaseActivity; import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity; -import ml.docilealligator.infinityforreddit.activities.MainActivity; -import ml.docilealligator.infinityforreddit.activities.ViewSubredditDetailActivity; -import ml.docilealligator.infinityforreddit.activities.ViewUserDetailActivity; import ml.docilealligator.infinityforreddit.adapters.PostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.customviews.CustomToroContainer; @@ -407,47 +405,14 @@ public class PostFragment extends Fragment implements FragmentCommunicator { return false; }); - if (activity instanceof MainActivity) { + if (activity instanceof PostFragmentContentScrollingInterface) { mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { - ((MainActivity) activity).postScrollDown(); + ((PostFragmentContentScrollingInterface) activity).contentScrollDown(); } else if (dy < 0) { - ((MainActivity) activity).postScrollUp(); - } - } - }); - } else if (activity instanceof ViewSubredditDetailActivity) { - mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy > 0) { - ((ViewSubredditDetailActivity) activity).contentScrollDown(); - } else if (dy < 0) { - ((ViewSubredditDetailActivity) activity).contentScrollUp(); - } - } - }); - } else if (activity instanceof ViewUserDetailActivity) { - mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy > 0) { - ((ViewUserDetailActivity) activity).contentScrollDown(); - } else if (dy < 0) { - ((ViewUserDetailActivity) activity).contentScrollUp(); - } - } - }); - } else if (activity instanceof FilteredPostsActivity) { - mPostRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { - @Override - public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { - if (dy > 0) { - ((FilteredPostsActivity) activity).contentScrollDown(); - } else if (dy < 0) { - ((FilteredPostsActivity) activity).contentScrollUp(); + ((PostFragmentContentScrollingInterface) activity).contentScrollUp(); } } }); diff --git a/app/src/main/res/layout/activity_search_result.xml b/app/src/main/res/layout/activity_search_result.xml index 889a1732..58100f8d 100644 --- a/app/src/main/res/layout/activity_search_result.xml +++ b/app/src/main/res/layout/activity_search_result.xml @@ -47,4 +47,11 @@ android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> + <com.google.android.material.floatingactionbutton.FloatingActionButton + android:id="@+id/fab_search_result_activity" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_margin="@dimen/fab_margin" + android:layout_gravity="bottom|end" /> + </androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file |