From 91d65b4e27c45e259c7d7c6e316e268a35de1611 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 8 Nov 2024 19:53:30 +0300 Subject: [PATCH] Fix search view state restoration & animation --- .../discover/SearchQueryFragment.java | 23 +++++++++++++++---- .../android/ui/SearchViewHelper.java | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java index eada4ece..b86d9ef8 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchQueryFragment.java @@ -95,7 +95,10 @@ public class SearchQueryFragment extends MastodonRecyclerFragment("", null, R.drawable.ic_person_24px, this::onGoToAccountClick); goToStatusSearchItem=new ListItem<>("", null, R.drawable.ic_search_24px, this::onGoToStatusSearchClick); goToAccountSearchItem=new ListItem<>("", null, R.drawable.ic_group_24px, this::onGoToAccountSearchClick); - currentQuery=getArguments().getString("query"); + if(savedInstanceState!=null) + currentQuery=savedInstanceState.getString("query"); + else + currentQuery=getArguments().getString("query"); dataLoaded(); doLoadData(0, 0); @@ -181,6 +184,9 @@ public class SearchQueryFragment extends MastodonRecyclerFragment!isInRecentMode() && vh.getAbsoluteAdapterPosition()==topOptions.size()-1)); @@ -285,6 +291,12 @@ public class SearchQueryFragment extends MastodonRecyclerFragment anims=new ArrayList<>(); + int searchLayoutXOffset=isRTL ? V.dp(4) : V.dp(-4); anims.add(boundsAnim=ObjectAnimator.ofFloat(outlineProvider, "boundsFraction", 0f, 1f)); anims.add(ObjectAnimator.ofFloat(outlineProvider, "radius", enter ? buttonRadius : screenRadius, enter ? screenRadius : buttonRadius)); anims.add(ObjectAnimator.ofFloat(toolbar, View.TRANSLATION_X, enter ? toolbarTX : 0, enter ? 0 : toolbarTX)); anims.add(ObjectAnimator.ofFloat(toolbar, View.TRANSLATION_Y, enter ? toolbarTY : 0, enter ? 0 : toolbarTY)); - anims.add(ObjectAnimator.ofFloat(searchViewHelper.getSearchLayout(), View.TRANSLATION_X, enter ? V.dp(-4) : 0, enter ? 0 : V.dp(-4))); + anims.add(ObjectAnimator.ofFloat(searchViewHelper.getSearchLayout(), View.TRANSLATION_X, enter ? searchLayoutXOffset : 0, enter ? 0 : searchLayoutXOffset)); anims.add(ObjectAnimator.ofFloat(searchViewHelper.getDivider(), View.ALPHA, enter ? 0 : 1, enter ? 1 : 0)); View parentContent=prev.findViewById(R.id.discover_content); View parentContentParent=(View) parentContent.getParent(); parentContentParent.setBackgroundColor(UiUtils.getThemeColor(getActivity(), R.attr.colorM3Surface)); if(enter){ anims.add(ObjectAnimator.ofFloat(contentWrap, View.TRANSLATION_Y, V.dp(-16), 0)); - }else{ } anims.add(ObjectAnimator.ofFloat(contentWrap, View.ALPHA, enter ? 0 : 1, enter ? 1 : 0)); for(Animator anim:anims){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/SearchViewHelper.java b/mastodon/src/main/java/org/joinmastodon/android/ui/SearchViewHelper.java index d64bb300..71da1527 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/SearchViewHelper.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/SearchViewHelper.java @@ -67,6 +67,7 @@ public class SearchViewHelper{ searchEdit.setTextAppearance(R.style.m3_body_large); searchEdit.setHintTextColor(UiUtils.getThemeColor(toolbarContext, R.attr.colorM3OnSurfaceVariant)); searchEdit.setTextColor(UiUtils.getThemeColor(toolbarContext, R.attr.colorM3OnSurface)); + searchEdit.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START); searchLayout.addView(searchEdit, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1f)); clearSearchButton=new ImageButton(context);