Fix search header rendering after rotation.

The sticky header cache was keeping views across rotations, causing them
to render incorrectly afterwards. I added a method to invalidate the
header layouts after rotation.

Fixes #7890.
This commit is contained in:
Greyson Parrelli 2018-06-14 10:50:21 -07:00
parent 44f5cc9070
commit 626e6930a5
2 changed files with 22 additions and 5 deletions

View File

@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.search;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.arch.lifecycle.ViewModelProviders; import android.arch.lifecycle.ViewModelProviders;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -11,7 +12,6 @@ import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -41,8 +41,9 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
public static final String TAG = "SearchFragment"; public static final String TAG = "SearchFragment";
public static final String EXTRA_LOCALE = "locale"; public static final String EXTRA_LOCALE = "locale";
private TextView noResultsView; private TextView noResultsView;
private RecyclerView listView; private RecyclerView listView;
private StickyHeaderDecoration listDecoration;
private SearchViewModel viewModel; private SearchViewModel viewModel;
private SearchListAdapter listAdapter; private SearchListAdapter listAdapter;
@ -90,10 +91,12 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
noResultsView = view.findViewById(R.id.search_no_results); noResultsView = view.findViewById(R.id.search_no_results);
listView = view.findViewById(R.id.search_list); listView = view.findViewById(R.id.search_list);
listAdapter = new SearchListAdapter(GlideApp.with(this), this, locale); listAdapter = new SearchListAdapter(GlideApp.with(this), this, locale);
listDecoration = new StickyHeaderDecoration(listAdapter, false, false);
listView.setAdapter(listAdapter); listView.setAdapter(listAdapter);
listView.addItemDecoration(listDecoration);
listView.setLayoutManager(new LinearLayoutManager(getContext())); listView.setLayoutManager(new LinearLayoutManager(getContext()));
listView.addItemDecoration(new StickyHeaderDecoration(listAdapter, false, false));
} }
@Override @Override
@ -118,6 +121,16 @@ public class SearchFragment extends Fragment implements SearchListAdapter.EventL
}); });
} }
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (listDecoration != null) {
listDecoration.invalidateLayouts();
}
}
@Override @Override
public void onConversationClicked(@NonNull ThreadRecord threadRecord) { public void onConversationClicked(@NonNull ThreadRecord threadRecord) {
ConversationListActivity conversationList = (ConversationListActivity) getActivity(); ConversationListActivity conversationList = (ConversationListActivity) getActivity();

View File

@ -181,6 +181,10 @@ public class StickyHeaderDecoration extends RecyclerView.ItemDecoration {
((LinearLayoutManager)parent.getLayoutManager()).getReverseLayout(); ((LinearLayoutManager)parent.getLayoutManager()).getReverseLayout();
} }
public void invalidateLayouts() {
headerCache.clear();
}
/** /**
* The adapter to assist the {@link StickyHeaderDecoration} in creating and binding the header views. * The adapter to assist the {@link StickyHeaderDecoration} in creating and binding the header views.
* *