
package com.jachdev.consumerprotection.ui.exercise;

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.Exercise;
import com.jachdev.consumerprotection.ui.adapter.CommonAdaptor;
import com.jachdev.consumerprotection.ui.classifier.ClassifierViewModel;

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

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

public class ExercisesActivity extends BaseActivity {

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

    private CommonAdaptor<Exercise> adaptor;
    private List<Exercise> exercises = new ArrayList<>();

    private ExerciseViewModel exerciseViewModel;


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

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

        exerciseViewModel = new ViewModelProvider(this).get(ExerciseViewModel.class);

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

    private void observeViewModels() {
        exerciseViewModel.getExerData().observe(ExercisesActivity.this, new Observer<List<Exercise>>() {
            @Override
            public void onChanged(List<Exercise> list) {

                adaptor.setItems(list);
            }
        });
    }

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

            }
        });

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

    private void getData() {
        exerciseViewModel.getExer();
    }
}