57 lines
2.0 KiB
Java
57 lines
2.0 KiB
Java
package com.thebrokenrail.mtudining.activity.list;
|
|
|
|
import android.content.Intent;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
import com.thebrokenrail.mtudining.activity.menu.MenuActivity;
|
|
import com.thebrokenrail.mtudining.activity.task.Task;
|
|
import com.thebrokenrail.mtudining.activity.task.TaskAdapter;
|
|
import com.thebrokenrail.mtudining.api.method.AllLocations;
|
|
import com.thebrokenrail.mtudining.util.Category;
|
|
import com.thebrokenrail.mtudining.widget.CategoryView;
|
|
|
|
/**
|
|
* Adapter for listing dining halls.
|
|
*/
|
|
class ListAdapter extends TaskAdapter<ListData> {
|
|
ListAdapter(Task<ListData> task) {
|
|
super(task);
|
|
}
|
|
|
|
@Override
|
|
protected View createItemView(@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 category;
|
|
}
|
|
|
|
@Override
|
|
protected void bindItemView(View view, int position) {
|
|
Category<AllLocations.Response.Location> data = getResult().categories.get(position - getFirstElementPosition());
|
|
// Setup View
|
|
CategoryView category = (CategoryView) view;
|
|
category.setup(data, () -> {
|
|
// Open/Close Category
|
|
data.isOpen = !data.isOpen;
|
|
notifyItemChanged(getResult().categories.indexOf(data) + getFirstElementPosition());
|
|
}, location -> {
|
|
// Open Menu
|
|
Intent intent = new Intent(category.getContext(), MenuActivity.class);
|
|
intent.putExtra(MenuActivity.ID_EXTRA, location.id);
|
|
intent.putExtra(MenuActivity.NAME_EXTRA, location.name);
|
|
category.getContext().startActivity(intent);
|
|
});
|
|
}
|
|
|
|
@Override
|
|
protected int getDataSize() {
|
|
return getResult().categories.size();
|
|
}
|
|
}
|