????Android MVP???????
?????remCarpediem ???????[ 2017/3/14 16:38:24 ] ??????????????? Android
?????????????е?Android???????????????????MVP???????1??????????????????????????????????????????????ɡ?
????MVP????
????MVP???Model??View??Presenter????д????MVC??????????檔MVP??????????Android???????????????????????????presentation Layer?з????? ??????????н????????????????????????Щ?????????? ?????????£?MVP???????????л??????????????
?????????????????????????MVP?????? ???????? ?????????presentation Layer????Android????У??????????Domain Layer??Data Layer??????????????????????洢??????????layer???????????? clear Architecture ??
????The presenter
????The presenter??????view??model????м????????????model???????????????view??顣 ????????MVC??presenter???????????????潻????????????? ??
????The View
????View??飬?????Activity????Fragment???????View?????????????presenter?????????????????????presenter??????????£?????????dagger????????????view???????????????????????????presenter???????????????????
????The Model
???????????????????У?model??????domain layer????????????????????? clear architecture ?????????????????н??????????????????model??
????MVP???
????????MVP?????????к?????? google?????? ????????????????????????????????????????????????
????????????? BaseView ?? BasePresenter ?????????????? BaseActivity ?? BaseFragment ??????????????????????????View????????????????????presenter??????????? BaseView ?????????????????????????????? initPresenter ?????й???????????presenter???? showLoading ?? stopLoading ????????????????????????????????????????????????????????????????????????????????? BaseActivity ???????
????public interface BaseView<T> {
????void showLoading();
????void stopLoading();
????void initPresnter();
????T getPresenter();
????}
????public interface BasePresenter {
????}
????public class BaseActivity extends Activity{
????public void showLoading() {
????}
????public void stopLoading() {
????}
????}
????public class BaseFragment extends Fragment {
????public void showLoading() {
????}
????public void stopLoading() {
????}
????}
?????????data????е????????????塣?????? DataContract ????ж???????????view??data??
????public interface DataContract {
????interface DataView extends BaseView<DataPresenter> {
????void showFragment(BaseFragment fragment);
????}
????interface DataPresenter extends BasePresenter {
????void switchToDataList();
????void switchToDataTree();
????}
????interface DataListView extends BaseView<DataListPresenter> {
????void showDataList(List<String> data);
????}
????interface DataListPresenter extends BasePresenter {
????void loadDataList();
????}
????interface DataTreeView extends BaseView<DataTreePresenter> {}
????interface DataTreePresenter extends BasePresenter {}
????}
?????? DataContract ????У????????????????????????????е?view??presenter??????????????????????????????????????????????????????????棬??????????? DataListFragmnet ?? DataListPresenter ??????
????public class DataListFragment extends BaseFragment implements DataContract.DataListView {
????private DataContract.DataListPresenter mPresenter;
????@Override
????public void initPresnter() {
????mPresenter = new DataListPresenter(this);
????}
????@Override
????public DataContract.DataListPresenter getPresenter() {
????return mPresenter;
????}
????@Override
????public void onCreate(Bundle savedInstanceState) {
????super.onCreate(savedInstanceState);
????initPresnter();
????//??????????????????????????????????presenter?????г?????????????
????mPresenter.loadDataList();
????}
????@Override
????public View onCreateView(LayoutInflater inflater?? ViewGroup container??
????Bundle savedInstanceState) {
????return inflater.inflate(R.layout.fragment_data_list?? container?? false);
????}
????@Override
????public void showDataList(List<String> data) {
????//?????????adapter?????????????
????}
????}
????public class DataListPresenter implements DataContract.DataListPresenter {
????private DataContract.DataListView mView;
????public DataListPresenter(DataContract.DataListView view) {
????super();
????this.mView = view;
????}
????@Override
????public void loadDataList() {
????//????baseview???????Щ????????baseFragment????BaseActivity??
????mView.showLoading();
????//getdata from network
????mView.stopLoading();
????mView.showDataList(Arrays.asList("a"??"b"??"c"));
????}
????}
???????????????к?????ú???????????????? showLoading ?? stopLoading ?????????????????????????????? BaseView ??????? BaseFragment ??????? DataListFragment ????? BaseFragment ????????? BaseView ??????????????ζ???????????????????????app?У???????????laoding???????????μ???????view??presenter??亯????????????????view????????????????????????????????????presenter?????????????????????д???????????????????????????presenter????view????????view???????????view????presenter???????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11