diff --git a/.idea/encodings.xml b/.idea/encodings.xml index 090eeed..fb1af55 100644 --- a/.idea/encodings.xml +++ b/.idea/encodings.xml @@ -1,8 +1,8 @@ - - + + \ No newline at end of file diff --git a/app/src/main/java/com/zhoujinlong/AndroidApp.java b/app/src/main/java/com/zhoujinlong/AndroidApp.java index 2f2ac4c..4001c6d 100644 --- a/app/src/main/java/com/zhoujinlong/AndroidApp.java +++ b/app/src/main/java/com/zhoujinlong/AndroidApp.java @@ -2,8 +2,8 @@ import com.android.core.MainApp; import com.android.core.model.control.LogicProxy; -import com.zhoujinlong.presenter.CompeteLogic; import com.zhoujinlong.presenter.LoginLogic; +import com.zhoujinlong.presenter.MainLogic; /** * author miekoz on 2016/3/17. @@ -16,6 +16,6 @@ public void onCreate() { super.onCreate(); LogicProxy.getInstance().init( - LoginLogic.class, CompeteLogic.class); + LoginLogic.class, MainLogic.class); } } diff --git a/app/src/main/java/com/zhoujinlong/adapter/CustomViewPageAdapter.java b/app/src/main/java/com/zhoujinlong/adapter/CustomViewPageAdapter.java new file mode 100644 index 0000000..e8e893f --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/adapter/CustomViewPageAdapter.java @@ -0,0 +1,49 @@ +package com.zhoujinlong.adapter; + +import android.content.Context; +import android.support.v4.view.PagerAdapter; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; + +import com.zhoujinlong.R; + +import java.util.List; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz + */ +public class CustomViewPageAdapter extends PagerAdapter { + public List comm_data_ls; + private Context context; + private View itemView; + + public CustomViewPageAdapter(Context context, List comm_data_ls) { + this.context = context; + this.comm_data_ls = comm_data_ls; + } + + @Override + public int getCount() { + return comm_data_ls.size() > 0 ? comm_data_ls.size() == 1 ? 1 : Integer.MAX_VALUE : 0; + } + + public Object instantiateItem(ViewGroup container, final int position) { + itemView = View.inflate(context, R.layout.item_viewpage_content, null); + ImageView imageView = ((ImageView) itemView.findViewById(R.id.image)); + imageView.setBackgroundResource(comm_data_ls.get(position % comm_data_ls.size())); + container.addView(itemView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + return itemView; + } + + @Override + public void destroyItem(ViewGroup container, int position, Object obj) { +// container.removeView(itemView); + } + + public boolean isViewFromObject(View arg0, Object arg1) { + return arg0 == (arg1); + } +} diff --git a/app/src/main/java/com/zhoujinlong/adapter/HomeRecyclerAdapter.java b/app/src/main/java/com/zhoujinlong/adapter/HomeRecyclerAdapter.java new file mode 100644 index 0000000..42edc24 --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/adapter/HomeRecyclerAdapter.java @@ -0,0 +1,44 @@ +package com.zhoujinlong.adapter; + +import android.content.Context; +import android.net.Uri; +import android.support.design.widget.Snackbar; +import android.view.View; +import android.widget.ImageView; + +import com.android.core.adapter.RecyclerAdapter; +import com.android.core.adapter.RecyclerViewHolder; +import com.bumptech.glide.Glide; +import com.zhoujinlong.R; +import com.zhoujinlong.model.bean.Classify; +import com.zhoujinlong.ui.activity.SwipBackActivity; + +import java.util.List; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz + */ +public class HomeRecyclerAdapter extends RecyclerAdapter { + + private String URL_Base = "http://tnfs.tngou.net/image"; + + public HomeRecyclerAdapter(Context context, int layoutId, List datas) { + super(context, layoutId, datas); + } + + @Override + public void convert(final RecyclerViewHolder holder, final Classify.TngouEntity item) { + Uri uri = Uri.parse(URL_Base + item.getImg()); + Glide.with(mContext).load(uri).into((ImageView) holder.getView(R.id.sv_classitfy_img)); + holder.setText(R.id.sv_classitfy_des, item.getTitle()); + holder.setOnClickListener(R.id.sv_classitfy_img, new View.OnClickListener() { + @Override + public void onClick(View v) { + Snackbar.make(holder.getView(R.id.sv_classitfy_img), item.getTitle(), Snackbar.LENGTH_LONG).show(); + SwipBackActivity.start(mContext); + } + }); + } +} diff --git a/app/src/main/java/com/zhoujinlong/model/bean/Classify.java b/app/src/main/java/com/zhoujinlong/model/bean/Classify.java index 601c2ba..32470d4 100644 --- a/app/src/main/java/com/zhoujinlong/model/bean/Classify.java +++ b/app/src/main/java/com/zhoujinlong/model/bean/Classify.java @@ -3,8 +3,9 @@ import java.util.List; /** - * author meikoz on 2016/4/27. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public class Classify { private boolean status; diff --git a/app/src/main/java/com/zhoujinlong/model/config/ApiConstant.java b/app/src/main/java/com/zhoujinlong/model/config/ApiConstant.java index 5047d68..dbb3804 100644 --- a/app/src/main/java/com/zhoujinlong/model/config/ApiConstant.java +++ b/app/src/main/java/com/zhoujinlong/model/config/ApiConstant.java @@ -1,8 +1,9 @@ package com.zhoujinlong.model.config; /** - * author meikoz on 2016/4/19. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public interface ApiConstant { diff --git a/app/src/main/java/com/zhoujinlong/model/config/LocalStorage.java b/app/src/main/java/com/zhoujinlong/model/config/LocalStorage.java index 3b79697..0cf561f 100644 --- a/app/src/main/java/com/zhoujinlong/model/config/LocalStorage.java +++ b/app/src/main/java/com/zhoujinlong/model/config/LocalStorage.java @@ -1,8 +1,9 @@ package com.zhoujinlong.model.config; /** - * author meikoz on 2016/3/30. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public class LocalStorage { } diff --git a/app/src/main/java/com/zhoujinlong/model/http/BaseHttpService.java b/app/src/main/java/com/zhoujinlong/model/http/BaseHttpService.java index 5e622b9..87efe80 100644 --- a/app/src/main/java/com/zhoujinlong/model/http/BaseHttpService.java +++ b/app/src/main/java/com/zhoujinlong/model/http/BaseHttpService.java @@ -9,13 +9,12 @@ import retrofit2.http.Query; /** - * author miekoz on 2016/3/17. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public interface BaseHttpService { - - @Headers("Cache-Control: public, max-age=3600") @GET("tnfs/api/list") Call getImageClassify(@Query("id") int id); diff --git a/app/src/main/java/com/zhoujinlong/model/http/BaseUserService.java b/app/src/main/java/com/zhoujinlong/model/http/BaseUserService.java index 920f4c6..c0269d9 100644 --- a/app/src/main/java/com/zhoujinlong/model/http/BaseUserService.java +++ b/app/src/main/java/com/zhoujinlong/model/http/BaseUserService.java @@ -1,8 +1,9 @@ package com.zhoujinlong.model.http; /** - * author meikoz on 2016/4/26. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public interface BaseUserService { } diff --git a/app/src/main/java/com/zhoujinlong/model/http/Factory.java b/app/src/main/java/com/zhoujinlong/model/http/Factory.java index 788fc28..d0ecdd9 100644 --- a/app/src/main/java/com/zhoujinlong/model/http/Factory.java +++ b/app/src/main/java/com/zhoujinlong/model/http/Factory.java @@ -8,8 +8,9 @@ /** - * author miekoz on 2016/3/21. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 14:15 + * @GitHub: https://github.com/meikoz */ public class Factory { diff --git a/app/src/main/java/com/zhoujinlong/presenter/CompeteLogic.java b/app/src/main/java/com/zhoujinlong/presenter/CompeteLogic.java deleted file mode 100644 index 99d2aa9..0000000 --- a/app/src/main/java/com/zhoujinlong/presenter/CompeteLogic.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.zhoujinlong.presenter; - -import com.android.core.model.annotation.Implement; -import com.android.core.model.control.BaseLogic; -import com.zhoujinlong.presenter.impl.CompeteLogicImpl; -import com.zhoujinlong.ui.view.CompeteView; - -/** - * author meikoz on 2016/4/27. - * email meikoz@126.com - */ -@Implement(CompeteLogicImpl.class) -public interface CompeteLogic extends BaseLogic { - - void onRefreshData(); - - void onLoadMoreData(); - -} diff --git a/app/src/main/java/com/zhoujinlong/presenter/LoginLogic.java b/app/src/main/java/com/zhoujinlong/presenter/LoginLogic.java index fbecf63..5fc081b 100644 --- a/app/src/main/java/com/zhoujinlong/presenter/LoginLogic.java +++ b/app/src/main/java/com/zhoujinlong/presenter/LoginLogic.java @@ -3,14 +3,9 @@ import com.android.core.model.annotation.Implement; import com.android.core.model.control.BaseLogic; import com.zhoujinlong.presenter.impl.LoginLogicImpl; -import com.zhoujinlong.ui.view.LoginView; +import com.zhoujinlong.presenter.view.LoginView; -/** - * author meikoz on 2016/4/13. - * email meikoz@126.com - */ - @Implement(LoginLogicImpl.class) public interface LoginLogic extends BaseLogic { diff --git a/app/src/main/java/com/zhoujinlong/presenter/MainLogic.java b/app/src/main/java/com/zhoujinlong/presenter/MainLogic.java new file mode 100644 index 0000000..88e0a80 --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/presenter/MainLogic.java @@ -0,0 +1,14 @@ +package com.zhoujinlong.presenter; + +import com.android.core.model.annotation.Implement; +import com.zhoujinlong.presenter.impl.MainLogicImpl; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 12:03 + * @GitHub: https://github.com/meikoz + */ +@Implement(MainLogicImpl.class) +public interface MainLogic { + void onLoadRemoteData(boolean isMore, int page); +} diff --git a/app/src/main/java/com/zhoujinlong/presenter/base/CommonView.java b/app/src/main/java/com/zhoujinlong/presenter/base/CommonView.java new file mode 100644 index 0000000..28a86db --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/presenter/base/CommonView.java @@ -0,0 +1,13 @@ +package com.zhoujinlong.presenter.base; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 11:47 + * @GitHub: https://github.com/meikoz + */ +public interface CommonView { + + void onLoadComplete(); + + void onShowListData(T response, boolean isMore); +} diff --git a/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogic.java b/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogic.java new file mode 100644 index 0000000..025fcd6 --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogic.java @@ -0,0 +1,17 @@ +package com.zhoujinlong.presenter.base; + +import com.android.core.model.control.BaseLogic; + +import retrofit2.Response; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 14:39 + * @GitHub: https://github.com/meikoz + */ +public interface LoadSuccessLogic extends BaseLogic> { + + void onLoadListSuccessHandle(Response response, boolean isMore); + + void onLoadFail(String msg); +} diff --git a/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogicImpl.java b/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogicImpl.java new file mode 100644 index 0000000..75d2695 --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/presenter/base/LoadSuccessLogicImpl.java @@ -0,0 +1,44 @@ +package com.zhoujinlong.presenter.base; + +import retrofit2.Response; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 11:51 + * @GitHub: https://github.com/meikoz + */ +public class LoadSuccessLogicImpl implements LoadSuccessLogic { + + CommonView view; + + /** + * 处理获取列表成功回调的公共函数 + * + * @param response + * @param isMore + */ + public void onLoadListSuccessHandle(Response response, boolean isMore) { + view.onLoadComplete(); + T body = response.body(); + if (body != null) { + view.onShowListData(body, isMore); + } +// else { +// if (isMore) { +// //加载更多 Toast "没有更多数据" +// } else { +//// Toast "没有更多数据" +// } +// } + } + + @Override + public void onLoadFail(String msg) { + //提示请求失败 + } + + @Override + public void attachView(CommonView v) { + view = v; + } +} diff --git a/app/src/main/java/com/zhoujinlong/presenter/impl/CompeteLogicImpl.java b/app/src/main/java/com/zhoujinlong/presenter/impl/CompeteLogicImpl.java deleted file mode 100644 index 3d7bff5..0000000 --- a/app/src/main/java/com/zhoujinlong/presenter/impl/CompeteLogicImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.zhoujinlong.presenter.impl; - -import com.zhoujinlong.model.bean.Classify; -import com.zhoujinlong.model.http.BaseHttpService; -import com.zhoujinlong.model.http.Factory; -import com.zhoujinlong.presenter.CompeteLogic; -import com.zhoujinlong.ui.view.CompeteView; - -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Response; - -/** - * author meikoz on 2016/4/27. - * email meikoz@126.com - */ -public class CompeteLogicImpl implements CompeteLogic { - private CompeteView mView; - private BaseHttpService service; - - - @Override - public void onRefreshData() { - service.getImageClassify(1).enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - Classify body = response.body(); - if (body.isStatus()) - mView.onSuccess(body.getTngou()); - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - }); - } - - @Override - public void onLoadMoreData() { - service.getImageClassify(2).enqueue(new Callback() { - @Override - public void onResponse(Call call, Response response) { - Classify body = response.body(); - if (body.isStatus()) - mView.onSuccess(body.getTngou()); - } - - @Override - public void onFailure(Call call, Throwable t) { - - } - }); - } - - @Override - public void attachView(CompeteView mvpView) { - this.mView = mvpView; - service = Factory.provideHttpService(); - } -} diff --git a/app/src/main/java/com/zhoujinlong/presenter/impl/LoginLogicImpl.java b/app/src/main/java/com/zhoujinlong/presenter/impl/LoginLogicImpl.java index 248e562..e8d20e9 100644 --- a/app/src/main/java/com/zhoujinlong/presenter/impl/LoginLogicImpl.java +++ b/app/src/main/java/com/zhoujinlong/presenter/impl/LoginLogicImpl.java @@ -3,7 +3,7 @@ import com.zhoujinlong.model.http.BaseHttpService; import com.zhoujinlong.model.http.Factory; import com.zhoujinlong.presenter.LoginLogic; -import com.zhoujinlong.ui.view.LoginView; +import com.zhoujinlong.presenter.view.LoginView; /** * author meikoz on 2016/4/13. @@ -16,7 +16,10 @@ public class LoginLogicImpl implements LoginLogic { @Override public void login(String name, String passwrod) { - + if (name.equals("zhangsan") && passwrod.equals("123")) + mView.onLoginSuccess(); + else + mView.onLoginFail(); } @Override diff --git a/app/src/main/java/com/zhoujinlong/presenter/impl/MainLogicImpl.java b/app/src/main/java/com/zhoujinlong/presenter/impl/MainLogicImpl.java new file mode 100644 index 0000000..bdba5be --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/presenter/impl/MainLogicImpl.java @@ -0,0 +1,32 @@ +package com.zhoujinlong.presenter.impl; + +import com.zhoujinlong.model.bean.Classify; +import com.zhoujinlong.model.http.Factory; +import com.zhoujinlong.presenter.MainLogic; +import com.zhoujinlong.presenter.base.LoadSuccessLogicImpl; + +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 12:05 + * @GitHub: https://github.com/meikoz + */ +public class MainLogicImpl extends LoadSuccessLogicImpl implements MainLogic { + @Override + public void onLoadRemoteData(final boolean isMore, int page) { + Factory.provideHttpService().getImageClassify(page).enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + onLoadListSuccessHandle(response, isMore); + } + + @Override + public void onFailure(Call call, Throwable t) { + onLoadFail("wangluocuwu"); + } + }); + } +} diff --git a/app/src/main/java/com/zhoujinlong/ui/view/CompeteView.java b/app/src/main/java/com/zhoujinlong/presenter/view/HomeView.java similarity index 73% rename from app/src/main/java/com/zhoujinlong/ui/view/CompeteView.java rename to app/src/main/java/com/zhoujinlong/presenter/view/HomeView.java index 5c165b7..c9c0db5 100644 --- a/app/src/main/java/com/zhoujinlong/ui/view/CompeteView.java +++ b/app/src/main/java/com/zhoujinlong/presenter/view/HomeView.java @@ -1,4 +1,4 @@ -package com.zhoujinlong.ui.view; +package com.zhoujinlong.presenter.view; import com.zhoujinlong.model.bean.Classify; @@ -8,6 +8,6 @@ * author meikoz on 2016/3/30. * email meikoz@126.com */ -public interface CompeteView { +public interface HomeView { void onSuccess(List list); } diff --git a/app/src/main/java/com/zhoujinlong/ui/view/LoginView.java b/app/src/main/java/com/zhoujinlong/presenter/view/LoginView.java similarity index 78% rename from app/src/main/java/com/zhoujinlong/ui/view/LoginView.java rename to app/src/main/java/com/zhoujinlong/presenter/view/LoginView.java index 0cec658..9bb706f 100644 --- a/app/src/main/java/com/zhoujinlong/ui/view/LoginView.java +++ b/app/src/main/java/com/zhoujinlong/presenter/view/LoginView.java @@ -1,4 +1,4 @@ -package com.zhoujinlong.ui.view; +package com.zhoujinlong.presenter.view; /** * author meikoz on 2016/4/19. diff --git a/app/src/main/java/com/zhoujinlong/ui/view/MainView.java b/app/src/main/java/com/zhoujinlong/presenter/view/MainView.java similarity index 81% rename from app/src/main/java/com/zhoujinlong/ui/view/MainView.java rename to app/src/main/java/com/zhoujinlong/presenter/view/MainView.java index ac9e89d..be6cab1 100644 --- a/app/src/main/java/com/zhoujinlong/ui/view/MainView.java +++ b/app/src/main/java/com/zhoujinlong/presenter/view/MainView.java @@ -1,4 +1,4 @@ -package com.zhoujinlong.ui.view; +package com.zhoujinlong.presenter.view; /** * author meikoz on 2016/4/19. diff --git a/app/src/main/java/com/zhoujinlong/ui/activity/AutoLoadMoreListView.java b/app/src/main/java/com/zhoujinlong/ui/activity/AutoLoadMoreListView.java deleted file mode 100644 index bc73ec3..0000000 --- a/app/src/main/java/com/zhoujinlong/ui/activity/AutoLoadMoreListView.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.zhoujinlong.ui.activity; - -import android.content.Context; -import android.util.AttributeSet; -import android.view.LayoutInflater; -import android.view.MotionEvent; -import android.view.View; -import android.widget.AbsListView; -import android.widget.ListView; - -import com.zhoujinlong.R; - -/** - * @ClassName: XListView.java - * @author: 蜡笔小新 - * @date: 2016-04-28 17:53 - */ -public class AutoLoadMoreListView extends ListView implements AbsListView.OnScrollListener { - - int mFirstVisibleItem; //当前第一个可见Item的位置 - int mTotalItemCount; - int mLastVisibleItem; //最后一个可见Item的位置 - boolean isMarkItem; // 标记第一个出现的Item - - int mScrollState; // 滚动状态 - int state; //当前状态 - - final int NONE = 0; // 正常状态 - final int PULL = 1; // 下拉刷新状态 - final int RELESE = 2; // 松开释放状态 - - boolean isLoading; //正在加载 - private View mFooterView; - private ILoadMoreCallback mCallback; - private int startY; - - public AutoLoadMoreListView(Context context) { - super(context); - initView(context); - } - - public AutoLoadMoreListView(Context context, AttributeSet attrs) { - super(context, attrs); - initView(context); - } - - public AutoLoadMoreListView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - initView(context); - } - - private void initView(Context context) { - LayoutInflater inflater = LayoutInflater.from(context); - mFooterView = inflater.inflate(R.layout.view_footer_layout, null); - mFooterView.setVisibility(GONE); - - // 设置滚动监听 - setOnScrollListener(this); - // 去掉底部分割线 - setFooterDividersEnabled(false); - } - - @Override - public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - mFirstVisibleItem = firstVisibleItem; - mTotalItemCount = totalItemCount; - mLastVisibleItem = firstVisibleItem + visibleItemCount; - } - - @Override - public void onScrollStateChanged(AbsListView view, int scrollState) { - mScrollState = scrollState; - if (mTotalItemCount == mLastVisibleItem && mScrollState == SCROLL_STATE_IDLE) { - if (!isLoading) { - isLoading = true; - mFooterView.setVisibility(VISIBLE); - mCallback.onLoadMore(); - } - } - } - - - @Override - public boolean onTouchEvent(MotionEvent ev) { - switch (ev.getAction()) { - case MotionEvent.ACTION_DOWN: - if (mFirstVisibleItem == 0) { - isMarkItem = true; - startY = (int) ev.getY(); - } - break; - - case MotionEvent.ACTION_MOVE: - onMove(ev); - break; - case MotionEvent.ACTION_UP: - - break; - } - return super.onTouchEvent(ev); - } - - - /* - * 判断移动过程中的操作 - */ - private void onMove(MotionEvent e) { - - } - - - public void setOnLoadMoreListener(ILoadMoreCallback callback) { - mCallback = callback; - } - - public interface ILoadMoreCallback { - void onRefresh(); - - void onLoadMore(); - } -} diff --git a/app/src/main/java/com/zhoujinlong/ui/activity/LoginActivity.java b/app/src/main/java/com/zhoujinlong/ui/activity/LoginActivity.java index 0382097..b834ec1 100644 --- a/app/src/main/java/com/zhoujinlong/ui/activity/LoginActivity.java +++ b/app/src/main/java/com/zhoujinlong/ui/activity/LoginActivity.java @@ -4,19 +4,19 @@ import android.content.Intent; import android.widget.EditText; -import com.android.core.model.control.LogicProxy; import com.android.core.ui.BaseActivity; import com.zhoujinlong.ui.widget.TitleBar; import com.zhoujinlong.R; import com.zhoujinlong.presenter.LoginLogic; -import com.zhoujinlong.ui.view.LoginView; +import com.zhoujinlong.presenter.view.LoginView; import butterknife.Bind; import butterknife.OnClick; /** - * author meikoz on 2016/4/13. - * email meikoz@126.com + * @author: 蜡笔小新 + * @date: 2016-05-31 10:51 + * @GitHub: https://github.com/meikoz */ public class LoginActivity extends BaseActivity implements LoginView { @@ -55,11 +55,11 @@ protected void onInitData() { @OnClick(R.id.btn_login) void login() { mLoginLogic.login("zhangsan", "123"); - startActivity(new Intent(LoginActivity.this, SwipBackActivity.class)); } @Override public void onLoginSuccess() { + startActivity(new Intent(LoginActivity.this, MainActivity.class)); } @Override diff --git a/app/src/main/java/com/zhoujinlong/ui/activity/MainActivity.java b/app/src/main/java/com/zhoujinlong/ui/activity/MainActivity.java index f160af8..ecdc8ea 100644 --- a/app/src/main/java/com/zhoujinlong/ui/activity/MainActivity.java +++ b/app/src/main/java/com/zhoujinlong/ui/activity/MainActivity.java @@ -1,22 +1,25 @@ package com.zhoujinlong.ui.activity; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.support.v4.app.FragmentActivity; +import android.view.Window; import com.android.core.widget.TabStripView; import com.zhoujinlong.R; -import com.zhoujinlong.ui.fragment.CompeteFragment; +import com.zhoujinlong.ui.fragment.HomeFragment; import com.zhoujinlong.ui.fragment.DiscoveryFragment; import com.zhoujinlong.ui.fragment.PersonFragment; -public class MainActivity extends AppCompatActivity { +public class MainActivity extends FragmentActivity { private TabStripView navigateTabBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); + navigateTabBar = (TabStripView) findViewById(R.id.navigateTabBar); //对应xml中的containerId navigateTabBar.setFrameLayoutId(R.id.main_container); @@ -28,7 +31,7 @@ protected void onCreate(Bundle savedInstanceState) { //恢复选项状态 navigateTabBar.onRestoreInstanceState(savedInstanceState); - navigateTabBar.addTab(CompeteFragment.class, new TabStripView.TabParam(R.drawable.ic_tab_bar_home, R.drawable.ic_tab_bar_home_selected, R.string.abc_tab_text_home)); + navigateTabBar.addTab(HomeFragment.class, new TabStripView.TabParam(R.drawable.ic_tab_bar_home, R.drawable.ic_tab_bar_home_selected, R.string.abc_tab_text_home)); navigateTabBar.addTab(DiscoveryFragment.class, new TabStripView.TabParam(R.drawable.ic_tab_bar_find, R.drawable.ic_tab_bar_find_selected, R.string.abc_tab_text_find)); navigateTabBar.addTab(PersonFragment.class, new TabStripView.TabParam(R.drawable.ic_tab_bar_person, R.drawable.ic_tab_bar_person_selected, R.string.abc_tab_text_person)); } diff --git a/app/src/main/java/com/zhoujinlong/ui/activity/SplashActivity.java b/app/src/main/java/com/zhoujinlong/ui/activity/SplashActivity.java index 1aba25b..779f84f 100644 --- a/app/src/main/java/com/zhoujinlong/ui/activity/SplashActivity.java +++ b/app/src/main/java/com/zhoujinlong/ui/activity/SplashActivity.java @@ -51,7 +51,7 @@ private void startScaleAnimation() { AnimationUtil.setAnimationListener(animation, new AnimationUtil.AnimListener() { @Override public void onAnimFinish() { - startActivity(new Intent(SplashActivity.this, MainActivity.class)); + startActivity(new Intent(SplashActivity.this, LoginActivity.class)); // finish(); // LoginActivity.start(SplashActivity.this); } diff --git a/app/src/main/java/com/zhoujinlong/ui/activity/SwipBackActivity.java b/app/src/main/java/com/zhoujinlong/ui/activity/SwipBackActivity.java index 0806118..1500c45 100644 --- a/app/src/main/java/com/zhoujinlong/ui/activity/SwipBackActivity.java +++ b/app/src/main/java/com/zhoujinlong/ui/activity/SwipBackActivity.java @@ -1,5 +1,7 @@ package com.zhoujinlong.ui.activity; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; import com.android.core.ui.BaseSwipeBackActivity; @@ -12,6 +14,11 @@ */ public class SwipBackActivity extends BaseSwipeBackActivity { + public static void start(Context context) { + Intent intent = new Intent(context, SwipBackActivity.class); + context.startActivity(intent); + } + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); diff --git a/app/src/main/java/com/zhoujinlong/ui/fragment/CompeteFragment.java b/app/src/main/java/com/zhoujinlong/ui/fragment/CompeteFragment.java deleted file mode 100644 index a2f316f..0000000 --- a/app/src/main/java/com/zhoujinlong/ui/fragment/CompeteFragment.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.zhoujinlong.ui.fragment; - - -import android.os.Bundle; -import android.support.v7.widget.RecyclerView; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; - -import com.android.core.ui.BaseFragment; -import com.jcodecraeer.xrecyclerview.XRecyclerView; -import com.pacific.adapter.RecyclerAdapter; -import com.pacific.adapter.RecyclerAdapterHelper; -import com.zhoujinlong.R; -import com.zhoujinlong.model.bean.Classify; -import com.zhoujinlong.ui.view.CompeteView; - -import java.util.List; - -import butterknife.Bind; -import butterknife.ButterKnife; - -/** - * author meikoz on 2016/3/30. - * email meikoz@126.com - */ -public class CompeteFragment extends BaseFragment implements CompeteView { - - @Bind(R.id.recly_view) - XRecyclerView reclyView; - - @Override - protected int getLayoutResource() { - return R.layout.fragment_compete; - } - - @Override - protected void onInitView() { - RecyclerView.Adapter adapter = new RecyclerAdapter(getActivity(), R.layout.item_home_list) { - @Override - protected void convert(RecyclerAdapterHelper helper, Object item) { - - } - }; - reclyView.setAdapter(adapter); - } - - @Override - protected void onInitData() { - - } - - @Override - public void onSuccess(List list) { - - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - // TODO: inflate a fragment view - View rootView = super.onCreateView(inflater, container, savedInstanceState); - ButterKnife.bind(this, rootView); - return rootView; - } - - @Override - public void onDestroyView() { - super.onDestroyView(); - ButterKnife.unbind(this); - } -} diff --git a/app/src/main/java/com/zhoujinlong/ui/fragment/HomeFragment.java b/app/src/main/java/com/zhoujinlong/ui/fragment/HomeFragment.java new file mode 100644 index 0000000..78195a1 --- /dev/null +++ b/app/src/main/java/com/zhoujinlong/ui/fragment/HomeFragment.java @@ -0,0 +1,144 @@ +package com.zhoujinlong.ui.fragment; + + +import android.os.Bundle; +import android.os.Handler; +import android.support.v7.widget.LinearLayoutManager; +import android.view.View; + +import com.android.core.ui.BaseFragment; +import com.android.core.util.StatusBarUtil; +import com.android.core.widget.CustomViewpager; +import com.android.core.widget.SpacesItemDecoration; +import com.jcodecraeer.xrecyclerview.ProgressStyle; +import com.jcodecraeer.xrecyclerview.XRecyclerView; +import com.zhoujinlong.R; +import com.zhoujinlong.adapter.CustomViewPageAdapter; +import com.zhoujinlong.adapter.HomeRecyclerAdapter; +import com.android.core.adapter.RecyclerAdapter; +import com.zhoujinlong.model.bean.Classify; +import com.zhoujinlong.presenter.MainLogic; +import com.zhoujinlong.presenter.base.CommonView; + +import java.util.ArrayList; +import java.util.List; + +import butterknife.Bind; +import butterknife.ButterKnife; + +/** + * @author: 蜡笔小新 + * @date: 2016-05-31 10:51 + * @GitHub: https://github.com/meikoz + */ +public class HomeFragment extends BaseFragment implements CommonView, XRecyclerView.LoadingListener { + + @Bind(R.id.recly_view) + XRecyclerView mRecyclerView; + + private List classifys = new ArrayList<>(); + private CustomViewpager mViewpage; + private MainLogic mHomeLogic; + private RecyclerAdapter recyclerAdapter; + private int page = 1; + + @Override + protected int getLayoutResource() { + return R.layout.fragment_compete; + } + + @Override + protected void onInitView() { + StatusBarUtil.setTransparent(getActivity()); + } + + @Override + protected void onInitData() { + mHomeLogic = getLogicImpl(MainLogic.class, this); + } + + // 广告数据 + public static List getAdData() { + List adList = new ArrayList<>(); + adList.add(R.drawable.abc_adv_1); + adList.add(R.drawable.abc_adv_2); + adList.add(R.drawable.abc_adv_3); + return adList; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + + LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); + layoutManager.setOrientation(LinearLayoutManager.VERTICAL); + //分割线 + mRecyclerView.addItemDecoration(new SpacesItemDecoration(1)); + mRecyclerView.setLayoutManager(layoutManager); + + mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader); + mRecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate); + mRecyclerView.setArrowImageView(R.drawable.abc_icon_down_arrow); + + View header = View.inflate(getActivity(), R.layout.abc_viewpager_view, null); + mViewpage = (CustomViewpager) header.findViewById(R.id.viewpager); + mRecyclerView.addHeaderView(header); + + CustomViewPageAdapter adapter = new CustomViewPageAdapter(getActivity(), getAdData()); + mViewpage.updateIndicatorView(getAdData().size(), 0); + mViewpage.setAdapter(adapter); + mViewpage.startScorll(); + + recyclerAdapter = new HomeRecyclerAdapter(getActivity(), R.layout.item_compete_classitfy, classifys); + mRecyclerView.setAdapter(recyclerAdapter); + mRecyclerView.setLoadingListener(this); + onRefresh(); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + ButterKnife.unbind(this); + } + + @Override + public void onLoadComplete() { + //加载完成需要做的操作 + } + + /** + * 网络加载成功后显示数据 + */ + @Override + public void onShowListData(Classify listData, boolean isMore) { + if (listData.isStatus()) { + if (!isMore) + classifys.clear(); + classifys.addAll(listData.getTngou()); + recyclerAdapter.notifyDataSetChanged(); + } + } + + @Override + public void onRefresh() { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + mHomeLogic.onLoadRemoteData(false, 1); + mRecyclerView.refreshComplete(); + } + }, 2000); + } + + @Override + public void onLoadMore() { + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + page++; + mHomeLogic.onLoadRemoteData(true, page); + mRecyclerView.loadMoreComplete(); + } + }, 2000); + } +} diff --git a/app/src/main/res/drawable-xhdpi/abc_adv_1.jpg b/app/src/main/res/drawable-xhdpi/abc_adv_1.jpg new file mode 100644 index 0000000..03f099c Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/abc_adv_1.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/abc_adv_2.jpg b/app/src/main/res/drawable-xhdpi/abc_adv_2.jpg new file mode 100644 index 0000000..4ac99f2 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/abc_adv_2.jpg differ diff --git a/app/src/main/res/drawable-xhdpi/abc_adv_3.jpg b/app/src/main/res/drawable-xhdpi/abc_adv_3.jpg new file mode 100644 index 0000000..2879d27 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/abc_adv_3.jpg differ diff --git a/app/src/main/res/layout/abc_viewpager_view.xml b/app/src/main/res/layout/abc_viewpager_view.xml new file mode 100644 index 0000000..5c00e17 --- /dev/null +++ b/app/src/main/res/layout/abc_viewpager_view.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/app/src/main/res/layout/activity_listview.xml b/app/src/main/res/layout/activity_listview.xml deleted file mode 100644 index ac0b52a..0000000 --- a/app/src/main/res/layout/activity_listview.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 2d30260..940ce6d 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -5,17 +5,19 @@ android:background="@android:color/white" android:orientation="vertical"> - + + android:layout_height="wrap_content" + android:text="zhangsan" /> + android:layout_height="wrap_content" + android:text="123" />