[feature] : Add ability to filter server list

This commit is contained in:
Olivier Bouillet 2020-09-25 18:15:07 +02:00
parent 95353ca673
commit dd7fce8313
5 changed files with 46 additions and 11 deletions

View File

@ -28,7 +28,10 @@ import retrofit2.Response;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@ -46,9 +49,13 @@ public class SearchServerActivity extends CommonActivity {
private ServerSearchAdapter serverAdapter;
private SwipeRefreshLayout swipeRefreshLayout;
private EditText searchTextView;
private final static String TAG = "SearchServerActivity";
private int currentStart = 0;
private int count = 12;
private final int count = 12;
private String lastSearchtext = "";
private TextView emptyView;
private RecyclerView recyclerView;
@ -77,11 +84,20 @@ public class SearchServerActivity extends CommonActivity {
}
TextView.OnEditorActionListener onSearchTextValidated = ( textView, i, keyEvent ) -> {
if ( keyEvent != null && keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| i == EditorInfo.IME_ACTION_GO ) {
loadServers(currentStart, count, textView.getText().toString());
}
return false;
};
private void loadList() {
recyclerView = findViewById(R.id.serverRecyclerView);
swipeRefreshLayout = findViewById(R.id.serversSwipeRefreshLayout);
searchTextView = findViewById(R.id.search_server_input_field );
searchTextView.setOnEditorActionListener( onSearchTextValidated );
emptyView = findViewById(R.id.empty_server_selection_view);
@ -91,7 +107,7 @@ public class SearchServerActivity extends CommonActivity {
serverAdapter = new ServerSearchAdapter(new ArrayList<>(), this);
recyclerView.setAdapter(serverAdapter);
loadServers(currentStart, count);
loadServers(currentStart, count, searchTextView.getText().toString() );
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
@ -107,7 +123,7 @@ public class SearchServerActivity extends CommonActivity {
if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
if (!isLoading) {
currentStart = currentStart + count;
loadServers(currentStart, count);
loadServers(currentStart, count, searchTextView.getText().toString());
}
}
}
@ -119,26 +135,29 @@ public class SearchServerActivity extends CommonActivity {
// Refresh items
if (!isLoading) {
currentStart = 0;
loadServers(currentStart, count);
loadServers(currentStart, count, searchTextView.getText().toString());
}
});
}
private void loadServers(int start, int count) {
private void loadServers(int start, int count, String searchtext) {
isLoading = true;
GetServerListDataService service = RetrofitInstance.getRetrofitInstance(
APIUrlHelper.getServerIndexUrl(SearchServerActivity.this)
).create(GetServerListDataService.class);
if ( !searchtext.equals( lastSearchtext ) )
{
currentStart = 0;
lastSearchtext = searchtext;
}
Call<ServerList> call;
call = service.getInstancesData(start, count);
call = service.getInstancesData(start, count, searchtext);
Log.d("URL Called", call.request().url() + "");

View File

@ -27,7 +27,8 @@ public interface GetServerListDataService {
@GET("instances/")
Call<ServerList> getInstancesData(
@Query("start") int start,
@Query("count") int count
@Query("count") int count,
@Query("search") String text
);
}

View File

@ -6,6 +6,11 @@
android:layout_height="match_parent"
tools:context=".activity.SearchServerActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_server_selection"
android:layout_width="match_parent"
@ -29,11 +34,19 @@
android:text="@string/no_data_available"
android:visibility="gone" />
<EditText
android:id="@+id/search_server_input_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/server_selection_filter_hint"
android:singleLine="true"
android:imeOptions="actionGo"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/serversSwipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/appbar_server_selection"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
@ -45,5 +58,5 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -86,6 +86,7 @@
<string name="server_selection_set_server">Serveur réglé sur : %s</string>
<string name="server_selection_select_a_server">Sélectionnez un serveur de la liste ci-dessous ou entrez-le directement.</string>
<string name="server_selection_peertube_server_url">URL du serveur PeerTube</string>
<string name="server_selection_filter_hint">Filtrer la liste</string>
<string name="title_activity_account">Compte</string>
<string name="menu_video_more_report">Signaler</string>
<string name="menu_video_more_blacklist">Liste noire</string>

View File

@ -292,6 +292,7 @@
<string name="server_selection_set_server">Server set to: %s</string>
<string name="server_selection_select_a_server">Select a server from the list below or enter it directly.</string>
<string name="server_selection_peertube_server_url">PeerTube Server URL</string>
<string name="server_selection_filter_hint">Filter list</string>
<string name="title_activity_account">Account</string>
<string name="menu_video_more_report">Report</string>
<string name="menu_video_more_blacklist">Blacklist</string>