Merge pull request #229 from freeboub/feature/add_ability_to_filter_server_list

[feature] : Add ability to filter server list
This commit is contained in:
Stefan Schüller 2020-09-26 18:02:10 +02:00 committed by GitHub
commit 45ed4ebe18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 11 deletions

View File

@ -28,7 +28,10 @@ import retrofit2.Response;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -47,9 +50,13 @@ public class SearchServerActivity extends CommonActivity {
private ServerSearchAdapter serverAdapter; private ServerSearchAdapter serverAdapter;
private SwipeRefreshLayout swipeRefreshLayout; private SwipeRefreshLayout swipeRefreshLayout;
private EditText searchTextView;
private final static String TAG = "SearchServerActivity";
private int currentStart = 0; private int currentStart = 0;
private int count = 12; private final int count = 12;
private String lastSearchtext = "";
private TextView emptyView; private TextView emptyView;
private RecyclerView recyclerView; private RecyclerView recyclerView;
@ -78,11 +85,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() { private void loadList() {
recyclerView = findViewById(R.id.serverRecyclerView); recyclerView = findViewById(R.id.serverRecyclerView);
swipeRefreshLayout = findViewById(R.id.serversSwipeRefreshLayout); swipeRefreshLayout = findViewById(R.id.serversSwipeRefreshLayout);
searchTextView = findViewById(R.id.search_server_input_field );
searchTextView.setOnEditorActionListener( onSearchTextValidated );
emptyView = findViewById(R.id.empty_server_selection_view); emptyView = findViewById(R.id.empty_server_selection_view);
@ -92,7 +108,7 @@ public class SearchServerActivity extends CommonActivity {
serverAdapter = new ServerSearchAdapter(new ArrayList<>(), this); serverAdapter = new ServerSearchAdapter(new ArrayList<>(), this);
recyclerView.setAdapter(serverAdapter); recyclerView.setAdapter(serverAdapter);
loadServers(currentStart, count); loadServers(currentStart, count, searchTextView.getText().toString() );
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override @Override
@ -108,7 +124,7 @@ public class SearchServerActivity extends CommonActivity {
if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) { if (!recyclerView.canScrollVertically(RecyclerView.FOCUS_DOWN)) {
if (!isLoading) { if (!isLoading) {
currentStart = currentStart + count; currentStart = currentStart + count;
loadServers(currentStart, count); loadServers(currentStart, count, searchTextView.getText().toString());
} }
} }
} }
@ -120,26 +136,29 @@ public class SearchServerActivity extends CommonActivity {
// Refresh items // Refresh items
if (!isLoading) { if (!isLoading) {
currentStart = 0; currentStart = 0;
loadServers(currentStart, count); loadServers(currentStart, count, searchTextView.getText().toString());
} }
}); });
} }
private void loadServers(int start, int count, String searchtext) {
private void loadServers(int start, int count) {
isLoading = true; isLoading = true;
GetServerListDataService service = RetrofitInstance.getRetrofitInstance( GetServerListDataService service = RetrofitInstance.getRetrofitInstance(
APIUrlHelper.getServerIndexUrl(SearchServerActivity.this) APIUrlHelper.getServerIndexUrl(SearchServerActivity.this)
).create(GetServerListDataService.class); ).create(GetServerListDataService.class);
if ( !searchtext.equals( lastSearchtext ) )
{
currentStart = 0;
lastSearchtext = searchtext;
}
Call<ServerList> call; Call<ServerList> call;
call = service.getInstancesData(start, count); call = service.getInstancesData(start, count, searchtext);
Log.d("URL Called", call.request().url() + ""); Log.d("URL Called", call.request().url() + "");

View File

@ -27,7 +27,8 @@ public interface GetServerListDataService {
@GET("instances/") @GET("instances/")
Call<ServerList> getInstancesData( Call<ServerList> getInstancesData(
@Query("start") int start, @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" android:layout_height="match_parent"
tools:context=".activity.SearchServerActivity"> tools:context=".activity.SearchServerActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout <com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_server_selection" android:id="@+id/appbar_server_selection"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -29,11 +34,19 @@
android:text="@string/no_data_available" android:text="@string/no_data_available"
android:visibility="gone" /> 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 <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/serversSwipeRefreshLayout" android:id="@+id/serversSwipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_below="@+id/appbar_server_selection"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
@ -45,5 +58,5 @@
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </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_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_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_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="title_activity_account">Compte</string>
<string name="menu_video_more_report">Signaler</string> <string name="menu_video_more_report">Signaler</string>
<string name="menu_video_more_blacklist">Liste noire</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_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_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_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="title_activity_account">Account</string>
<string name="menu_video_more_report">Report</string> <string name="menu_video_more_report">Report</string>
<string name="menu_video_more_blacklist">Blacklist</string> <string name="menu_video_more_blacklist">Blacklist</string>