Fix error panel and search fragment state saving
This commit is contained in:
parent
c2b6cec37d
commit
c3cf1d81c2
|
@ -30,7 +30,11 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
|
|||
private View emptyStateView;
|
||||
@Nullable
|
||||
private ProgressBar loadingProgressBar;
|
||||
|
||||
private ErrorPanelHelper errorPanelHelper;
|
||||
@Nullable
|
||||
@State
|
||||
protected ErrorInfo lastPanelError = null;
|
||||
|
||||
@Override
|
||||
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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (lastPanelError != null) {
|
||||
showError(lastPanelError);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@ -98,7 +110,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
|
|||
if (loadingProgressBar != null) {
|
||||
animate(loadingProgressBar, true, 400);
|
||||
}
|
||||
errorPanelHelper.hide();
|
||||
hideErrorPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -109,7 +121,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
|
|||
if (loadingProgressBar != null) {
|
||||
animate(loadingProgressBar, false, 0);
|
||||
}
|
||||
errorPanelHelper.hide();
|
||||
hideErrorPanel();
|
||||
}
|
||||
|
||||
public void showEmptyState() {
|
||||
|
@ -120,7 +132,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
|
|||
if (loadingProgressBar != null) {
|
||||
animate(loadingProgressBar, false, 0);
|
||||
}
|
||||
errorPanelHelper.hide();
|
||||
hideErrorPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -158,6 +170,7 @@ public abstract class BaseStateFragment<I> extends BaseFragment implements ViewC
|
|||
}
|
||||
|
||||
errorPanelHelper.showError(errorInfo);
|
||||
lastPanelError = errorInfo;
|
||||
}
|
||||
|
||||
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() {
|
||||
errorPanelHelper.hide();
|
||||
lastPanelError = null;
|
||||
}
|
||||
|
||||
public final boolean isErrorPanelVisible() {
|
||||
|
|
|
@ -256,13 +256,19 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
|||
"Getting service for id " + serviceId, e);
|
||||
}
|
||||
|
||||
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
|
||||
initSuggestionObserver();
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(searchString)) {
|
||||
if (wasLoading.getAndSet(false)) {
|
||||
search(searchString, contentFilter, sortFilter);
|
||||
return;
|
||||
} else if (infoListAdapter.getItemsList().isEmpty()) {
|
||||
if (savedState == null) {
|
||||
search(searchString, contentFilter, sortFilter);
|
||||
} else if (!isLoading.get() && !wasSearchFocused) {
|
||||
return;
|
||||
} else if (!isLoading.get() && !wasSearchFocused && lastPanelError == null) {
|
||||
infoListAdapter.clearStreamItemList();
|
||||
showEmptyState();
|
||||
}
|
||||
|
@ -274,10 +280,6 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
|||
disposables.add(showMetaInfoInTextView(metaInfo == null ? null : Arrays.asList(metaInfo),
|
||||
searchBinding.searchMetaInfoTextView, searchBinding.searchMetaInfoSeparator));
|
||||
|
||||
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
|
||||
initSuggestionObserver();
|
||||
}
|
||||
|
||||
if (TextUtils.isEmpty(searchString) || wasSearchFocused) {
|
||||
showKeyboardSearch();
|
||||
showSuggestionsPanel();
|
||||
|
@ -719,14 +721,12 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
|||
suggestionDisposable.dispose();
|
||||
}
|
||||
|
||||
final Observable<String> observable = suggestionPublisher
|
||||
suggestionDisposable = suggestionPublisher
|
||||
.debounce(SUGGESTIONS_DEBOUNCE, TimeUnit.MILLISECONDS)
|
||||
.startWithItem(searchString != null
|
||||
? searchString
|
||||
: "")
|
||||
.filter(ss -> isSuggestionsEnabled);
|
||||
|
||||
suggestionDisposable = observable
|
||||
.filter(ss -> isSuggestionsEnabled)
|
||||
.switchMap(query -> {
|
||||
final Flowable<List<SearchHistoryEntry>> flowable = historyRecordManager
|
||||
.getRelatedSearches(query, 3, 25);
|
||||
|
|
|
@ -107,8 +107,7 @@
|
|||
layout="@layout/error_panel"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="50dp"
|
||||
android:layout_centerInParent="true"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
|
|
Loading…
Reference in New Issue