aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-06-05 06:19:38 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-06-05 06:19:38 +0000
commit8311507acd0e96a537c6d540a066a06895bbcfff (patch)
treebaadcd29b362ccc0943cb9c8f48eac6c86aa7850 /app/src/main/java/ml/docilealligator/infinityforreddit
parenta9d2108c00942c2fa95d18a7772cb420a55353c1 (diff)
downloadinfinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar.gz
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar.bz2
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar.lz
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar.xz
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.tar.zst
infinity-for-reddit-8311507acd0e96a537c6d540a066a06895bbcfff.zip
Long press the toolbar to go to top.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java12
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java19
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java23
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java21
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java18
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java11
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java15
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java24
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java23
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java5
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java10
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java6
25 files changed, 316 insertions, 28 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
index 6ff51607..81cb85c7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountPostsActivity.java
@@ -25,6 +25,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@@ -40,7 +41,8 @@ import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
-public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+public class AccountPostsActivity extends BaseActivity implements SortTypeSelectionCallback,
+ PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
static final String EXTRA_USER_WHERE = "EUW";
@@ -118,6 +120,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -288,4 +291,11 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
((FragmentCommunicator) mFragment).changePostLayout(postLayout);
}
}
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((PostFragment) mFragment).goBackToTop();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
index 11062a31..d3c3caf9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/AccountSavedThingActivity.java
@@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@@ -43,7 +44,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import retrofit2.Retrofit;
-public class AccountSavedThingActivity extends BaseActivity {
+public class AccountSavedThingActivity extends BaseActivity implements ActivityToolbarInterface {
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS";
@@ -109,6 +110,7 @@ public class AccountSavedThingActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -275,6 +277,13 @@ public class AccountSavedThingActivity extends BaseActivity {
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private CommentsListingFragment commentsListingFragment;
@@ -383,5 +392,13 @@ public class AccountSavedThingActivity extends BaseActivity {
postFragment.changeNSFW(nsfw);
}
}
+
+ public void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ postFragment.goBackToTop();
+ } else {
+ commentsListingFragment.goBackToTop();
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
index bbbdf950..d6e61ecc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/BaseActivity.java
@@ -25,6 +25,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.ContentFontStyle;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@@ -183,6 +184,18 @@ public abstract class BaseActivity extends AppCompatActivity {
return immersiveInterface;
}
+ protected void setToolbarGoToTop(Toolbar toolbar) {
+ toolbar.setOnLongClickListener(new View.OnLongClickListener() {
+ @Override
+ public boolean onLongClick(View view) {
+ if (BaseActivity.this instanceof ActivityToolbarInterface) {
+ ((ActivityToolbarInterface) BaseActivity.this).onLongPress();
+ }
+ return true;
+ }
+ });
+ }
+
protected void adjustToolbar(Toolbar toolbar) {
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
index cd39817c..01c74de3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/FilteredThingActivity.java
@@ -25,6 +25,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@@ -45,7 +46,7 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ";
@@ -123,6 +124,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@@ -429,4 +431,11 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((PostFragment) mFragment).goBackToTop();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
index 6bc4189a..4a88fa6a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/MainActivity.java
@@ -58,6 +58,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
@@ -97,7 +98,8 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
+ ActivityToolbarInterface {
static final String EXTRA_POST_TYPE = "EPT";
static final String EXTRA_MESSSAGE_FULLNAME = "ENF";
@@ -247,6 +249,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
setSupportActionBar(toolbar);
+ setToolbarGoToTop(toolbar);
drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
@@ -921,6 +924,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mLockBottomAppBar = changeLockBottomAppBarEvent.lockBottomAppBar;
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment tab1;
private PostFragment tab2;
@@ -1341,5 +1351,15 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
}
}
}
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ tab1.goBackToTop();
+ } else if (viewPager.getCurrentItem() == 1) {
+ tab2.goBackToTop();
+ } else {
+ tab3.goBackToTop();
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
index dc168e74..9dc8941b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchResultActivity.java
@@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@@ -51,7 +52,7 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
static final String EXTRA_QUERY = "QK";
static final String EXTRA_SUBREDDIT_NAME = "ESN";
@@ -121,6 +122,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
if (savedInstanceState == null) {
getCurrentAccountAndInitializeViewPager();
@@ -295,6 +297,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
@@ -417,7 +426,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
}
}
- public void changeNSFW(boolean nsfw) {
+ void changeNSFW(boolean nsfw) {
if (postFragment != null) {
postFragment.changeNSFW(nsfw);
}
@@ -429,5 +438,15 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ postFragment.goBackToTop();
+ } else if (viewPager.getCurrentItem() == 1) {
+ subredditListingFragment.goBackToTop();
+ } else {
+ userListingFragment.goBackToTop();
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
index 1548362c..092cd5d8 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SearchSubredditsResultActivity.java
@@ -24,6 +24,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@@ -32,7 +33,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
-public class SearchSubredditsResultActivity extends BaseActivity {
+public class SearchSubredditsResultActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_QUERY = "EQ";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
@@ -90,6 +91,7 @@ public class SearchSubredditsResultActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
String query = getIntent().getExtras().getString(EXTRA_QUERY);
@@ -180,4 +182,11 @@ public class SearchSubredditsResultActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((SubredditListingFragment) mFragment).goBackToTop();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
index 4e612476..96bbabdb 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SelectedSubredditsActivity.java
@@ -24,12 +24,13 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.SelectedSubredditsRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R;
-public class SelectedSubredditsActivity extends BaseActivity {
+public class SelectedSubredditsActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_SELECTED_SUBREDDITS = "ESS";
public static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
@@ -51,6 +52,7 @@ public class SelectedSubredditsActivity extends BaseActivity {
SharedPreferences mSharedPreferences;
@Inject
CustomThemeWrapper mCustomThemeWrapper;
+ private LinearLayoutManager linearLayoutManager;
private SelectedSubredditsRecyclerViewAdapter adapter;
private ArrayList<String> subreddits;
@@ -65,6 +67,7 @@ public class SelectedSubredditsActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
if (savedInstanceState != null) {
subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
@@ -73,7 +76,8 @@ public class SelectedSubredditsActivity extends BaseActivity {
}
adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits);
- recyclerView.setLayoutManager(new LinearLayoutManager(this));
+ linearLayoutManager = new LinearLayoutManager(this);
+ recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
@@ -154,4 +158,11 @@ public class SelectedSubredditsActivity extends BaseActivity {
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
applyFABTheme(fab);
}
+
+ @Override
+ public void onLongPress() {
+ if (linearLayoutManager != null) {
+ linearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
index d0ffcfa8..d464ecec 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditMultiselectionActivity.java
@@ -34,6 +34,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.SubredditMultiselectionRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@@ -43,7 +44,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import retrofit2.Retrofit;
-public class SubredditMultiselectionActivity extends BaseActivity {
+public class SubredditMultiselectionActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
@@ -82,6 +83,7 @@ public class SubredditMultiselectionActivity extends BaseActivity {
private boolean mNullAccessToken = false;
private String mAccessToken;
private String mAccountName;
+ private LinearLayoutManager mLinearLayoutManager;
private SubredditMultiselectionRecyclerViewAdapter mAdapter;
private RequestManager mGlide;
@Override
@@ -149,7 +151,8 @@ public class SubredditMultiselectionActivity extends BaseActivity {
}
private void bindView() {
- mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ mLinearLayoutManager = new LinearLayoutManager(this);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
mAdapter = new SubredditMultiselectionRecyclerViewAdapter(this, mCustomThemeWrapper);
mRecyclerView.setAdapter(mAdapter);
@@ -240,4 +243,11 @@ public class SubredditMultiselectionActivity extends BaseActivity {
applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar);
mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
}
+
+ @Override
+ public void onLongPress() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
index efc50700..f48cb952 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubredditSelectionActivity.java
@@ -28,6 +28,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@@ -42,7 +43,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import retrofit2.Retrofit;
-public class SubredditSelectionActivity extends BaseActivity {
+public class SubredditSelectionActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_EXTRA_CLEAR_SELECTION = "EECS";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
@@ -274,4 +275,11 @@ public class SubredditSelectionActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish();
}
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((SubscribedSubredditsListingFragment) mFragment).goBackToTop();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
index 48568085..1cb7303e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubscribedThingListingActivity.java
@@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@@ -46,7 +47,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import retrofit2.Retrofit;
-public class SubscribedThingListingActivity extends BaseActivity {
+public class SubscribedThingListingActivity extends BaseActivity implements ActivityToolbarInterface {
private static final String INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
@@ -108,6 +109,7 @@ public class SubscribedThingListingActivity extends BaseActivity {
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
if (savedInstanceState != null) {
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
@@ -225,6 +227,13 @@ public class SubscribedThingListingActivity extends BaseActivity {
finish();
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment;
@@ -287,7 +296,7 @@ public class SubscribedThingListingActivity extends BaseActivity {
return fragment;
}
- public void stopRefreshProgressbar() {
+ void stopRefreshProgressbar() {
if (subscribedSubredditsListingFragment != null) {
((FragmentCommunicator) subscribedSubredditsListingFragment).stopRefreshProgressbar();
}
@@ -295,5 +304,13 @@ public class SubscribedThingListingActivity extends BaseActivity {
((FragmentCommunicator) followedUsersListingFragment).stopRefreshProgressbar();
}
}
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ subscribedSubredditsListingFragment.goBackToTop();
+ } else {
+ followedUsersListingFragment.goBackToTop();
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
index e8fe5334..a71cf47b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMessageActivity.java
@@ -35,6 +35,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
@@ -48,7 +49,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import retrofit2.Retrofit;
-public class ViewMessageActivity extends BaseActivity {
+public class ViewMessageActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
@@ -90,6 +91,7 @@ public class ViewMessageActivity extends BaseActivity {
private String mNewAccountName;
private MessageRecyclerViewAdapter mAdapter;
private RequestManager mGlide;
+ private LinearLayoutManager mLinearLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -127,6 +129,7 @@ public class ViewMessageActivity extends BaseActivity {
mToolbar.setTitle(R.string.inbox);
setSupportActionBar(mToolbar);
+ setToolbarGoToTop(mToolbar);
if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@@ -199,10 +202,10 @@ public class ViewMessageActivity extends BaseActivity {
private void bindView() {
mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mCustomThemeWrapper,
mAccessToken, () -> mMessageViewModel.retryLoadingMore());
- LinearLayoutManager layoutManager = new LinearLayoutManager(this);
- mRecyclerView.setLayoutManager(layoutManager);
+ mLinearLayoutManager = new LinearLayoutManager(this);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(mAdapter);
- DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, layoutManager.getOrientation());
+ DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, mLinearLayoutManager.getOrientation());
mRecyclerView.addItemDecoration(dividerItemDecoration);
MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit,
@@ -296,4 +299,11 @@ public class ViewMessageActivity extends BaseActivity {
private void onRefresh() {
mMessageViewModel.refresh();
}
+
+ @Override
+ public void onLongPress() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
index f1ee3a02..52162d5a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewMultiRedditDetailActivity.java
@@ -26,6 +26,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
@@ -46,7 +47,7 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit;
public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_MULTIREDDIT_DATA = "EMD";
public static final String EXTRA_MULTIREDDIT_PATH = "EMP";
@@ -136,6 +137,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@@ -337,4 +339,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
}
+
+ @Override
+ public void onLongPress() {
+ if (mFragment != null) {
+ ((PostFragment) mFragment).goBackToTop();
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
index e258124b..d18aba55 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewPostDetailActivity.java
@@ -55,6 +55,7 @@ import butterknife.ButterKnife;
import im.ene.toro.exoplayer.ExoCreator;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
@@ -98,7 +99,7 @@ import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.RETU
import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
- SortTypeSelectionCallback {
+ SortTypeSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_POST_DATA = "EPD";
public static final String EXTRA_POST_LIST_POSITION = "EPLI";
@@ -242,6 +243,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mToolbar.setTitle("");
setSupportActionBar(mToolbar);
+ setToolbarGoToTop(mToolbar);
mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false);
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, false);
@@ -1629,4 +1631,11 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mSlidrInterface.unlock();
}
}
+
+ @Override
+ public void onLongPress() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
index 5dfdad77..826ba33d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSidebarActivity.java
@@ -43,6 +43,7 @@ import io.noties.markwon.recycler.table.TableEntry;
import io.noties.markwon.recycler.table.TableEntryPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FetchSubredditData;
@@ -53,7 +54,7 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import retrofit2.Retrofit;
-public class ViewSidebarActivity extends BaseActivity {
+public class ViewSidebarActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
@BindView(R.id.coordinator_layout_view_sidebar_activity)
@@ -77,6 +78,7 @@ public class ViewSidebarActivity extends BaseActivity {
@Inject
CustomThemeWrapper mCustomThemeWrapper;
public SubredditViewModel mSubredditViewModel;
+ private LinearLayoutManager mLinearLayoutManager;
private String subredditName;
private int markdownColor;
@@ -123,6 +125,7 @@ public class ViewSidebarActivity extends BaseActivity {
toolbar.setTitle("r/" + subredditName);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
+ setToolbarGoToTop(toolbar);
Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() {
@@ -161,7 +164,8 @@ public class ViewSidebarActivity extends BaseActivity {
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
- markdownRecyclerView.setLayoutManager(new LinearLayoutManager(this));
+ mLinearLayoutManager = new LinearLayoutManager(this);
+ markdownRecyclerView.setLayoutManager(mLinearLayoutManager);
markdownRecyclerView.setAdapter(markwonAdapter);
mSubredditViewModel = new ViewModelProvider(this,
@@ -237,4 +241,11 @@ public class ViewSidebarActivity extends BaseActivity {
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
markdownColor = mCustomThemeWrapper.getSecondaryTextColor();
}
+
+ @Override
+ public void onLongPress() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
index f22b6361..c0d3357a 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewSubredditDetailActivity.java
@@ -50,6 +50,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredditAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
@@ -81,7 +82,8 @@ import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostTypeBottomSheetFragment.PostTypeSelectionCallback, PostLayoutBottomSheetFragment.PostLayoutSelectionCallback,
+ ActivityToolbarInterface {
public static final String EXTRA_SUBREDDIT_NAME_KEY = "ESN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@@ -327,6 +329,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
toolbar.setTitle(title);
adjustToolbar(toolbar);
setSupportActionBar(toolbar);
+ setToolbarGoToTop(toolbar);
glide = Glide.with(this);
Locale locale = getResources().getConfiguration().locale;
@@ -843,6 +846,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment;
private SidebarFragment sidebarFragment;
@@ -965,5 +975,17 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ if (postFragment != null) {
+ postFragment.goBackToTop();
+ }
+ } else {
+ if (sidebarFragment != null) {
+ sidebarFragment.goBackToTop();
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
index c6bda8bd..8cd8202e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewUserDetailActivity.java
@@ -49,6 +49,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
+import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsFollowingUserAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
@@ -81,7 +82,7 @@ import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback,
- PostLayoutBottomSheetFragment.PostLayoutSelectionCallback {
+ PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_USER_NAME_KEY = "EUNK";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@@ -220,6 +221,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
toolbar.setTitle(title);
setSupportActionBar(toolbar);
+ setToolbarGoToTop(toolbar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow();
@@ -711,6 +713,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
}
+ @Override
+ public void onLongPress() {
+ if (sectionsPagerAdapter != null) {
+ sectionsPagerAdapter.goBackToTop();
+ }
+ }
+
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
private UserDao userDao;
@@ -876,5 +885,17 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
((FragmentCommunicator) postFragment).changePostLayout(postLayout);
}
}
+
+ void goBackToTop() {
+ if (viewPager.getCurrentItem() == 0) {
+ if (postFragment != null) {
+ postFragment.goBackToTop();
+ }
+ } else {
+ if (commentsListingFragment != null) {
+ commentsListingFragment.goBackToTop();
+ }
+ }
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java
new file mode 100644
index 00000000..42a9870b
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ActivityToolbarInterface.java
@@ -0,0 +1,5 @@
+package ml.docilealligator.infinityforreddit;
+
+public interface ActivityToolbarInterface {
+ void onLongPress();
+}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
index caf3a5cf..4abc1701 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/CommentsListingFragment.java
@@ -95,6 +95,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private String mAccessToken;
private RequestManager mGlide;
private Activity mActivity;
+ private LinearLayoutManager mLinearLayoutManager;
private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime;
private boolean mShowCommentDivider;
@@ -162,7 +163,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
}
private void bindView(Resources resources) {
- mCommentRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mCommentRecyclerView.setLayoutManager(mLinearLayoutManager);
boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper,
@@ -265,4 +267,10 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
mGlide.load(R.drawable.error_image).into(mFetchCommentInfoImageView);
}
}
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java
index f34dee6c..98b49d2e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/FollowedUsersListingFragment.java
@@ -74,6 +74,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
SubscribedUserViewModel mSubscribedUserViewModel;
private Activity mActivity;
private RequestManager mGlide;
+ private LinearLayoutManager mLinearLayoutManager;
public FollowedUsersListingFragment() {
// Required empty public constructor
@@ -104,7 +105,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
mGlide = Glide.with(this);
- mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity,
mOauthRetrofit, mRedditDataRoomDatabase, customThemeWrapper,
getArguments().getString(EXTRA_ACCESS_TOKEN));
@@ -164,4 +166,10 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
}
mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
}
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
index d9c0368b..29b4ffa2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/PostFragment.java
@@ -923,6 +923,20 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
}
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ if (isInLazyMode) {
+ lazyModeRunnable.resetOldPosition();
+ }
+ } else if (mStaggeredGridLayoutManager != null) {
+ mStaggeredGridLayoutManager.scrollToPositionWithOffset(0, 0);
+ if (isInLazyMode) {
+ lazyModeRunnable.resetOldPosition();
+ }
+ }
+ }
+
@Override
public void onPause() {
super.onPause();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
index 2d819696..dbafed2d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SidebarFragment.java
@@ -63,6 +63,7 @@ public class SidebarFragment extends Fragment {
private Activity activity;
private String subredditName;
public SubredditViewModel mSubredditViewModel;
+ private LinearLayoutManager linearLayoutManager;
private int markdownColor;
@Inject
@Named("no_oauth")
@@ -133,7 +134,8 @@ public class SidebarFragment extends Fragment {
.textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build();
- recyclerView.setLayoutManager(new LinearLayoutManager(activity));
+ linearLayoutManager = new LinearLayoutManager(activity);
+ recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(markwonAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
@@ -188,4 +190,10 @@ public class SidebarFragment extends Fragment {
}
});
}
+
+ public void goBackToTop() {
+ if (linearLayoutManager != null) {
+ linearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
index 2625d1bb..afb3013f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubredditListingFragment.java
@@ -221,4 +221,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
mFetchSubredditListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
}
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java
index 7ee62bdf..8e14ce96 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/SubscribedSubredditsListingFragment.java
@@ -78,6 +78,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private Activity mActivity;
private RequestManager mGlide;
+ private LinearLayoutManager mLinearLayoutManager;
public SubscribedSubredditsListingFragment() {
// Required empty public constructor
@@ -110,7 +111,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mGlide = Glide.with(this);
- mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
+ mLinearLayoutManager = new LinearLayoutManager(mActivity);
+ mRecyclerView.setLayoutManager(mLinearLayoutManager);
SubscribedSubredditsRecyclerViewAdapter adapter;
if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
@@ -180,4 +182,10 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mSwipeRefreshLayout.setEnabled(false);
}
}
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
index 0cf3ea71..21c2c154 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Fragment/UserListingFragment.java
@@ -201,4 +201,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
mFetchUserListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
}
+
+ public void goBackToTop() {
+ if (mLinearLayoutManager != null) {
+ mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
+ }
+ }
}