kopia lustrzana https://github.com/SP8EBC/MeteoSystem
feat: Search view in all station activity (#4)
* feat: Search view in all station activity * Fix searchbar width and animationmaster
rodzic
a2dd3149e9
commit
4c3b17fbfe
|
@ -40,12 +40,19 @@
|
|||
<activity android:name=".activity.StationDetailsPlotsHumidity" />
|
||||
<activity android:name=".activity.StationDetailsSummaryActivity" />
|
||||
<activity android:name=".activity.StationDetailsActivity" />
|
||||
<activity android:name=".activity.AllStationsActivity" />
|
||||
<activity
|
||||
android:name=".activity.AllStationsActivity"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.SEARCH" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
<activity android:name=".activity.FavouritesActivity" />
|
||||
<activity android:name=".activity.MainActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
|
|
@ -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<WeatherStation> allStationsList = new LinkedList<>();
|
||||
private List<WeatherStation> 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<WeatherStation> 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<WeatherStation> 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());
|
||||
}
|
||||
|
|
|
@ -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<Recy
|
|||
}
|
||||
}
|
||||
|
||||
public void update(@NonNull List<WeatherStation> 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
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M15.5,14h-0.79l-0.28,-0.27C15.41,12.59 16,11.11 16,9.5 16,5.91 13.09,3 9.5,3S3,5.91 3,9.5 5.91,16 9.5,16c1.61,0 3.09,-0.59 4.23,-1.57l0.27,0.28v0.79l5,4.99L20.49,19l-4.99,-5zM9.5,14C7.01,14 5,11.99 5,9.5S7.01,5 9.5,5 14,7.01 14,9.5 11.99,14 9.5,14z"/>
|
||||
</vector>
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:id="@+id/search"
|
||||
android:title="@string/search_bar"
|
||||
android:icon="@drawable/ic_search"
|
||||
app:actionViewClass="android.widget.SearchView"
|
||||
app:showAsAction="always" />
|
||||
|
||||
</menu>
|
|
@ -118,4 +118,6 @@
|
|||
<string name="all_station_empty_list2">Proszę poczekać lub pociągnąć w dół aby odświeżyć.</string>
|
||||
<string name="please_wait">Proszę czekać</string>
|
||||
<string name="loading">Ładowanie...</string>
|
||||
<string name="search_for_station">Wyszukaj stacji</string>
|
||||
<string name="search_bar">Wyszukaj</string>
|
||||
</resources>
|
|
@ -118,4 +118,6 @@
|
|||
<string name="all_stations_empty_list1">There are no stations on this list.</string>
|
||||
<string name="all_station_empty_list2">Please wait or pull down to refresh list.</string>
|
||||
<string name="loading">Ładowanie...</string>
|
||||
<string name="search_for_station">Wyszukaj stacji</string>
|
||||
<string name="search_bar">Wyszukaj</string>
|
||||
</resources>
|
|
@ -150,4 +150,6 @@
|
|||
<string name="please_wait">Please Wait</string>
|
||||
<string name="loading">Loading...</string>
|
||||
<string name="credits_2_rafal" translatable="false">Rafał Woloszyn</string>
|
||||
<string name="search_for_station">Search for station</string>
|
||||
<string name="search_bar">Search</string>
|
||||
</resources>
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:label="@string/app_name"
|
||||
android:hint="@string/search_for_station" />
|
Ładowanie…
Reference in New Issue