Wrap emoji pages with coordinator layout. Fix issue with bubble coloring in wallpaper preview.

fork-5.53.8
Alex Hart 2021-06-03 14:02:37 -03:00
rodzic a644c81736
commit a3a4b10f83
6 zmienionych plików z 74 dodań i 93 usunięć

Wyświetl plik

@ -9,11 +9,14 @@ import android.widget.FrameLayout;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.annimon.stream.Stream;
import com.google.android.material.appbar.AppBarLayout;
import org.jetbrains.annotations.NotNull;
import org.signal.core.util.logging.Log;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiKeyboardProvider.EmojiEventListener;
@ -33,8 +36,8 @@ public class EmojiPageView extends FrameLayout implements VariationSelectorListe
private RecyclerView.OnItemTouchListener scrollDisabler;
private VariationSelectorListener variationSelectorListener;
private EmojiVariationSelectorPopup popup;
private AppBarLayout appBarLayout;
private boolean searchEnabled;
private SpanSizeLookup spanSizeLookup;
public EmojiPageView(@NonNull Context context,
@NonNull EmojiEventListener emojiSelectionListener,
@ -66,13 +69,13 @@ public class EmojiPageView extends FrameLayout implements VariationSelectorListe
emojiSelectionListener,
this,
allowVariations,
displayItemLayoutResId,
searchCallbacks);
displayItemLayoutResId);
if (layoutManager instanceof GridLayoutManager) {
spanSizeLookup = new SpanSizeLookup();
((GridLayoutManager) layoutManager).setSpanSizeLookup(spanSizeLookup);
}
this.appBarLayout = view.findViewById(R.id.emoji_keyboard_search_appbar);
((CoordinatorLayout.LayoutParams) this.appBarLayout.getLayoutParams()).setBehavior(new BlockableScrollBehavior());
KeyboardPageSearchView searchView = view.findViewById(R.id.emoji_keyboard_search_text);
searchView.setCallbacks(searchCallbacks);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(null);
@ -98,38 +101,12 @@ public class EmojiPageView extends FrameLayout implements VariationSelectorListe
EmojiPageViewGridAdapter adapter = adapterFactory.create();
recyclerView.setAdapter(adapter);
adapter.submitList(getMappingModelList(), () -> {
layoutManager.scrollToPosition(1);
recyclerView.post(() -> {
if (!searchEnabled || recyclerView.getAdapter() == null) {
return;
}
KeyboardPageSearchView searchView = (KeyboardPageSearchView) layoutManager.findViewByPosition(0);
if (searchView == null) {
return;
}
int allowedScrollDistance = recyclerView.computeVerticalScrollRange() - recyclerView.computeVerticalScrollExtent();
if (allowedScrollDistance < searchView.getMeasuredHeight()) {
View lastView = Objects.requireNonNull(layoutManager.findViewByPosition(recyclerView.getAdapter().getItemCount() - 1));
int scrollDelta = searchView.getMeasuredHeight() - allowedScrollDistance;
int distanceFromBottom = Math.max(0, recyclerView.getMeasuredHeight() - lastView.getBottom());
lastView.setPadding(lastView.getPaddingLeft(), lastView.getPaddingTop(), lastView.getPaddingRight(), lastView.getPaddingBottom() + scrollDelta + distanceFromBottom);
recyclerView.post(() -> layoutManager.scrollToPosition(1));
}
});
});
adapter.submitList(getMappingModelList());
}
private @NonNull MappingModelList getMappingModelList() {
MappingModelList mappingModels = new MappingModelList();
if (searchEnabled) {
mappingModels.add(new EmojiPageViewGridAdapter.SearchModel());
}
if (model != null) {
mappingModels.addAll(Stream.of(model.getDisplayEmoji()).map(EmojiPageViewGridAdapter.EmojiModel::new).toList());
}
@ -150,7 +127,6 @@ public class EmojiPageView extends FrameLayout implements VariationSelectorListe
int idealWidth = getContext().getResources().getDimensionPixelOffset(R.dimen.emoji_drawer_item_width);
int spanCount = Math.max(w / idealWidth, 1);
spanSizeLookup.setSpansPerRow(spanCount);
((GridLayoutManager) layoutManager).setSpanCount(spanCount);
}
}
@ -185,17 +161,20 @@ public class EmojiPageView extends FrameLayout implements VariationSelectorListe
public void onRequestDisallowInterceptTouchEvent(boolean b) { }
}
private class SpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
private int spansPerRow;
public void setSpansPerRow(int spansPerRow) {
this.spansPerRow = spansPerRow;
private class BlockableScrollBehavior extends AppBarLayout.Behavior {
@Override public boolean onStartNestedScroll(@NonNull CoordinatorLayout parent,
@NonNull AppBarLayout child,
@NonNull View directTargetChild,
View target,
int nestedScrollAxes,
int type)
{
return searchEnabled && super.onStartNestedScroll(parent, child, directTargetChild, target, nestedScrollAxes, type);
}
@Override
public int getSpanSize(int position) {
return position == 0 && searchEnabled ? spansPerRow : 1;
public boolean onTouchEvent(@NonNull @NotNull CoordinatorLayout parent, @NonNull @NotNull AppBarLayout child, @NonNull @NotNull MotionEvent ev) {
return searchEnabled && super.onTouchEvent(parent, child, ev);
}
}

Wyświetl plik

@ -2,8 +2,10 @@ package org.thoughtcrime.securesms.components.emoji;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.Space;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
@ -25,17 +27,12 @@ public class EmojiPageViewGridAdapter extends MappingAdapter implements PopupWin
@NonNull EmojiEventListener emojiEventListener,
@NonNull VariationSelectorListener variationSelectorListener,
boolean allowVariations,
@LayoutRes int displayItemLayoutResId,
@Nullable KeyboardPageSearchView.Callbacks callbacks)
@LayoutRes int displayItemLayoutResId)
{
this.variationSelectorListener = variationSelectorListener;
popup.setOnDismissListener(this);
registerFactory(SearchModel.class, new LayoutFactory<>(v -> {
((KeyboardPageSearchView) v).setCallbacks(callbacks);
return new SearchViewHolder(v);
}, R.layout.emoji_page_view_search));
registerFactory(EmojiModel.class, new LayoutFactory<>(v -> new EmojiViewHolder(v, emojiEventListener, variationSelectorListener, popup, allowVariations), displayItemLayoutResId));
}
@ -44,28 +41,6 @@ public class EmojiPageViewGridAdapter extends MappingAdapter implements PopupWin
variationSelectorListener.onVariationSelectorStateChanged(false);
}
static class SearchModel implements MappingModel<SearchModel> {
@Override
public boolean areItemsTheSame(@NonNull @NotNull SearchModel newItem) {
return true;
}
@Override
public boolean areContentsTheSame(@NonNull @NotNull SearchModel newItem) {
return true;
}
}
static class SearchViewHolder extends MappingViewHolder<SearchModel> {
public SearchViewHolder(@NonNull View itemView) {
super(itemView);
}
@Override
public void bind(@NonNull @NotNull SearchModel model) {
}
}
static class EmojiModel implements MappingModel<EmojiModel> {
private final Emoji emoji;

Wyświetl plik

@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.wallpaper;
import android.content.Context;
import android.content.Intent;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
@ -111,6 +110,7 @@ public class ChatWallpaperPreviewActivity extends PassphraseRequiredActivity {
} else {
onPageChanged = new OnPageChanged();
viewPager.registerOnPageChangeCallback(onPageChanged);
bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
}
new FullscreenHelper(this).showSystemUI();
@ -131,7 +131,6 @@ public class ChatWallpaperPreviewActivity extends PassphraseRequiredActivity {
public void onPageSelected(int position) {
ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(position);
updateChatColors(model.getWallpaper().getAutoChatColors());
}
}
@ -148,6 +147,21 @@ public class ChatWallpaperPreviewActivity extends PassphraseRequiredActivity {
bubble2.getBackground().setColorFilter(chatColors.getChatBubbleColorFilter());
}
private class UpdateChatColorsOnNextLayoutChange implements View.OnLayoutChangeListener {
private final ChatColors chatColors;
private UpdateChatColorsOnNextLayoutChange(@NonNull ChatColors chatColors) {
this.chatColors = chatColors;
}
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
v.removeOnLayoutChangeListener(this);
updateChatColors(chatColors);
}
}
@Override
protected void onResume() {
super.onResume();

Wyświetl plik

@ -1,14 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/signal_background_secondary">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/emoji_keyboard_search_appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/signal_background_secondary"
app:elevation="0dp"
app:expanded="false">
<org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView
android:id="@+id/emoji_keyboard_search_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:click_only="true"
app:layout_scrollFlags="scroll"
app:search_hint="@string/KeyboardPagerFragment_search_emoji"
app:show_always="true" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/emoji"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="8dp"/>
android:paddingBottom="8dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</FrameLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

Wyświetl plik

@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/emoji_search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:click_only="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:search_hint="@string/KeyboardPagerFragment_search_emoji"
app:show_always="true" />

Wyświetl plik

@ -4,8 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/signal_background_secondary"
android:paddingBottom="33dp">
android:background="@color/signal_background_tertiary">
<org.thoughtcrime.securesms.keyboard.emoji.KeyboardPageSearchView
android:id="@+id/emoji_search_view"
@ -37,7 +36,9 @@
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/emoji_search_view" />