Add scroll to bottom button in conversation view

Added a FloatingActionButton to the conversation_fragment
that appears and disappears using the same logic as the
existing compose divider: appear when the conversation list
is scrolled away from the bottom, disappear when the list is
scrolled to the bottom.

Fixes #5651
This commit is contained in:
Stuart Gilbert 2017-01-23 00:34:10 -08:00 committed by Moxie Marlinspike
parent 4c815db076
commit aa9d8e4d14
4 changed files with 32 additions and 2 deletions

View File

@ -21,4 +21,16 @@
android:alpha="0"
android:visibility="invisible" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/scroll_to_bottom_button"
android:visibility="invisible"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/scroll_to_bottom_button_margin_end"
android:layout_marginRight="@dimen/scroll_to_bottom_button_margin_end"
android:layout_marginBottom="@dimen/scroll_to_bottom_button_margin_bottom"
android:layout_gravity="bottom|end"
android:contentDescription="@string/conversation_fragment__scroll_to_the_bottom_content_description"
android:src="@drawable/ic_keyboard_arrow_down_white_36dp" />
</FrameLayout>

View File

@ -66,4 +66,7 @@
<dimen name="onboarding_subtitle_size">20sp</dimen>
<dimen name="scribble_stroke_size">3dp</dimen>
<dimen name="scroll_to_bottom_button_margin_end">10dp</dimen>
<dimen name="scroll_to_bottom_button_margin_bottom">10dp</dimen>
</resources>

View File

@ -729,6 +729,9 @@
<string name="conversation_fragment_cab__batch_selection_mode">Batch selection mode</string>
<string name="conversation_fragment_cab__batch_selection_amount">%s selected</string>
<!-- conversation_fragment -->
<string name="conversation_fragment__scroll_to_the_bottom_content_description">Scroll to the bottom</string>
<!-- country_selection_fragment -->
<string name="country_selection_fragment__loading_countries">Loading countries...</string>
<string name="country_selection_fragment__search">Search</string>

View File

@ -91,6 +91,7 @@ public class ConversationFragment extends Fragment
private RecyclerView list;
private View loadMoreView;
private View composeDivider;
private View scrollToBottomButton;
@Override
public void onCreate(Bundle icicle) {
@ -102,8 +103,16 @@ public class ConversationFragment extends Fragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
final View view = inflater.inflate(R.layout.conversation_fragment, container, false);
list = ViewUtil.findById(view, android.R.id.list);
composeDivider = ViewUtil.findById(view, R.id.compose_divider);
list = ViewUtil.findById(view, android.R.id.list);
composeDivider = ViewUtil.findById(view, R.id.compose_divider);
scrollToBottomButton = ViewUtil.findById(view, R.id.scroll_to_bottom_button);
scrollToBottomButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
scrollToBottom();
}
});
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true);
list.setHasFixedSize(false);
@ -407,11 +416,14 @@ public class ConversationFragment extends Fragment
if (wasAtBottom != currentlyAtBottom) {
composeDivider.setVisibility(currentlyAtBottom ? View.INVISIBLE : View.VISIBLE);
scrollToBottomButton.setVisibility(currentlyAtBottom ? View.INVISIBLE : View.VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
composeDivider.animate().alpha(currentlyAtBottom ? 0 : 1);
scrollToBottomButton.animate().alpha(currentlyAtBottom ? 0 : 1);
} else if (Build.VERSION.SDK_INT > Build.VERSION_CODES.HONEYCOMB) {
composeDivider.setAlpha(currentlyAtBottom ? 0 : 1);
scrollToBottomButton.setAlpha(currentlyAtBottom ? 0 : 1);
}
wasAtBottom = currentlyAtBottom;