Commit 816991a9 authored by Toni Beier's avatar Toni Beier

Merge branch 'FixesCanteen' into 'develop'

Fixes Canteen

See merge request OpenASiST/openasist4android_core!14
parents 5c00bca4 29a1f103
......@@ -14,6 +14,7 @@ import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
......@@ -89,6 +90,17 @@ public class ExpandableMensaList extends AbstractASiSTFragment {
daten = new ArrayList<String>();
menus = new HashMap<String, List<CanteenMenu>>();
List<CanteenMenu> firstMenuList = new ArrayList<CanteenMenu>();
firstMenuList.addAll(selectedCanteen.getMenuItems());
Date maxDate = Calendar.getInstance().getTime();
for(final CanteenMenu menu : firstMenuList){
Date maxDateTemp = menu.getDate();
if(maxDateTemp.compareTo(maxDate) > 0){
maxDate = maxDateTemp;
}
}
//Adding Daten
for(int i = 0;i < 5;i++){
if(calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY){
......@@ -99,8 +111,6 @@ public class ExpandableMensaList extends AbstractASiSTFragment {
add(calendar);
}
daten.add(cleanDate(calendar));
List<CanteenMenu> firstMenuList = new ArrayList<CanteenMenu>();
firstMenuList.addAll(selectedCanteen.getMenuItems());
//Sorts for Categorys (Menu 1 should be on top)
Collections.sort(firstMenuList, new Comparator<CanteenMenu>() {
......@@ -122,10 +132,13 @@ public class ExpandableMensaList extends AbstractASiSTFragment {
menuListWithMatchingDates.add(menu);
}
}
firstMenuList.clear();
add(calendar);
menus.put(daten.get(i), menuListWithMatchingDates);
String temp;
temp = cleanDate(calendar);
if(temp.compareTo(cleanDate(maxDate)) > 0) break;
}
firstMenuList.clear();
}
//Calendar goes one Day ahead
......@@ -152,4 +165,15 @@ public class ExpandableMensaList extends AbstractASiSTFragment {
return format.format(cal.getTime());
}
private String cleanDate(Date date){
SimpleDateFormat format = new SimpleDateFormat(DATE_Format);
return format.format(date.getTime());
}
@Override
public void onResume() {
super.onResume();
//Changes prices if settings change and gone back to MensaFragment
expandableMensaListAdapter.notifyDataSetChanged();
}
}
......@@ -32,6 +32,8 @@ public class MensaFragment extends AbstractASiSTFragment {
private ViewPager viewPager;
private ViewPagerAdapter adapter;
private List<Canteen> canteens;
public MensaFragment() {
// Required empty public constructor
}
......@@ -47,7 +49,7 @@ public class MensaFragment extends AbstractASiSTFragment {
adapter = new ViewPagerAdapter(getChildFragmentManager());
//get Canteens
List<Canteen> canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
canteens = CanteenDatabaseManager.getInstance().getAllCanteens(getActivity());
if(canteens.size() == 0){
if(canteens.size() == 0){
Toast.makeText(getContext(),getText(R.string.module_canteen_noCanteen_found_toast),Toast.LENGTH_LONG).show();
......@@ -114,11 +116,7 @@ public class MensaFragment extends AbstractASiSTFragment {
int limit = (adapter.getCount() > 1 ? adapter.getCount() - 1 : 1);
viewPager.setOffscreenPageLimit(limit);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//TODO replace Key
String canteen = sharedPreferences.getString("canteens",null);
viewPager.setCurrentItem(getIndexItemLocation(canteen,canteens));
return view;
}
......@@ -147,4 +145,15 @@ public class MensaFragment extends AbstractASiSTFragment {
}
return 0;
}
@Override
public void onResume() {
super.onResume();
//Goes to in Preferences used Tab
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
//TODO replace Key
String canteen = sharedPreferences.getString("canteens",null);
viewPager.setCurrentItem(getIndexItemLocation(canteen,canteens));
}
}
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/defaultColor"
android:state_selected="true"/>
<item android:drawable="@color/backgroundColor"/>
</selector>
\ No newline at end of file
......@@ -14,7 +14,7 @@
app:tabMode="scrollable"
app:tabGravity="center"
android:textAlignment="center"
app:tabBackground="@color/defaultTitleColor"/>
app:tabBackground="@color/tab_background_color_selector"/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
......
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