Skip to content

Commit c32df13

Browse files
committed
fix list update
1 parent 774c23f commit c32df13

File tree

7 files changed

+79
-93
lines changed

7 files changed

+79
-93
lines changed

app/src/main/java/com/brian/csdnblog/activity/BlogListFrag.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void convert(ViewHolder holder, final BlogInfo item) {
114114
TextView nameView = holder.getView(R.id.msg);
115115

116116
Bloger bloger = Bloger.fromJson(item.blogerJson);
117-
if (bloger != null && !TextUtils.isEmpty(bloger.nickName)) {
117+
if (bloger != null && !TextUtils.isEmpty(bloger.nickName) && !TextUtils.isEmpty(item.extraMsg)) {
118118
SpannableStringBuilder builder = new SpannableStringBuilder(item.extraMsg);
119119
int indexStart = item.extraMsg.indexOf(bloger.nickName);
120120
builder.setSpan(mColorSpanName, indexStart, indexStart + bloger.nickName.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
@@ -451,9 +451,14 @@ public void onEventMainThread(TypeChangeEvent event) {
451451
}
452452

453453
private void startRefresh() {
454-
if (mRefreshable) {
454+
if (mRefreshable && checkUpdateTime()) {
455455
mRefreshLayout.setRefreshing(true);
456456
loadData(true);
457457
}
458458
}
459+
460+
private boolean checkUpdateTime() {
461+
long lastUpdateTime = FileUtil.getFileLastModified(Env.getContext().getFilesDir() + "/cache_" + mType);
462+
return System.currentTimeMillis() - lastUpdateTime > 3000_000;
463+
}
459464
}

app/src/main/java/com/brian/csdnblog/activity/MainTabActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public void onCreate(Bundle savedInstanceState) {
7878
private void initUI() {
7979
mTabAdapter = new MainTabAdapter(getSupportFragmentManager());
8080
// 视图切换器
81-
mViewpager.setOffscreenPageLimit(4);// 预先加载页面的数量
81+
mViewpager.setOffscreenPageLimit(1);// 预先加载页面的数量
8282
mViewpager.setAdapter(mTabAdapter);
8383
mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);//设置滑动模式
8484
mTabLayout.setupWithViewPager(mViewpager);

app/src/main/java/com/brian/csdnblog/adapter/MainTabAdapter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import android.support.v4.app.FragmentManager;
55
import android.support.v4.app.FragmentPagerAdapter;
6+
import android.view.ViewGroup;
67

78
import com.brian.csdnblog.activity.BlogListFrag;
89
import com.brian.csdnblog.manager.TypeManager;
@@ -74,4 +75,9 @@ public int getCount() {
7475
return mTabTitles.length;
7576
}
7677

78+
@Override
79+
public void destroyItem(ViewGroup container, int position, Object object) {
80+
// 避免视图被销毁
81+
// super.destroyItem(container, position, object);
82+
}
7783
}

app/src/main/java/com/brian/csdnblog/parser/CSDNHtmlParser.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,10 @@ private String getSearchUrlByKeyword(String keyword, String page) {
338338
* 若该链接是博文链接,则返回链接地址,若不是则返回空
339339
*/
340340
public String getBlogContentUrl(String... urls) {
341-
String blogUrl = "";
342-
String url = urls[0];
343-
if (url.contains("/article/details")) {// 链接为CSDN博客内容
344-
if (url.startsWith("/")) {
345-
blogUrl = URL_CSDN_BLOG_BASE + url;
346-
} else {
347-
blogUrl = url;
341+
String blogUrl = urls[0];
342+
if (blogUrl.contains("/article/details")) {// 链接为CSDN博客内容
343+
if (blogUrl.startsWith("/")) {
344+
blogUrl = URL_CSDN_BLOG_BASE + blogUrl;
348345
}
349346
}
350347
return blogUrl;

app/src/main/java/com/brian/csdnblog/util/DeviceUtil.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ public static String getUUID() {
4141
return uniqueId;
4242
}
4343
final TelephonyManager tm = (TelephonyManager) Env.getContext().getSystemService(Context.TELEPHONY_SERVICE);
44-
final String tmDevice, tmSerial, androidId;
45-
tmDevice = "" + tm.getDeviceId();
44+
String deviceId, tmSerial, androidId;
45+
try {
46+
deviceId = tm.getDeviceId();
47+
} catch (Exception e) {
48+
deviceId = "";
49+
}
4650
tmSerial = "" + tm.getSimSerialNumber();
4751
androidId = "" + Settings.Secure.getString(Env.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
48-
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
52+
UUID deviceUuid = new UUID(androidId.hashCode(), ((long) deviceId.hashCode() << 32) | tmSerial.hashCode());
4953
uniqueId = Md5.getMD5ofStr(deviceUuid.toString());
5054
LogUtil.d("uuid=" + uniqueId);
5155
return uniqueId;
@@ -55,19 +59,16 @@ public static String getUUID() {
5559
* 获取分辨率,格式:640x480
5660
*/
5761
public static String getResolution(Context context) {
58-
String resolution = context.getResources().getDisplayMetrics().widthPixels
62+
return context.getResources().getDisplayMetrics().widthPixels
5963
+ "x" + context.getResources().getDisplayMetrics().heightPixels;
60-
return resolution;
6164
}
6265

6366
/**
6467
* 获取屏幕密度
6568
*/
6669
public static int getScreenDensity(Context context) {
6770
DisplayMetrics metric = context.getResources().getDisplayMetrics();
68-
int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
69-
70-
return densityDpi;
71+
return metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
7172
}
7273

7374
/**
@@ -170,17 +171,15 @@ public static String getSerial() {
170171
* 获取手机操作系统
171172
*/
172173
public static String getSystemId() {
173-
String systemId = Build.VERSION.RELEASE;
174-
return systemId;
174+
return Build.VERSION.RELEASE;
175175
}
176176

177177

178178
/**
179179
* 获取手机SDK版本号
180180
*/
181181
public static int getSdkVersion() {
182-
int sdkVersion = Build.VERSION.SDK_INT;
183-
return sdkVersion;
182+
return Build.VERSION.SDK_INT;
184183
}
185184

186185
/**
@@ -197,7 +196,7 @@ public static String getCPU() {
197196
sCPU = "";
198197

199198
String str1 = "/proc/cpuinfo";
200-
String str2 = "";
199+
String str2;
201200
String[] cpuInfo = {"", ""}; // 1-cpu型号 //2-cpu频率
202201
String[] arrayOfString;
203202
try {
@@ -214,7 +213,7 @@ public static String getCPU() {
214213
localBufferedReader.close();
215214
sCPU = cpuInfo[0];
216215
} catch (IOException e) {
217-
216+
LogUtil.printError(e);
218217
}
219218
return sCPU;
220219
}
@@ -236,7 +235,7 @@ public static String getKernel() {
236235
try {
237236
process = Runtime.getRuntime().exec("cat /proc/version");
238237
} catch (IOException e) {
239-
238+
LogUtil.printError(e);
240239
}
241240

242241
// get the output line
@@ -253,10 +252,10 @@ public static String getKernel() {
253252
// result += " ";
254253
}
255254
} catch (IOException e) {
256-
255+
LogUtil.printError(e);
257256
}
258257

259-
if (result != "") {
258+
if (!TextUtils.isEmpty(result)) {
260259
String Keyword = "version ";
261260
int index = result.indexOf(Keyword);
262261
line = result.substring(index + Keyword.length());

0 commit comments

Comments
 (0)