Added nav to message bottom

This commit is contained in:
M66B 2019-05-22 10:53:28 +02:00
parent a715dab78e
commit ca51112088
4 changed files with 65 additions and 22 deletions

View File

@ -121,6 +121,7 @@ public class FragmentMessages extends FragmentBase {
private TextView tvNoEmail;
private FixedRecyclerView rvMessage;
private SeekBar seekBar;
private ImageButton ibDown;
private ImageButton ibUp;
private BottomNavigationView bottom_navigation;
private ContentLoadingProgressBar pbWait;
@ -265,6 +266,7 @@ public class FragmentMessages extends FragmentBase {
tvNoEmail = view.findViewById(R.id.tvNoEmail);
rvMessage = view.findViewById(R.id.rvMessage);
seekBar = view.findViewById(R.id.seekBar);
ibDown = view.findViewById(R.id.ibDown);
ibUp = view.findViewById(R.id.ibUp);
bottom_navigation = view.findViewById(R.id.bottom_navigation);
pbWait = view.findViewById(R.id.pbWait);
@ -456,28 +458,17 @@ public class FragmentMessages extends FragmentBase {
}
});
ibDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollToVisibleItem(llm, true);
}
});
ibUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int pos = llm.findLastVisibleItemPosition();
if (pos != RecyclerView.NO_POSITION)
do {
Long key = adapter.getKeyAtPosition(pos);
if (key != null && isExpanded(key)) {
int first = llm.findFirstVisibleItemPosition();
View child = rvMessage.getChildAt(pos - (first < 0 ? 0 : first));
if (child != null) {
TranslateAnimation bounce = new TranslateAnimation(
0, 0, Helper.dp2pixels(getContext(), 12), 0);
bounce.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
child.startAnimation(bounce);
}
rvMessage.scrollToPosition(pos);
break;
}
pos--;
} while (pos >= 0);
scrollToVisibleItem(llm, false);
}
});
@ -646,6 +637,7 @@ public class FragmentMessages extends FragmentBase {
swipeRefresh.setEnabled(pull);
tvNoEmail.setVisibility(View.GONE);
seekBar.setVisibility(View.GONE);
ibDown.setVisibility(View.GONE);
ibUp.setVisibility(View.GONE);
bottom_navigation.getMenu().findItem(R.id.action_prev).setEnabled(false);
bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(false);
@ -775,6 +767,35 @@ public class FragmentMessages extends FragmentBase {
super.onDestroy();
}
private void scrollToVisibleItem(LinearLayoutManager llm, boolean bottom) {
int pos = llm.findLastVisibleItemPosition();
if (pos == RecyclerView.NO_POSITION)
return;
do {
Long key = adapter.getKeyAtPosition(pos);
if (key != null && isExpanded(key)) {
int first = llm.findFirstVisibleItemPosition();
View child = rvMessage.getChildAt(pos - (first < 0 ? 0 : first));
if (child != null) {
TranslateAnimation bounce = new TranslateAnimation(
0, 0, Helper.dp2pixels(getContext(), bottom ? -12 : 12), 0);
bounce.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));
child.startAnimation(bounce);
}
if (bottom && child != null)
llm.scrollToPositionWithOffset(pos, rvMessage.getHeight() - llm.getDecoratedMeasuredHeight(child));
else
rvMessage.scrollToPosition(pos);
break;
}
pos--;
} while (pos >= 0);
}
private void onSwipeRefresh() {
Bundle args = new Bundle();
args.putLong("folder", folder);
@ -854,6 +875,7 @@ public class FragmentMessages extends FragmentBase {
if ("expanded".equals(name)) {
if (enabled)
handleExpand(id);
ibDown.setVisibility(values.get(name).size() > 0 ? View.VISIBLE : View.GONE);
ibUp.setVisibility(values.get(name).size() > 0 ? View.VISIBLE : View.GONE);
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M16,13h-3V3h-2v10H8l4,4 4,-4zM4,19v2h16v-2H4z"/>
</vector>

View File

@ -6,5 +6,5 @@
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z"/>
android:pathData="M8,11h3v10h2V11h3l-4,-4 -4,4zM4,3v2h16V3H4z"/>
</vector>

View File

@ -180,12 +180,23 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/ibDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:padding="12dp"
android:src="@drawable/baseline_vertical_align_bottom_24"
app:layout_constraintBottom_toTopOf="@id/seekBar"
app:layout_constraintEnd_toStartOf="@id/ibUp" />
<ImageButton
android:id="@+id/ibUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="12dp"
android:src="@drawable/baseline_home_24"
android:background="?attr/selectableItemBackground"
android:padding="12dp"
android:src="@drawable/baseline_vertical_align_top_24"
app:layout_constraintBottom_toTopOf="@id/seekBar"
app:layout_constraintEnd_toEndOf="@id/seekBar" />