Created
September 15, 2016 07:28
-
-
Save mladenrakonjac/4343802b1196efa66f2bfd74548c1765 to your computer and use it in GitHub Desktop.
Implementation of Contract.Presenter in MVP pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package me.fleka.deltacity.presentation.shopping; | |
import android.support.annotation.NonNull; | |
import java.util.List; | |
import me.fleka.deltacity.data.category.CategoryDataSource; | |
import me.fleka.deltacity.domain.models.Category; | |
import static com.google.gson.internal.$Gson$Preconditions.checkNotNull; | |
/** | |
* Created by mladenrakonjac on 14/09/16. | |
* | |
* Listens to user actions from the UI ({@link ShoppingFragment}) , retrieves the data and | |
* updates the UI as required. | |
*/ | |
public class ShoppingPresenterImpl implements ShoppingContract.Presenter, | |
CategoryDataSource.LoadCategoriesCallback { | |
private final CategoryDataSource mCategoryRepository; | |
private final ShoppingContract.View mShoppingView; | |
/** | |
* Creates a presenter for Categories presentation and Shop searching | |
* @param categoryRepository a repository fo data for categories | |
* @param shoppingView search shop/ categories view | |
*/ | |
public ShoppingPresenterImpl(@NonNull CategoryDataSource categoryRepository, | |
@NonNull ShoppingContract.View shoppingView) { | |
mCategoryRepository = checkNotNull(categoryRepository); | |
mShoppingView = checkNotNull(shoppingView); | |
mShoppingView.setPresenter(this); | |
} | |
@Override public void loadCategories() { | |
mShoppingView.setLoadingIndicator(true); | |
mCategoryRepository.getCategories(this); | |
} | |
@Override public void openCategory(int categoryId) { | |
//Todo | |
} | |
@Override public void searchShop(String searchText) { | |
//Todo | |
} | |
@Override public void openShop(int shopId) { | |
//Todo | |
} | |
@Override public void cleanSearch() { | |
//Todo | |
} | |
@Override public void start() { | |
mShoppingView.setLoadingIndicator(true); | |
loadCategories(); | |
} | |
@Override public void onCategoriesLoaded(List<Category> categories) { | |
mShoppingView.setLoadingIndicator(false); | |
mShoppingView.showCategories(categories); | |
} | |
@Override public void onDataNotAvailable() { | |
mShoppingView.showNoShopsFound(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment