Long press the toolbar to go to top.

This commit is contained in:
Alex Ning 2020-06-05 14:19:38 +08:00
parent a9d2108c00
commit 8311507acd
25 changed files with 316 additions and 28 deletions

View File

@ -25,6 +25,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@ -40,7 +41,8 @@ import ml.docilealligator.infinityforreddit.SortType;
import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback; import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; 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"; static final String EXTRA_USER_WHERE = "EUW";
@ -118,6 +120,7 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@ -288,4 +291,11 @@ public class AccountPostsActivity extends BaseActivity implements SortTypeSelect
((FragmentCommunicator) mFragment).changePostLayout(postLayout); ((FragmentCommunicator) mFragment).changePostLayout(postLayout);
} }
} }
@Override
public void onLongPress() {
if (mFragment != null) {
((PostFragment) mFragment).goBackToTop();
}
}
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@ -43,7 +44,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import retrofit2.Retrofit; 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 NULL_ACCESS_TOKEN_STATE = "NATS";
private static final String ACCESS_TOKEN_STATE = "ATS"; private static final String ACCESS_TOKEN_STATE = "ATS";
@ -109,6 +110,7 @@ public class AccountSavedThingActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@ -275,6 +277,13 @@ public class AccountSavedThingActivity extends BaseActivity {
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment; private PostFragment postFragment;
private CommentsListingFragment commentsListingFragment; private CommentsListingFragment commentsListingFragment;
@ -383,5 +392,13 @@ public class AccountSavedThingActivity extends BaseActivity {
postFragment.changeNSFW(nsfw); postFragment.changeNSFW(nsfw);
} }
} }
public void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
postFragment.goBackToTop();
} else {
commentsListingFragment.goBackToTop();
}
}
} }
} }

View File

@ -25,6 +25,7 @@ import com.google.android.material.appbar.AppBarLayout;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout; import com.google.android.material.tabs.TabLayout;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.ContentFontStyle; import ml.docilealligator.infinityforreddit.ContentFontStyle;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@ -183,6 +184,18 @@ public abstract class BaseActivity extends AppCompatActivity {
return immersiveInterface; 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) { protected void adjustToolbar(Toolbar toolbar) {
int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); int statusBarResourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (statusBarResourceId > 0) { if (statusBarResourceId > 0) {

View File

@ -25,6 +25,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@ -45,7 +46,7 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback, public class FilteredThingActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
public static final String EXTRA_NAME = "ESN"; public static final String EXTRA_NAME = "ESN";
public static final String EXTRA_QUERY = "EQ"; public static final String EXTRA_QUERY = "EQ";
@ -123,6 +124,7 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams(); params = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
@ -429,4 +431,11 @@ public class FilteredThingActivity extends BaseActivity implements SortTypeSelec
public void onAccountSwitchEvent(SwitchAccountEvent event) { public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish(); finish();
} }
@Override
public void onLongPress() {
if (mFragment != null) {
((PostFragment) mFragment).goBackToTop();
}
}
} }

View File

@ -58,6 +58,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.Account.AccountViewModel; import ml.docilealligator.infinityforreddit.Account.AccountViewModel;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.NavigationDrawerRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; 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; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
public class MainActivity extends BaseActivity implements SortTypeSelectionCallback, 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_POST_TYPE = "EPT";
static final String EXTRA_MESSSAGE_FULLNAME = "ENF"; static final String EXTRA_MESSSAGE_FULLNAME = "ENF";
@ -247,6 +249,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment(); postLayoutBottomSheetFragment = new PostLayoutBottomSheetFragment();
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
drawer = findViewById(R.id.drawer_layout); drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
@ -921,6 +924,13 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mLockBottomAppBar = changeLockBottomAppBarEvent.lockBottomAppBar; mLockBottomAppBar = changeLockBottomAppBarEvent.lockBottomAppBar;
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment tab1; private PostFragment tab1;
private PostFragment tab2; 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();
}
}
} }
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent; import ml.docilealligator.infinityforreddit.Event.ChangeNSFWEvent;
@ -51,7 +52,7 @@ import ml.docilealligator.infinityforreddit.SortTypeSelectionCallback;
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback, public class SearchResultActivity extends BaseActivity implements SortTypeSelectionCallback,
PostLayoutBottomSheetFragment.PostLayoutSelectionCallback { PostLayoutBottomSheetFragment.PostLayoutSelectionCallback, ActivityToolbarInterface {
static final String EXTRA_QUERY = "QK"; static final String EXTRA_QUERY = "QK";
static final String EXTRA_SUBREDDIT_NAME = "ESN"; static final String EXTRA_SUBREDDIT_NAME = "ESN";
@ -121,6 +122,7 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
if (savedInstanceState == null) { if (savedInstanceState == null) {
getCurrentAccountAndInitializeViewPager(); getCurrentAccountAndInitializeViewPager();
@ -295,6 +297,13 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment; 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) { if (postFragment != null) {
postFragment.changeNSFW(nsfw); postFragment.changeNSFW(nsfw);
} }
@ -429,5 +438,15 @@ public class SearchResultActivity extends BaseActivity implements SortTypeSelect
((FragmentCommunicator) postFragment).changePostLayout(postLayout); ((FragmentCommunicator) postFragment).changePostLayout(postLayout);
} }
} }
void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
postFragment.goBackToTop();
} else if (viewPager.getCurrentItem() == 1) {
subredditListingFragment.goBackToTop();
} else {
userListingFragment.goBackToTop();
}
}
} }
} }

View File

@ -24,6 +24,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent; import ml.docilealligator.infinityforreddit.Event.SwitchAccountEvent;
@ -32,7 +33,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; 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_QUERY = "EQ";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
@ -90,6 +91,7 @@ public class SearchSubredditsResultActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
String query = getIntent().getExtras().getString(EXTRA_QUERY); String query = getIntent().getExtras().getString(EXTRA_QUERY);
@ -180,4 +182,11 @@ public class SearchSubredditsResultActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) { public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish(); finish();
} }
@Override
public void onLongPress() {
if (mFragment != null) {
((SubredditListingFragment) mFragment).goBackToTop();
}
}
} }

View File

@ -24,12 +24,13 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.SelectedSubredditsRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.SelectedSubredditsRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.R; 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_SELECTED_SUBREDDITS = "ESS";
public static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS"; public static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
@ -51,6 +52,7 @@ public class SelectedSubredditsActivity extends BaseActivity {
SharedPreferences mSharedPreferences; SharedPreferences mSharedPreferences;
@Inject @Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
private LinearLayoutManager linearLayoutManager;
private SelectedSubredditsRecyclerViewAdapter adapter; private SelectedSubredditsRecyclerViewAdapter adapter;
private ArrayList<String> subreddits; private ArrayList<String> subreddits;
@ -65,6 +67,7 @@ public class SelectedSubredditsActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
if (savedInstanceState != null) { if (savedInstanceState != null) {
subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE); subreddits = savedInstanceState.getStringArrayList(SELECTED_SUBREDDITS_STATE);
@ -73,7 +76,8 @@ public class SelectedSubredditsActivity extends BaseActivity {
} }
adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits); adapter = new SelectedSubredditsRecyclerViewAdapter(mCustomThemeWrapper, subreddits);
recyclerView.setLayoutManager(new LinearLayoutManager(this)); linearLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -154,4 +158,11 @@ public class SelectedSubredditsActivity extends BaseActivity {
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
applyFABTheme(fab); applyFABTheme(fab);
} }
@Override
public void onLongPress() {
if (linearLayoutManager != null) {
linearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -34,6 +34,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.SubredditMultiselectionRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.SubredditMultiselectionRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@ -43,7 +44,7 @@ import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel; import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.SubscribedSubredditViewModel;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class SubredditMultiselectionActivity extends BaseActivity { public class SubredditMultiselectionActivity extends BaseActivity implements ActivityToolbarInterface {
static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS"; static final String EXTRA_RETURN_SELECTED_SUBREDDITS = "ERSS";
@ -82,6 +83,7 @@ public class SubredditMultiselectionActivity extends BaseActivity {
private boolean mNullAccessToken = false; private boolean mNullAccessToken = false;
private String mAccessToken; private String mAccessToken;
private String mAccountName; private String mAccountName;
private LinearLayoutManager mLinearLayoutManager;
private SubredditMultiselectionRecyclerViewAdapter mAdapter; private SubredditMultiselectionRecyclerViewAdapter mAdapter;
private RequestManager mGlide; private RequestManager mGlide;
@Override @Override
@ -149,7 +151,8 @@ public class SubredditMultiselectionActivity extends BaseActivity {
} }
private void bindView() { private void bindView() {
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mLinearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
mAdapter = new SubredditMultiselectionRecyclerViewAdapter(this, mCustomThemeWrapper); mAdapter = new SubredditMultiselectionRecyclerViewAdapter(this, mCustomThemeWrapper);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
@ -240,4 +243,11 @@ public class SubredditMultiselectionActivity extends BaseActivity {
applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar); applyAppBarLayoutAndToolbarTheme(mAppBarLayout, mToolbar);
mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor()); mErrorTextView.setTextColor(mCustomThemeWrapper.getSecondaryTextColor());
} }
@Override
public void onLongPress() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -28,6 +28,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@ -42,7 +43,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import retrofit2.Retrofit; 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_EXTRA_CLEAR_SELECTION = "EECS";
static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN"; static final String EXTRA_RETURN_SUBREDDIT_NAME = "ERSN";
@ -274,4 +275,11 @@ public class SubredditSelectionActivity extends BaseActivity {
public void onAccountSwitchEvent(SwitchAccountEvent event) { public void onAccountSwitchEvent(SwitchAccountEvent event) {
finish(); finish();
} }
@Override
public void onLongPress() {
if (mFragment != null) {
((SubscribedSubredditsListingFragment) mFragment).goBackToTop();
}
}
} }

View File

@ -30,6 +30,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubscribedThingsAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
@ -46,7 +47,7 @@ import ml.docilealligator.infinityforreddit.SubscribedSubredditDatabase.Subscrib
import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData; import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUserData;
import retrofit2.Retrofit; 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 INSERT_SUBSCRIBED_SUBREDDIT_STATE = "ISSS";
private static final String NULL_ACCESS_TOKEN_STATE = "NATS"; private static final String NULL_ACCESS_TOKEN_STATE = "NATS";
@ -108,6 +109,7 @@ public class SubscribedThingListingActivity extends BaseActivity {
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE); mInsertSuccess = savedInstanceState.getBoolean(INSERT_SUBSCRIBED_SUBREDDIT_STATE);
@ -225,6 +227,13 @@ public class SubscribedThingListingActivity extends BaseActivity {
finish(); finish();
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment; private SubscribedSubredditsListingFragment subscribedSubredditsListingFragment;
@ -287,7 +296,7 @@ public class SubscribedThingListingActivity extends BaseActivity {
return fragment; return fragment;
} }
public void stopRefreshProgressbar() { void stopRefreshProgressbar() {
if (subscribedSubredditsListingFragment != null) { if (subscribedSubredditsListingFragment != null) {
((FragmentCommunicator) subscribedSubredditsListingFragment).stopRefreshProgressbar(); ((FragmentCommunicator) subscribedSubredditsListingFragment).stopRefreshProgressbar();
} }
@ -295,5 +304,13 @@ public class SubscribedThingListingActivity extends BaseActivity {
((FragmentCommunicator) followedUsersListingFragment).stopRefreshProgressbar(); ((FragmentCommunicator) followedUsersListingFragment).stopRefreshProgressbar();
} }
} }
void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
subscribedSubredditsListingFragment.goBackToTop();
} else {
followedUsersListingFragment.goBackToTop();
}
}
} }
} }

View File

@ -35,6 +35,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.MessageRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask;
@ -48,7 +49,7 @@ import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase; import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewMessageActivity extends BaseActivity { public class ViewMessageActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN"; public static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
@ -90,6 +91,7 @@ public class ViewMessageActivity extends BaseActivity {
private String mNewAccountName; private String mNewAccountName;
private MessageRecyclerViewAdapter mAdapter; private MessageRecyclerViewAdapter mAdapter;
private RequestManager mGlide; private RequestManager mGlide;
private LinearLayoutManager mLinearLayoutManager;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -127,6 +129,7 @@ public class ViewMessageActivity extends BaseActivity {
mToolbar.setTitle(R.string.inbox); mToolbar.setTitle(R.string.inbox);
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
setToolbarGoToTop(mToolbar);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@ -199,10 +202,10 @@ public class ViewMessageActivity extends BaseActivity {
private void bindView() { private void bindView() {
mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mCustomThemeWrapper, mAdapter = new MessageRecyclerViewAdapter(this, mOauthRetrofit, mCustomThemeWrapper,
mAccessToken, () -> mMessageViewModel.retryLoadingMore()); mAccessToken, () -> mMessageViewModel.retryLoadingMore());
LinearLayoutManager layoutManager = new LinearLayoutManager(this); mLinearLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(layoutManager); mRecyclerView.setLayoutManager(mLinearLayoutManager);
mRecyclerView.setAdapter(mAdapter); mRecyclerView.setAdapter(mAdapter);
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, layoutManager.getOrientation()); DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(this, mLinearLayoutManager.getOrientation());
mRecyclerView.addItemDecoration(dividerItemDecoration); mRecyclerView.addItemDecoration(dividerItemDecoration);
MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit, MessageViewModel.Factory factory = new MessageViewModel.Factory(mOauthRetrofit,
@ -296,4 +299,11 @@ public class ViewMessageActivity extends BaseActivity {
private void onRefresh() { private void onRefresh() {
mMessageViewModel.refresh(); mMessageViewModel.refresh();
} }
@Override
public void onLongPress() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -26,6 +26,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent; import ml.docilealligator.infinityforreddit.Event.RefreshMultiRedditsEvent;
@ -46,7 +47,7 @@ import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewMultiRedditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, 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_DATA = "EMD";
public static final String EXTRA_MULTIREDDIT_PATH = "EMP"; public static final String EXTRA_MULTIREDDIT_PATH = "EMP";
@ -136,6 +137,7 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
if (savedInstanceState != null) { if (savedInstanceState != null) {
mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE); mNullAccessToken = savedInstanceState.getBoolean(NULL_ACCESS_TOKEN_STATE);
@ -337,4 +339,11 @@ public class ViewMultiRedditDetailActivity extends BaseActivity implements SortT
coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor()); coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar);
} }
@Override
public void onLongPress() {
if (mFragment != null) {
((PostFragment) mFragment).goBackToTop();
}
}
} }

View File

@ -55,6 +55,7 @@ import butterknife.ButterKnife;
import im.ene.toro.exoplayer.ExoCreator; import im.ene.toro.exoplayer.ExoCreator;
import im.ene.toro.media.PlaybackInfo; import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo; import im.ene.toro.media.VolumeInfo;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.Adapter.CommentAndPostRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.SwitchAccountAsyncTask; 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; import static ml.docilealligator.infinityforreddit.Activity.CommentActivity.WRITE_COMMENT_REQUEST_CODE;
public class ViewPostDetailActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback, 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_DATA = "EPD";
public static final String EXTRA_POST_LIST_POSITION = "EPLI"; public static final String EXTRA_POST_LIST_POSITION = "EPLI";
@ -242,6 +243,7 @@ public class ViewPostDetailActivity extends BaseActivity implements FlairBottomS
mToolbar.setTitle(""); mToolbar.setTitle("");
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
setToolbarGoToTop(mToolbar);
mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false); mVolumeKeysNavigateComments = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOLUME_KEYS_NAVIGATE_COMMENTS, false);
mLockFab = mSharedPreferences.getBoolean(SharedPreferencesUtils.LOCK_JUMP_TO_NEXT_TOP_LEVEL_COMMENT_BUTTON, 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(); mSlidrInterface.unlock();
} }
} }
@Override
public void onLongPress() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -43,6 +43,7 @@ import io.noties.markwon.recycler.table.TableEntry;
import io.noties.markwon.recycler.table.TableEntryPlugin; import io.noties.markwon.recycler.table.TableEntryPlugin;
import io.noties.markwon.simple.ext.SimpleExtPlugin; import io.noties.markwon.simple.ext.SimpleExtPlugin;
import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute; import io.noties.markwon.urlprocessor.UrlProcessorRelativeToAbsolute;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.InsertSubredditDataAsyncTask;
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.FetchSubredditData; import ml.docilealligator.infinityforreddit.FetchSubredditData;
@ -53,7 +54,7 @@ import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditData;
import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel; import ml.docilealligator.infinityforreddit.SubredditDatabase.SubredditViewModel;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewSidebarActivity extends BaseActivity { public class ViewSidebarActivity extends BaseActivity implements ActivityToolbarInterface {
public static final String EXTRA_SUBREDDIT_NAME = "ESN"; public static final String EXTRA_SUBREDDIT_NAME = "ESN";
@BindView(R.id.coordinator_layout_view_sidebar_activity) @BindView(R.id.coordinator_layout_view_sidebar_activity)
@ -77,6 +78,7 @@ public class ViewSidebarActivity extends BaseActivity {
@Inject @Inject
CustomThemeWrapper mCustomThemeWrapper; CustomThemeWrapper mCustomThemeWrapper;
public SubredditViewModel mSubredditViewModel; public SubredditViewModel mSubredditViewModel;
private LinearLayoutManager mLinearLayoutManager;
private String subredditName; private String subredditName;
private int markdownColor; private int markdownColor;
@ -123,6 +125,7 @@ public class ViewSidebarActivity extends BaseActivity {
toolbar.setTitle("r/" + subredditName); toolbar.setTitle("r/" + subredditName);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setToolbarGoToTop(toolbar);
Markwon markwon = Markwon.builder(this) Markwon markwon = Markwon.builder(this)
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(new AbstractMarkwonPlugin() {
@ -161,7 +164,8 @@ public class ViewSidebarActivity extends BaseActivity {
.textLayoutIsRoot(R.layout.view_table_entry_cell))) .textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build(); .build();
markdownRecyclerView.setLayoutManager(new LinearLayoutManager(this)); mLinearLayoutManager = new LinearLayoutManager(this);
markdownRecyclerView.setLayoutManager(mLinearLayoutManager);
markdownRecyclerView.setAdapter(markwonAdapter); markdownRecyclerView.setAdapter(markwonAdapter);
mSubredditViewModel = new ViewModelProvider(this, mSubredditViewModel = new ViewModelProvider(this,
@ -237,4 +241,11 @@ public class ViewSidebarActivity extends BaseActivity {
swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent()); swipeRefreshLayout.setColorSchemeColors(mCustomThemeWrapper.getColorAccent());
markdownColor = mCustomThemeWrapper.getSecondaryTextColor(); markdownColor = mCustomThemeWrapper.getSecondaryTextColor();
} }
@Override
public void onLongPress() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -50,6 +50,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredditAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsSubscribedToSubredditAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
@ -81,7 +82,8 @@ import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewSubredditDetailActivity extends BaseActivity implements SortTypeSelectionCallback, 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_SUBREDDIT_NAME_KEY = "ESN";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@ -327,6 +329,7 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
toolbar.setTitle(title); toolbar.setTitle(title);
adjustToolbar(toolbar); adjustToolbar(toolbar);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
glide = Glide.with(this); glide = Glide.with(this);
Locale locale = getResources().getConfiguration().locale; Locale locale = getResources().getConfiguration().locale;
@ -843,6 +846,13 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private class SectionsPagerAdapter extends FragmentPagerAdapter { private class SectionsPagerAdapter extends FragmentPagerAdapter {
private PostFragment postFragment; private PostFragment postFragment;
private SidebarFragment sidebarFragment; private SidebarFragment sidebarFragment;
@ -965,5 +975,17 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp
((FragmentCommunicator) postFragment).changePostLayout(postLayout); ((FragmentCommunicator) postFragment).changePostLayout(postLayout);
} }
} }
void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
postFragment.goBackToTop();
}
} else {
if (sidebarFragment != null) {
sidebarFragment.goBackToTop();
}
}
}
} }
} }

View File

@ -49,6 +49,7 @@ import javax.inject.Named;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.ActivityToolbarInterface;
import ml.docilealligator.infinityforreddit.AppBarStateChangeListener; import ml.docilealligator.infinityforreddit.AppBarStateChangeListener;
import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsFollowingUserAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.CheckIsFollowingUserAsyncTask;
import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask; import ml.docilealligator.infinityforreddit.AsyncTask.GetCurrentAccountAsyncTask;
@ -81,7 +82,7 @@ import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit; import retrofit2.Retrofit;
public class ViewUserDetailActivity extends BaseActivity implements SortTypeSelectionCallback, 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_USER_NAME_KEY = "EUNK";
public static final String EXTRA_MESSAGE_FULLNAME = "ENF"; public static final String EXTRA_MESSAGE_FULLNAME = "ENF";
@ -220,6 +221,7 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
toolbar.setTitle(title); toolbar.setTitle(title);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setToolbarGoToTop(toolbar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Window window = getWindow(); Window window = getWindow();
@ -711,6 +713,13 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw); sectionsPagerAdapter.changeNSFW(changeNSFWEvent.nsfw);
} }
@Override
public void onLongPress() {
if (sectionsPagerAdapter != null) {
sectionsPagerAdapter.goBackToTop();
}
}
private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> { private static class InsertUserDataAsyncTask extends AsyncTask<Void, Void, Void> {
private UserDao userDao; private UserDao userDao;
@ -876,5 +885,17 @@ public class ViewUserDetailActivity extends BaseActivity implements SortTypeSele
((FragmentCommunicator) postFragment).changePostLayout(postLayout); ((FragmentCommunicator) postFragment).changePostLayout(postLayout);
} }
} }
void goBackToTop() {
if (viewPager.getCurrentItem() == 0) {
if (postFragment != null) {
postFragment.goBackToTop();
}
} else {
if (commentsListingFragment != null) {
commentsListingFragment.goBackToTop();
}
}
}
} }
} }

View File

@ -0,0 +1,5 @@
package ml.docilealligator.infinityforreddit;
public interface ActivityToolbarInterface {
void onLongPress();
}

View File

@ -95,6 +95,7 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
private String mAccessToken; private String mAccessToken;
private RequestManager mGlide; private RequestManager mGlide;
private Activity mActivity; private Activity mActivity;
private LinearLayoutManager mLinearLayoutManager;
private CommentsListingRecyclerViewAdapter mAdapter; private CommentsListingRecyclerViewAdapter mAdapter;
private boolean mShowElapsedTime; private boolean mShowElapsedTime;
private boolean mShowCommentDivider; private boolean mShowCommentDivider;
@ -162,7 +163,8 @@ public class CommentsListingFragment extends Fragment implements FragmentCommuni
} }
private void bindView(Resources resources) { 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); boolean voteButtonsOnTheRight = mSharedPreferences.getBoolean(SharedPreferencesUtils.VOTE_BUTTONS_ON_THE_RIGHT_KEY, false);
mAdapter = new CommentsListingRecyclerViewAdapter(mActivity, mOauthRetrofit, customThemeWrapper, 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); mGlide.load(R.drawable.error_image).into(mFetchCommentInfoImageView);
} }
} }
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -74,6 +74,7 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
SubscribedUserViewModel mSubscribedUserViewModel; SubscribedUserViewModel mSubscribedUserViewModel;
private Activity mActivity; private Activity mActivity;
private RequestManager mGlide; private RequestManager mGlide;
private LinearLayoutManager mLinearLayoutManager;
public FollowedUsersListingFragment() { public FollowedUsersListingFragment() {
// Required empty public constructor // Required empty public constructor
@ -104,7 +105,8 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
mGlide = Glide.with(this); mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); mLinearLayoutManager = new LinearLayoutManager(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity, FollowedUsersRecyclerViewAdapter adapter = new FollowedUsersRecyclerViewAdapter(mActivity,
mOauthRetrofit, mRedditDataRoomDatabase, customThemeWrapper, mOauthRetrofit, mRedditDataRoomDatabase, customThemeWrapper,
getArguments().getString(EXTRA_ACCESS_TOKEN)); getArguments().getString(EXTRA_ACCESS_TOKEN));
@ -164,4 +166,10 @@ public class FollowedUsersListingFragment extends Fragment implements FragmentCo
} }
mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); mErrorTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
} }
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -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 @Override
public void onPause() { public void onPause() {
super.onPause(); super.onPause();

View File

@ -63,6 +63,7 @@ public class SidebarFragment extends Fragment {
private Activity activity; private Activity activity;
private String subredditName; private String subredditName;
public SubredditViewModel mSubredditViewModel; public SubredditViewModel mSubredditViewModel;
private LinearLayoutManager linearLayoutManager;
private int markdownColor; private int markdownColor;
@Inject @Inject
@Named("no_oauth") @Named("no_oauth")
@ -133,7 +134,8 @@ public class SidebarFragment extends Fragment {
.textLayoutIsRoot(R.layout.view_table_entry_cell))) .textLayoutIsRoot(R.layout.view_table_entry_cell)))
.build(); .build();
recyclerView.setLayoutManager(new LinearLayoutManager(activity)); linearLayoutManager = new LinearLayoutManager(activity);
recyclerView.setLayoutManager(linearLayoutManager);
recyclerView.setAdapter(markwonAdapter); recyclerView.setAdapter(markwonAdapter);
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -188,4 +190,10 @@ public class SidebarFragment extends Fragment {
} }
}); });
} }
public void goBackToTop() {
if (linearLayoutManager != null) {
linearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -221,4 +221,10 @@ public class SubredditListingFragment extends Fragment implements FragmentCommun
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
mFetchSubredditListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); mFetchSubredditListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
} }
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -78,6 +78,7 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
public SubscribedSubredditViewModel mSubscribedSubredditViewModel; public SubscribedSubredditViewModel mSubscribedSubredditViewModel;
private Activity mActivity; private Activity mActivity;
private RequestManager mGlide; private RequestManager mGlide;
private LinearLayoutManager mLinearLayoutManager;
public SubscribedSubredditsListingFragment() { public SubscribedSubredditsListingFragment() {
// Required empty public constructor // Required empty public constructor
@ -110,7 +111,8 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mGlide = Glide.with(this); mGlide = Glide.with(this);
mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity)); mLinearLayoutManager = new LinearLayoutManager(mActivity);
mRecyclerView.setLayoutManager(mLinearLayoutManager);
SubscribedSubredditsRecyclerViewAdapter adapter; SubscribedSubredditsRecyclerViewAdapter adapter;
if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) { if (getArguments().getBoolean(EXTRA_IS_SUBREDDIT_SELECTION)) {
@ -180,4 +182,10 @@ public class SubscribedSubredditsListingFragment extends Fragment implements Fra
mSwipeRefreshLayout.setEnabled(false); mSwipeRefreshLayout.setEnabled(false);
} }
} }
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }

View File

@ -201,4 +201,10 @@ public class UserListingFragment extends Fragment implements FragmentCommunicato
mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent()); mSwipeRefreshLayout.setColorSchemeColors(customThemeWrapper.getColorAccent());
mFetchUserListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor()); mFetchUserListingInfoTextView.setTextColor(customThemeWrapper.getSecondaryTextColor());
} }
public void goBackToTop() {
if (mLinearLayoutManager != null) {
mLinearLayoutManager.scrollToPositionWithOffset(0, 0);
}
}
} }