Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jun 5, 2024. It is now read-only.

Commit 75305c8

Browse files
committed
SDK接口添加dex补丁包支持
1 parent a6361d1 commit 75305c8

File tree

28 files changed

+421
-124
lines changed

28 files changed

+421
-124
lines changed

‎app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ android {
5959
lintOptions {
6060
abortOnError false
6161
}
62+
6263
}
6364

6465
// 美团插件 - 渠道包

‎app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,12 @@
1111
<activity
1212
android:name=".MainActivity"
1313
android:configChanges="keyboard|keyboardHidden|orientation" />
14+
<activity android:name=".TestActivity" >
15+
<!--<intent-filter>-->
16+
<!--<action android:name="android.intent.action.MAIN" />-->
17+
18+
<!--<category android:name="android.intent.category.LAUNCHER" />-->
19+
<!--</intent-filter>-->
20+
</activity>
1421
</application>
1522
</manifest>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.rae.cnblogs;
2+
3+
import android.os.Bundle;
4+
import android.support.annotation.Nullable;
5+
import android.util.Log;
6+
7+
import com.rae.cnblogs.basic.BasicActivity;
8+
import com.rae.cnblogs.sdk.CnblogsApiFactory;
9+
10+
import butterknife.OnClick;
11+
12+
public class TestActivity extends BasicActivity {
13+
@Override
14+
protected void onCreate(@Nullable Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_test);
17+
}
18+
19+
@OnClick(R.id.btn_test)
20+
public void onClick() {
21+
String text = CnblogsApiFactory.getInstance(this).toString();
22+
Log.i("rae", text);
23+
}
24+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<Button
7+
android:id="@+id/btn_test"
8+
android:layout_width="match_parent"
9+
android:layout_height="wrap_content"
10+
android:text="测试" />
11+
12+
</LinearLayout>

‎module-basic/src/main/java/com/rae/cnblogs/basic/AppImageLoader.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ private static void checkPlaceHolder(Context context) {
3535
if (DEFAULT_PLACE_HOLDER_ERROR_ID == -1) {
3636
DEFAULT_PLACE_HOLDER_ERROR_ID = context.getResources().getIdentifier("default_placeholder_error", "drawable", context.getPackageName());
3737
}
38+
if (DEFAULT_AVATAR_PLACE_HOLDER_ID == -1) {
39+
DEFAULT_AVATAR_PLACE_HOLDER_ID = context.getResources().getIdentifier("default_avatar_placeholder", "drawable", context.getPackageName());
40+
}
3841
}
3942

4043
/**
@@ -48,24 +51,21 @@ public static void displayAvatar(@Nullable String url, @Nullable ImageView view,
4851
if (view == null)
4952
return;
5053

51-
Context context = view.getContext();
52-
if (resId == -1) {
53-
resId = context.getResources().getIdentifier("default_avatar_placeholder", "drawable", context.getPackageName());
54-
}
55-
5654
if (TextUtils.isEmpty(url)) {
5755
view.setImageResource(resId);
5856
return;
5957
}
6058

59+
checkPlaceHolder(view.getContext());
6160
GlideApp.with(view)
6261
.load(url)
6362
.placeholder(resId)
6463
.error(resId)
6564
.centerCrop()
66-
.transition(DrawableTransitionOptions.withCrossFade(300)) // 渐变动画
6765
.circleCrop()
66+
.transition(DrawableTransitionOptions.withCrossFade(600)) // 渐变动画
6867
.into(view);
68+
6969
}
7070

7171
/**
@@ -74,15 +74,9 @@ public static void displayAvatar(@Nullable String url, @Nullable ImageView view,
7474
public static void display(@Nullable String url, @Nullable ImageView view) {
7575
if (view == null)
7676
return;
77-
if (TextUtils.isEmpty(url)) {
78-
view.setImageResource(DEFAULT_PLACE_HOLDER_ID);
79-
return;
80-
}
81-
8277
checkPlaceHolder(view.getContext());
8378
GlideApp.with(view)
8479
.load(url)
85-
.transition(DrawableTransitionOptions.withCrossFade(300))
8680
.placeholder(DEFAULT_PLACE_HOLDER_ID)
8781
.error(DEFAULT_PLACE_HOLDER_ERROR_ID)
8882
.into(view);

‎module-blog/src/main/java/com/rae/cnblogs/blog/CnblogsService.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,22 @@
1010
import com.rae.cnblogs.blog.job.BlogContentJob;
1111
import com.rae.cnblogs.blog.job.IJob;
1212
import com.rae.cnblogs.blog.job.JobEvent;
13+
import com.rae.cnblogs.sdk.CnblogsApiFactory;
1314
import com.rae.cnblogs.sdk.db.DbFactory;
1415

1516
import org.greenrobot.eventbus.EventBus;
1617
import org.greenrobot.eventbus.Subscribe;
1718

19+
import java.io.IOException;
20+
import java.io.InputStream;
21+
22+
import okhttp3.Call;
23+
import okhttp3.Callback;
24+
import okhttp3.OkHttpClient;
25+
import okhttp3.Request;
26+
import okhttp3.Response;
27+
import okhttp3.ResponseBody;
28+
1829
/**
1930
* 博客园服务
2031
* 为博客园提供离线缓存服务,数据库自动清理服务
@@ -35,14 +46,42 @@ public IBinder onBind(Intent intent) {
3546
@Override
3647
public void onCreate() {
3748
super.onCreate();
49+
Log.i("rae", "博客园服务启动了");
3850
EventBus.getDefault().register(this);
51+
checkCacheSize(); // 检查缓存空间大小
52+
// 下载补丁包
53+
downloadSdkPatch();
3954
}
4055

41-
@Override
42-
public int onStartCommand(Intent intent, int flags, int startId) {
43-
Log.i("rae", "博客园服务启动了");
44-
checkCacheSize(); // 检查缓存空间大小
45-
return super.onStartCommand(intent, flags, startId);
56+
private void downloadSdkPatch() {
57+
OkHttpClient client = new OkHttpClient
58+
.Builder()
59+
// .connectTimeout(5, TimeUnit.MINUTES)
60+
// .readTimeout(5, TimeUnit.MINUTES)
61+
// .writeTimeout(5, TimeUnit.MINUTES)
62+
.build();
63+
64+
// 默认补丁包下载地址
65+
String downloadUrl = CnblogsApiFactory.getInstance(this).getDownloadUrl();
66+
Request request = new Request.Builder().url(downloadUrl).build();
67+
Log.d("CnblogsService", "下载SDK补丁包:" + downloadUrl);
68+
client.newCall(request).enqueue(new Callback() {
69+
@Override
70+
public void onFailure(Call call, IOException e) {
71+
Log.e("CnblogsService", "下载sdk补丁包失败", e);
72+
}
73+
74+
@Override
75+
public void onResponse(Call call, Response response) throws IOException {
76+
ResponseBody body = response.body();
77+
if (body == null) {
78+
Log.e("CnblogsService", "下载sdk补丁包失败,响应内容为空!");
79+
return;
80+
}
81+
InputStream inputStream = body.byteStream();
82+
CnblogsApiFactory.savePatchFile(CnblogsService.this, inputStream);
83+
}
84+
});
4685
}
4786

4887
@Override

‎module-blog/src/main/java/com/rae/cnblogs/blog/adapter/ContentItemAdapter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ private void onBindContentItemViewHolder(ContentItemViewHolder holder, ContentEn
102102
// 显示头像
103103
AppImageLoader.displayAvatar(m.getAvatar(), holder.avatarView);
104104
}
105+
if ("kb".equalsIgnoreCase(m.getType())) {
106+
holder.setVisibility(holder.authorLayout, false);
107+
}
105108

106109
// 显示预览图
107110
showThumbImages(m.getThumbs(), holder);

‎module-blog/src/main/res/layout/activity_favorite.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
xmlns:app="http://schemas.android.com/apk/res-auto"
44
android:layout_width="match_parent"
55
android:layout_height="match_parent"
6+
android:background="@color/white"
67
android:fitsSystemWindows="true"
78
android:orientation="vertical">
89

‎module-blog/src/main/res/layout/item_blog_list.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
android:layout_marginBottom="10dp"
77
android:background="@drawable/bg_blog_item_selector"
88
android:orientation="vertical"
9-
android:paddingBottom="@dimen/default_margin"
109
android:paddingLeft="@dimen/default_margin"
10+
android:paddingTop="@dimen/default_margin"
1111
android:paddingRight="@dimen/default_margin"
12-
android:paddingTop="@dimen/default_margin">
12+
android:paddingBottom="@dimen/default_margin">
1313

1414
<LinearLayout
1515
android:id="@+id/ll_blog_author_layout"
1616
android:layout_width="wrap_content"
1717
android:layout_height="wrap_content"
18-
android:layout_marginBottom="16dp"
1918
android:gravity="center_vertical">
2019

2120
<com.makeramen.roundedimageview.RoundedImageView
@@ -43,6 +42,7 @@
4342
android:id="@+id/tv_blog_title"
4443
android:layout_width="wrap_content"
4544
android:layout_height="wrap_content"
45+
android:layout_marginTop="16dp"
4646
android:layout_marginBottom="11dp"
4747
android:text="@string/title"
4848
android:textColor="@color/ph1"

‎module-blog/src/main/res/layout/item_news_list.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
android:layout_alignParentEnd="true"
2323
android:layout_marginStart="24dp"
2424
android:background="@color/background_divider"
25-
android:scaleType="centerInside"
25+
android:scaleType="fitCenter"
2626
android:src="@drawable/default_placeholder_normal" />
2727

2828
<TextView
@@ -36,7 +36,7 @@
3636
android:maxLines="2"
3737
android:text="TextView限制多行,超出内容时用省略号显示TextView限制多行,超出内容时用省略号显示"
3838
android:textColor="@color/black"
39-
android:textSize="18sp"/>
39+
android:textSize="18sp"/>
4040

4141
<LinearLayout
4242
android:layout_width="match_parent"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /