Fix error panel and search fragment state saving

This commit is contained in:
Stypox 2021-01-15 15:38:25 +01:00
parent c2b6cec37d
commit c3cf1d81c2
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 27 additions and 14 deletions

View File

@ -30,7 +30,11 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
private View emptyStateView; private View emptyStateView;
@Nullable @Nullable
private ProgressBar loadingProgressBar; private ProgressBar loadingProgressBar;
private ErrorPanelHelper errorPanelHelper; private ErrorPanelHelper errorPanelHelper;
@Nullable
@State
protected ErrorInfo lastPanelError = null;
@Override @Override
public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) { public void onViewCreated(@NonNull final View rootView, final Bundle savedInstanceState) {
@ -44,6 +48,14 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
wasLoading.set(isLoading.get()); wasLoading.set(isLoading.get());
} }
@Override
public void onResume() {
super.onResume();
if (lastPanelError != null) {
showError(lastPanelError);
}
}
@Override @Override
public void onDestroy() { public void onDestroy() {
super.onDestroy(); super.onDestroy();
@ -98,7 +110,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
if (loadingProgressBar != null) { if (loadingProgressBar != null) {
animate(loadingProgressBar, true, 400); animate(loadingProgressBar, true, 400);
} }
errorPanelHelper.hide(); hideErrorPanel();
} }
@Override @Override
@ -109,7 +121,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
if (loadingProgressBar != null) { if (loadingProgressBar != null) {
animate(loadingProgressBar, false, 0); animate(loadingProgressBar, false, 0);
} }
errorPanelHelper.hide(); hideErrorPanel();
} }
public void showEmptyState() { public void showEmptyState() {
@ -120,7 +132,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
if (loadingProgressBar != null) { if (loadingProgressBar != null) {
animate(loadingProgressBar, false, 0); animate(loadingProgressBar, false, 0);
} }
errorPanelHelper.hide(); hideErrorPanel();
} }
@Override @Override
@ -158,6 +170,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
} }
errorPanelHelper.showError(errorInfo); errorPanelHelper.showError(errorInfo);
lastPanelError = errorInfo;
} }
public final void showTextError(@NonNull final String errorString) { public final void showTextError(@NonNull final String errorString) {
@ -175,6 +188,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
public final void hideErrorPanel() { public final void hideErrorPanel() {
errorPanelHelper.hide(); errorPanelHelper.hide();
lastPanelError = null;
} }
public final boolean isErrorPanelVisible() { public final boolean isErrorPanelVisible() {

View File

@ -256,13 +256,19 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
"Getting service for id " + serviceId, e); "Getting service for id " + serviceId, e);
} }
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
}
if (!TextUtils.isEmpty(searchString)) { if (!TextUtils.isEmpty(searchString)) {
if (wasLoading.getAndSet(false)) { if (wasLoading.getAndSet(false)) {
search(searchString, contentFilter, sortFilter); search(searchString, contentFilter, sortFilter);
return;
} else if (infoListAdapter.getItemsList().isEmpty()) { } else if (infoListAdapter.getItemsList().isEmpty()) {
if (savedState == null) { if (savedState == null) {
search(searchString, contentFilter, sortFilter); search(searchString, contentFilter, sortFilter);
} else if (!isLoading.get() && !wasSearchFocused) { return;
} else if (!isLoading.get() && !wasSearchFocused && lastPanelError == null) {
infoListAdapter.clearStreamItemList(); infoListAdapter.clearStreamItemList();
showEmptyState(); showEmptyState();
} }
@ -274,10 +280,6 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
disposables.add(showMetaInfoInTextView(metaInfo == null ? null : Arrays.asList(metaInfo), disposables.add(showMetaInfoInTextView(metaInfo == null ? null : Arrays.asList(metaInfo),
searchBinding.searchMetaInfoTextView, searchBinding.searchMetaInfoSeparator)); searchBinding.searchMetaInfoTextView, searchBinding.searchMetaInfoSeparator));
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
}
if (TextUtils.isEmpty(searchString) || wasSearchFocused) { if (TextUtils.isEmpty(searchString) || wasSearchFocused) {
showKeyboardSearch(); showKeyboardSearch();
showSuggestionsPanel(); showSuggestionsPanel();
@ -719,14 +721,12 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
suggestionDisposable.dispose(); suggestionDisposable.dispose();
} }
final Observable<String> observable = suggestionPublisher suggestionDisposable = suggestionPublisher
.debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS) .debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS)
.startWithItem(searchString != null .startWithItem(searchString != null
? searchString ? searchString
: "") : "")
.filter(ss -> isSuggestionsEnabled); .filter(ss -> isSuggestionsEnabled)
suggestionDisposable = observable
.switchMap(query -> { .switchMap(query -> {
final Flowable<List<SearchHistoryEntry>> flowable = historyRecordManager final Flowable<List<SearchHistoryEntry>> flowable = historyRecordManager
.getRelatedSearches(query, 3, 25); .getRelatedSearches(query, 3, 25);

View File

@ -107,8 +107,7 @@
layout="@layout/error_panel" layout="@layout/error_panel"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" android:layout_centerInParent="true"
android:layout_marginTop="50dp"
android:visibility="gone" android:visibility="gone"
tools:visibility="visible" /> tools:visibility="visible" />