Update look and feel of fast-scroll-to-bottom

Closes #6086
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2017-01-24 11:04:32 -08:00
parent aa9d8e4d14
commit e2b81c9637
8 changed files with 59 additions and 37 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 498 B

View File

@ -2,7 +2,8 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="@android:id/list"
@ -11,26 +12,29 @@
android:scrollbars="vertical"
android:cacheColorHint="?conversation_background" />
<!--suppress AndroidLintUnusedAttribute-->
<View android:id="@+id/compose_divider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@drawable/compose_divider_background"
android:alpha="0"
android:alpha="1"
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" />
<ImageButton
android:id="@+id/scroll_to_bottom_button"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
android:layout_gravity="bottom|end"
android:background="@drawable/circle_tintable"
android:tint="@color/grey_600"
android:elevation="1dp"
android:alpha="0.9"
android:contentDescription="@string/conversation_fragment__scroll_to_the_bottom_content_description"
android:src="@drawable/ic_scroll_down"/>
</FrameLayout>

View File

@ -66,7 +66,4 @@
<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

@ -24,6 +24,7 @@ import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.Loader;
@ -44,6 +45,8 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Toast;
import org.thoughtcrime.securesms.ConversationAdapter.ItemClickListener;
@ -79,7 +82,6 @@ public class ConversationFragment extends Fragment
private final ActionModeCallback actionModeCallback = new ActionModeCallback();
private final ItemClickListener selectionClickListener = new ConversationFragmentItemClickListener();
private final OnScrollListener scrollListener = new ConversationScrollListener();
private ConversationFragmentListener listener;
@ -117,7 +119,6 @@ public class ConversationFragment extends Fragment
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, true);
list.setHasFixedSize(false);
list.setLayoutManager(layoutManager);
list.addOnScrollListener(scrollListener);
list.setItemAnimator(null);
loadMoreView = inflater.inflate(R.layout.load_more_header, container, false);
@ -173,8 +174,11 @@ public class ConversationFragment extends Fragment
}
private void initializeResources() {
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
this.recipients = RecipientFactory.getRecipientsForIds(getActivity(), getActivity().getIntent().getLongArrayExtra("recipients"), true);
this.threadId = this.getActivity().getIntent().getLongExtra("thread_id", -1);
OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
list.addOnScrollListener(scrollListener);
}
private void initializeListAdapter() {
@ -408,26 +412,39 @@ public class ConversationFragment extends Fragment
}
private class ConversationScrollListener extends OnScrollListener {
private boolean wasAtBottom = true;
private final Animation scrollButtonInAnimation;
private final Animation scrollButtonOutAnimation;
private boolean wasAtBottom = true;
private boolean wasAtZoomScrollHeight = false;
ConversationScrollListener(@NonNull Context context) {
this.scrollButtonInAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_in);
this.scrollButtonOutAnimation = AnimationUtils.loadAnimation(context, R.anim.fade_scale_out);
this.scrollButtonInAnimation.setDuration(100);
this.scrollButtonOutAnimation.setDuration(50);
}
@Override
public void onScrolled(final RecyclerView rv, final int dx, final int dy) {
boolean currentlyAtBottom = isAtBottom();
boolean currentlyAtBottom = isAtBottom();
boolean currentlyAtZoomScrollHeight = isAtZoomScrollHeight();
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;
if (currentlyAtBottom && !wasAtBottom) {
ViewUtil.fadeOut(composeDivider, 50, View.INVISIBLE);
ViewUtil.animateOut(scrollToBottomButton, scrollButtonOutAnimation, View.INVISIBLE);
} else if (!currentlyAtBottom && wasAtBottom) {
ViewUtil.fadeIn(composeDivider, 500);
}
if (currentlyAtZoomScrollHeight && !wasAtZoomScrollHeight) {
ViewUtil.animateIn(scrollToBottomButton, scrollButtonInAnimation);
}
wasAtBottom = currentlyAtBottom;
wasAtZoomScrollHeight = currentlyAtZoomScrollHeight;
}
private boolean isAtBottom() {
@ -439,6 +456,10 @@ public class ConversationFragment extends Fragment
return isAtBottom && bottomView.getBottom() <= list.getHeight();
}
private boolean isAtZoomScrollHeight() {
return ((LinearLayoutManager) list.getLayoutManager()).findFirstCompletelyVisibleItemPosition() > 4;
}
}
private class ConversationFragmentItemClickListener implements ItemClickListener {