67 lines
2.5 KiB
Java
67 lines
2.5 KiB
Java
package com.thebrokenrail.mtudining.activity.list;
|
|
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.LinearLayout;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.appcompat.widget.AppCompatTextView;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.google.android.material.card.MaterialCardView;
|
|
import com.thebrokenrail.mtudining.activity.task.Task;
|
|
import com.thebrokenrail.mtudining.activity.task.TaskAdapter;
|
|
import com.thebrokenrail.mtudining.widget.CategoryView;
|
|
import com.thebrokenrail.mtudining.widget.LoaderView;
|
|
|
|
/**
|
|
* Adapter for listing dining halls.
|
|
*/
|
|
public class ListAdapter extends TaskAdapter<ListData, ListAdapter.ViewHolder> {
|
|
public static class ViewHolder extends RecyclerView.ViewHolder {
|
|
private final CategoryView view;
|
|
private ViewHolder(@NonNull View itemView) {
|
|
super(itemView);
|
|
view = (CategoryView) itemView;
|
|
}
|
|
}
|
|
|
|
public ListAdapter(Task<ListData> task) {
|
|
super(task);
|
|
}
|
|
|
|
@Override
|
|
protected ViewHolder createItemViewHolder(@NonNull ViewGroup parent) {
|
|
// Create View
|
|
CategoryView category = new CategoryView(parent.getContext(), null);
|
|
RecyclerView.LayoutParams layoutParams = new RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT);
|
|
category.setLayoutParams(layoutParams);
|
|
return new ViewHolder(category);
|
|
}
|
|
|
|
@Override
|
|
protected void bindDataViewHolder(@NonNull ViewHolder holder, int position) {
|
|
ListData.Category data = getResult().categories.get(position);
|
|
// Setup View
|
|
holder.view.setup(data.isOpen, data.name, () -> {
|
|
// Open/Close Category
|
|
data.isOpen = !data.isOpen;
|
|
notifyItemChanged(getResult().categories.indexOf(data));
|
|
});
|
|
// Add Locations
|
|
holder.view.children.removeAllViews();
|
|
for (ListData.Element location : data.locations) {
|
|
AppCompatTextView textView = new AppCompatTextView(holder.view.getContext());
|
|
textView.setText(location.name);
|
|
MaterialCardView.LayoutParams innerLayoutParams = new MaterialCardView.LayoutParams(MaterialCardView.LayoutParams.MATCH_PARENT, MaterialCardView.LayoutParams.WRAP_CONTENT);
|
|
textView.setLayoutParams(innerLayoutParams);
|
|
holder.view.children.addView(textView);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected int getDataSize() {
|
|
return getResult().categories.size();
|
|
}
|
|
}
|