
package com.jachdev.consumerprotection.ui.classifier;

import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

import android.os.Bundle;

import com.jachdev.commonlibs.base.BaseActivity;
import com.jachdev.consumerprotection.R;
import com.jachdev.consumerprotection.data.DietPlan;
import com.jachdev.consumerprotection.data.Notification;
import com.jachdev.consumerprotection.ui.adapter.CommonAdaptor;

import java.util.ArrayList;
import java.util.List;

public class DietPlanActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView mRecyclerView;

    private CommonAdaptor<DietPlan> adaptor;
    private List<DietPlan> dietPlans = new ArrayList<>();

    private ClassifierViewModel classifierViewModel;


    @Override
    protected int layoutRes() {
        return R.layout.activity_diet_plan;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        classifierViewModel = new ViewModelProvider(this).get(ClassifierViewModel.class);

        observeViewModels();
        init();
        getData();
    }

    private void observeViewModels() {
        classifierViewModel.getDietPlanData().observe(DietPlanActivity.this, new Observer<List<DietPlan>>() {
            @Override
            public void onChanged(List<DietPlan> dietPlans) {

                adaptor.setItems(dietPlans);
            }
        });
    }

    private void init() {
        adaptor = new CommonAdaptor<>(DietPlanActivity.this, dietPlans, new CommonAdaptor.CommonAdaptorCallback() {
            @Override
            public void onView(int viewType, int position) {

            }
        });

        adaptor.setViewType(CommonAdaptor.VIEW_TYPE_DIET_PLAN);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(DietPlanActivity.this, LinearLayoutManager.VERTICAL,false));
        mRecyclerView.setAdapter(adaptor);
    }

    private void getData() {
        classifierViewModel.getDietPlan();
    }
}