Commit 0ba6782f authored by Fabius's avatar Fabius

Änderungswunsch Reihenfolg der Mensen/Cafeterien #16

parent c33045ee
...@@ -35,8 +35,12 @@ public class CanteenSettingsFragment extends PreferenceFragment implements Share ...@@ -35,8 +35,12 @@ public class CanteenSettingsFragment extends PreferenceFragment implements Share
private void load_ListPreferences(){ private void load_ListPreferences(){
ListPreference listPreference = (ListPreference)findPreference("canteens"); ListPreference listPreference = (ListPreference)findPreference("canteens");
//get Canteens //get Canteens
final List<Canteen> canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity()); List<Canteen> canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
//sort
//Sorts canteens like "Mensa, Cafeteria, Mensa, Cafeteria" (but the ugly way)
List<Canteen> canteens2 = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
String reichenhainer = "Reichenhainer";
String StraNa = "Straße der Nationen";
Collections.sort(canteens, new Comparator<Canteen>() { Collections.sort(canteens, new Comparator<Canteen>() {
@Override @Override
public int compare(Canteen canteen2, Canteen canteen1) { public int compare(Canteen canteen2, Canteen canteen1) {
...@@ -46,6 +50,22 @@ public class CanteenSettingsFragment extends PreferenceFragment implements Share ...@@ -46,6 +50,22 @@ public class CanteenSettingsFragment extends PreferenceFragment implements Share
return canteen1.getTitle().compareTo(canteen2.getTitle()); return canteen1.getTitle().compareTo(canteen2.getTitle());
} }
}); });
canteens2.clear();
for(Canteen canteen : canteens){
if(canteen.getTitle().contains(reichenhainer)){
canteens2.add(canteen);
}
}
for(Canteen canteen : canteens){
if(canteen.getTitle().contains(StraNa)){
canteens2.add(canteen);
}
}
canteens.clear();
canteens = canteens2;
CharSequence canteenTitels[] = new String[canteens.size()]; CharSequence canteenTitels[] = new String[canteens.size()];
CharSequence entryValues[] = new String[canteens.size()]; CharSequence entryValues[] = new String[canteens.size()];
int i = 0; int i = 0;
......
...@@ -14,6 +14,7 @@ import android.view.View; ...@@ -14,6 +14,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
...@@ -46,13 +47,17 @@ public class MensaFragment extends AbstractASiSTFragment { ...@@ -46,13 +47,17 @@ public class MensaFragment extends AbstractASiSTFragment {
adapter = new ViewPagerAdapter(getChildFragmentManager()); adapter = new ViewPagerAdapter(getChildFragmentManager());
//get Canteens //get Canteens
final List<Canteen> canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity()); List<Canteen> canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
if(canteens.size() == 0){ if(canteens.size() == 0){
if(canteens.size() == 0){ if(canteens.size() == 0){
Toast.makeText(getContext(),getText(R.string.module_canteen_noCanteen_found_toast),Toast.LENGTH_LONG).show(); Toast.makeText(getContext(),getText(R.string.module_canteen_noCanteen_found_toast),Toast.LENGTH_LONG).show();
} }
} }
//sort
//Sorts canteens like "Mensa, Cafeteria, Mensa, Cafeteria" (but the ugly way)
List<Canteen> canteens2 = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
String reichenhainer = "Reichenhainer";
String StraNa = "Straße der Nationen";
Collections.sort(canteens, new Comparator<Canteen>() { Collections.sort(canteens, new Comparator<Canteen>() {
@Override @Override
public int compare(Canteen canteen2, Canteen canteen1) { public int compare(Canteen canteen2, Canteen canteen1) {
...@@ -62,6 +67,34 @@ public class MensaFragment extends AbstractASiSTFragment { ...@@ -62,6 +67,34 @@ public class MensaFragment extends AbstractASiSTFragment {
return canteen1.getTitle().compareTo(canteen2.getTitle()); return canteen1.getTitle().compareTo(canteen2.getTitle());
} }
}); });
canteens2.clear();
for(Canteen canteen : canteens){
if(canteen.getTitle().contains(reichenhainer)){
canteens2.add(canteen);
}
}
for(Canteen canteen : canteens){
if(canteen.getTitle().contains(StraNa)){
canteens2.add(canteen);
}
}
canteens.clear();
canteens = canteens2;
/*
//sort the old way
Collections.sort(canteens, new Comparator<Canteen>() {
@Override
public int compare(Canteen canteen2, Canteen canteen1) {
if (canteen1 == null || canteen2 == null || canteen1.getTitle() == null) {
return 0;
}
return canteen2.getTitle().compareTo(canteen1.getTitle());
}
});
*/
for(int i = 0; i < canteens.size();i++){ for(int i = 0; i < canteens.size();i++){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment