以前总是通过HDMI线将电脑连接电视看剧看电影,但是每次想快进啊进行一些操作过于麻烦,手机上的APP的资源又太少,于是想到将电影网站打包成一个APP!
APP已经差不多做好了,最近也比较忙,没什么时间去弄,界面很丑,这里我讲讲我的主要思路,自己动手才有乐趣!
在做之前整理下思路,怎样才能把网站搬到APP上呢?
有两个方法:
1.通过WebView简单粗暴将整个网站搬过来,几十行代码搞定!但是用户体验不是很好,广告多,字体小,操作也不是很方便
2.利用爬虫,需要什么爬什么!然后将数据显示在自己做的界面上!
Let'go
首先我们搭一个界面大概的界面出来
[Java]纯文本查看复制代码
ButterKnife.bind(this);
mTabBar.init(getSupportFragmentManager())
.setImgSize(50, 50)
.setFontSize(10)
.setTabPadding(4, 6, 10)
.setChangeColor(Color.RED, Color.DKGRAY)
.addTabItem("首页", R.mipmap.ic_launcher_round, HomeFragment.class)
.addTabItem("电影", R.mipmap.ic_launcher_round, MoveFragment.class)
.addTabItem("电视剧", R.mipmap.ic_launcher_round, TVplayFragment.class)
.addTabItem("动漫", R.mipmap.ic_launcher_round, CartoonFragment.class);
[Java]纯文本查看复制代码
public class DataBean {
private String DataName;
private String DataScore;
private String DataImg;
private String DataNetWork;
public String getDataName() {
return DataName;
}
public void setDataName(String dataName) {
DataName = dataName;
}
public String getDataScore() {
return DataScore;
}
public void setDataScore(String dataScore) {
DataScore = dataScore;
}
public String getDataImg() {
return DataImg;
}
public void setDataImg(String dataImg) {
DataImg = dataImg;
}
public String getDataNetWork() {
return DataNetWork;
}
public void setDataNetWork(String dataNetWork) {
DataNetWork = dataNetWork;
}
}
[Java]纯文本查看复制代码
RequestQueue queue = Volley.newRequestQueue(getActivity());
MyStringRequest stringRequest = new MyStringRequest(getHosturl(), new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String regEx = "<li><div class=li-box><div class=img-box></div><a href=\"(.+?)\"><img src=\"(.+?)\" onerror=\".+?\"><span class=back></span><span>(.+?)</span></div><P><a href=\".+?\" target=\"_blank\">(.+?)</a></P></li>";
Pattern pattern = Pattern.compile(regEx);
mMatcher = pattern.matcher(response);
if (mData != null) {
mData.clear();
}
new Thread(new Runnable() {
@Override
public void run() {
while (mMatcher.find()) {
//Log.e(TAG, matcher.group());
/*Log.e(TAG, mMatcher.group(1));
Log.e(TAG, mMatcher.group(2));
Log.e(TAG, mMatcher.group(3));
Log.e(TAG, mMatcher.group(4));*/
DataBean dataBean = new DataBean();
dataBean.setDataNetWork(mMatcher.group(1));
dataBean.setDataImg(mMatcher.group(2));
dataBean.setDataName(mMatcher.group(4));
dataBean.setDataScore(mMatcher.group(3));
mData.add(dataBean);
}
}
}).start();
if (mHomeAdapter == null) {
mHomeAdapter = new homeAdapter(getContext(), mData, mGridLayoutManager);
}
mRecyclerView.setAdapter(mHomeAdapter);
mHomeAdapter.notifyDataSetChanged();
mTvThisPage.setText("第"+mThisPage+"页");
Toast.makeText(getContext(), "第" + mThisPage + "页", Toast.LENGTH_SHORT).show();
mHomeAdapter.setItemClickListener(new homeAdapter.OnItemClickListener() {
@Override
public void onItemClick(int position) {
String url = mData.get(position).getDataNetWork();
String title = mData.get(position).getDataName();
String img_url = mData.get(position).getDataImg();
String requestUrl = getHosturl() + url;
//Toast.makeText(getContext(), requestUrl, Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), DetailsActivity.class);
intent.putExtra("title", title);
intent.putExtra("img_url", img_url);
intent.putExtra("requestUrl", requestUrl);
startActivity(intent);
}
});
//Log.e(TAG, response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.getMessage(), error);
mThisPage--;
Toast.makeText(getContext(), "网络不稳定!加载失败!请稍后重试!", Toast.LENGTH_SHORT).show();
}
});
queue.add(stringRequest);
}
[Java]纯文本查看复制代码
public class MoveFragment extends HomeFragment implements View.OnClickListener {
@Override
protected void intitView() {
hostUrl = "http://m.yiybb.com/dianying/";
super.intitView();
mThisPage = 1;
listTpye = "List_15_";
mTvThisPage.setVisibility(View.VISIBLE);
}
@Override
protected void initData() {
super.initData();
}
@Override
protected String setTitle() {
return "电影";
}
@Override
protected void setViibilly() {
page.setVisibility(View.VISIBLE);
}
[Java]纯文本查看复制代码
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课
最后于 2018-8-30 11:26
被wushaominkk编辑
,原因: 上传源码