Когда я вхожу (с помощью google mail), LoginFragment
заменяется на DrinkCategoryFragment
, который содержит RecyclerView
.
Элементы правильно извлекаются из базы данных Firebase, но макета там нет, и я не могу понять, почему.
RecyclerView
инициализируется внутри DrinkCategoriesViewMvcImpl.java
:
public class DrinkCategoriesViewMvcImpl implements DrinkCategoriesViewMvc {
private View rootView;
private RecyclerView recyclerView;
private FloatingActionButton shareButton;
private DrinkCategoriesAdapter adapter;
public DrinkCategoriesViewMvcImpl(LayoutInflater inflater, ViewGroup parent) {
initializeViews(inflater, parent);
}
@Override
public View getRootView() {
return rootView;
}
@Override
public void setOnDrinkCategoryClickListener(OnDrinkCategoryClickListener listener) {
}
@Override
public void bindDrinkCategories(List<DrinkCategory> drinkCategories) {
adapter.addDrinkCategories(drinkCategories);
adapter.notifyDataSetChanged();
}
private void initializeViews(LayoutInflater inflater, ViewGroup parent) {
rootView = inflater.inflate(R.layout.activity_main_list, parent, false);
shareButton = rootView.findViewById(R.id.fab_share);
setupRecyclerView();
}
private void setupRecyclerView() {
recyclerView = rootView.findViewById(R.id.recyclerView);
LinearLayoutManager layoutManager = new LinearLayoutManager(rootView.getContext(),LinearLayoutManager.VERTICAL,false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
adapter = new DrinkCategoriesAdapter(rootView.getContext());
recyclerView.setAdapter(adapter);
}
Вот класс адаптера:
public class DrinkCategoriesAdapter extends RecyclerView.Adapter<DrinkCategoriesAdapter.CategoryItemHolder> {
private Context context;
private List<DrinkCategory> drinkCategories;
public DrinkCategoriesAdapter(Context context) {
this.context = context;
}
public void addDrinkCategories(List<DrinkCategory> drinkCategories) {
this.drinkCategories = drinkCategories;
}
@NonNull
@Override
public CategoryItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(context).inflate(R.layout.activity_main_list_item, parent, false);
return new CategoryItemHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull CategoryItemHolder holder, int position) {
if (drinkCategories != null && drinkCategories.size() > 0) {
holder.bindViews(drinkCategories.get(position));
}
}
@Override
public int getItemCount() {
if (drinkCategories != null) {
return drinkCategories.size();
}
return 0;
}
class CategoryItemHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView title, subtitle;
private ImageView_3_2 poster;
public CategoryItemHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
title = itemView.findViewById(R.id.textview_title);
subtitle = itemView.findViewById(R.id.textview_subtitle);
poster = itemView.findViewById(R.id.imageview_background);
}
@Override
public void onClick(View v) {
}
public void bindViews(DrinkCategory drinkCategory) {
title.setText(drinkCategory.getTitle());
// TODO: subtitle will be set from sharedpreferences
}
}
}
Здесь также находится файл макета:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:background="@color/colorPrimary">
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_share"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="16dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@drawable/ic_share_black_24dp"
app:fabSize="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
</android.support.constraint.ConstraintLayout>
Почему это происходит? ( проект на Github )