package com.maniu.mn_vip_jetpack_other.paging;

import android.annotation.SuppressLint;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.paging.PagedList;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.maniu.mn_vip_jetpack_other.R;

public class PagingActivity extends AppCompatActivity {
    RecyclerView mRecyclerView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_paging);
        init();
    }

    @SuppressLint("WrongConstant")
    private void init() {
        mRecyclerView = findViewById(R.id.recyclerView);
        final RecyclerAdapter adapter = new RecyclerAdapter();
        ConcertViewModel viewModel =
                ViewModelProviders.of(this).get(ConcertViewModel.class);
        viewModel.getConvertList().observe(this, new Observer<PagedList<Concert>>() {
            @Override
            public void onChanged(PagedList<Concert> concerts) {
                adapter.submitList(concerts);
            }
        });
        mRecyclerView.setAdapter(adapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    }
}
