-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d30cc6
commit 655fe09
Showing
19 changed files
with
444 additions
and
44 deletions.
There are no files selected for viewing
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
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
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
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
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
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseItem.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
@org.parceler.Parcel(org.parceler.Parcel.Serialization.BEAN) | ||
class BaseItem { | ||
|
||
private int type; | ||
|
||
public BaseItem(int type) { | ||
this.type = type; | ||
} | ||
|
||
public BaseItem() { | ||
} | ||
|
||
int getType() { | ||
return type; | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseItemType.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
public class BaseItemType{ | ||
public static final int TYPE_PROGRESS = 1; | ||
} |
61 changes: 61 additions & 0 deletions
61
...rc/main/java/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseListAdapter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
|
||
import com.wisdomlanna.www.dagger2_mvp_example.ui.base.exception.MvpPresenterNotCreateException; | ||
|
||
import java.util.List; | ||
|
||
public abstract class BaseListAdapter<VH extends BaseViewHolder, P extends BaseListAdapterInterface.Presenter> | ||
extends RecyclerView.Adapter<VH> | ||
implements BaseListAdapterInterface.Adapter{ | ||
|
||
private P presenter; | ||
|
||
public interface OnLoadMoreListener{ | ||
void onLoadMore(); | ||
} | ||
|
||
@SuppressWarnings( "unchecked" ) | ||
public BaseListAdapter(){ | ||
presenter = createPresenter(); | ||
presenter.setAdapter( this ); | ||
} | ||
|
||
abstract P createPresenter(); | ||
|
||
@Override | ||
public P getPresenter(){ | ||
if( presenter != null ) return presenter; | ||
throw new MvpPresenterNotCreateException(); | ||
} | ||
|
||
@SuppressWarnings( "unchecked" ) | ||
public List<BaseItem> getItems(){ | ||
return getPresenter().getItems(); | ||
} | ||
|
||
public BaseItem getItem( int pos ){ | ||
return getPresenter().getItem( pos ); | ||
} | ||
|
||
public boolean hasItems(){ | ||
return getPresenter().hasItems(); | ||
} | ||
|
||
public void setItems( List<BaseItem> items ){ | ||
getPresenter().setItems( items ); | ||
} | ||
|
||
public void addItem( BaseItem item ){ | ||
getPresenter().addItem( item ); | ||
} | ||
|
||
public void removeItem( int index ){ | ||
getPresenter().removeItem( index ); | ||
} | ||
|
||
public void removeAllItems(){ | ||
getPresenter().removeAllItems(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...ava/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseListAdapterInterface.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
import java.util.List; | ||
|
||
interface BaseListAdapterInterface { | ||
|
||
interface Adapter { | ||
Presenter getPresenter(); | ||
|
||
void notifyDataSetChanged(); | ||
|
||
void notifyItemInserted(int index); | ||
|
||
void notifyItemRemoved(int index); | ||
} | ||
|
||
interface Presenter<A extends BaseListAdapterInterface.Adapter> { | ||
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); | ||
|
||
void addItem(BaseItem item); | ||
|
||
void removeItem(int index); | ||
|
||
void removeAllItems(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...ava/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseListAdapterPresenter.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
import com.wisdomlanna.www.dagger2_mvp_example.ui.base.exception.MvpViewNotAttachedException; | ||
|
||
import java.lang.ref.WeakReference; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class BaseListAdapterPresenter<A extends BaseListAdapterInterface.Adapter> | ||
implements BaseListAdapterInterface.Presenter<A> { | ||
|
||
private WeakReference<A> adapter; | ||
private List<BaseItem> items; | ||
|
||
public BaseListAdapterPresenter() { | ||
this.items = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public void setAdapter(A adapter) { | ||
this.adapter = new WeakReference<>(adapter); | ||
} | ||
|
||
@Override | ||
public A getAdapter() { | ||
if (adapter != null) return adapter.get(); | ||
throw new MvpViewNotAttachedException(); | ||
} | ||
|
||
@Override | ||
public int getItemViewType(int pos) { | ||
return getPrivateItems().get(pos).getType(); | ||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return getPrivateItems().size(); | ||
} | ||
|
||
@Override | ||
public List<BaseItem> getItems() { | ||
return getPrivateItems(); | ||
} | ||
|
||
@Override | ||
public BaseItem getItem(int pos) { | ||
return getPrivateItems().get(pos); | ||
} | ||
|
||
@Override | ||
public boolean hasItems() { | ||
return getItemCount() > 0; | ||
} | ||
|
||
@Override | ||
public void setItems(List<BaseItem> items) { | ||
this.items = items; | ||
getAdapter().notifyDataSetChanged(); | ||
} | ||
|
||
@Override | ||
public void addItem(BaseItem item) { | ||
getPrivateItems().add(item); | ||
getAdapter().notifyItemInserted(getItemCount() - 1); | ||
} | ||
|
||
@Override | ||
public void removeItem(int index) { | ||
getPrivateItems().remove(index); | ||
getAdapter().notifyItemRemoved(index); | ||
} | ||
|
||
@Override | ||
public void removeAllItems() { | ||
getPrivateItems().clear(); | ||
getAdapter().notifyDataSetChanged(); | ||
} | ||
|
||
private List<BaseItem> getPrivateItems() { | ||
if (items == null) return new ArrayList<>(); | ||
return items; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...src/main/java/com/wisdomlanna/www/dagger2_mvp_example/ui/base/adapter/BaseViewHolder.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.wisdomlanna.www.dagger2_mvp_example.ui.base.adapter; | ||
|
||
import android.content.Context; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.ViewGroup; | ||
|
||
import butterknife.ButterKnife; | ||
|
||
abstract class BaseViewHolder extends RecyclerView.ViewHolder { | ||
|
||
public BaseViewHolder(ViewGroup parent, int layout) { | ||
super(LayoutInflater.from(parent.getContext()).inflate(layout, parent, false)); | ||
ButterKnife.bind(this, itemView); | ||
} | ||
|
||
protected Context getContext() { | ||
return itemView.getContext(); | ||
} | ||
} |
Oops, something went wrong.