Skip to content

Commit 9aa851b

Browse files
committed
博主界面UI重新调整,兼容部分机型滑动冲突问题。
1 parent 3efa474 commit 9aa851b

File tree

9 files changed

+78
-67
lines changed

9 files changed

+78
-67
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
xmlns:tools="http://schemas.android.com/tools"
43
package="com.rae.cnblogs">
54

65

@@ -12,9 +11,6 @@
1211
<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
1312
<uses-permission android:name="android.permission.CAMERA"/>
1413
<uses-permission android:name="android.permission.INTERNET"/>
15-
<!--<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
16-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
17-
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/>-->
1814
<uses-permission android:name="android.permission.READ_LOGS"/>
1915

2016
<application
@@ -29,23 +25,22 @@
2925
android:name=".activity.LauncherActivity"
3026

3127
android:theme="@style/AppTheme.NoActionBar.FullScreen">
32-
<!-- <intent-filter>
28+
<intent-filter>
3329
<action android:name="android.intent.action.MAIN"/>
3430

3531
<category android:name="android.intent.category.LAUNCHER"/>
36-
</intent-filter>-->
32+
</intent-filter>
3733
</activity>
3834

3935
<!--主界面-->
4036
<activity
4137
android:name=".activity.MainActivity"
42-
4338
android:theme="@style/AppTheme.Dark">
44-
<intent-filter>
45-
<action android:name="android.intent.action.MAIN"/>
39+
<!-- <intent-filter>
40+
<action android:name="android.intent.action.MAIN"/>
4641
47-
<category android:name="android.intent.category.LAUNCHER"/>
48-
</intent-filter>
42+
<category android:name="android.intent.category.LAUNCHER"/>
43+
</intent-filter>-->
4944
</activity>
5045

5146
<activity
@@ -254,20 +249,6 @@
254249
android:name="UMENG_CHANNEL"
255250
android:value="${UMENG_CHANNEL}"/>
256251

257-
<!--开始-快速开发需要移除下面的多进程-->
258-
<service
259-
android:name="com.squareup.leakcanary.internal.HeapAnalyzerService"
260-
android:enabled="false"
261-
tools:remove="process"/>
262-
<service
263-
android:name="com.tencent.tinker.lib.service.TinkerPatchService"
264-
android:exported="false"
265-
tools:remove="process"/>
266-
<service
267-
android:name="com.tencent.tinker.lib.service.TinkerPatchService$InnerService"
268-
android:exported="false"
269-
tools:remove="process"/>
270-
<!--结束-快速开发需要移除下面的多进程-->
271252

272253
</application>
273254

app/src/main/java/com/rae/cnblogs/ThemeCompat.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.graphics.drawable.Drawable;
77
import android.os.Build;
88
import android.support.annotation.NonNull;
9+
import android.support.v4.content.ContextCompat;
910
import android.text.TextUtils;
1011
import android.util.AttributeSet;
1112
import android.view.View;
@@ -168,7 +169,16 @@ public void onFailed(String s) {
168169
* @param nightMode 是否为深色模式
169170
*/
170171
public static void refreshStatusColor(Activity context, boolean nightMode) {
172+
if (context == null || context.getWindow() == null) return;
171173
changeMiUIStatusMode(context.getWindow(), nightMode);
174+
175+
// 改变系统状态颜色
176+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
177+
context.getWindow().setStatusBarColor(nightMode ?
178+
ContextCompat.getColor(context, android.R.color.black) :
179+
ContextCompat.getColor(context, android.R.color.white));
180+
}
181+
172182
}
173183

174184
/**
@@ -177,7 +187,7 @@ public static void refreshStatusColor(Activity context, boolean nightMode) {
177187
* @param dark 状态栏黑色字体
178188
*/
179189
private static void changeMiUIStatusMode(Window window, boolean dark) {
180-
if (!Build.BRAND.toLowerCase().equalsIgnoreCase("xiaomi")) {
190+
if (!Build.BRAND.toLowerCase().contains("mi")) {
181191
return;
182192
}
183193

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
1919
showHomeAsUp();
2020
getSupportFragmentManager()
2121
.beginTransaction()
22-
.add(R.id.content, newFragment())
22+
.replace(R.id.content, newFragment())
2323
.commitNowAllowingStateLoss();
2424

2525
}

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

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
import android.support.annotation.Nullable;
66
import android.support.design.widget.AppBarLayout;
77
import android.support.design.widget.DesignTabLayout;
8+
import android.support.v4.content.ContextCompat;
89
import android.support.v4.view.ViewPager;
910
import android.support.v7.widget.Toolbar;
1011
import android.text.TextUtils;
12+
import android.util.Log;
1113
import android.view.View;
1214
import android.widget.Button;
1315
import android.widget.ImageView;
@@ -17,11 +19,13 @@
1719
import com.bumptech.glide.load.engine.GlideException;
1820
import com.bumptech.glide.request.RequestListener;
1921
import com.bumptech.glide.request.target.Target;
22+
import com.jcodecraeer.xrecyclerview.AppBarStateChangeListener;
2023
import com.rae.cnblogs.AppMobclickAgent;
2124
import com.rae.cnblogs.AppRoute;
2225
import com.rae.cnblogs.AppUI;
2326
import com.rae.cnblogs.GlideApp;
2427
import com.rae.cnblogs.R;
28+
import com.rae.cnblogs.ThemeCompat;
2529
import com.rae.cnblogs.fragment.BlogListFragment;
2630
import com.rae.cnblogs.message.UserInfoEvent;
2731
import com.rae.cnblogs.model.FeedListFragment;
@@ -53,8 +57,8 @@ public class BloggerActivity extends SwipeBackBaseActivity implements IBloggerPr
5357
@BindView(R.id.img_blog_avatar)
5458
ImageView mAvatarView;
5559

56-
// @BindView(R.id.tv_blogger_name)
57-
// TextView mBloggerNameView;
60+
@BindView(R.id.tv_blogger_name)
61+
TextView mBloggerNameView;
5862

5963
@BindView(R.id.tv_follow_count)
6064
TextView mFollowCountView;
@@ -139,22 +143,30 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
139143

140144
mTabLayout.addOnTabSelectedListener(this);
141145

142-
// mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
143-
// @Override
144-
// public void onStateChanged(AppBarLayout appBarLayout, State state) {
145-
// if (state == State.COLLAPSED) {
146-
// getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_back);
147-
// mFollowView.setBackgroundResource(R.drawable.bg_btn_follow_drak);
148-
// mFollowView.setTextColor(ContextCompat.getColor(getContext(), R.color.ph2));
149-
//// mAlphaImageView.setBackgroundColor(ContextCompat.getColor(appBarLayout.getContext(), android.R.color.white));
150-
// } else {
151-
// getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_back_white);
152-
// mFollowView.setBackgroundResource(R.drawable.bg_btn_follow);
153-
// mFollowView.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
154-
//// mAlphaImageView.setBackgroundColor(ContextCompat.getColor(appBarLayout.getContext(), R.color.blogger_image_alpha_color));
155-
// }
156-
// }
157-
// });
146+
mAppBarLayout.addOnOffsetChangedListener(new AppBarStateChangeListener() {
147+
@Override
148+
public void onStateChanged(AppBarLayout appBarLayout, State state) {
149+
Log.i("rae", "状态改变:" + state);
150+
if (state == State.COLLAPSED) {
151+
ThemeCompat.refreshStatusColor(getContext(), true);
152+
setHomeAsUpIndicator(R.drawable.ic_back);
153+
mFollowView.setBackgroundResource(R.drawable.bg_btn_follow_drak);
154+
mFollowView.setTextColor(ContextCompat.getColor(getContext(), R.color.ph2));
155+
mTitleView.setVisibility(View.VISIBLE);
156+
} else {
157+
mTitleView.setVisibility(View.GONE);
158+
ThemeCompat.refreshStatusColor(getContext(), false);
159+
setHomeAsUpIndicator(R.drawable.ic_back_white);
160+
mFollowView.setBackgroundResource(R.drawable.bg_btn_follow);
161+
mFollowView.setTextColor(ContextCompat.getColor(getContext(), R.color.white));
162+
}
163+
}
164+
165+
void setHomeAsUpIndicator(int homeAsUpIndicator) {
166+
if (getSupportActionBar() != null)
167+
getSupportActionBar().setHomeAsUpIndicator(homeAsUpIndicator);
168+
}
169+
});
158170

159171
// mBloggerLayout.setOnScrollPercentChangeListener(new BloggerLayout.ScrollPercentChangeListener() {
160172
// @Override
@@ -248,7 +260,7 @@ public boolean onResourceReady(Drawable drawable, Object o, Target<Drawable> tar
248260
.into(mBackgroundView);
249261
}
250262

251-
// mBloggerNameView.setText(userInfo.getDisplayName());
263+
mBloggerNameView.setText(userInfo.getDisplayName());
252264
mTitleView.setText(userInfo.getDisplayName());
253265
mFansCountView.setText(userInfo.getFans());
254266
mFollowCountView.setText(userInfo.getFollows());
@@ -359,7 +371,7 @@ public void onTabReselected(DesignTabLayout.Tab tab) {
359371
takeScrollToTop(tab.getPosition());
360372
}
361373

362-
@OnClick(R.id.tv_title)
374+
@OnClick(R.id.tool_bar)
363375
public void onTitleClick() {
364376
takeScrollToTop(mViewPager.getCurrentItem());
365377
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.greenrobot.eventbus.EventBus;
4242
import org.greenrobot.eventbus.Subscribe;
4343

44-
import java.io.IOException;
4544
import java.io.InputStream;
4645

4746
import butterknife.BindView;
@@ -223,14 +222,15 @@ public void run() {
223222
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
224223
try {
225224
// 避免切换夜间模式闪烁问题
226-
if (isDetached() || getContext() == null || !isAdded()) return; // fix bug #638
225+
if (isDetached() || getContext() == null || !isAdded() || !isVisible())
226+
return; // fix bug #638
227227
InputStream stream = getResources().getAssets().open("view.html");
228228
byte[] data = new byte[stream.available()];
229229
stream.read(data);
230230
stream.close();
231231
String content = new String(data).replace("{{theme}}", ThemeCompat.isNight() ? "rae-night.css" : "rae.css");
232232
mWebView.loadDataWithBaseURL("file:///android_asset/view.html", content, "text/html", "UTF-8", null);
233-
} catch (Exception e) {
233+
} catch (Throwable e) {
234234
e.printStackTrace();
235235
// 如果加载失败了,就从默认打开
236236
mWebView.loadUrl("file:///android_asset/view.html");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ public ObservableSource<Empty> apply(List<CategoryBean> categoryBeans) throws Ex
317317
.subscribe(new Consumer<Empty>() {
318318
@Override
319319
public void accept(@NonNull Empty empty) throws Exception {
320-
if (enableNotify) {
320+
// fix bug #812
321+
if (enableNotify && mHandler!=null) {
321322
mHandler.removeMessages(0);
322323
mHandler.sendEmptyMessageDelayed(0, 200);
323324
}

app/src/main/java/com/rae/cnblogs/presenter/impl/SearchPresenterImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.rae.cnblogs.sdk.api.ISearchApi;
88

99
import java.util.List;
10+
import java.util.concurrent.TimeUnit;
1011

1112
import io.reactivex.annotations.NonNull;
1213
import io.reactivex.disposables.Disposable;
@@ -42,6 +43,8 @@ public void accept(@NonNull Disposable disposable) throws Exception {
4243
mSuggestionSubscriber = disposable;
4344
}
4445
})
46+
// 延迟,避免响应过快 fix bug #717
47+
.delay(300, TimeUnit.MILLISECONDS)
4548
.subscribe(new ApiDefaultObserver<List<String>>() {
4649
@Override
4750
protected void onError(String message) {
@@ -50,6 +53,7 @@ protected void onError(String message) {
5053

5154
@Override
5255
protected void accept(List<String> data) {
56+
5357
mView.onSuggestionSuccess(data);
5458
}
5559
});

app/src/main/java/com/rae/cnblogs/presenter/impl/blog/BlogListPresenterImpl.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ protected ApiDefaultObserver<List<BlogBean>> getBlogObserver() {
8383

8484
@Override
8585
public void onError(Throwable e) {
86+
// fix bug #649
87+
if (mView == null) return;
8688
if (isNetworkError()) {
8789
loadOfflineData(mView.getCategory(), mPageIndex);
8890
return;
@@ -93,12 +95,14 @@ public void onError(Throwable e) {
9395

9496
@Override
9597
protected void onError(String message) {
96-
98+
if (mView == null) return;
9799
mView.onLoadFailed(mPageIndex, message);
98100
}
99101

100102
@Override
101103
protected void accept(List<BlogBean> blogBeans) {
104+
if (mView == null) return;
105+
102106
if (Rx.isEmpty(blogBeans)) {
103107
// 没有更多
104108
if (mPageIndex > 1)

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
android:layout_height="wrap_content"
1313
android:background="@android:color/white"
1414
android:orientation="vertical"
15-
android:theme="@style/ThemeOverlay.AppCompat.Light"
16-
app:elevation="0dp">
15+
android:theme="@style/ThemeOverlay.AppCompat.Light">
1716

1817
<android.support.design.widget.CollapsingToolbarLayout
1918
android:id="@+id/toolbar_layout"
2019
android:layout_width="match_parent"
2120
android:layout_height="wrap_content"
21+
app:contentScrim="@android:color/white"
2222
app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed"
2323
app:statusBarScrim="?colorPrimaryDark">
2424

@@ -76,7 +76,7 @@
7676

7777

7878
<TextView
79-
android:id="@+id/tv_title"
79+
android:id="@+id/tv_blogger_name"
8080
android:layout_width="match_parent"
8181
android:layout_height="wrap_content"
8282
android:layout_alignTop="@+id/ll_blog_avatar"
@@ -91,7 +91,7 @@
9191
<LinearLayout
9292
android:layout_width="match_parent"
9393
android:layout_height="wrap_content"
94-
android:layout_below="@+id/tv_title"
94+
android:layout_below="@+id/tv_blogger_name"
9595
android:layout_marginLeft="18dp"
9696
android:layout_toRightOf="@+id/ll_blog_avatar"
9797
android:gravity="start|center_vertical"
@@ -241,17 +241,16 @@
241241
android:layout_width="match_parent"
242242
android:layout_height="wrap_content">
243243

244-
<!--
245-
246-
<TextView
247-
android:id="@+id/tv_title"
248-
android:layout_width="match_parent"
249-
android:layout_height="wrap_content"
250-
android:layout_toLeftOf="@+id/btn_blogger_follow"
251-
android:gravity="center"
252-
android:textColor="@android:color/white"
253-
android:textSize="@dimen/h1"/>
254-
-->
244+
245+
<TextView
246+
android:id="@+id/tv_title"
247+
android:layout_width="match_parent"
248+
android:layout_height="wrap_content"
249+
android:layout_toLeftOf="@+id/btn_blogger_follow"
250+
android:gravity="center"
251+
android:textColor="@color/ph1"
252+
android:textSize="@dimen/h1"
253+
android:visibility="gone"/>
255254

256255
<ProgressBar
257256
android:id="@+id/pb_blogger_follow"

0 commit comments

Comments
 (0)