Skip to content

Commit 80acf2e

Browse files
committed
1、新增Retrofit设置多个BaseUrl类FastMultiUrl
2、优化Demo展示效果降低页面过度绘制 3、优化Demo对平板的适配
1 parent df2cb6b commit 80acf2e

File tree

19 files changed

+459
-86
lines changed

19 files changed

+459
-86
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ android {
1010
applicationId "com.aries.library.fast.demo"
1111
minSdkVersion ext.minSdkVersion
1212
targetSdkVersion ext.targetSdkVersion
13-
versionCode 201
14-
versionName "2.0.1"
13+
versionCode 202
14+
versionName "2.0.2"
1515
multiDexEnabled true
1616
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1717
buildConfigField "String", "BASE_URL", "\"https://api.douban.com/\""

app/src/main/AndroidManifest.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.aries.library.fast.demo">
44

5+
<uses-feature android:name="android.hardware.screen.portrait"/>
6+
57
<uses-permission android:name="android.permission.INTERNET"/>
68
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
79
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
810
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
911
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
1012
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
1113
<!--AgentWeb 是默认启动定位-->
12-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
13-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
14+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
15+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
1416

1517
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
1618
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
@@ -26,6 +28,8 @@
2628
android:theme="@style/AppTheme">
2729
<activity
2830
android:name=".module.SplashActivity"
31+
android:screenOrientation="portrait"
32+
android:configChanges="orientation|locale|mcc|mnc"
2933
android:theme="@style/AppTheme.NotTranslucent">
3034
<intent-filter>
3135
<action android:name="android.intent.action.MAIN"/>
@@ -35,6 +39,8 @@
3539
</activity>
3640
<activity
3741
android:name=".module.main.MainActivity"
42+
android:screenOrientation="portrait"
43+
android:configChanges="orientation|locale|mcc|mnc"
3844
android:theme="@style/AppTheme.NotTranslucent"/>
3945
<!--应用内浏览器-->
4046
<activity

app/src/main/java/com/aries/library/fast/demo/App.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.aries.library.fast.FastApplication;
66
import com.aries.library.fast.manager.LoggerManager;
77
import com.aries.library.fast.retrofit.FastRetrofit;
8+
import com.aries.library.fast.util.SizeUtil;
89
import com.aries.library.fast.util.ToastUtil;
910

1011
import java.util.HashMap;
@@ -19,6 +20,7 @@
1920
public class App extends FastApplication {
2021
private static Context mContext;
2122
private String TAG = "FastLib";
23+
private static int imageHeight = 0;
2224

2325
@Override
2426
public void onCreate() {
@@ -34,9 +36,32 @@ public void onCreate() {
3436
FastRetrofit.getInstance()
3537
.setBaseUrl(BuildConfig.BASE_URL)
3638
.trustAllSSL()//信任所有证书--也可设置useSingleSignedSSL(单向认证)或useBothSignedSSL(双向验证)
37-
.setHeaders(header)//设置统一请求头
39+
// .setHeaders(header)//设置统一请求头
3840
.setLogEnable(BuildConfig.DEBUG)//设置请求全局log-可设置tag及Level类型
3941
// .setLogEnable(BuildConfig.DEBUG, TAG, HttpLoggingInterceptor.Level.BASIC)
4042
.setTimeout(30);//设置统一超时--也可单独调用read/write/connect超时(可以设置时间单位TimeUnit)
43+
44+
//以下为配置多BaseUrl
45+
//step1
46+
//FastMultiUrl.getInstance().putBaseUrl("test", "http://www.baidu.com");
47+
48+
//step2
49+
// 需要step1中baseUrl的方法需要在对应service里增加
50+
// @Headers({FastMultiUrl.BASE_URL_NAME_HEADER + "test"})
51+
//增加一个Header配置注意FastMultiUrl.BASE_URL_NAME_HEADER是必须后面"test"作为标记
52+
// FastMultiUrl里增加的拦截器才找得到对应的BaseUrl
53+
54+
}
55+
56+
/**
57+
* 获取banner及个人中心设置ImageView宽高
58+
*
59+
* @return
60+
*/
61+
public static int getImageHeight() {
62+
if (imageHeight == 0) {
63+
imageHeight = (int) (SizeUtil.getScreenWidth() * 0.55);
64+
}
65+
return imageHeight;
4166
}
4267
}

app/src/main/java/com/aries/library/fast/demo/base/BaseRefreshLoadActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ public void beforeInitView() {
4444
mRefreshLayout.setPrimaryColorsId(R.color.colorTextBlackLight);
4545
}
4646
}
47+
4748
}

app/src/main/java/com/aries/library/fast/demo/base/BaseTitleFragment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.aries.library.fast.demo.base;
22

3-
import com.aries.library.fast.demo.R;
43
import com.aries.library.fast.demo.helper.TitleBarHelper;
54
import com.aries.library.fast.module.fragment.FastTitleFragment;
65
import com.aries.ui.view.title.TitleBarView;
@@ -20,7 +19,6 @@ public boolean isLightStatusBarEnable() {
2019
@Override
2120
public void beforeSetTitleBar(TitleBarView titleBar) {
2221
super.beforeSetTitleBar(titleBar);
23-
mContentView.setBackgroundResource(R.color.colorBackground);
2422
TitleBarHelper.getInstance().setTitleBarView(titleBar, mContext,false);
2523
}
2624
}

app/src/main/java/com/aries/library/fast/demo/module/activity/MovieBaseFragment.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ public int getContentLayout() {
7070

7171
@Override
7272
public void initView(Bundle savedInstanceState) {
73-
mContentView.setBackgroundResource(R.color.colorBackground);
7473
mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
7574
@Override
7675
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

app/src/main/java/com/aries/library/fast/demo/module/main/HomeFragment.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import android.support.v7.app.AlertDialog;
77
import android.view.View;
88
import android.widget.ImageView;
9+
import android.widget.LinearLayout;
910

11+
import com.aries.library.fast.demo.App;
1012
import com.aries.library.fast.demo.R;
1113
import com.aries.library.fast.demo.adapter.WidgetAdapter;
1214
import com.aries.library.fast.demo.base.BaseTitleRefreshLoadFragment;
@@ -23,6 +25,7 @@
2325
import com.aries.library.fast.retrofit.FastObserver;
2426
import com.aries.library.fast.util.FastUtil;
2527
import com.aries.library.fast.util.SPUtil;
28+
import com.aries.library.fast.util.SizeUtil;
2629
import com.aries.ui.view.title.TitleBarView;
2730
import com.chad.library.adapter.base.BaseQuickAdapter;
2831
import com.chad.library.adapter.base.BaseViewHolder;
@@ -194,6 +197,9 @@ public void onBannerItemClick(BGABanner banner, View itemView, Object model, int
194197
}
195198
});
196199
mAdapter.addHeaderView(v);
200+
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) banner.getLayoutParams();
201+
params.height = App.getImageHeight();
202+
LoggerManager.d("banner:" + params.height + ";width:" + SizeUtil.getScreenWidth());
197203
}
198204
banner.setData(images, getTips(images));
199205
banner.setTransitionEffect(listTransitionEffect.get(transitionIndex));

app/src/main/java/com/aries/library/fast/demo/module/mine/MineFragment.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
import android.widget.ImageView;
77

88
import com.allen.library.SuperTextView;
9+
import com.aries.library.fast.demo.App;
910
import com.aries.library.fast.demo.R;
1011
import com.aries.library.fast.demo.base.BaseTitleFragment;
1112
import com.aries.library.fast.demo.helper.RefreshHeaderHelper;
1213
import com.aries.library.fast.demo.module.WebViewActivity;
1314
import com.aries.library.fast.manager.GlideManager;
15+
import com.aries.library.fast.manager.LoggerManager;
1416
import com.aries.library.fast.manager.RxJavaManager;
1517
import com.aries.library.fast.util.FastUtil;
18+
import com.aries.library.fast.util.SizeUtil;
1619
import com.aries.ui.view.title.TitleBarView;
1720
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
1821
import com.scwang.smartrefresh.layout.api.RefreshLayout;
@@ -63,6 +66,10 @@ public void beforeInitView() {
6366
public void initView(Bundle savedInstanceState) {
6467
GlideManager.loadCircleImg("https://avatars3.githubusercontent.com/u/19605922?v=4&s=460", ivHead);
6568
setImageBack();
69+
fLayoutMine.getLayoutParams().height = App.getImageHeight();
70+
ivHead.getLayoutParams().height = (int) (SizeUtil.getScreenWidth() * 0.167);
71+
ivHead.getLayoutParams().width = (int) (SizeUtil.getScreenWidth() * 0.167);
72+
LoggerManager.d("imageHeight:" + ivHead.getLayoutParams().height + ";screenWidth:" + SizeUtil.getScreenWidth());
6673
}
6774

6875
private void initRefresh() {
@@ -116,19 +123,5 @@ public void onViewClicked(View view) {
116123
public void loadData() {
117124
smartLayout.autoRefresh();
118125
mIsFirstShow = true;
119-
// ApiRepository.getInstance().getInMovie(0, 1)
120-
// .compose(bindUntilEvent(FragmentEvent.DESTROY))
121-
// .subscribe(new FastObserver<JsonObject>() {
122-
// @Override
123-
// public void _onNext(JsonObject entity) {
124-
// LoggerManager.json(new Gson().toJson(entity));
125-
// Log.d(TAG, "_onNext: " + new Gson().toJson(entity));
126-
// }
127-
//
128-
// @Override
129-
// public void _onError(int errorRes, int errorCode, Throwable e) {
130-
// ToastUtil.show(errorRes);
131-
// }
132-
// });
133126
}
134127
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.aries.library.fast.demo.util;
2+
3+
import android.content.Context;
4+
import android.content.res.Configuration;
5+
6+
/**
7+
* Created: AriesHoo on 2017/9/21 18:19
8+
* Function:
9+
* Desc:
10+
*/
11+
12+
public class AppUtil {
13+
14+
public static boolean isPad(Context context) {
15+
return (context.getResources().getConfiguration().screenLayout
16+
& Configuration.SCREENLAYOUT_SIZE_MASK)
17+
>= Configuration.SCREENLAYOUT_SIZE_LARGE;
18+
}
19+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<vector android:height="96dp" android:viewportHeight="1024.0"
2-
android:viewportWidth="1024.0" android:width="96dp" xmlns:android="http://schemas.android.com/apk/res/android">
1+
<vector android:height="72dp" android:viewportHeight="1024.0"
2+
android:viewportWidth="1024.0" android:width="72dp" xmlns:android="http://schemas.android.com/apk/res/android">
33
<path android:fillColor="#333333" android:pathData="M512,0c-282.7,0 -511.9,229.2 -511.9,512 0,282.6 229.2,511.9 511.9,511.9 282.7,0 512,-229.3 512,-511.9C1024,229.3 794.7,0 512,0zM512,979.5c-258.1,0 -467.4,-209.3 -467.4,-467.5 0,-258.2 209.3,-467.5 467.4,-467.5 258.1,0 467.4,209.3 467.4,467.5C979.4,770.2 770.1,979.5 512,979.5zM645,168 L254.5,512.4 537.3,559.9 397.7,853 765.9,469.8 504.2,433.4Z"/>
44
</vector>

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

Lines changed: 44 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,60 @@
99
app:srlEnableHeaderTranslationContent="true"
1010
app:srlEnableLoadmore="false">
1111

12-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
13-
xmlns:app="http://schemas.android.com/apk/res-auto"
14-
android:layout_width="match_parent"
15-
android:layout_height="match_parent"
16-
android:background="@color/colorBackground"
17-
android:orientation="vertical">
1812

19-
<FrameLayout
20-
android:id="@+id/fLayout_mine"
13+
<ScrollView
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:overScrollMode="never"
17+
android:scrollbars="none">
18+
19+
<LinearLayout
2120
android:layout_width="match_parent"
22-
android:layout_height="@dimen/dp_bg_mine"
23-
android:background="@color/colorWhite">
21+
android:layout_height="wrap_content"
22+
android:orientation="vertical">
2423

25-
<ImageView
26-
android:id="@+id/iv_bgMine"
24+
<FrameLayout
25+
android:id="@+id/fLayout_mine"
2726
android:layout_width="match_parent"
28-
android:layout_height="match_parent"/>
29-
30-
<ImageView
31-
android:id="@+id/iv_headMine"
32-
android:layout_width="60dp"
33-
android:layout_height="60dp"
34-
android:layout_gravity="center"/>
27+
android:layout_height="@dimen/dp_bg_mine"
28+
android:background="@color/colorWhite">
3529

36-
<include layout="@layout/fast_layout_title_bar"/>
37-
</FrameLayout>
30+
<ImageView
31+
android:id="@+id/iv_bgMine"
32+
android:layout_width="match_parent"
33+
android:layout_height="match_parent"/>
3834

39-
<ScrollView
40-
android:layout_width="match_parent"
41-
android:layout_height="0dp"
42-
android:layout_weight="1"
43-
android:overScrollMode="never"
44-
android:scrollbars="none">
35+
<ImageView
36+
android:id="@+id/iv_headMine"
37+
android:layout_width="60dp"
38+
android:layout_height="60dp"
39+
android:layout_gravity="center"/>
4540

46-
<LinearLayout
47-
android:layout_width="match_parent"
48-
android:layout_height="wrap_content"
49-
android:orientation="vertical">
41+
<include layout="@layout/fast_layout_title_bar"/>
42+
</FrameLayout>
5043

51-
<com.allen.library.SuperTextView
52-
android:id="@+id/stv_setting"
53-
style="@style/SupperTextStyleItem"
54-
app:sLeftTextString="@string/setting"/>
44+
<com.allen.library.SuperTextView
45+
android:id="@+id/stv_setting"
46+
style="@style/SupperTextStyleItem"
47+
app:sLeftTextString="@string/setting"/>
5548

56-
<com.allen.library.SuperTextView
57-
android:id="@+id/stv_libraryMine"
58-
style="@style/SupperTextStyleItem"
59-
app:sLeftTextString="@string/library_address"/>
49+
<com.allen.library.SuperTextView
50+
android:id="@+id/stv_libraryMine"
51+
style="@style/SupperTextStyleItem"
52+
app:sLeftTextString="@string/library_address"/>
6053

61-
<com.allen.library.SuperTextView
62-
android:id="@+id/stv_gitMine"
63-
style="@style/SupperTextStyleItem"
64-
android:layout_marginTop="0dp"
65-
app:sDividerLineType="bottom"
66-
app:sLeftTextString="GitHub"/>
54+
<com.allen.library.SuperTextView
55+
android:id="@+id/stv_gitMine"
56+
style="@style/SupperTextStyleItem"
57+
android:layout_marginTop="0dp"
58+
app:sDividerLineType="bottom"
59+
app:sLeftTextString="GitHub"/>
6760

68-
<com.allen.library.SuperTextView
69-
android:id="@+id/stv_thirdLib"
70-
style="@style/SupperTextStyleItem"
71-
app:sLeftTextString="@string/third_part"/>
72-
</LinearLayout>
73-
</ScrollView>
61+
<com.allen.library.SuperTextView
62+
android:id="@+id/stv_thirdLib"
63+
style="@style/SupperTextStyleItem"
64+
app:sLeftTextString="@string/third_part"/>
65+
</LinearLayout>
66+
</ScrollView>
7467

75-
</LinearLayout>
7668
</com.scwang.smartrefresh.layout.SmartRefreshLayout>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
app:banner_isNeedShowIndicatorOnOnlyOnePage="true"
1515
app:banner_placeholderDrawable="@drawable/fast_shape_placeholder_common"
1616
app:banner_pointAutoPlayInterval="2500"
17-
app:banner_pointContainerLeftRightPadding="10dp"
1817
app:banner_pointContainerBackground="#80000000"
18+
app:banner_pointContainerLeftRightPadding="10dp"
1919
app:banner_pointDrawable="@drawable/selector_banner_point"
2020
app:banner_tipTextColor="@android:color/white"
2121
app:banner_tipTextSize="14dp"

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<color name="colorPrimary">#FFFFFF</color>
44
<color name="colorPrimaryDark">#FFFFFF</color>
55
<color name="colorAccent">#393939</color>
6+
<!--不设置style里
7+
<item name="colorAccent">@color/colorAccent</item>
8+
属性指向可单独设置改颜色用于达到相同效果-->
9+
<color name="accent_material_light">#b640ff</color>
610

711
<!--普通有灰色背景的用这个-->
812
<color name="colorBackground">#f8f8f8</color>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<item name="android:windowNoDisplay">false</item>
1212
<item name="android:windowIsTranslucent">true</item>
1313
<item name="android:windowBackground">@color/colorSwipeBackBackground</item>
14+
<!--建议使用全透明-减少一层绘制避免过度绘制-->
15+
<!--<item name="android:windowBackground">@android:color/transparent</item>-->
1416
</style>
1517

1618
<!--不使用滑动返回的Activity必须使用这个主题 4.4上避免滑动透明桌面-->

library/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ android {
88
defaultConfig {
99
minSdkVersion 15
1010
targetSdkVersion 25
11-
versionCode 201
12-
versionName "2.0.1"
11+
versionCode 202
12+
versionName "2.0.2"
1313
}
1414
buildTypes {
1515
release {

library/src/main/java/com/aries/library/fast/FastConstant.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
* Desc:
88
*/
99
public class FastConstant {
10-
public final static String EXCEPTION_NOT_INIT = "You have to call static method init() first in Application";
10+
public final static String EXCEPTION_NOT_INIT = "You've to call static method init() first in Application";
11+
public final static String EXCEPTION_EMPTY_URL = "You've configured an invalid url";
1112
}

0 commit comments

Comments
 (0)