diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 30dc261..4351582 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -40,12 +40,19 @@
-
+
+
+
+
+
+
-
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
index e91a1e2..cc47cd8 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/activity/AllStationsActivity.java
@@ -1,6 +1,12 @@
package cc.pogoda.mobile.meteosystem.activity;
+import android.app.SearchManager;
+import android.content.Context;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.Menu;
+import android.view.MenuInflater;
+import android.widget.SearchView;
import android.widget.Toast;
import androidx.annotation.NonNull;
@@ -15,6 +21,8 @@ import org.greenrobot.eventbus.ThreadMode;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
+import java.util.stream.Collectors;
import cc.pogoda.mobile.meteosystem.Main;
import cc.pogoda.mobile.meteosystem.R;
@@ -26,7 +34,7 @@ import cc.pogoda.mobile.meteosystem.type.WeatherStation;
public class AllStationsActivity extends AppCompatActivity {
- private final List allStationsList = new LinkedList<>();
+ private List allStationsList;
private SwipeRefreshLayout refreshLayout;
private WeatherStationRecyclerViewAdapter adapter;
@@ -43,9 +51,33 @@ public class AllStationsActivity extends AppCompatActivity {
RecyclerView recyclerViewAllStations = findViewById(R.id.recyclerViewAllStations);
adapter = new WeatherStationRecyclerViewAdapter(
- allStationsList, this, ParceableFavsCallReason.Reason.ALL_STATIONS);
+ new LinkedList<>(), this, ParceableFavsCallReason.Reason.ALL_STATIONS);
recyclerViewAllStations.setAdapter(adapter);
recyclerViewAllStations.setLayoutManager(new LinearLayoutManager(this));
+
+ handleIntent(getIntent());
+ }
+
+
+ private void handleIntent(Intent intent) {
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ filterStationList(query);
+ }
+ }
+
+ private void filterStationList(String searchQuery) {
+ if (allStationsList == null || allStationsList.isEmpty())
+ return;
+
+ if(searchQuery.isEmpty())
+ adapter.update(allStationsList);
+
+ List newList = allStationsList.stream()
+ .filter(station -> station.getDisplayedName()
+ .toLowerCase(Locale.ROOT).contains(searchQuery.toLowerCase(Locale.ROOT)))
+ .collect(Collectors.toList());
+ adapter.update(newList);
}
@Override
@@ -61,12 +93,47 @@ public class AllStationsActivity extends AppCompatActivity {
EventBus.getDefault().unregister(this);
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.main_activity_all_stations, menu);
+
+ // Associate searchable configuration with the SearchView
+ SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView =
+ (SearchView) menu.findItem(R.id.search).getActionView();
+ searchView.setSearchableInfo(
+ searchManager.getSearchableInfo(getComponentName()));
+ searchView.setMaxWidth(Integer.MAX_VALUE);
+
+ searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){
+
+ @Override
+ public boolean onQueryTextSubmit(String s) {
+ return false;
+ }
+
+ @Override
+ public boolean onQueryTextChange(String s) {
+ filterStationList(s);
+ return false;
+ }
+ });
+
+ searchView.setOnCloseListener(() -> {
+ adapter.update(allStationsList);
+ return false;
+ });
+
+ return true;
+ }
+
private void updateStationList(List stations) {
if (stations != null) {
- allStationsList.clear();
- allStationsList.addAll(stations);
refreshLayout.setRefreshing(false);
- adapter.notifyDataSetChanged();
+ allStationsList = stations;
+ adapter.update(stations);
} else {
EventBus.getDefault().post(new StartStationsRefreshEvent());
}
diff --git a/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java b/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
index cd47ba1..f1a0c4c 100644
--- a/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
+++ b/app/src/main/java/cc/pogoda/mobile/meteosystem/adapter/WeatherStationRecyclerViewAdapter.java
@@ -21,8 +21,6 @@ import cc.pogoda.mobile.meteosystem.R;
import cc.pogoda.mobile.meteosystem.activity.handler.AllStationsActRecyclerViewButtonClickEvent;
import cc.pogoda.mobile.meteosystem.activity.updater.FavouritesStationDetailsOnListUpdater;
import cc.pogoda.mobile.meteosystem.activity.view.AllStationsActRecyclerViewHolder;
-import cc.pogoda.mobile.meteosystem.dao.AvailableParametersDao;
-import cc.pogoda.mobile.meteosystem.dao.SummaryDao;
import cc.pogoda.mobile.meteosystem.type.ParceableFavsCallReason;
import cc.pogoda.mobile.meteosystem.type.WeatherStation;
@@ -144,6 +142,12 @@ public class WeatherStationRecyclerViewAdapter extends RecyclerView.Adapter updatedStations) {
+ stations.clear();
+ stations.addAll(updatedStations);
+ notifyDataSetChanged();
+ }
+
@Override
public int getItemCount() {
// In case of empty station list at least 1 should be returned to properly select view type
diff --git a/app/src/main/res/drawable/ic_search.xml b/app/src/main/res/drawable/ic_search.xml
new file mode 100644
index 0000000..e2dd96c
--- /dev/null
+++ b/app/src/main/res/drawable/ic_search.xml
@@ -0,0 +1,5 @@
+
+
+
diff --git a/app/src/main/res/menu/main_activity_all_stations.xml b/app/src/main/res/menu/main_activity_all_stations.xml
new file mode 100644
index 0000000..4c483da
--- /dev/null
+++ b/app/src/main/res/menu/main_activity_all_stations.xml
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values-pl-rPL/strings.xml b/app/src/main/res/values-pl-rPL/strings.xml
index e16ee9e..469d15a 100644
--- a/app/src/main/res/values-pl-rPL/strings.xml
+++ b/app/src/main/res/values-pl-rPL/strings.xml
@@ -118,4 +118,6 @@
Proszę poczekać lub pociągnąć w dół aby odświeżyć.
Proszę czekać
Ładowanie...
+ Wyszukaj stacji
+ Wyszukaj
\ No newline at end of file
diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml
index e4c68b0..618c01c 100644
--- a/app/src/main/res/values-pl/strings.xml
+++ b/app/src/main/res/values-pl/strings.xml
@@ -118,4 +118,6 @@
There are no stations on this list.
Please wait or pull down to refresh list.
Ładowanie...
+ Wyszukaj stacji
+ Wyszukaj
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 83a7415..9f62e33 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -150,4 +150,6 @@
Please Wait
Loading...
Rafał Woloszyn
+ Search for station
+ Search
\ No newline at end of file
diff --git a/app/src/main/res/xml/searchable.xml b/app/src/main/res/xml/searchable.xml
new file mode 100644
index 0000000..0bd8319
--- /dev/null
+++ b/app/src/main/res/xml/searchable.xml
@@ -0,0 +1,5 @@
+
+
+