kopia lustrzana https://github.com/SP8EBC/MeteoSystem
sorting favourites list
rodzic
022016d605
commit
22d340efbd
|
@ -2,23 +2,45 @@ package cc.pogoda.mobile.pogodacc.activity;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import cc.pogoda.mobile.pogodacc.R;
|
||||
import cc.pogoda.mobile.pogodacc.adapter.WeatherStationRecyclerViewAdapter;
|
||||
import cc.pogoda.mobile.pogodacc.config.AppConfiguration;
|
||||
import cc.pogoda.mobile.pogodacc.type.ParceableFavsCallReason;
|
||||
import cc.pogoda.mobile.pogodacc.type.ParceableStationsList;
|
||||
import cc.pogoda.mobile.pogodacc.type.WeatherStation;
|
||||
|
||||
public class FavouritesActivity extends AppCompatActivity {
|
||||
|
||||
RecyclerView recyclerViewFavourites;
|
||||
|
||||
ParceableStationsList favourites;
|
||||
ParceableStationsList favourites, sortedFavourites;
|
||||
|
||||
boolean sorting = false;
|
||||
|
||||
WeatherStationRecyclerViewAdapter adapter = null;
|
||||
|
||||
ParceableFavsCallReason callReason;
|
||||
|
||||
private class WxStationComparator implements Comparator<WeatherStation> {
|
||||
|
||||
@Override
|
||||
public int compare(WeatherStation station, WeatherStation t1) {
|
||||
String name = station.getDisplayedName();
|
||||
String name1 = t1.getDisplayedName();
|
||||
|
||||
return (name.compareTo(name1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
@ -28,13 +50,49 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||
//return super.onOptionsItemSelected(item);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.fav_sort_alph_oder:
|
||||
sorting = true;
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
adapter = new WeatherStationRecyclerViewAdapter(sortedFavourites.getList(), this, callReason.getReason());
|
||||
|
||||
recyclerViewFavourites.setAdapter(adapter);
|
||||
}
|
||||
|
||||
break;
|
||||
case R.id.fav_sort_add_order:
|
||||
sorting = false;
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites.getList(), this, callReason.getReason());
|
||||
|
||||
recyclerViewFavourites.setAdapter(adapter);
|
||||
}
|
||||
|
||||
break;
|
||||
case R.id.fav_remove_noext:
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
favourites = getIntent().getParcelableExtra("favs");
|
||||
|
||||
ParceableFavsCallReason callReason = getIntent().getParcelableExtra("callReason");
|
||||
sortedFavourites = new ParceableStationsList(favourites);
|
||||
|
||||
sortedFavourites.getList().sort(new WxStationComparator());
|
||||
|
||||
callReason = getIntent().getParcelableExtra("callReason");
|
||||
|
||||
if (favourites == null || favourites.getList().size() == 0) {
|
||||
setContentView(R.layout.activity_favourites_empty);
|
||||
|
@ -45,8 +103,6 @@ public class FavouritesActivity extends AppCompatActivity {
|
|||
recyclerViewFavourites = findViewById(R.id.recyclerViewFavourites);
|
||||
|
||||
if (recyclerViewFavourites != null) {
|
||||
WeatherStationRecyclerViewAdapter adapter = null;
|
||||
|
||||
adapter = new WeatherStationRecyclerViewAdapter(favourites.getList(), this, callReason.getReason());
|
||||
|
||||
recyclerViewFavourites.setAdapter(adapter);
|
||||
|
|
|
@ -121,6 +121,11 @@ public class ParceableStationsList implements Parcelable {
|
|||
|
||||
}
|
||||
|
||||
public ParceableStationsList(ParceableStationsList in ) {
|
||||
this.list = new ArrayList<>(in.getList());
|
||||
this.listSize = this.list.size();
|
||||
}
|
||||
|
||||
public ParceableStationsList() {
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,13 @@
|
|||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:title="@string/sort_alphabetical" />
|
||||
<item android:title="@string/sort_in_adding_order" />
|
||||
<item android:title="@string/clear_from_non_existent" />
|
||||
<item
|
||||
android:id="@+id/fav_sort_alph_oder"
|
||||
android:title="@string/sort_alphabetical" />
|
||||
<item
|
||||
android:id="@+id/fav_sort_add_order"
|
||||
android:title="@string/sort_in_adding_order" />
|
||||
<item
|
||||
android:id="@+id/fav_remove_noext"
|
||||
android:title="@string/clear_from_non_existent" />
|
||||
</menu>
|
Ładowanie…
Reference in New Issue