Skip to content

Commit 0c19232

Browse files
author
ChenRui
committed
夜间模式适配
优化首页列表展示模式
1 parent a58e9c1 commit 0c19232

File tree

11 files changed

+103
-98
lines changed

11 files changed

+103
-98
lines changed

app/build.gradle

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,13 @@ dependencies {
9696
compile 'com.android.support:multidex:1.0.1'
9797
compile project(':sdk')
9898
compile 'com.michaelpardo:activeandroid:3.1.0-SNAPSHOT'
99-
compile 'com.jakewharton:butterknife:8.7.0'
100-
annotationProcessor 'com.jakewharton:butterknife-compiler:8.7.0'
99+
compile 'com.jakewharton:butterknife:8.8.1'
100+
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
101101
compile 'in.srain.cube:ultra-ptr:1.0.11'
102102
compile 'com.github.raee:XRecyclerView:1.3.2'
103-
compile 'com.makeramen:roundedimageview:2.2.1'
104-
// compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
105-
103+
compile 'com.makeramen:roundedimageview:2.3.0'
106104
compile 'com.github.bumptech.glide:glide:4.0.0'
107105
annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0'
108-
109106
compile 'com.umeng.analytics:analytics:6.1.2'
110107
// 事件通知
111108
compile 'org.greenrobot:eventbus:3.0.0'

app/src/main/AndroidManifest.xml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,35 @@
2727
android:name=".activity.LauncherActivity"
2828
android:screenOrientation="portrait"
2929
android:theme="@style/AppTheme.NoActionBar.FullScreen">
30-
<intent-filter>
31-
<action android:name="android.intent.action.MAIN"/>
30+
<!-- <intent-filter>
31+
<action android:name="android.intent.action.MAIN"/>
3232
33-
<category android:name="android.intent.category.LAUNCHER"/>
34-
</intent-filter>
33+
<category android:name="android.intent.category.LAUNCHER"/>
34+
</intent-filter>-->
3535
</activity>
3636

3737
<!--主界面-->
3838
<activity
3939
android:name=".activity.MainActivity"
4040
android:screenOrientation="portrait"
4141
android:theme="@style/AppTheme.Dark">
42-
<!-- <intent-filter>
42+
<intent-filter>
4343
<action android:name="android.intent.action.MAIN"/>
4444
<category android:name="android.intent.category.LAUNCHER"/>
45-
</intent-filter>-->
45+
</intent-filter>
4646
</activity>
4747

48-
<!-- <activity
49-
android:name=".activity.TestActivity"
50-
android:label="博客园测试"
51-
android:screenOrientation="portrait"
52-
android:theme="@style/AppTheme.Dark">
53-
<intent-filter>
54-
<action android:name="android.intent.action.MAIN"/>
55-
56-
<category android:name="android.intent.category.LAUNCHER"/>
57-
</intent-filter>
58-
</activity>-->
48+
<activity
49+
android:name=".activity.TestActivity"
50+
android:label="博客园测试"
51+
android:screenOrientation="portrait"
52+
android:theme="@style/AppTheme.Dark">
53+
<intent-filter>
54+
<action android:name="android.intent.action.MAIN"/>
55+
56+
<category android:name="android.intent.category.LAUNCHER"/>
57+
</intent-filter>
58+
</activity>
5959

6060
<!--博文-->
6161
<activity

app/src/main/java/com/rae/cnblogs/activity/TestActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99

1010
import com.rae.cnblogs.AppUI;
1111
import com.rae.cnblogs.R;
12+
import com.rae.cnblogs.fragment.BlogListFragment;
1213
import com.rae.cnblogs.sdk.UserProvider;
14+
import com.rae.cnblogs.sdk.bean.BlogType;
15+
import com.rae.cnblogs.sdk.bean.CategoryBean;
1316
import com.tencent.bugly.beta.tinker.TinkerManager;
1417

1518
import java.io.File;
@@ -34,6 +37,11 @@ public void onClick(View v) {
3437

3538
}
3639
});
40+
41+
CategoryBean categroy = new CategoryBean();
42+
categroy.setName("首页");
43+
categroy.setType("home");
44+
getSupportFragmentManager().beginTransaction().add(R.id.content, BlogListFragment.newInstance(0,categroy, BlogType.BLOG)).commitNowAllowingStateLoss();
3745
}
3846

3947
@OnClick(R.id.btn_main)

app/src/main/java/com/rae/cnblogs/fragment/MineFragment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected void onCreateView(View view) {
6767
mNightModeButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
6868
@Override
6969
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
70-
ThemeCompat.switchNightMode(isChecked);
70+
ThemeCompat.switchNightMode();
7171
}
7272
});
7373
}
@@ -82,6 +82,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
8282
public void onResume() {
8383
super.onResume();
8484
loadUserInfo();
85+
// 夜间模式处理
86+
mNightModeButton.setCheckedNoEvent(ThemeCompat.isNight());
8587
}
8688

8789
private boolean isNotLogin() {
@@ -226,7 +228,7 @@ public void onSettingClick() {
226228
*/
227229
@OnClick(R.id.ll_night)
228230
public void onNightClick() {
229-
mNightModeButton.toggle();
231+
mNightModeButton.performClick();
230232
}
231233

232234
}

app/src/main/java/com/rae/cnblogs/widget/RaeSwitchCheckBox.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

app/src/main/res/layout/activity_setting.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@
8080
</LinearLayout>
8181

8282

83+
<LinearLayout
84+
android:id="@+id/ll_help_center"
85+
android:layout_width="match_parent"
86+
android:layout_height="wrap_content">
87+
88+
<TextView
89+
style="@style/ItemStyle"
90+
android:layout_width="match_parent"
91+
android:layout_height="wrap_content"
92+
android:text="@string/help_center"
93+
android:textColor="@color/ph1"/>
94+
95+
</LinearLayout>
96+
8397
<LinearLayout
8498
android:id="@+id/ll_github"
8599
android:layout_width="match_parent"
@@ -123,8 +137,8 @@
123137
android:layout_height="wrap_content"
124138
android:layout_weight="1"
125139
android:text="@string/check_update"
126-
android:textSize="16sp"
127-
android:textColor="@color/ph1"/>
140+
android:textColor="@color/ph1"
141+
android:textSize="16sp"/>
128142

129143

130144
<ProgressBar

app/src/main/res/layout/activity_test.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@
3030
android:layout_height="wrap_content"
3131
android:text="补丁测试"/>
3232

33-
<com.rae.cnblogs.widget.RaeSwitchCheckBox
34-
android:background="@color/colorPrimary"
35-
android:layout_width="wrap_content"
36-
android:layout_height="wrap_content"
37-
android:layout_gravity="center"/>
33+
<FrameLayout
34+
android:id="@+id/content"
35+
android:layout_width="match_parent"
36+
android:layout_height="match_parent">
37+
38+
</FrameLayout>
3839

3940
</LinearLayout>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,5 @@
104104
<string name="night_mode">夜间模式</string>
105105
<string name="day_mode">日间模式</string>
106106
<string name="check_update">检查更新</string>
107+
<string name="help_center">帮助中心</string>
107108
</resources>

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ buildscript {
66
dependencies {
77
// classpath 'com.android.tools.build:gradle:3.0.0-beta2'
88
classpath 'com.android.tools.build:gradle:2.3.3'
9-
classpath 'com.jakewharton:butterknife-gradle-plugin:8.7.0'
9+
classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.1'
1010
// 热更新插件
1111
classpath "com.tencent.bugly:tinker-support:1.0.8"
1212
}
1313
}
1414

1515
allprojects {
1616
repositories {
17-
// maven { url 'https://maven.google.com.hk'}
17+
google()
1818
maven { url 'http://maven.raeblog.com:8081/repository/maven-public/' }
1919
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
2020
jcenter()

sdk/src/main/java/com/rae/cnblogs/sdk/parser/BlogListParser.java

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
import org.jsoup.select.Elements;
1717

1818
import java.util.ArrayList;
19+
import java.util.Comparator;
1920
import java.util.List;
21+
import java.util.Map;
22+
import java.util.TreeMap;
2023

2124
/**
2225
* 博客列表解析器
@@ -66,18 +69,48 @@ protected void cacheThumbUrls(BlogBean m) {
6669
private String createThumbUrls(String content) {
6770
try {
6871
List<String> result = new ArrayList<>();
72+
// 排序的MAP
73+
Map<String, String> sortMap = new TreeMap<>(new Comparator<Object>() {
74+
@Override
75+
public int compare(Object o1, Object o2) {
76+
return o1.toString().compareTo(o2.toString());
77+
}
78+
});
79+
6980
Elements elements = Jsoup.parse(content).select("img");
7081
for (Element element : elements) {
71-
String src = element.attr("src");
72-
82+
String src = ApiUtils.getUrl(element.attr("src"));
7383
// 过滤一些没有用的图片
7484
if (TextUtils.isEmpty(src) || src.contains(".gif")) {
7585
continue;
7686
}
7787

78-
result.add(ApiUtils.getUrl(src));
88+
// 优先级处理
89+
// 1、封面图优先,只取一个图片
90+
if (element.hasAttr("app-cover")) {
91+
result.clear();
92+
result.add(0, src);
93+
break;
94+
}
95+
// 2、小图优先
96+
else if (element.hasAttr("app-thumb")) {
97+
String key = element.attr("app-thumb");
98+
if (TextUtils.isEmpty(key)) {
99+
result.add(src);
100+
} else {
101+
sortMap.put(key, src);
102+
}
103+
} else {
104+
result.add(src);
105+
}
106+
}
107+
108+
if (sortMap.size() > 0) {
109+
result.addAll(0, sortMap.values());
110+
sortMap.clear();
79111
}
80112

113+
81114
return mGson.toJson(result);
82115
} catch (Exception e) {
83116
e.printStackTrace();

sdk/src/main/java/com/rae/cnblogs/sdk/utils/ApiUtils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ public static String getNumber(String text) {
104104
return text;
105105
}
106106

107+
public static int parseInt(String text, int defaultValue) {
108+
if (TextUtils.isEmpty(text)) return defaultValue;
109+
try {
110+
return Integer.parseInt(text);
111+
} catch (NumberFormatException e) {
112+
e.printStackTrace();
113+
}
114+
return defaultValue;
115+
}
116+
107117
public static String getCount(String text) {
108118
if (TextUtils.isEmpty(text)) return "0";
109119
return getNumber(text.trim());

0 commit comments

Comments
 (0)