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