/* * Copyright 2015 Hannes Dorfmann. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.hannesdorfmann.mosby3.sample.mvp.lce.activity; import android.os.Bundle; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import butterknife.BindView; import butterknife.ButterKnife; import com.hannesdorfmann.mosby3.mvp.lce.MvpLceActivity; import com.hannesdorfmann.mosby3.sample.R; import com.hannesdorfmann.mosby3.sample.mvp.CountriesAdapter; import com.hannesdorfmann.mosby3.sample.mvp.CountriesErrorMessage; import com.hannesdorfmann.mosby3.sample.mvp.CountriesPresenter; import com.hannesdorfmann.mosby3.sample.mvp.CountriesView; import com.hannesdorfmann.mosby3.sample.mvp.lce.SimpleCountriesPresenter; import com.hannesdorfmann.mosby3.sample.mvp.model.Country; import java.util.List; public class CountriesActivity extends MvpLceActivity<SwipeRefreshLayout, List<Country>, CountriesView, CountriesPresenter> implements CountriesView, SwipeRefreshLayout.OnRefreshListener { @BindView(R.id.recyclerView) RecyclerView recyclerView; CountriesAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.countries_list); ButterKnife.bind(this); // Setup contentView == SwipeRefreshView contentView.setOnRefreshListener(this); // Setup recycler view adapter = new CountriesAdapter(this); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.setAdapter(adapter); loadData(false); } @Override protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); } public void loadData(boolean pullToRefresh) { presenter.loadCountries(pullToRefresh); } @Override protected String getErrorMessage(Throwable e, boolean pullToRefresh) { return CountriesErrorMessage.get(e, pullToRefresh, this); } @Override public CountriesPresenter createPresenter() { return new SimpleCountriesPresenter(); } @Override public void setData(List<Country> data) { adapter.setCountries(data); adapter.notifyDataSetChanged(); } @Override public void onRefresh() { loadData(true); } @Override public void showContent() { super.showContent(); contentView.setRefreshing(false); } @Override public void showError(Throwable e, boolean pullToRefresh) { super.showError(e, pullToRefresh); contentView.setRefreshing(false); } }