Skip to content

Commit 1b692a2

Browse files
committed
Modified hot fragment, add loadingview
1 parent ccd1e0c commit 1b692a2

36 files changed

+5662
-30
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 新增bugly的bug上报和应用更新!通过JbuglyManger修改appid和appkey 并初始化bugly
77
* 添加支持设置系统状态栏颜色,兼容Android 4.4.2(API 19)以上
88
* library 加入Butterknife 8.4.0 提供注解支持
9+
* 新增LoadingDrawable加载动画,具体用法可参考[dinuscxj的README](https://github.com/dinuscxj/LoadingDrawable/blob/master/README.md)
910

1011
##### 使用CrashHandler收集crash日志,并重启应用
1112

@@ -95,7 +96,7 @@
9596
#### Gradle
9697
```
9798
dependencies {
98-
compile 'com.code4a:jlibrary:1.0.6'
99+
compile 'com.code4a:jlibrary:1.0.7'
99100
}
100101
```
101102

@@ -104,7 +105,7 @@ dependencies {
104105
<dependency>
105106
<groupId>com.code4a</groupId>
106107
<artifactId>jlibrary</artifactId>
107-
<version>1.0.6</version>
108+
<version>1.0.7</version>
108109
<type>pom</type>
109110
</dependency>
110111
```
@@ -117,6 +118,7 @@ This project use this libraries ~ Thanks to them.
117118
[Gson](https://github.com/google/gson) <br>
118119
[Bugly](https://github.com/BuglyDevTeam/Bugly-Android-Demo) <br>
119120
[status-bar-compat](https://github.com/msdx/status-bar-compat) <br>
121+
[LoadingDrawable](https://github.com/dinuscxj/LoadingDrawable) <br>
120122

121123

122124
License

app/src/main/java/com/code4a/jlibrarydemo/JLibraryApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class JLibraryApp extends Application {
1616

1717
private static JLibraryApp mApp;
1818

19-
public static String currentGirl = "http://ww2.sinaimg.cn/large/610dc034jw1f5k1k4azguj20u00u0421.jpg";
19+
public static String currentGirl = "http://ww4.sinaimg.cn/large/610dc034jw1fbeerrs7aqj20u011htec.jpg";
2020

2121
@Override
2222
public void onCreate() {

app/src/main/java/com/code4a/jlibrarydemo/home/frag/home/two/girls/GirlsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class GirlsFragment extends BaseFragment implements GirlsView, SwipeRefre
3737
private GirlsAdapter mAdapter;
3838

3939
private GirlsPresenter mPresenter;
40-
private int page = 1;
40+
private int page = 20;
4141
private int size = 20;
4242

4343
// private Unbinder unbinder;

app/src/main/java/com/code4a/jlibrarydemo/home/frag/hot/HotFragment.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.bumptech.glide.Glide;
99
import com.bumptech.glide.load.engine.DiskCacheStrategy;
10+
import com.code4a.jlibrary.loading.LoadingView;
1011
import com.code4a.jlibrarydemo.R;
1112
import com.code4a.jlibrarydemo.data.GirlsBean;
1213
import com.code4a.jlibrarydemo.home.frag.HomeBaseFragment;
@@ -19,13 +20,16 @@
1920
import butterknife.BindViews;
2021

2122

22-
public class HotFragment extends HomeBaseFragment implements HotView{
23+
public class HotFragment extends HomeBaseFragment implements HotView {
2324

2425
@BindView(R.id.mLoopRotarySwitchView)
2526
LoopRotarySwitchView mLoopRotarySwitchView;
2627
@BindView(R.id.current_hot_name)
2728
TextView hotName;
2829

30+
@BindView(R.id.collision_loadingview)
31+
LoadingView mLoadView;
32+
2933
@BindViews({R.id.hot_movie1, R.id.hot_movie2, R.id.hot_movie3, R.id.hot_movie4, R.id.hot_movie5, R.id.hot_movie6})
3034
List<ImageView> imageViews;
3135

@@ -37,19 +41,21 @@ protected void initView(View view, Bundle savedInstanceState) {
3741

3842
mHotPresenter = new HotPresenterImpl(this);
3943

40-
mLoopRotarySwitchView.setR(700);
44+
mLoopRotarySwitchView.setR(650);
4145
mLoopRotarySwitchView.setOnItemSelectedListener(new OnItemSelectedListener() {
4246
@Override
4347
public void selected(int item, View view) {
4448
hotName.setText("当前第" + item + "页");
4549
}
4650
});
51+
52+
loadDefaultImg();
4753
}
4854

4955
@Override
5056
public void onResume() {
5157
super.onResume();
52-
mHotPresenter.start(1, imageViews.size());
58+
mHotPresenter.start(imageViews.size(), imageViews.size());
5359
}
5460

5561
@Override
@@ -63,9 +69,19 @@ protected int getLayoutId() {
6369
return R.layout.fragment_hot;
6470
}
6571

72+
@Override
73+
public void showLoadingView() {
74+
mLoadView.setVisibility(View.VISIBLE);
75+
}
76+
77+
@Override
78+
public void hideLoadingView() {
79+
mLoadView.setVisibility(View.GONE);
80+
}
81+
6682
@Override
6783
public void showGirl(List<GirlsBean.ResultsEntity> datas) {
68-
for (int i = 0; i< imageViews.size(); i++){
84+
for (int i = 0; i < imageViews.size(); i++) {
6985
Glide.with(getActivity())
7086
.load(datas.get(i).getUrl())
7187
.into(imageViews.get(i));
@@ -74,9 +90,13 @@ public void showGirl(List<GirlsBean.ResultsEntity> datas) {
7490

7591
@Override
7692
public void showGirl() {
77-
for (int i = 0; i< imageViews.size(); i++){
93+
loadDefaultImg();
94+
}
95+
96+
private void loadDefaultImg() {
97+
for (int i = 0; i < imageViews.size(); i++) {
7898
Glide.with(getActivity())
79-
.load(R.drawable.login_bg)
99+
.load(R.drawable.default_error)
80100
.diskCacheStrategy(DiskCacheStrategy.SOURCE)
81101
.into(imageViews.get(i));
82102
}

app/src/main/java/com/code4a/jlibrarydemo/home/frag/hot/HotPresenterImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,18 @@ protected HotPresenterImpl(HotView view) {
1919

2020
@Override
2121
public void start(int page, int size) {
22+
getView().showLoadingView();
2223
girlsCommonInteractor.getRes(page, size, new GirlsCommonInteractor.LoadSplashResListener() {
2324
@Override
2425
public void onResLoaded(GirlsBean girlsBean) {
2526
getView().showGirl(girlsBean.getResults());
27+
getView().hideLoadingView();
2628
}
2729

2830
@Override
2931
public void onDataNotAvailable() {
3032
getView().showGirl();
33+
getView().hideLoadingView();
3134
}
3235
});
3336
}

app/src/main/java/com/code4a/jlibrarydemo/home/frag/hot/HotView.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
public interface HotView extends BasePresenterView {
1313

14+
void showLoadingView();
15+
16+
void hideLoadingView();
17+
1418
void showGirl(List<GirlsBean.ResultsEntity> datas);
1519

1620
void showGirl();
112 KB
Loading
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,80 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
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/light_gray"
7-
android:orientation="vertical">
6+
android:background="@color/light_gray">
87

9-
<include layout="@layout/fragment_toolbar" />
8+
<include
9+
android:id="@+id/hot_toolbar"
10+
layout="@layout/fragment_toolbar" />
1011

1112
<com.dalong.library.view.LoopRotarySwitchView
1213
android:id="@+id/mLoopRotarySwitchView"
13-
android:layout_width="fill_parent"
14-
android:layout_height="0dp"
15-
android:paddingTop="20dp"
14+
android:layout_below="@id/hot_toolbar"
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent"
17+
android:paddingTop="10dp"
1618
android:paddingBottom="20dp"
17-
android:layout_weight="1"
1819
android:gravity="center"
1920
app:direction="right">
2021

2122
<ImageView
2223
android:id="@+id/hot_movie1"
2324
android:layout_width="wrap_content"
2425
android:layout_height="wrap_content"
25-
android:scaleType="fitCenter"/>
26+
android:scaleType="center"/>
2627

2728
<ImageView
2829
android:id="@+id/hot_movie2"
2930
android:layout_width="wrap_content"
3031
android:layout_height="wrap_content"
31-
android:scaleType="fitCenter" />
32+
android:scaleType="center" />
3233

3334
<ImageView
3435
android:id="@+id/hot_movie3"
3536
android:layout_width="wrap_content"
3637
android:layout_height="wrap_content"
37-
android:scaleType="fitCenter" />
38+
android:scaleType="center" />
3839

3940
<ImageView
4041
android:id="@+id/hot_movie4"
4142
android:layout_width="wrap_content"
4243
android:layout_height="wrap_content"
43-
android:scaleType="fitCenter" />
44+
android:scaleType="center" />
4445

4546
<ImageView
4647
android:id="@+id/hot_movie5"
4748
android:layout_width="wrap_content"
4849
android:layout_height="wrap_content"
49-
android:scaleType="fitCenter" />
50+
android:scaleType="center" />
5051

5152
<ImageView
5253
android:id="@+id/hot_movie6"
5354
android:layout_width="wrap_content"
5455
android:layout_height="wrap_content"
55-
android:scaleType="fitCenter" />
56+
android:scaleType="center" />
5657
</com.dalong.library.view.LoopRotarySwitchView>
5758

5859
<TextView
5960
android:id="@+id/current_hot_name"
6061
android:layout_width="wrap_content"
6162
android:layout_height="wrap_content"
62-
android:layout_gravity="center_horizontal|bottom"
63-
android:layout_marginBottom="30dp"
63+
android:layout_centerHorizontal="true"
64+
android:layout_alignParentBottom="true"
65+
android:layout_marginBottom="25dp"
6466
android:gravity="center"
6567
android:lineSpacingMultiplier="1.2"
6668
android:text="@string/app_name"
67-
android:textColor="@color/white"
69+
android:textColor="@color/colorToolBar"
6870
android:textSize="18sp" />
6971

70-
</LinearLayout>
72+
<com.code4a.jlibrary.loading.LoadingView
73+
android:id="@+id/collision_loadingview"
74+
android:layout_width="120dp"
75+
android:layout_height="160dp"
76+
android:layout_centerInParent="true"
77+
android:background="@color/transparent"
78+
app:loading_renderer="CollisionLoadingRenderer" />
79+
80+
</RelativeLayout>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
android:id="@+id/splash"
99
android:layout_width="match_parent"
1010
android:layout_height="match_parent"
11-
android:scaleType="centerCrop"/>
11+
android:src="@drawable/default_error"
12+
android:scaleType="center"/>
1213

1314
<TextView
1415
android:id="@+id/splash_msg"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<color name="font_bar_color">#3F51B5</color>
1414
<color name="font_white">#FFFFFF</color>
1515
<color name="main_color">#5CB85C</color>
16+
<color name="transparent">#00000000</color>
1617

1718
<color name="swipe_background_color">#ffffff</color>
1819
</resources>

jlibrary/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ ext{
4545
siteUrl = 'https://github.com/code4a/JLibraryDemo'
4646
gitUrl = 'https://github.com/code4a/JLibraryDemo.git'
4747

48-
libraryVersion = '1.0.6'
48+
libraryVersion = '1.0.7'
4949

5050
developerId = 'code4a'
5151
developerName = 'code4a'
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.code4a.jlibrary.loading;
2+
3+
import android.content.Context;
4+
5+
public class DensityUtil {
6+
7+
public static float dip2px(Context context, float dpValue) {
8+
float scale = context.getResources().getDisplayMetrics().density;
9+
return dpValue * scale;
10+
}
11+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.code4a.jlibrary.loading;
2+
3+
import android.content.Context;
4+
import android.content.res.TypedArray;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.ImageView;
8+
9+
import com.code4a.jlibrary.R;
10+
import com.code4a.jlibrary.loading.render.LoadingDrawable;
11+
import com.code4a.jlibrary.loading.render.LoadingRenderer;
12+
import com.code4a.jlibrary.loading.render.LoadingRendererFactory;
13+
14+
15+
public class LoadingView extends ImageView {
16+
private LoadingDrawable mLoadingDrawable;
17+
18+
public LoadingView(Context context) {
19+
super(context);
20+
}
21+
22+
public LoadingView(Context context, AttributeSet attrs) {
23+
super(context, attrs);
24+
initAttrs(context, attrs);
25+
}
26+
27+
private void initAttrs(Context context, AttributeSet attrs) {
28+
try {
29+
TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LoadingView);
30+
int loadingRendererId = ta.getInt(R.styleable.LoadingView_loading_renderer, 0);
31+
LoadingRenderer loadingRenderer = LoadingRendererFactory.createLoadingRenderer(context, loadingRendererId);
32+
setLoadingRenderer(loadingRenderer);
33+
ta.recycle();
34+
} catch (Exception e) {
35+
e.printStackTrace();
36+
}
37+
}
38+
39+
public void setLoadingRenderer(LoadingRenderer loadingRenderer) {
40+
mLoadingDrawable = new LoadingDrawable(loadingRenderer);
41+
setImageDrawable(mLoadingDrawable);
42+
}
43+
44+
@Override
45+
protected void onAttachedToWindow() {
46+
super.onAttachedToWindow();
47+
startAnimation();
48+
}
49+
50+
@Override
51+
protected void onDetachedFromWindow() {
52+
super.onDetachedFromWindow();
53+
stopAnimation();
54+
}
55+
56+
@Override
57+
protected void onVisibilityChanged(View changedView, int visibility) {
58+
super.onVisibilityChanged(changedView, visibility);
59+
60+
final boolean visible = visibility == VISIBLE && getVisibility() == VISIBLE;
61+
if (visible) {
62+
startAnimation();
63+
} else {
64+
stopAnimation();
65+
}
66+
}
67+
68+
private void startAnimation() {
69+
if (mLoadingDrawable != null) {
70+
mLoadingDrawable.start();
71+
}
72+
}
73+
74+
private void stopAnimation() {
75+
if (mLoadingDrawable != null) {
76+
mLoadingDrawable.stop();
77+
}
78+
}
79+
}

0 commit comments

Comments
 (0)