From dd7fce83132b2f98e8c901d27617d50f6b47c518 Mon Sep 17 00:00:00 2001 From: Olivier Bouillet Date: Fri, 25 Sep 2020 18:15:07 +0200 Subject: [PATCH] [feature] : Add ability to filter server list --- .../activity/SearchServerActivity.java | 35 ++++++++++++++----- .../network/GetServerListDataService.java | 3 +- .../res/layout/activity_search_server.xml | 17 +++++++-- app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java b/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java index 6c57cf7..38ec7b0 100644 --- a/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java +++ b/app/src/main/java/net/schueller/peertube/activity/SearchServerActivity.java @@ -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 call; - call = service.getInstancesData(start, count); + call = service.getInstancesData(start, count, searchtext); Log.d("URL Called", call.request().url() + ""); diff --git a/app/src/main/java/net/schueller/peertube/network/GetServerListDataService.java b/app/src/main/java/net/schueller/peertube/network/GetServerListDataService.java index bdb8a26..eb2d431 100644 --- a/app/src/main/java/net/schueller/peertube/network/GetServerListDataService.java +++ b/app/src/main/java/net/schueller/peertube/network/GetServerListDataService.java @@ -27,7 +27,8 @@ public interface GetServerListDataService { @GET("instances/") Call getInstancesData( @Query("start") int start, - @Query("count") int count + @Query("count") int count, + @Query("search") String text ); } \ No newline at end of file diff --git a/app/src/main/res/layout/activity_search_server.xml b/app/src/main/res/layout/activity_search_server.xml index 1860129..991e091 100644 --- a/app/src/main/res/layout/activity_search_server.xml +++ b/app/src/main/res/layout/activity_search_server.xml @@ -6,6 +6,11 @@ android:layout_height="match_parent" tools:context=".activity.SearchServerActivity"> + + + + + - + \ No newline at end of file diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index c19c6ff..2ddab4e 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -86,6 +86,7 @@ Serveur réglé sur : %s Sélectionnez un serveur de la liste ci-dessous ou entrez-le directement. URL du serveur PeerTube + Filtrer la liste Compte Signaler Liste noire diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4636d89..87644e4 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -292,6 +292,7 @@ Server set to: %s Select a server from the list below or enter it directly. PeerTube Server URL + Filter list Account Report Blacklist