|
|
@ -57,6 +57,7 @@ public class TimelineFragment extends SFragment implements |
|
|
|
private TimelineAdapter adapter; |
|
|
|
private TimelineAdapter adapter; |
|
|
|
private Kind kind; |
|
|
|
private Kind kind; |
|
|
|
private String hashtagOrId; |
|
|
|
private String hashtagOrId; |
|
|
|
|
|
|
|
private RecyclerView recyclerView; |
|
|
|
private LinearLayoutManager layoutManager; |
|
|
|
private LinearLayoutManager layoutManager; |
|
|
|
private EndlessOnScrollListener scrollListener; |
|
|
|
private EndlessOnScrollListener scrollListener; |
|
|
|
private TabLayout.OnTabSelectedListener onTabSelectedListener; |
|
|
|
private TabLayout.OnTabSelectedListener onTabSelectedListener; |
|
|
@ -95,7 +96,7 @@ public class TimelineFragment extends SFragment implements |
|
|
|
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); |
|
|
|
swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); |
|
|
|
swipeRefreshLayout.setOnRefreshListener(this); |
|
|
|
swipeRefreshLayout.setOnRefreshListener(this); |
|
|
|
// Setup the RecyclerView.
|
|
|
|
// Setup the RecyclerView.
|
|
|
|
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); |
|
|
|
recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler_view); |
|
|
|
recyclerView.setHasFixedSize(true); |
|
|
|
recyclerView.setHasFixedSize(true); |
|
|
|
layoutManager = new LinearLayoutManager(context); |
|
|
|
layoutManager = new LinearLayoutManager(context); |
|
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
|
recyclerView.setLayoutManager(layoutManager); |
|
|
@ -105,23 +106,30 @@ public class TimelineFragment extends SFragment implements |
|
|
|
R.drawable.status_divider_dark); |
|
|
|
R.drawable.status_divider_dark); |
|
|
|
divider.setDrawable(drawable); |
|
|
|
divider.setDrawable(drawable); |
|
|
|
recyclerView.addItemDecoration(divider); |
|
|
|
recyclerView.addItemDecoration(divider); |
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) { |
|
|
|
adapter = new TimelineAdapter(this); |
|
|
|
|
|
|
|
recyclerView.setAdapter(adapter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jumpToTopAllowed()) { |
|
|
|
|
|
|
|
TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout); |
|
|
|
|
|
|
|
onTabSelectedListener = new TabLayout.OnTabSelectedListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onScrolled(RecyclerView view, int dx, int dy) { |
|
|
|
public void onTabSelected(TabLayout.Tab tab) {} |
|
|
|
super.onScrolled(view, dx, dy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); |
|
|
|
@Override |
|
|
|
|
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {} |
|
|
|
|
|
|
|
|
|
|
|
if (dy > 0 && prefs.getBoolean("fabHide", false) && MainActivity.composeBtn.isShown()) { |
|
|
|
@Override |
|
|
|
MainActivity.composeBtn.hide(); // hides the button if we're scrolling down
|
|
|
|
public void onTabReselected(TabLayout.Tab tab) { |
|
|
|
} else if (dy < 0 && prefs.getBoolean("fabHide", false) && !MainActivity.composeBtn.isShown()) { |
|
|
|
jumpToTop(); |
|
|
|
MainActivity.composeBtn.show(); // shows it if we are scrolling up
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
layout.addOnTabSelectedListener(onTabSelectedListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return rootView; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
private void onLoadMore(RecyclerView view) { |
|
|
|
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { |
|
|
|
|
|
|
|
TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); |
|
|
|
TimelineAdapter adapter = (TimelineAdapter) view.getAdapter(); |
|
|
|
Status status = adapter.getItem(adapter.getItemCount() - 2); |
|
|
|
Status status = adapter.getItem(adapter.getItemCount() - 2); |
|
|
|
if (status != null) { |
|
|
|
if (status != null) { |
|
|
@ -130,29 +138,49 @@ public class TimelineFragment extends SFragment implements |
|
|
|
sendFetchTimelineRequest(); |
|
|
|
sendFetchTimelineRequest(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(scrollListener); |
|
|
|
|
|
|
|
adapter = new TimelineAdapter(this); |
|
|
|
|
|
|
|
recyclerView.setAdapter(adapter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (jumpToTopAllowed()) { |
|
|
|
|
|
|
|
TabLayout layout = (TabLayout) getActivity().findViewById(R.id.tab_layout); |
|
|
|
|
|
|
|
onTabSelectedListener = new TabLayout.OnTabSelectedListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onTabSelected(TabLayout.Tab tab) {} |
|
|
|
public void onActivityCreated(@Nullable Bundle savedInstanceState) { |
|
|
|
|
|
|
|
super.onActivityCreated(savedInstanceState); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* This is delayed until onActivityCreated solely because MainActivity.composeButton isn't |
|
|
|
|
|
|
|
* guaranteed to be set until then. */ |
|
|
|
|
|
|
|
if (followButtonPresent()) { |
|
|
|
|
|
|
|
/* Use a modified scroll listener that both loads more statuses as it goes, and hides |
|
|
|
|
|
|
|
* the follow button on down-scroll. */ |
|
|
|
|
|
|
|
MainActivity activity = (MainActivity) getActivity(); |
|
|
|
|
|
|
|
final FloatingActionButton composeButton = activity.composeButton; |
|
|
|
|
|
|
|
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences( |
|
|
|
|
|
|
|
activity); |
|
|
|
|
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onTabUnselected(TabLayout.Tab tab) {} |
|
|
|
public void onScrolled(RecyclerView view, int dx, int dy) { |
|
|
|
|
|
|
|
super.onScrolled(view, dx, dy); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (preferences.getBoolean("fabHide", false)) { |
|
|
|
|
|
|
|
if (dy > 0 && composeButton.isShown()) { |
|
|
|
|
|
|
|
composeButton.hide(); // hides the button if we're scrolling down
|
|
|
|
|
|
|
|
} else if (dy < 0 && !composeButton.isShown()) { |
|
|
|
|
|
|
|
composeButton.show(); // shows it if we are scrolling up
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onTabReselected(TabLayout.Tab tab) { |
|
|
|
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { |
|
|
|
jumpToTop(); |
|
|
|
TimelineFragment.this.onLoadMore(view); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
layout.addOnTabSelectedListener(onTabSelectedListener); |
|
|
|
} else { |
|
|
|
|
|
|
|
// Just use the basic scroll listener to load more statuses.
|
|
|
|
|
|
|
|
scrollListener = new EndlessOnScrollListener(layoutManager) { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onLoadMore(int page, int totalItemsCount, RecyclerView view) { |
|
|
|
|
|
|
|
TimelineFragment.this.onLoadMore(view); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
return rootView; |
|
|
|
} |
|
|
|
|
|
|
|
recyclerView.addOnScrollListener(scrollListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -174,6 +202,10 @@ public class TimelineFragment extends SFragment implements |
|
|
|
return kind != Kind.TAG && kind != Kind.FAVOURITES; |
|
|
|
return kind != Kind.TAG && kind != Kind.FAVOURITES; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean followButtonPresent() { |
|
|
|
|
|
|
|
return kind != Kind.TAG && kind != Kind.FAVOURITES; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void jumpToTop() { |
|
|
|
private void jumpToTop() { |
|
|
|
layoutManager.scrollToPosition(0); |
|
|
|
layoutManager.scrollToPosition(0); |
|
|
|
scrollListener.reset(); |
|
|
|
scrollListener.reset(); |
|
|
|