Commit f586141a authored by Rafael Kellermann Streit's avatar Rafael Kellermann Streit Committed by GitHub

Merge pull request #446 from filipedelimabrito/local-spotlight

[NEW] Spotlight now searchs the rooms that you are subscribed.
parents 6bc115ff a0e2abf6
......@@ -19,6 +19,8 @@ public interface SidebarMainContract {
void showRoomSidebarList(@NonNull List<RoomSidebar> roomSidebarList);
void filterRoomSidebarList(CharSequence term);
void show(User user);
}
......@@ -30,6 +32,8 @@ public interface SidebarMainContract {
Flowable<List<Spotlight>> searchSpotlight(String term);
void disposeSubscriptions();
void onUserOnline();
void onUserAway();
......
......@@ -41,17 +41,18 @@ import chat.rocket.persistence.realm.repositories.RealmSpotlightRepository;
import chat.rocket.persistence.realm.repositories.RealmUserRepository;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
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 String hostname;
private static final String HOSTNAME = "hostname";
......@@ -138,24 +139,66 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
});
RecyclerView recyclerView = rootView.findViewById(R.id.room_list_container);
recyclerView = rootView.findViewById(R.id.room_list_container);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
loadMoreResultsText = rootView.findViewById(R.id.text_load_more_results);
RxSearchView.queryTextChanges(searchView)
.compose(bindToLifecycle())
.debounce(100, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.switchMap(charSequence -> {
if (charSequence.length() == 0) {
.subscribe(charSequence -> {
adapter.setMode(RoomListAdapter.MODE_ROOM);
return Observable.just(Collections.<Spotlight>emptyList());
if (charSequence.length() == 0) {
loadMoreResultsText.setVisibility(View.GONE);
presenter.bindView(this);
recyclerView.setVisibility(View.VISIBLE);
} else {
adapter.setMode(RoomListAdapter.MODE_SPOTLIGHT);
return presenter.searchSpotlight(charSequence.toString()).toObservable();
presenter.disposeSubscriptions();
filterRoomSidebarList(charSequence);
}
});
loadMoreResultsText.setOnClickListener(view -> loadMoreResults());
}
@Override
public void showRoomSidebarList(@NonNull List<RoomSidebar> roomSidebarList) {
this.roomSidebarList = roomSidebarList;
adapter.setRoomSidebarList(roomSidebarList);
}
@Override
public void filterRoomSidebarList(CharSequence term) {
List<RoomSidebar> filteredRoomSidebarList = new ArrayList<>();
for (RoomSidebar roomSidebar: roomSidebarList) {
if (roomSidebar.getRoomName().contains(term)) {
filteredRoomSidebarList.add(roomSidebar);
}
})
.subscribe(this::showSearchSuggestions, Logger::report);
}
if (filteredRoomSidebarList.isEmpty()) {
recyclerView.setVisibility(View.GONE);
} else {
recyclerView.setVisibility(View.VISIBLE);
adapter.setRoomSidebarList(filteredRoomSidebarList);
}
loadMoreResultsText.setVisibility(View.VISIBLE);
}
private void loadMoreResults() {
presenter.searchSpotlight(searchView.getQuery().toString())
.toObservable()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::showSearchSuggestions);
}
private void showSearchSuggestions(List<Spotlight> spotlightList) {
loadMoreResultsText.setVisibility(View.GONE);
adapter.setMode(RoomListAdapter.MODE_SPOTLIGHT);
adapter.setSpotlightList(spotlightList);
recyclerView.setVisibility(View.VISIBLE);
}
@SuppressLint("RxLeakedSubscription")
......@@ -188,15 +231,10 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
rootView.setVisibility(View.INVISIBLE);
}
@Override
public void showRoomSidebarList(@NonNull List<RoomSidebar> roomSidebarList) {
adapter.setRoomSidebarList(roomSidebarList);
}
@Override
public void show(User user) {
onRenderCurrentUser(user);
updateRoomListMode(user);
updateRoomListMode();
}
private void setupUserStatusButtons() {
......@@ -227,7 +265,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
}
}
private void updateRoomListMode(User user) {
private void updateRoomListMode() {
final List<RoomListHeader> roomListHeaders = new ArrayList<>();
roomListHeaders.add(new UnreadRoomListHeader(
......@@ -283,7 +321,4 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
dialog.show(getFragmentManager(), "AbstractAddRoomDialogFragment");
}
private void showSearchSuggestions(List<Spotlight> spotlightList) {
adapter.setSpotlightList(spotlightList);
}
}
\ No newline at end of file
......@@ -135,6 +135,11 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
methodCallHelper.logout().continueWith(new LogIfError());
}
@Override
public void disposeSubscriptions() {
clearSubscriptions();
}
private void subscribeToRooms() {
final Disposable subscription = roomInteractor.getOpenRooms()
.distinctUntilChanged()
......
......@@ -28,8 +28,16 @@ public class ChannelRoomListHeader implements RoomListHeader {
@Override
public boolean shouldShow(@NonNull List<RoomSidebar> roomSidebarList) {
for (RoomSidebar roomSidebar: roomSidebarList) {
if ((roomSidebar.getType().equals(Room.TYPE_CHANNEL)
|| roomSidebar.getType().equals(Room.TYPE_PRIVATE))
&& !roomSidebar.isAlert()
&& !roomSidebar.isFavorite()) {
return true;
}
}
return false;
}
@Override
public ClickListener getClickListener() {
......
......@@ -28,8 +28,15 @@ public class DirectMessageRoomListHeader implements RoomListHeader {
@Override
public boolean shouldShow(@NonNull List<RoomSidebar> roomSidebarList) {
for (RoomSidebar roomSidebar: roomSidebarList) {
if (roomSidebar.getType().equals(Room.TYPE_DIRECT_MESSAGE)
&& !roomSidebar.isAlert()
&& !roomSidebar.isFavorite()) {
return true;
}
}
return false;
}
@Override
public ClickListener getClickListener() {
......
......@@ -26,7 +26,7 @@ public class FavoriteRoomListHeader implements RoomListHeader {
@Override
public boolean shouldShow(@NonNull List<RoomSidebar> roomSidebarList) {
for (RoomSidebar roomSidebar: roomSidebarList) {
if (roomSidebar.isFavorite()) {
if (roomSidebar.isFavorite() && !roomSidebar.isAlert()) {
return true;
}
}
......
......@@ -5,6 +5,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/AppTheme.Dark"
android:background="?attr/colorPrimary"
tools:context="chat.rocket.android.fragment.sidebar.SidebarMainFragment">
<LinearLayout
......@@ -82,9 +83,18 @@
android:id="@+id/room_list_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/search_box"
android:layout_above="@+id/text_load_more_results"
android:layout_below="@+id/search_box" />
<TextView
android:id="@+id/text_load_more_results"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:background="?attr/colorPrimary" />
android:text="@string/spotlight_load_more_results"
android:background="?attr/colorPrimary"
android:visibility="gone" />
<android.support.v4.widget.NestedScrollView
android:id="@+id/user_action_outer_container"
......
......@@ -64,6 +64,7 @@
<string name="open_your_authentication_app_and_enter_the_code">Open your authentication app and enter the code</string>
<string name="two_factor_code">Two-factor code</string>
<string name="spotlight_search">Search</string>
<string name="spotlight_load_more_results">Load more results</string>
<string name="edit_message">Edit message</string>
<string name="message_options_no_message_info">Ooops. Something\'s up!</string>
<string name="message_options_no_permissions_info">You have no permissions</string>
......
......@@ -34,6 +34,8 @@
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:maxLines="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:textAppearance="@style/TextAppearance.AppCompat.Body2" />
......
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