Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

of

NongBeer MVP Demo application Slide 1 NongBeer MVP Demo application Slide 2 NongBeer MVP Demo application Slide 3 NongBeer MVP Demo application Slide 4 NongBeer MVP Demo application Slide 5 NongBeer MVP Demo application Slide 6 NongBeer MVP Demo application Slide 7 NongBeer MVP Demo application Slide 8 NongBeer MVP Demo application Slide 9 NongBeer MVP Demo application Slide 10 NongBeer MVP Demo application Slide 11 NongBeer MVP Demo application Slide 12 NongBeer MVP Demo application Slide 13 NongBeer MVP Demo application Slide 14 NongBeer MVP Demo application Slide 15 NongBeer MVP Demo application Slide 16 NongBeer MVP Demo application Slide 17 NongBeer MVP Demo application Slide 18 NongBeer MVP Demo application Slide 19 NongBeer MVP Demo application Slide 20 NongBeer MVP Demo application Slide 21 NongBeer MVP Demo application Slide 22 NongBeer MVP Demo application Slide 23 NongBeer MVP Demo application Slide 24 NongBeer MVP Demo application Slide 25 NongBeer MVP Demo application Slide 26 NongBeer MVP Demo application Slide 27 NongBeer MVP Demo application Slide 28 NongBeer MVP Demo application Slide 29 NongBeer MVP Demo application Slide 30 NongBeer MVP Demo application Slide 31 NongBeer MVP Demo application Slide 32 NongBeer MVP Demo application Slide 33 NongBeer MVP Demo application Slide 34 NongBeer MVP Demo application Slide 35 NongBeer MVP Demo application Slide 36 NongBeer MVP Demo application Slide 37 NongBeer MVP Demo application Slide 38 NongBeer MVP Demo application Slide 39 NongBeer MVP Demo application Slide 40 NongBeer MVP Demo application Slide 41 NongBeer MVP Demo application Slide 42
Upcoming SlideShare
What to Upload to SlideShare
Next
Download to read offline and view in fullscreen.

0 Likes

Share

Download to read offline

NongBeer MVP Demo application

Download to read offline

GitHub: https://github.com/TheKhaeng/nongbeer-mvp-android-demo

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to like this

NongBeer MVP Demo application

  1. 1. Requirements
  2. 2. MVP
  3. 3. View Controller Model Android framework Activity Fragment … How can I test easy ? MVC(basic) Manager
  4. 4. MVP Manager (Android component) View Model (business logic) (POJO) (POJO) Presenter (middle man between view and model) Easy to test
  5. 5. MainActivity BeerProductItem ServiceManager MVP MainActivityPresenter
  6. 6. MVP PresenterInterface MainActivity BeerProductItem ServiceManager MainActivityPresenter ViewInterface
  7. 7. Base class
  8. 8. BaseMvpInterface.Presenter BaseMvpActivity BaseMvpPresenter BaseMvpInterface.View Presenter getPresenter( ); V getView( ); void attachView( mvpView ); void detachView( ); void onViewCreate( ); void onViewDestroy( ); void onViewStart( ); void onViewStop( );
  9. 9. One Single responsibility Presenter createPresenter( ); Int getLayoutView( ); void bindView( mvpView ); void setupInstance( ); void setupView( ); void initialize( ); void restoreView( savedInstanceState ); void onCreate( … ); void onRestoreInstanceState( … ); BaseMvpActivity BaseMvpInterface.View
  10. 10. One Single responsibility Presenter createPresenter( ); Void onRestoreInstanceState( … ); void onCreate( … ); void onCreateView( … ); void onViewCreated( … ); Int getLayoutView( ); void bindView( mvpView ); void setupInstance( ); void setupView( ); void initialize( ); void restoreView( savedInstanceState ); BaseMvpFragment BaseMvpInterface.View
  11. 11. Template
  12. 12. BaseMvpInterface.Presenter BaseMvpActivity BaseMvpPresenter BaseMvpInterface.View CustomActivity <extend> CustomPresenter <extend> CustomInterface.View <extend> CustomInterface.Presenter <extend>
  13. 13. Adapter
  14. 14. BaseMvpInterfaceAdapter.Presenter BaseMvpAdapter BaseMvpAdapterPresenter BaseMvpAdapterInterface.View Presenter getPresenter(); void notifyDataSetChanged(); void notifyItemInserted( int index ); void notifyItemRemoved( int index );
  15. 15. BaseMvpInterfaceAdapter.Presenter BaseMvpAdapter BaseMvpAdapterPresenter BaseMvpAdapterInterface.View void setAdapter( A adapter ); A getAdapter(); int getItemViewType( int pos ); int getItemCount(); boolean hasItems(); List<BaseItem> getItems(); BaseItem getItem( int pos ); void setItems( List<BaseItem> items, boolean isNextAvailable ); void addItem( BaseItem item ); void removeItem( int index ); void removeAllItems();
  16. 16. BaseMvpAdapterPresenter @Override public void addItem( BaseItem item ){ getPrivateItems( ).add( item ); getAdapter( ).notifyItemInserted( getItemCount() - 1 ); } Example
  17. 17. public abstract class BaseViewHolder extends RecyclerView.ViewHolder{ public BaseViewHolder( ViewGroup parent, int layout ){ super( LayoutInflater .from( parent.getContext() ) .inflate( layout, parent, false ) ); bindView( itemView ); } public abstract void bindView( View view ); public Context getContext(){ return itemView.getContext(); } } BaseViewHolder
  18. 18. Example public BeerProductHolder( ViewGroup viewGroup ){ super( viewGroup, R.layout.holder_beer_product ); } @Override public void bindView( View view ){ … } BeerProductHolder
  19. 19. public class BaseItem { protected int type; public BaseItem( int type ){ this.type = type; } public int getType(){ return type; } } BaseItem
  20. 20. @Override public int getItemCount(){ return getPresenter().getItemCount(); } @Override public int getItemViewType( int position ){ return getPresenter().getItemViewType( position ); } @Override public BaseViewHolder onCreateViewHolder( ViewGroup viewGroup, int viewType ){ switch( viewType ){ case TYPE_BEER_PRODUCT: return new BeerProductHolder( viewGroup ); } return null; } BeerAdapter BaseItem BeerProductItem <extend> Example TYPE_BEER_PRODUCT
  21. 21. Load more public interface OnLoadMoreListener{ void onLoadMore(); } @Override public VH onCreateViewHolder( ViewGroup parent, int viewType ){ if( viewType == BaseItemType.TYPE_PROGRESS ){ return (VH) new ProgressHolder( parent ); } throw new RuntimeException( "View type not found: " + viewType ); } @Override public void onBindViewHolder( VH holder, int position ){ if( getItemViewType( position ) == BaseItemType.TYPE_PROGRESS ){ if( loadMoreListener != null ){ loadMoreListener.onLoadMore(); } } }
  22. 22. Load more @Override public void onBindViewHolder( BaseViewHolder viewHolder, final int position ){ super.onBindViewHolder( viewHolder, position ); … } @Override public BaseViewHolder onCreateViewHolder( ViewGroup viewGroup, int viewType ){ … return super.onCreateViewHolder( viewGroup, viewType ); } Example
  23. 23. Template
  24. 24. BaseMvpAdapterInterface.Presenter BaseMvpAdapter BaseMvpAdapterPresenter BaseMvpAdapterInterface.View CustomAdapter <extend> CustomAdapterPresenter <extend> CustomAdapterInterface.View <extend> CustomAdapterInterface.Presenter <extend>
  25. 25. Converter
  26. 26. Normally Raw DataNetwork If you want to custom? Adapter
  27. 27. Converter Network Adapter Raw Data Converter Adapter Data Response Body Adapter item Easy to maintain
  28. 28. String id; String name; int price; String id; String name; int price; int amount = 1; boolean isAdded = false; Converter Network Adapter Raw Data Converter Adapter Data BeerResult BeerItem Easy to maintain
  29. 29. RxBus
  30. 30. MainActivity BeerFragment ClearAddedButtonStateEvent ClearAddedButtonStateAllEvent AddBeerToCartEvent RemoveBeerFromCartEvent
  31. 31. Test
  32. 32. Phase 1 Phase 2 Phase 3 Test must done Test must done MVP MVP
  33. 33. PresenterInterface MainActivity BeerProductItem ServiceManager MainActivityPresenter ViewInterface Unit test Activity/Fragment
  34. 34. PresenterInterface MainActivity BeerProductItem ServiceManager MainActivityPresenter CUT MOCK Unit test MOCK MOCK Activity/Fragment ViewInterface
  35. 35. PresenterInterface BeerAdapter BeerAdapterPresenter AdapterInterface Unit test Adapter
  36. 36. PresenterInterface BeerAdapter Unit test Adapter MOCK CUT AdapterInterface BeerAdapterPresenter
  37. 37. PresenterInterface MainActivity BeerProductItem ServiceManager MainActivityPresenter CUT ViewInterface MOCK Integration test MOCK MOCK Activity/Fragment
  38. 38. PresenterInterface MainActivity BeerProductItem ServiceManager MainActivityPresenter CUT ViewInterface MOCK Integration test MOCK CUT Activity/Fragment

GitHub: https://github.com/TheKhaeng/nongbeer-mvp-android-demo

Views

Total views

160

On Slideshare

0

From embeds

0

Number of embeds

2

Actions

Downloads

3

Shares

0

Comments

0

Likes

0

×