Commit 30fdb3bc authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update SidebarMainFragment.java

parent 6c48f18d
......@@ -42,16 +42,18 @@ import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import java.util.ArrayList;
import java.util.List;
public class SidebarMainFragment extends AbstractFragment implements SidebarMainContract.View {
private SidebarMainContract.Presenter presenter;
private RoomListAdapter adapter;
private RecyclerView recyclerView;
private SearchView searchView;
private TextView loadMoreResultsText;
private List<RoomSidebar> roomSidebarList;
private Disposable spotlightDisposable;
private String hostname;
private static final String HOSTNAME = "hostname";
......@@ -138,7 +140,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
});
recyclerView = rootView.findViewById(R.id.room_list_container);
RecyclerView recyclerView = rootView.findViewById(R.id.room_list_container);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
......@@ -147,13 +149,15 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
RxSearchView.queryTextChanges(searchView)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(charSequence -> {
adapter.setMode(RoomListAdapter.MODE_ROOM);
if (spotlightDisposable != null && !spotlightDisposable.isDisposed()) {
spotlightDisposable.dispose();
}
presenter.disposeSubscriptions();
if (charSequence.length() == 0) {
loadMoreResultsText.setVisibility(View.GONE);
adapter.setMode(RoomListAdapter.MODE_ROOM);
presenter.bindView(this);
recyclerView.setVisibility(View.VISIBLE);
} else {
presenter.disposeSubscriptions();
filterRoomSidebarList(charSequence);
}
});
......@@ -178,16 +182,16 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
if (filteredRoomSidebarList.isEmpty()) {
recyclerView.setVisibility(View.GONE);
loadMoreResults();
} else {
recyclerView.setVisibility(View.VISIBLE);
loadMoreResultsText.setVisibility(View.VISIBLE);
adapter.setMode(RoomListAdapter.MODE_ROOM);
adapter.setRoomSidebarList(filteredRoomSidebarList);
}
loadMoreResultsText.setVisibility(View.VISIBLE);
}
private void loadMoreResults() {
presenter.searchSpotlight(searchView.getQuery().toString())
spotlightDisposable = presenter.searchSpotlight(searchView.getQuery().toString())
.toObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::showSearchSuggestions);
......@@ -197,7 +201,6 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
loadMoreResultsText.setVisibility(View.GONE);
adapter.setMode(RoomListAdapter.MODE_SPOTLIGHT);
adapter.setSpotlightList(spotlightList);
recyclerView.setVisibility(View.VISIBLE);
}
@SuppressLint("RxLeakedSubscription")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment