GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 三级缓存添加 · java02014/Coder@e0ea63a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .idea
    • misc.xml
    • modules.xml
  • app
    • build.gradle
    • src/main
      • AndroidManifest.xml
      • java/com/coder/guoy/recyclerview
        • Constants.java
        • HomeActivity.java
        • HomeAdapter.java
        • api/bean
          • ImageBean.java
        • ui/cache
          • CacheActivity.java
          • CacheAdapter.java
          • Data.java
          • Database.java
      • res/layout
        • activity_cache.xml
        • activity_play_coordinator_toolbar.xml
        • item_cache.xml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.idea/misc.xml‎

Copy file name to clipboardExpand all lines: .idea/misc.xml
+1-4Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎.idea/modules.xml‎

Copy file name to clipboardExpand all lines: .idea/modules.xml
+1-1Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎app/build.gradle‎

Copy file name to clipboardExpand all lines: app/build.gradle
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ dependencies {
4646
compile 'com.squareup.okhttp3:okhttp:3.2.0'
4747
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
4848
compile 'com.android.support:multidex:1.0.0'
49+
compile 'org.jsoup:jsoup:1.10.3'
4950
testCompile 'junit:junit:4.12'
5051
}
Collapse file

‎app/src/main/AndroidManifest.xml‎

Copy file name to clipboardExpand all lines: app/src/main/AndroidManifest.xml
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@
144144
<activity
145145
android:name=".ui.ClassificationAdapterActivity"
146146
android:screenOrientation="portrait"/>
147-
<activity android:name=".TestActivity">
148-
</activity>
147+
<activity android:name=".ui.cache.CacheActivity"/>
149148
</application>
150149

151150
</manifest>
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/Constants.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/coder/guoy/recyclerview/Constants.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ public class Constants {
1111
public static final String GANK_URL = "http://gank.io/api/";
1212
//豆瓣
1313
public static final String DOUBAN_URL = "Https://api.douban.com/";
14-
14+
//壁纸
15+
public static final String BZ_URl = "http://www.win4000.com/";
16+
//桌面壁纸
17+
public static final String ZMBZ = BZ_URl + "wallpaper.html";
1518
//================= TYPE ====================
1619
//福利
1720
public static final String FULI = "福利";
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/HomeActivity.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/coder/guoy/recyclerview/HomeActivity.java
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ public class HomeActivity extends AppCompatActivity implements View.OnClickListe
2222
private HomeAdapter adapter;
2323
private LinearLayoutManager mLayoutManager;
2424
private String[] model = {"Material Design", "RecyclerView", "CardView", "Customize", "Animation",
25-
"Design Pattern", "目标1", "目标2", "目标3", "目标4"};
25+
"Design Pattern", "Cache", "目标2", "目标3", "目标4"};
2626
private String[] describe = {"材料设计", "", "卡片控件", "自定义", "动画",
27-
"设计模式", "", "", "", ""};
27+
"设计模式", "三级缓存", "", "", ""};
2828

2929
@Override
3030
protected void onCreate(Bundle savedInstanceState) {
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/HomeAdapter.java‎

Copy file name to clipboardExpand all lines: app/src/main/java/com/coder/guoy/recyclerview/HomeAdapter.java
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.coder.guoy.recyclerview.databinding.ItemHomeBannerBinding;
1515
import com.coder.guoy.recyclerview.databinding.ItemHomeBinding;
1616
import com.coder.guoy.recyclerview.ui.PlayCardView;
17+
import com.coder.guoy.recyclerview.ui.cache.CacheActivity;
1718
import com.coder.guoy.recyclerview.ui.holder.AnimationHolder;
1819
import com.coder.guoy.recyclerview.ui.holder.CustomizeHolder;
1920
import com.coder.guoy.recyclerview.ui.holder.DesignPatternHolder;
@@ -95,6 +96,7 @@ public void onClick(View v) {
9596
mContext.startActivity(new Intent(mContext, DesignPatternHolder.class));
9697
break;
9798
case 7://
99+
mContext.startActivity(new Intent(mContext, CacheActivity.class));
98100
break;
99101
}
100102
}
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/api/bean/ImageBean.java‎

Copy file name to clipboard
+87Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.coder.guoy.recyclerview.api.bean;
2+
3+
import android.os.Parcel;
4+
import android.os.Parcelable;
5+
6+
/**
7+
* @Version:
8+
* @Author:Guoy
9+
* @CreateTime:2017/10/9
10+
* @Descrpiton:美眉
11+
*/
12+
public class ImageBean implements Parcelable {
13+
private String linkUrl;
14+
private String imageUrl;
15+
private String thumbnailImageUrl;
16+
private String imgaeTitle;
17+
18+
public ImageBean(String linkUrl, String imageUrl, String imgaeTitle) {
19+
this.linkUrl = linkUrl;
20+
this.imageUrl = imageUrl;
21+
this.imgaeTitle = imgaeTitle;
22+
}
23+
24+
protected ImageBean(Parcel in) {
25+
linkUrl = in.readString();
26+
imageUrl = in.readString();
27+
imgaeTitle = in.readString();
28+
thumbnailImageUrl = in.readString();
29+
}
30+
31+
public static final Creator<ImageBean> CREATOR = new Creator<ImageBean>() {
32+
@Override
33+
public ImageBean createFromParcel(Parcel in) {
34+
return new ImageBean(in);
35+
}
36+
37+
@Override
38+
public ImageBean[] newArray(int size) {
39+
return new ImageBean[size];
40+
}
41+
};
42+
43+
public String getLinkUrl() {
44+
return linkUrl;
45+
}
46+
47+
public void setLinkUrl(String linkUrl) {
48+
this.linkUrl = linkUrl;
49+
}
50+
51+
public String getImageUrl() {
52+
return imageUrl;
53+
}
54+
55+
public void setImageUrl(String imageUrl) {
56+
this.imageUrl = imageUrl;
57+
}
58+
59+
public String getImgaeTitle() {
60+
return imgaeTitle;
61+
}
62+
63+
public void setImgaeTitle(String imgaeTitle) {
64+
this.imgaeTitle = imgaeTitle;
65+
}
66+
67+
public String getThumbnailImageUrl() {
68+
return thumbnailImageUrl;
69+
}
70+
71+
public void setThumbnailImageUrl(String thumbnailImageUrl) {
72+
this.thumbnailImageUrl = thumbnailImageUrl;
73+
}
74+
75+
@Override
76+
public int describeContents() {
77+
return 0;
78+
}
79+
80+
@Override
81+
public void writeToParcel(Parcel dest, int flags) {
82+
dest.writeString(linkUrl);
83+
dest.writeString(imageUrl);
84+
dest.writeString(imgaeTitle);
85+
dest.writeString(thumbnailImageUrl);
86+
}
87+
}
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/ui/cache/CacheActivity.java‎

Copy file name to clipboard
+108Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.coder.guoy.recyclerview.ui.cache;
2+
3+
import android.databinding.DataBindingUtil;
4+
import android.graphics.Color;
5+
import android.os.Bundle;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.GridLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
9+
import android.util.Log;
10+
import android.view.View;
11+
12+
import com.coder.guoy.recyclerview.Constants;
13+
import com.coder.guoy.recyclerview.R;
14+
import com.coder.guoy.recyclerview.api.bean.ImageBean;
15+
import com.coder.guoy.recyclerview.databinding.ActivityCacheBinding;
16+
import com.coder.guoy.recyclerview.utils.ToastUtil;
17+
18+
import java.util.List;
19+
20+
import rx.Observer;
21+
import rx.Subscription;
22+
23+
public class CacheActivity extends AppCompatActivity implements View.OnClickListener {
24+
private ActivityCacheBinding binding;
25+
private CacheAdapter adapter;
26+
private long startTime;
27+
protected Subscription subscription;
28+
29+
@Override
30+
protected void onCreate(Bundle savedInstanceState) {
31+
super.onCreate(savedInstanceState);
32+
binding = DataBindingUtil.setContentView(this, R.layout.activity_cache);
33+
transparentStatusBar();
34+
initRecyclerView(binding.recyclerviewModel2);
35+
binding.btn1.setOnClickListener(this);
36+
binding.btn2.setOnClickListener(this);
37+
binding.btn3.setOnClickListener(this);
38+
//最新
39+
getNetData(Constants.ZMBZ);
40+
}
41+
42+
// TODO: 透明状态栏
43+
private void transparentStatusBar() {
44+
View decorView = getWindow().getDecorView();
45+
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
46+
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
47+
decorView.setSystemUiVisibility(option);
48+
getWindow().setStatusBarColor(Color.TRANSPARENT);
49+
}
50+
51+
//TODO: 获取网络数据
52+
private void getNetData(final String url) {
53+
startTime = System.currentTimeMillis();
54+
unsubscribe();
55+
subscription = Data.getInstance().subscribeData(new Observer<List<ImageBean>>() {
56+
@Override
57+
public void onCompleted() {
58+
59+
}
60+
61+
@Override
62+
public void onError(Throwable e) {
63+
Log.i("cache_onError", e.toString());
64+
}
65+
66+
@Override
67+
public void onNext(List<ImageBean> imageBeen) {
68+
int loadTime = (int) (System.currentTimeMillis() - startTime);
69+
Log.i("cache_onNext", loadTime + "ms");
70+
adapter.setNewData(imageBeen);
71+
}
72+
}, url);
73+
}
74+
75+
// TODO: 图片列表
76+
private void initRecyclerView(RecyclerView recyclerView) {
77+
adapter = new CacheAdapter(this);
78+
GridLayoutManager mLayoutManager = new GridLayoutManager(this, 2);
79+
recyclerView.setLayoutManager(mLayoutManager);
80+
recyclerView.setAdapter(adapter);
81+
recyclerView.setNestedScrollingEnabled(false);
82+
}
83+
84+
protected void unsubscribe() {
85+
if (subscription != null && !subscription.isUnsubscribed()) {
86+
subscription.unsubscribe();
87+
}
88+
}
89+
90+
@Override
91+
public void onClick(View v) {
92+
switch (v.getId()) {
93+
case R.id.btn_1:
94+
Data.getInstance().clearMemoryCache();
95+
ToastUtil.show("内存缓存已清空");
96+
adapter.removeItems(null);
97+
break;
98+
case R.id.btn_2:
99+
Data.getInstance().clearMemoryAndDiskCache();
100+
ToastUtil.show("内存缓存和磁盘缓存已清空");
101+
adapter.removeItems(null);
102+
break;
103+
case R.id.btn_3:
104+
getNetData(Constants.ZMBZ);
105+
break;
106+
}
107+
}
108+
}
Collapse file

‎app/src/main/java/com/coder/guoy/recyclerview/ui/cache/CacheAdapter.java‎

Copy file name to clipboard
+85Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package com.coder.guoy.recyclerview.ui.cache;
2+
3+
import android.content.Context;
4+
import android.databinding.DataBindingUtil;
5+
import android.support.v7.widget.CardView;
6+
import android.support.v7.widget.RecyclerView;
7+
import android.view.LayoutInflater;
8+
import android.view.View;
9+
import android.view.ViewGroup;
10+
import android.widget.ImageView;
11+
import android.widget.TextView;
12+
13+
import com.coder.guoy.recyclerview.R;
14+
import com.coder.guoy.recyclerview.api.bean.ImageBean;
15+
import com.coder.guoy.recyclerview.databinding.ItemCacheBinding;
16+
import com.coder.guoy.recyclerview.utils.GlideUtils;
17+
18+
import java.util.List;
19+
20+
/**
21+
* @Version:V1.0
22+
* @Author:CoderGuoy
23+
* @CreateTime:2017年12月22日
24+
* @Descrpiton:
25+
*/
26+
public class CacheAdapter extends RecyclerView.Adapter {
27+
private List<ImageBean> mList;
28+
private LayoutInflater mInflater;
29+
private Context mContext;
30+
private ItemCacheBinding binding;
31+
32+
public CacheAdapter(Context context) {
33+
mInflater = LayoutInflater.from(context);
34+
mContext = context;
35+
}
36+
37+
// 获取条目数量
38+
@Override
39+
public int getItemCount() {
40+
return mList == null ? 0 : mList.size();
41+
}
42+
43+
public void setNewData(List data) {
44+
mList = data;
45+
notifyDataSetChanged();
46+
}
47+
48+
public void removeItems(List mList) {
49+
this.mList = mList;
50+
notifyDataSetChanged();
51+
}
52+
53+
private class NormalViewHolder extends RecyclerView.ViewHolder {
54+
public ImageView imageView;
55+
public TextView textTitle;
56+
public CardView cardView;
57+
58+
public NormalViewHolder(View itemView) {
59+
super(itemView);
60+
imageView = binding.itemImage;
61+
textTitle = binding.itemText;
62+
cardView = binding.cardview;
63+
}
64+
}
65+
66+
@Override
67+
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
68+
binding = DataBindingUtil.inflate(mInflater, R.layout.item_cache, parent, false);
69+
return new NormalViewHolder(binding.getRoot());
70+
}
71+
72+
@Override
73+
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
74+
final NormalViewHolder vh = (NormalViewHolder) holder;
75+
//设置图片
76+
if (mList.get(position).getImageUrl() != null) {
77+
GlideUtils.setImage(mContext,mList.get(position).getImageUrl(), vh.imageView);
78+
}
79+
//设置标题
80+
if (mList.get(position).getImgaeTitle() != null) {
81+
vh.textTitle.setText(mList.get(position).getImgaeTitle());
82+
}
83+
}
84+
85+
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.