Merge remote-tracking branch 'origin/master'

This commit is contained in:
Joshua
2018-08-15 12:26:48 +02:00
41 changed files with 404 additions and 418 deletions

BIN
app/src/main/ic_bio-web.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
app/src/main/ic_msc-web.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

View File

@@ -2,19 +2,30 @@ package de.sebse.fuplanner.fragments.canteen;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.services.Canteen.types.Day;
import de.sebse.fuplanner.services.Canteen.types.Meal;
import de.sebse.fuplanner.tools.Preferences;
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
import de.sebse.fuplanner.tools.ui.MealViewHolder;
import de.sebse.fuplanner.tools.ui.StringViewHolder;
class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private String[] CATEGORY_KEYS = new String[]{"Essen", "Aktionen", "Beilagen", "Desserts", "Salate", "Suppen", "Vorspeisen"};
@StringRes
private int[] CATEGORY_VALS = new int[]{R.string.meals, R.string.special_meals, R.string.side_dishes, R.string.desserts, R.string.salats, R.string.soups, R.string.starters};
@StringRes
private int CATEGORY_OTHER = R.string.others;
private ArrayList<Object> matchings = new ArrayList<>();
private Day mDay = null;
private final Context mContext;
@@ -25,15 +36,24 @@ class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
@NonNull
@Override
public MealViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
if (viewType == 0) {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_canteen_items, viewGroup, false);
return new MealViewHolder(view);
} else {
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.list_all_caption, viewGroup, false);
return new StringViewHolder(view);
}
}
@Override
public void onBindViewHolder(@NonNull MealViewHolder viewHolder, int i) {
Meal meal = getItem(i);
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == 0) {
MealViewHolder viewHolder = ((MealViewHolder) holder);
viewHolder.reset();
Meal meal = getMeal(position);
viewHolder.mTitle.setText(meal.getName());
String value;
switch (Preferences.getString(mContext, R.array.pref_price_group)) {
@@ -50,130 +70,84 @@ class MealAdapter extends RecyclerView.Adapter<MealViewHolder> {
value = mContext.getString(R.string.prices, meal.getPriceStdnt(), meal.getPriceEmply(), meal.getPriceOther());
}
viewHolder.mSubTitle.setText(value);
StringBuilder string = new StringBuilder();
List<String> notes = meal.getNotes();
for (int i1 = 0, notesSize = notes.size(); i1 < notesSize; i1++) {
if (i1 != 0)
string.append("\n");
String s = notes.get(i1);
string.append(" - ").append(s);
}
viewHolder.mNotes.setText(string.toString());
viewHolder.mCategory.setText(meal.getCategory());
viewHolder.mIconVegan.setVisibility(meal.getVegan() == Meal.VEGAN_VEGAN ? View.VISIBLE : View.GONE);
viewHolder.mIconVegetarian.setVisibility(meal.getVegan() == Meal.VEGAN_VEGETERIAN ? View.VISIBLE : View.GONE);
viewHolder.mIconBio.setVisibility((meal.getCertificates() & Meal.CERT_BIO) != 0 ? View.VISIBLE : View.GONE);
viewHolder.mIconMsc.setVisibility((meal.getCertificates() & Meal.CERT_MSC) != 0 ? View.VISIBLE : View.GONE);
} else {
StringViewHolder viewHolder = ((StringViewHolder) holder);
viewHolder.mString.setText(getHeading(position));
}
public Meal getItem(int groupPosition) {
if (this.mDay != null)
return this.mDay.get(groupPosition);
else
return null;
}
@Override
public int getItemCount() {
return matchings.size();
}
@Override
public int getItemViewType(int position) {
return matchings.get(position) instanceof String ? 1 : 0;
}
public Meal getMeal(int position) {
if (this.mDay != null)
return this.mDay.size();
else
return 0;
}
/*@Override
public String getChild(int groupPosition, int childPosititon) {
StringBuilder sb = new StringBuilder();
sb.append("\n\n");
for (String s : this.getGroup(groupPosition).getNotes())
{
sb.append(s);
sb.append("\n\n");
}
return sb.toString();
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public View getChildView(int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
final String childText = getChild(groupPosition, childPosition);
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_all_string, parent, false);
}
StringViewHolder itemHolder = new StringViewHolder(convertView);
itemHolder.mString.setText(childText);
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
return 1;
}
@Override
public Meal getGroup(int groupPosition) {
if (this.mDay != null)
return this.mDay.get(groupPosition);
return this.mDay.get((Integer) matchings.get(position));
else
return null;
}
@Override
public int getGroupCount() {
if (this.mDay != null)
return this.mDay.size();
else
return 0;
public String getHeading(int position) {
return (String) matchings.get(position);
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
Meal meal = getGroup(groupPosition);
if (convertView == null) {
convertView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_canteen_items, parent, false);
}
ItemViewHolder itemHolder = new ItemViewHolder(convertView);
//itemHolder.mTitle.setText(meal.getName());
//itemHolder.mSubLeft.setText(meal.getCategory());
String value;
switch (Preferences.getString(mContext, R.array.pref_price_group)) {
case "student":
value = mContext.getString(R.string.price, meal.getPriceStdnt());
break;
case "employee":
value = mContext.getString(R.string.price, meal.getPriceEmply());
break;
case "other":
value = mContext.getString(R.string.price, meal.getPriceOther());
break;
default:
value = mContext.getString(R.string.prices, meal.getPriceStdnt(), meal.getPriceEmply(), meal.getPriceOther());
}
//itemHolder.mSubRight.setText(value);
return convertView;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}*/
public void setDay(Day day) {
this.mDay = day;
this.setDay();
}
public void setDay() {
HashMap<String, ArrayList<Integer>> map = new HashMap<>();
for (int i = 0; i < this.mDay.size(); i++) {
String category = this.mDay.get(i).getCategory();
boolean found = false;
for (String category_key : CATEGORY_KEYS) {
if (category_key.equals(category)) {
found = true;
break;
}
}
if (!found) category = "---";
ArrayList<Integer> list = map.get(category);
if (list == null) {
list = new ArrayList<>();
map.put(category, list);
}
list.add(i);
}
matchings.clear();
for (int i = 0; i < CATEGORY_KEYS.length; i++) {
ArrayList<Integer> list = map.get(CATEGORY_KEYS[i]);
if (list != null) {
matchings.add(mContext.getString(CATEGORY_VALS[i]));
matchings.addAll(list);
}
}
ArrayList<Integer> list = map.get("---");
if (list != null) {
matchings.add(mContext.getString(CATEGORY_OTHER));
matchings.addAll(list);
}
this.notifyDataSetChanged();
}
}

View File

@@ -16,6 +16,7 @@ import de.sebse.fuplanner.services.KVV.types.Modules;
import de.sebse.fuplanner.tools.UtilsDate;
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
import de.sebse.fuplanner.tools.ui.StringViewHolder;
class ModDetailEventAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_HEADER = 0;
@@ -61,7 +62,7 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
case TYPE_HEADER:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_all_caption, parent, false);
return new HeaderViewHolder(view);
return new StringViewHolder(view);
case TYPE_ITEM:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_all_items, parent, false);
@@ -87,13 +88,13 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
Pair<Integer, Integer> data = mPositionalData.get(position);
switch (data.first) {
case TYPE_HEADER:
HeaderViewHolder h = (HeaderViewHolder) holder;
StringViewHolder h = (StringViewHolder) holder;
switch (data.second) {
case SECTION_PAST:
h.mCaption.setText(R.string.past_events);
h.mString.setText(R.string.past_events);
break;
case SECTION_UPCOMING:
h.mCaption.setText(R.string.upcoming_events);
h.mString.setText(R.string.upcoming_events);
break;
}
break;
@@ -145,27 +146,4 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
return mValue.events.sizePast();
return 0;
}
class HeaderViewHolder extends CustomViewHolder {
final TextView mCaption;
HeaderViewHolder(View view) {
super(view);
mCaption = view.findViewById(R.id.caption);
}
@Override
public String toString() {
return super.toString() + " '" + mCaption.getText() + "'";
}
}
}

View File

@@ -15,6 +15,7 @@ import de.sebse.fuplanner.R;
import de.sebse.fuplanner.services.KVV.types.Gradebook;
import de.sebse.fuplanner.services.KVV.types.Modules;
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
import de.sebse.fuplanner.tools.ui.StringViewHolder;
class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int TYPE_TOTAL = 0;
@@ -58,7 +59,7 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
case TYPE_TOTAL:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_all_caption, parent, false);
return new HeaderViewHolder(view);
return new StringViewHolder(view);
case TYPE_GRADE:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_moddetails_gradebook, parent, false);
@@ -85,8 +86,8 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
Pair<Integer, Integer> data = mPositionalData.get(position);
switch (data.first) {
case TYPE_TOTAL:
HeaderViewHolder h = (HeaderViewHolder) holder;
h.mCaption.setText(h.mView.getResources().getString(R.string.current_percentage, mValue.getGradebookPercent()*100));
StringViewHolder h = (StringViewHolder) holder;
h.mString.setText(h.mView.getResources().getString(R.string.current_percentage, mValue.getGradebookPercent()*100));
break;
case TYPE_GRADE:
int index = data.second / 1024;
@@ -118,20 +119,6 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
class HeaderViewHolder extends CustomViewHolder {
final TextView mCaption;
HeaderViewHolder(View view) {
super(view);
mCaption = view.findViewById(R.id.caption);
}
@Override
public String toString() {
return super.toString() + " '" + mCaption.getText() + "'";
}
}
private class GradebookViewHolder extends RecyclerView.ViewHolder {
private final TextView mGrade;

View File

@@ -22,6 +22,7 @@ import de.sebse.fuplanner.tools.UtilsDate;
import de.sebse.fuplanner.tools.logging.Logger;
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
import de.sebse.fuplanner.tools.ui.StringViewHolder;
class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private static final int MAX_ITEMS_PER_PREVIEW = 2;
@@ -77,7 +78,7 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
case TYPE_HEADER:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_all_caption, parent, false);
return new HeaderViewHolder(view);
return new StringViewHolder(view);
case TYPE_DESCRIPTION:
view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.list_moddetails_description, parent, false);
@@ -111,19 +112,19 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
Pair<Integer, Object> data = mPositionalData.get(position);
switch (data.first) {
case TYPE_HEADER:
HeaderViewHolder h = (HeaderViewHolder) holder;
StringViewHolder h = (StringViewHolder) holder;
switch ((Integer) data.second) {
case ModulePart.DESCRIPTION:
h.mCaption.setText(R.string.description);
h.mString.setText(R.string.description);
break;
case ModulePart.ANNOUNCEMENT:
h.mCaption.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
h.mString.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
break;
case ModulePart.ASSIGNMENT:
h.mCaption.setText(h.mView.getResources().getString(R.string.assignments_count, getAssignmentCount()));
h.mString.setText(h.mView.getResources().getString(R.string.assignments_count, getAssignmentCount()));
break;
case ModulePart.EVENT:
h.mCaption.setText(h.mView.getResources().getString(R.string.upcoming_events_count, getEventsCount()));
h.mString.setText(h.mView.getResources().getString(R.string.upcoming_events_count, getEventsCount()));
break;
}
break;
@@ -221,19 +222,7 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
class HeaderViewHolder extends CustomViewHolder {
final TextView mCaption;
HeaderViewHolder(View view) {
super(view);
mCaption = view.findViewById(R.id.caption);
}
@Override
public String toString() {
return super.toString() + " '" + mCaption.getText() + "'";
}
}
class DescriptionViewHolder extends CustomViewHolder {
final ExpandableTextView mText;

View File

@@ -1,10 +1,9 @@
package de.sebse.fuplanner.services.KVV;
import android.content.Context;
import android.text.Html;
import android.util.Pair;
import net.htmlparser.jericho.Source;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -108,7 +107,7 @@ class KVVModuleList extends HTTPService {
}
String type = site.getJSONObject("props").getString("kvv_coursetype");
String description = site.getString("description");
description = new Source(description).getRenderer().toString();
description = String.valueOf(Html.fromHtml(description));
String id = site.getString("id");
modules.addModule(semester, lvNumbers, title, lecturers, type, description, id);
}
@@ -224,7 +223,7 @@ class KVVModuleList extends HTTPService {
String id = site.getString("announcementId");
String title = site.getString("title");
String text = site.getString("body");
text = new Source(text).getRenderer().toString();
text = String.valueOf(Html.fromHtml(text));
String createdBy = site.getString("createdByDisplayName");
long createdOn = site.getLong("createdOn");
@@ -293,7 +292,7 @@ class KVVModuleList extends HTTPService {
String id = site.getString("id");
String title = site.getString("title");
String instructions = site.getString("instructions");
instructions = new Source(instructions).getRenderer().toString();
instructions = String.valueOf(Html.fromHtml(instructions));
long dueTime = site.getJSONObject("dueTime").getLong("time");
String gradebookItemName = site.optString("gradebookItemName", null);
String gradeScale = site.getString("gradeScale");

View File

@@ -31,8 +31,8 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
@Override
public T get(int index) {
if (split < 0)
sort();
//if (split < 0)
// sort();
if (reversed())
index = size() - index - 1;
return super.get(index);

View File

@@ -10,10 +10,14 @@ public class Logger {
}
public Logger(Object object) {
this.tag = getClassName(object);
}
public static String getClassName(Object object) {
if (object instanceof String)
this.tag = (String) object;
return (String) object;
else
this.tag = object.getClass().getSimpleName();
return object.getClass().getSimpleName();
}
public void d(Object... msg) {

View File

@@ -0,0 +1,27 @@
package de.sebse.fuplanner.tools.ui;
import android.view.View;
import de.sebse.fuplanner.tools.ui.cardview.ExpandableCardView;
public class ExpandableCardViewHolder extends CustomViewHolder {
ExpandableCardViewHolder(View view) {
super(view);
}
public void reset() {
getView().reset();
}
ExpandableCardView getView() {
return (ExpandableCardView) mView;
}
View getOuterView() {
return getView().getOuterView();
}
View getInnerView() {
return getView().getInnerView();
}
}

View File

@@ -1,19 +1,40 @@
package de.sebse.fuplanner.tools.ui;
import android.media.Image;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import de.sebse.fuplanner.R;
import org.w3c.dom.Text;
public class MealViewHolder extends CustomViewHolder {
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.tools.logging.Logger;
import de.sebse.fuplanner.tools.ui.cardview.ExpandableCardView;
public class MealViewHolder extends ExpandableCardViewHolder {
public final TextView mTitle;
public final TextView mSubTitle;
public final TextView mCategory;
public final TextView mNotes;
public final ImageView mIconVegan;
public final ImageView mIconVegetarian;
public final ImageView mIconBio;
public final ImageView mIconMsc;
public MealViewHolder(View view) {
super(view);
mTitle = view.findViewById(R.id.title);
mSubTitle = view.findViewById(R.id.sub_title);
View outerView = getOuterView();
View innerView = getInnerView();
mTitle = outerView.findViewById(R.id.title);
mSubTitle = outerView.findViewById(R.id.sub_title);
mNotes = innerView.findViewById(R.id.notes);
mCategory = innerView.findViewById(R.id.category);
mIconVegan = innerView.findViewById(R.id.icon_vegan);
mIconVegetarian = innerView.findViewById(R.id.icon_vegetarian);
mIconBio = innerView.findViewById(R.id.icon_bio);
mIconMsc = innerView.findViewById(R.id.icon_msc);
}
@Override

View File

@@ -3,27 +3,22 @@ package de.sebse.fuplanner.tools.ui.cardview;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.CardView;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.view.animation.Transformation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.tools.UtilsUi;
import de.sebse.fuplanner.tools.logging.Logger;
/**
*
@@ -46,21 +41,13 @@ import de.sebse.fuplanner.tools.UtilsUi;
* @author Alessandro Sperotti
*/
public class ExpandableCardView extends LinearLayout {
private String title;
private ViewGroup containerView;
private ImageButton arrowBtn;
//private ImageButton headerIcon;
//private TextView textViewTitle;
public class ExpandableCardView extends CardView {
private int innerViewRes;
private int outerViewRes;
//private Drawable iconDrawable;
private CardView card;
private View innerView;
private View outerView;
private ImageButton imageButton;
public static final int DEFAULT_ANIM_DURATION = 350;
private long animDuration = DEFAULT_ANIM_DURATION;
@@ -71,10 +58,10 @@ public class ExpandableCardView extends LinearLayout {
private boolean isExpanded = false;
private boolean isExpanding = false;
private boolean isCollapsing = false;
private boolean expandOnClick = false;
private boolean startExpanded = false;
private int previousHeight = 0;
private int collapsedHeight = 0;
private int expandedHeight = 0;
private OnExpandedListener listener;
@@ -82,9 +69,11 @@ public class ExpandableCardView extends LinearLayout {
if(isExpanded()) collapse();
else expand();
};
private Logger log = new Logger(this);
public ExpandableCardView(Context context) {
super(context);
initView(context);
}
public ExpandableCardView(Context context, AttributeSet attrs) {
@@ -103,19 +92,27 @@ public class ExpandableCardView extends LinearLayout {
private void initView(Context context){
//Inflating View
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (inflater == null) throw new AssertionError();
inflater.inflate(R.layout.expandable_cardview, this);
imageButton = new ImageButton(context);
imageButton.setImageDrawable(getResources().getDrawable(R.drawable.arrow_down));
imageButton.setPadding(
(int) UtilsUi.convertDpToPixels(getContext(), 10),
(int) UtilsUi.convertDpToPixels(getContext(), 10),
(int) UtilsUi.convertDpToPixels(getContext(), 10),
(int) UtilsUi.convertDpToPixels(getContext(), 10)
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
imageButton.setBackgroundResource(outValue.resourceId);
}
isExpanded = startExpanded;
}
private void initAttributes(Context context, AttributeSet attrs){
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableCardView);
title = typedArray.getString(R.styleable.ExpandableCardView_title);
//iconDrawable = typedArray.getDrawable(R.styleable.ExpandableCardView_icon);
innerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_inner_view, View.NO_ID);
outerViewRes = typedArray.getResourceId(R.styleable.ExpandableCardView_outer_view, View.NO_ID);
expandOnClick = typedArray.getBoolean(R.styleable.ExpandableCardView_expandOnClick, false);
animDuration = typedArray.getInteger(R.styleable.ExpandableCardView_animationDuration, DEFAULT_ANIM_DURATION);
startExpanded = typedArray.getBoolean(R.styleable.ExpandableCardView_startExpanded, false);
typedArray.recycle();
@@ -125,69 +122,91 @@ public class ExpandableCardView extends LinearLayout {
protected void onFinishInflate() {
super.onFinishInflate();
arrowBtn = findViewById(R.id.arrow);
//textViewTitle = findViewById(R.id.title);
//headerIcon = findViewById(R.id.icon);
//Setting attributes
/*if(!TextUtils.isEmpty(title)) textViewTitle.setText(title);
if(iconDrawable != null){
headerIcon.setVisibility(VISIBLE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
headerIcon.setBackground(iconDrawable);
}
}*/
card = findViewById(R.id.card);
setInnerView(innerViewRes);
setOuterView(outerViewRes);
containerView = findViewById(R.id.viewContainer);
innerView = inflateChild(innerViewRes);
outerView = inflateChild(outerViewRes);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setElevation(UtilsUi.convertDpToPixels(getContext(), 4));
}
if(startExpanded){
setAnimDuration(0);
expand();
setAnimDuration(animDuration);
setOnClickListener(defaultClickListener);
}
if(expandOnClick){
card.setOnClickListener(defaultClickListener);
arrowBtn.setOnClickListener(defaultClickListener);
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
removeAllViews();
int x = getPaddingLeft();
int y = getPaddingTop();
addView(outerView);
outerView.layout(x, y, x+outerView.getMeasuredWidth(), y+outerView.getMeasuredHeight());
addView(imageButton);
imageButton.layout(
getMeasuredWidth() - getPaddingRight() - imageButton.getMeasuredWidth(),
y,
getMeasuredWidth() - getPaddingRight(),
y+imageButton.getMeasuredHeight()
);
addView(innerView);
innerView.layout(x, y+outerView.getMeasuredHeight(), x+innerView.getMeasuredWidth(), y+outerView.getMeasuredHeight()+innerView.getMeasuredHeight());
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//log.d("w", MeasureSpec.toString(widthMeasureSpec));
//log.d("h", MeasureSpec.toString(heightMeasureSpec));
if (MeasureSpec.getSize(widthMeasureSpec) == 0 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED || MeasureSpec.getSize(heightMeasureSpec) == 0 && MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.UNSPECIFIED) {
log.w("This should not happen! Invalid dimension size");
setMeasuredDimension(reconcileSize(10, widthMeasureSpec), reconcileSize(10, heightMeasureSpec));
return;
}
int desiredWidth;
int desiredHeight;
int widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
int heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
imageButton.measure(widthMeasure, heightMeasure);
widthMeasure = atMostExactlySpec(Math.max(0, MeasureSpec.getSize(widthMeasureSpec)-imageButton.getMeasuredWidth()), widthMeasureSpec);
heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
outerView.measure(widthMeasure, heightMeasure);
desiredWidth = imageButton.getMeasuredWidth() + outerView.getMeasuredWidth();
desiredHeight = Math.max(imageButton.getMeasuredHeight(), outerView.getMeasuredHeight());
widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
heightMeasure = atMostSpec(Math.max(0, MeasureSpec.getSize(heightMeasureSpec)-desiredHeight), heightMeasureSpec);
innerView.measure(widthMeasure, heightMeasure);
desiredWidth = Math.max(desiredWidth, innerView.getMeasuredWidth());
desiredHeight += innerView.getMeasuredHeight();
desiredWidth += getPaddingLeft() + getPaddingRight();
desiredHeight += getPaddingTop() + getPaddingBottom();
if (MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
expandedHeight = desiredHeight;
collapsedHeight = desiredHeight - innerView.getMeasuredHeight();
}
setMeasuredDimension(reconcileSize(desiredWidth, widthMeasureSpec), reconcileSize(isExpanded ? expandedHeight : collapsedHeight, heightMeasureSpec));
}
public void expand() {
final int initialHeight = card.getHeight();
if(!isMoving()) {
previousHeight = initialHeight;
}
card.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
int targetHeight = card.getMeasuredHeight();
final int initialHeight = this.getHeight();
int targetHeight = expandedHeight;
//innerView.measure(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
//log.d(targetHeight, outerView.getHeight(), innerView.getHeight(), innerView.getMeasuredHeight());
if(targetHeight - initialHeight != 0) {
animateViews(initialHeight,
targetHeight - initialHeight,
EXPANDING);
animateViews(initialHeight, targetHeight - initialHeight, EXPANDING);
}
}
public void collapse() {
int initialHeight = card.getMeasuredHeight();
final int initialHeight = this.getHeight();
int targetHeight = collapsedHeight;
if(initialHeight - previousHeight != 0) {
animateViews(initialHeight,
initialHeight - previousHeight,
COLLAPSING);
if(initialHeight - targetHeight != 0) {
animateViews(initialHeight, initialHeight - targetHeight, COLLAPSING);
}
}
@@ -207,21 +226,17 @@ public class ExpandableCardView extends LinearLayout {
isCollapsing = false;
if (listener != null) {
if(animationType == EXPANDING){
listener.onExpandChanged(card,true);
}
else{
listener.onExpandChanged(card,false);
}
if (animationType == EXPANDING)
listener.onExpandChanged(ExpandableCardView.this, true);
else
listener.onExpandChanged(ExpandableCardView.this, false);
}
}
card.getLayoutParams().height = animationType == EXPANDING ? (int) (initialHeight + (distance * interpolatedTime)) :
(int) (initialHeight - (distance * interpolatedTime));
card.findViewById(R.id.viewContainer).requestLayout();
containerView.getLayoutParams().height = animationType == EXPANDING ? (int) (initialHeight + (distance * interpolatedTime)) :
(int) (initialHeight - (distance * interpolatedTime));
ExpandableCardView.this.getLayoutParams().height = animationType == EXPANDING
? (int) (initialHeight + (distance * interpolatedTime))
: (int) (initialHeight - (distance * interpolatedTime));
ExpandableCardView.this.requestLayout();
}
@@ -247,8 +262,7 @@ public class ExpandableCardView extends LinearLayout {
isCollapsing = animationType == COLLAPSING;
startAnimation(expandAnimation);
//Log.d("SO","Started animation: "+ (animationType == EXPANDING ? "Expanding" : "Collapsing"));
arrowBtn.startAnimation(arrowAnimation);
imageButton.startAnimation(arrowAnimation);
isExpanded = animationType == EXPANDING;
}
@@ -273,48 +287,21 @@ public class ExpandableCardView extends LinearLayout {
this.listener = null;
}
/*public void setTitle(String title){
if(textViewTitle != null) textViewTitle.setText(title);
private View inflateChild(@LayoutRes int resId) {
return inflate(getContext(), resId, null);
}
public void setTitle(int resId){
if(textViewTitle != null) textViewTitle.setText(resId);
public View getOuterView() {
return outerView;
}
public void setIcon(Drawable drawable){
if(headerIcon != null){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
headerIcon.setBackground(drawable);
public View getInnerView() {
return innerView;
}
iconDrawable = drawable;
}
}
public void setIcon(int resId){
if(headerIcon != null){
iconDrawable = ContextCompat.getDrawable(getContext(), resId);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
headerIcon.setBackground(iconDrawable);
}
}
}*/
private void setInnerView(int resId){
ViewStub stub = findViewById(R.id.viewStub);
stub.setLayoutResource(resId);
stub.inflate();
}
private void setOuterView(int resId){
ViewStub stub = findViewById(R.id.headerStub);
stub.setLayoutResource(resId);
View view = stub.inflate();
}
@Override
public void setOnClickListener(@Nullable OnClickListener l) {
if(arrowBtn != null) arrowBtn.setOnClickListener(l);
if(imageButton != null) imageButton.setOnClickListener(l);
super.setOnClickListener(l);
}
@@ -326,6 +313,50 @@ public class ExpandableCardView extends LinearLayout {
this.animDuration = animDuration;
}
private int reconcileSize(int contentSize, int measureSpec) {
final int mode = MeasureSpec.getMode(measureSpec);
final int specSize = MeasureSpec.getSize(measureSpec);
switch(mode) {
case MeasureSpec.EXACTLY:
return specSize;
case MeasureSpec.AT_MOST:
if (contentSize < specSize) {
return contentSize;
} else {
log.w("Your content may be cropped!");
return specSize;
}
case MeasureSpec.UNSPECIFIED:
default:
return contentSize;
}
}
private int atMostSpec(int atMostSpace, int measureSpec) {
if (MeasureSpec.getMode(measureSpec) == MeasureSpec.UNSPECIFIED)
return measureSpec;
else
return MeasureSpec.makeMeasureSpec(atMostSpace, MeasureSpec.AT_MOST);
}
private int atMostExactlySpec(int atMostExactlySpace, int measureSpec) {
if (MeasureSpec.getMode(measureSpec) == MeasureSpec.UNSPECIFIED)
return measureSpec;
else
return MeasureSpec.makeMeasureSpec(atMostExactlySpace, MeasureSpec.getMode(measureSpec));
}
public void reset() {
long anim = getAnimDuration();
this.setAnimDuration(0);
if (startExpanded) {
this.expand();
} else {
this.collapse();
}
this.setAnimDuration(anim);
}
/**
* Interfaces

View File

@@ -1,81 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView android:id="@+id/card"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="@dimen/default_vertical_padding"
android:paddingBottom="@dimen/default_vertical_padding"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/viewContainer"
android:layout_width="match_parent"
android:layout_height="@dimen/default_card_height"
android:gravity="center_vertical"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/default_card_height"
android:id="@+id/header"
android:gravity="center_vertical">
<!--<ImageButton
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/FUTheme.itemTitle"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:maxLines="1"
android:maxLength="39"
android:layout_toEndOf="@+id/icon"
android:layout_toRightOf="@+id/icon" />
<!-
android:textSize="16sp"
android:textColor="@android:color/primary_text_light"
-->
<ViewStub
android:layout_marginLeft="15dp"
android:layout_marginStart="15dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/headerStub"
android:inflatedId="@+id/outerView"
android:layout_toLeftOf="@id/arrow"
android:layout_toStartOf="@id/arrow"/>
<ImageButton
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_alignParentRight="true"
android:background="?selectableItemBackgroundBorderless"
android:src="@drawable/arrow_down"
android:layout_marginEnd="20dp"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<ViewStub
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/viewStub"
android:inflatedId="@+id/innerView"/>
</LinearLayout>
</android.support.v7.widget.CardView>

View File

@@ -6,7 +6,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/caption"
android:id="@+id/string"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"

View File

@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/FUTheme.itemValue"
android:id="@+id/category"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/category"
style="@style/FUTheme.itemValue"
android:id="@+id/notes"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:orientation="vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_vegan"
android:id="@+id/icon_vegan"
android:visibility="gone"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_vegetarian"
android:id="@+id/icon_vegetarian"
android:visibility="gone"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_msc"
android:id="@+id/icon_msc"
android:visibility="gone"
/>
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@mipmap/ic_bio"
android:id="@+id/icon_bio"
android:visibility="gone"
/>
</LinearLayout>
</RelativeLayout>

View File

@@ -2,7 +2,8 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"

View File

@@ -3,12 +3,11 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/profile"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="Passengers"
android:layout_margin="10dp"
app:outer_view="@layout/list_canteen_header"
app:inner_view="@layout/list_all_show_more"
app:expandOnClick="true"
app:inner_view="@layout/list_canteen_body"
app:animationDuration="300"
app:startExpanded="false" />
<!--

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 850 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View File

@@ -63,11 +63,8 @@
<attr name="defaultEventColor" format="color" />
</declare-styleable>
<declare-styleable name="ExpandableCardView">
<attr name="title" format="string"/>
<attr name="icon" format="reference"/>
<attr name="outer_view" format="reference"/>
<attr name="inner_view" format="reference"/>
<attr name="expandOnClick" format="boolean"/>
<attr name="animationDuration" format="integer"/>
<attr name="startExpanded" format="boolean"/>
</declare-styleable>

View File

@@ -53,4 +53,12 @@
<string name="pref_price_group_title">Canteen Price Group</string>
<string name="pref_price_group_summary">Only show specific price category</string>
<string name="pref_price_group_dialog">Price Group Selection</string>
<string name="meals">Meals</string>
<string name="special_meals">Special meals</string>
<string name="side_dishes">Side Dishes</string>
<string name="desserts">Desserts</string>
<string name="salats">Salats</string>
<string name="soups">Soups</string>
<string name="starters">Starters</string>
<string name="others">Others</string>
</resources>