|
@@ -1,18 +1,25 @@
|
|
|
package com.ynstkz.shitu.android.activity;
|
|
|
|
|
|
+import android.annotation.SuppressLint;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
+import android.os.Handler;
|
|
|
+import android.os.Message;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v4.view.ViewPager;
|
|
|
import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
|
+import android.widget.LinearLayout;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.common.library.okhttp.OkHttpUtils;
|
|
|
import com.common.library.okhttp.callback.Callback;
|
|
|
import com.google.gson.Gson;
|
|
|
import com.ynstkz.shitu.android.R;
|
|
|
+import com.ynstkz.shitu.android.adapter.ViewPagerAdapter;
|
|
|
import com.ynstkz.shitu.android.base.BaseBean;
|
|
|
import com.ynstkz.shitu.android.base.TitleBarActivity;
|
|
|
import com.ynstkz.shitu.android.bean.CourseDetilBean;
|
|
@@ -21,6 +28,9 @@ import com.ynstkz.shitu.android.data.SharedPreferencesUtils;
|
|
|
import com.ynstkz.shitu.android.data.UrlCat;
|
|
|
import com.ynstkz.shitu.android.helper.UmengShareHelper;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
import butterknife.Bind;
|
|
|
import okhttp3.Call;
|
|
|
import okhttp3.Response;
|
|
@@ -51,17 +61,27 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
ImageView ivShare;
|
|
|
@Bind(R.id.tv_course_marketprice)
|
|
|
TextView tvCourseMarketprice;
|
|
|
- @Bind(R.id.tv_enrollmentArea)
|
|
|
- TextView tvEnrollmentArea;
|
|
|
@Bind(R.id.tv_requirement)
|
|
|
TextView tvRequirement;
|
|
|
@Bind(R.id.tv_view_count)
|
|
|
TextView tvViewCount;
|
|
|
+ @Bind(R.id.ll_collect)
|
|
|
+ LinearLayout llCollect;
|
|
|
+ @Bind(R.id.iv_banner_bg)
|
|
|
+ ImageView ivBannerBg;
|
|
|
+ @Bind(R.id.ll_point_main)
|
|
|
+ LinearLayout llPointMain;
|
|
|
+ @Bind(R.id.tv_enrollmentArea)
|
|
|
+ TextView tvEnrollmentArea;
|
|
|
|
|
|
private String courseId;
|
|
|
private CourseDetilBean courseDetilBean;
|
|
|
private boolean isCollect;
|
|
|
|
|
|
+ private int bannerIndex;
|
|
|
+ private List<ImageView> listPointView;
|
|
|
+ private int pointIndex;
|
|
|
+
|
|
|
@Override
|
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
@@ -116,7 +136,7 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
public void onClick(View view) {
|
|
|
if (courseDetilBean != null) {
|
|
|
UmengShareHelper.show(CourseDetailActivity.this, courseDetilBean.getData().getTitle(), courseDetilBean.getData().getDetail(),
|
|
|
- "http://www.baidu.com", courseDetilBean.getData().getCoursePic());
|
|
|
+ "http://www.baidu.com", "");
|
|
|
}
|
|
|
}
|
|
|
});
|
|
@@ -138,6 +158,24 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ vpBanner.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageSelected(int position) {
|
|
|
+ pointIndex = position;
|
|
|
+ refreshPointView();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPageScrollStateChanged(int state) {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -147,7 +185,7 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
*/
|
|
|
private void getCourseDetail(String courseId) {
|
|
|
|
|
|
- RequestGroup.getCourseDetail(courseId, new Callback() {
|
|
|
+ RequestGroup.getCourseDetail(this, courseId, new Callback() {
|
|
|
@Override
|
|
|
public Object parseNetworkResponse(Response response, int id) throws Exception {
|
|
|
return new Gson().fromJson(response.body().string(), CourseDetilBean.class);
|
|
@@ -181,18 +219,120 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
return;
|
|
|
}
|
|
|
CourseDetilBean.DataBean dataBean = courseDetilBean.getData();
|
|
|
- tvViewCount.setText("收藏:" + courseDetilBean.getData().getViewCount() + "次");
|
|
|
+ initBannerView(dataBean);
|
|
|
+ tvViewCount.setText("收藏:" + courseDetilBean.getData().getCollectCount() + "次");
|
|
|
tvTitle.setText(dataBean.getTitle());
|
|
|
tvOrgName.setText(dataBean.getTitle());
|
|
|
tvOrgDesc.setText(dataBean.getDetail());
|
|
|
tvPrice.setText("¥" + dataBean.getPrice() + "元");
|
|
|
tvCourseMarketprice.setText("市场价¥" + dataBean.getMarketPrice());
|
|
|
isCollect = courseDetilBean.getData().isCollect();
|
|
|
- tvEnrollmentArea.setText(courseDetilBean.getData().getEnrollmentArea());
|
|
|
tvRequirement.setText(courseDetilBean.getData().getRequirement());
|
|
|
initCollectIcon();
|
|
|
+ //招生区域
|
|
|
+ initEnrollAreaList(dataBean);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 初始化banner信息
|
|
|
+ */
|
|
|
+ private void initBannerView(CourseDetilBean.DataBean dataBean) {
|
|
|
+
|
|
|
+ if (dataBean == null || dataBean.getCoursePicList() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<CourseDetilBean.DataBean.CoursePicListBean> coursePicList = courseDetilBean.getData().getCoursePicList();
|
|
|
+
|
|
|
+ if (coursePicList != null && coursePicList.size() > 0) {
|
|
|
+ ivBannerBg.setVisibility(View.GONE);
|
|
|
+ List<View> listShowPic = new ArrayList<>();
|
|
|
+ for (int i = 0; i < coursePicList.size(); i++) {
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ final CourseDetilBean.DataBean.CoursePicListBean coursePicListBean = coursePicList.get(i);
|
|
|
+ String picUrl = coursePicListBean.getPicUrl();
|
|
|
+ if (!TextUtils.isEmpty(picUrl)) {
|
|
|
+ if (picUrl.startsWith("http")) {
|
|
|
+ Glide.with(this).load(picUrl).into(imageView);
|
|
|
+ } else {
|
|
|
+ Glide.with(this).load(UrlCat.HOST + picUrl).into(imageView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ listShowPic.add(imageView);
|
|
|
+ }
|
|
|
+ ViewPagerAdapter adapter = new ViewPagerAdapter(listShowPic);
|
|
|
+ vpBanner.setAdapter(adapter);
|
|
|
+ vpBanner.setCurrentItem(bannerIndex);
|
|
|
+ adapter.notifyDataSetChanged();
|
|
|
+ initPointView(dataBean);
|
|
|
+ handler.sendEmptyMessageDelayed(0, 3000);
|
|
|
+ } else {
|
|
|
+ ivBannerBg.setVisibility(View.VISIBLE);
|
|
|
+ vpBanner.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 初始化焦点View
|
|
|
+ */
|
|
|
+ private void initPointView(CourseDetilBean.DataBean dataBean) {
|
|
|
+ if (dataBean == null || dataBean.getCoursePicList() == null || dataBean.getCoursePicList().size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int showPicSize = courseDetilBean.getData().getCoursePicList().size();
|
|
|
+ if (showPicSize > 0) {
|
|
|
+ listPointView = new ArrayList<>();
|
|
|
+ for (int i = 0; i < showPicSize; i++) {
|
|
|
+ ImageView imageView = new ImageView(this);
|
|
|
+ imageView.setImageResource(R.drawable.banner_point_nomal);
|
|
|
+ LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(15, 15);
|
|
|
+ params.rightMargin = 10;
|
|
|
+ imageView.setLayoutParams(params);
|
|
|
+ listPointView.add(imageView);
|
|
|
+ llPointMain.addView(imageView);
|
|
|
+ }
|
|
|
+ refreshPointView();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 刷新焦点图片
|
|
|
+ */
|
|
|
+ private void refreshPointView() {
|
|
|
+ if (courseDetilBean == null || courseDetilBean.getData() == null ||
|
|
|
+ courseDetilBean.getData().getCoursePicList() == null || courseDetilBean.getData().getCoursePicList().size() == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (pointIndex >= courseDetilBean.getData().getCoursePicList().size()) {
|
|
|
+ pointIndex = 0;
|
|
|
+ }
|
|
|
+ if (listPointView != null && courseDetilBean.getData().getCoursePicList().size() > 0) {
|
|
|
+ for (int i = 0; i < listPointView.size(); i++) {
|
|
|
+ if (i == pointIndex) {
|
|
|
+ listPointView.get(i).setImageResource(R.drawable.banner_point_press);
|
|
|
+ } else {
|
|
|
+ listPointView.get(i).setImageResource(R.drawable.banner_point_nomal);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 招生区域
|
|
|
+ *
|
|
|
+ * @param dataBean
|
|
|
+ */
|
|
|
+ private void initEnrollAreaList(CourseDetilBean.DataBean dataBean) {
|
|
|
+ if (dataBean == null || dataBean.getEnrollAreaList() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String areaName = "";
|
|
|
+ if (dataBean.getEnrollAreaList().size() > 0) {
|
|
|
+ for (int i = 0; i < dataBean.getEnrollAreaList().size(); i++) {
|
|
|
+ areaName = areaName + dataBean.getEnrollAreaList().get(i).getAddress() + "\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tvEnrollmentArea.setText(areaName);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 收藏
|
|
@@ -272,6 +412,27 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @SuppressLint("HandlerLeak")
|
|
|
+ Handler handler = new Handler() {
|
|
|
+ @Override
|
|
|
+ public void handleMessage(Message msg) {
|
|
|
+ switch (msg.what) {
|
|
|
+ case 0:
|
|
|
+ bannerIndex++;
|
|
|
+ pointIndex++;
|
|
|
+ if (bannerIndex < courseDetilBean.getData().getCoursePicList().size()) {
|
|
|
+ vpBanner.setCurrentItem(bannerIndex);
|
|
|
+ } else {
|
|
|
+ vpBanner.setCurrentItem(0);
|
|
|
+ bannerIndex = 0;
|
|
|
+ }
|
|
|
+ handler.sendEmptyMessageDelayed(0, 3000);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
@Override
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
switch (requestCode) {
|
|
@@ -280,4 +441,11 @@ public class CourseDetailActivity extends TitleBarActivity {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ handler.removeCallbacksAndMessages(null);
|
|
|
+ OkHttpUtils.getInstance().cancelTag(this);
|
|
|
+ }
|
|
|
}
|