Skip to content

Commit c112391

Browse files
committed
默认加载foot view
1 parent ded9853 commit c112391

File tree

13 files changed

+271
-3
lines changed

13 files changed

+271
-3
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
<activity android:name=".ui.ROtherLibraryActivity" android:label="@string/label_otherlibrary"/>
4141
<activity android:name=".ui.TLRSunofOtherActivity" android:label="@string/label_sunofother"/>
4242
<activity android:name=".ui.TLRMultiContentActivity" android:label="@string/label_multicontent"/>
43+
<activity android:name=".ui.LListViewActivity" android:label="@string/label_listview_load"/>
4344
</application>
4445

4546
</manifest>
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package com.think.uiloader.ui;
2+
3+
import android.os.Bundle;
4+
import android.os.Handler;
5+
import android.support.annotation.Nullable;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.view.View;
8+
import android.widget.AdapterView;
9+
import android.widget.ListView;
10+
import android.widget.Toast;
11+
12+
import com.think.tlr.TLRLinearLayout;
13+
import com.think.tlr.TLRUiHandlerAdapter;
14+
import com.think.uiloader.App;
15+
import com.think.uiloader.R;
16+
import com.think.uiloader.data.entity.ImageEntity;
17+
import com.think.uiloader.ui.di.components.ActivityComponent;
18+
import com.think.uiloader.ui.di.components.DaggerActivityComponent;
19+
import com.think.uiloader.ui.mvp.contract.ImageContract;
20+
import com.think.uiloader.ui.mvp.presenter.ImagePresenter;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
import javax.inject.Inject;
26+
27+
/**
28+
* Created by borney on 5/11/17.
29+
*/
30+
public class LListViewActivity extends AppCompatActivity implements ImageContract.View {
31+
private ListView mListView;
32+
private TLRLinearLayout mTLRLinearLayout;
33+
private ListImageAdapter mAdapter;
34+
private List<ImageEntity.Image> mImageList = new ArrayList<>();
35+
private App mApp;
36+
private int curIndex = 0;
37+
private Handler mHandler = new Handler();
38+
39+
@Inject
40+
ImagePresenter mPresenter;
41+
42+
@Override
43+
protected void onCreate(@Nullable Bundle savedInstanceState) {
44+
super.onCreate(savedInstanceState);
45+
mApp = (App) getApplication();
46+
initActivityComponent();
47+
setContentView(R.layout.activity_tlrlistview_load);
48+
mListView = (ListView) findViewById(R.id.content);
49+
mTLRLinearLayout = (TLRLinearLayout) findViewById(R.id.tlrlayout);
50+
mTLRLinearLayout.addTLRUiHandler(new TLRUiHandlerAdapter() {
51+
52+
@Override
53+
public void onLoadStatusChanged(View target, TLRLinearLayout.LoadStatus status) {
54+
if (status == TLRLinearLayout.LoadStatus.LOADING) {
55+
mPresenter.images(curIndex, 10);
56+
}
57+
}
58+
});
59+
mAdapter = new ListImageAdapter();
60+
mListView.setAdapter(mAdapter);
61+
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
62+
@Override
63+
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
64+
Toast.makeText(LListViewActivity.this, "onclick " + position, Toast.LENGTH_SHORT).show();
65+
}
66+
});
67+
}
68+
69+
private void initActivityComponent() {
70+
ActivityComponent component = DaggerActivityComponent.builder().applicationComponent(
71+
mApp.getApplicationComponent()).build();
72+
component.inject(this);
73+
mPresenter.setView(this);
74+
}
75+
76+
@Override
77+
protected void onResume() {
78+
super.onResume();
79+
}
80+
81+
@Override
82+
public void startImages() {
83+
84+
}
85+
86+
@Override
87+
public void imagesSuccess(final List<ImageEntity.Image> images) {
88+
mHandler.postDelayed(new Runnable() {
89+
@Override
90+
public void run() {
91+
mImageList.addAll(images);
92+
curIndex += images.size();
93+
mAdapter.notifyImages(mImageList);
94+
mTLRLinearLayout.finishLoad(true);
95+
}
96+
}, 1500);
97+
}
98+
99+
@Override
100+
public void endImages() {
101+
102+
}
103+
104+
@Override
105+
public void error(int errorCode) {
106+
107+
}
108+
}

app/src/main/java/com/think/uiloader/ui/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private List<ListItem<AppCompatActivity>> initList() {
5555
add(new ListItem(getString(R.string.label_refresh_max_move_distance), RRefreshMaxMoveDistanceActivity.class));
5656
add(new ListItem(getString(R.string.label_sunofother), TLRSunofOtherActivity.class));
5757
add(new ListItem(getString(R.string.label_multicontent), TLRMultiContentActivity.class));
58+
add(new ListItem(getString(R.string.label_listview_load), LListViewActivity.class));
5859
}
5960
};
6061
}

app/src/main/java/com/think/uiloader/ui/di/components/ActivityComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.think.uiloader.ui.di.components;
22

33

4+
import com.think.uiloader.ui.LListViewActivity;
45
import com.think.uiloader.ui.RAutoRefreshActivity;
56
import com.think.uiloader.ui.RCannotMoveHeadByTLRActivity;
67
import com.think.uiloader.ui.RGridViewActivity;
@@ -32,4 +33,5 @@ public interface ActivityComponent {
3233
void inject(ROtherLibraryActivity activity);
3334
void inject(TLRMultiContentActivity activity);
3435
void inject(TLRSunofOtherActivity activity);
36+
void inject(LListViewActivity activity);
3537
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.think.tlr.TLRLinearLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:uiloader="http://schemas.android.com/apk/res-auto"
5+
android:id="@+id/tlrlayout"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
uiloader:enableRefresh="false"
9+
uiloader:enableLoad="true"
10+
uiloader:keepFootLoading="true"
11+
uiloader:keepContentLayout="false">
12+
13+
<ListView
14+
android:id="@+id/content"
15+
android:layout_width="match_parent"
16+
android:layout_height="match_parent"
17+
uiloader:label="content"/>
18+
19+
20+
</com.think.tlr.TLRLinearLayout>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
<string name="label_multicontent">多个刷新体</string>
1717
<string name="label_sunofother">TLR做为子控件被集成</string>
1818
<string name="tip">Tips:更多内容敬请期待...</string>
19+
<string name="label_listview_load">上拉加载-ListView</string>
1920
</resources>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package com.think.tlr;
2+
3+
import android.animation.ValueAnimator;
4+
import android.content.Context;
5+
import android.graphics.drawable.AnimationDrawable;
6+
import android.util.AttributeSet;
7+
import android.view.View;
8+
import android.view.animation.LinearInterpolator;
9+
import android.widget.ImageView;
10+
import android.widget.LinearLayout;
11+
import android.widget.TextView;
12+
13+
/**
14+
* @author borney
15+
* @date 4/28/17
16+
* @see TLRUiHandler
17+
*/
18+
public class TLRDefFootView extends LinearLayout implements TLRUiHandler {
19+
private ImageView mImageView;
20+
private TextView mTextView;
21+
private ValueAnimator mReleaseAnimator;
22+
private AnimationDrawable mAnimationDrawable;
23+
24+
public TLRDefFootView(Context context) {
25+
this(context, null);
26+
}
27+
28+
public TLRDefFootView(Context context, AttributeSet attrs) {
29+
this(context, attrs, 0);
30+
}
31+
32+
public TLRDefFootView(Context context, AttributeSet attrs, int defStyleAttr) {
33+
super(context, attrs, defStyleAttr);
34+
inflate(context, R.layout.tlr_def_foot_layout, this);
35+
setWillNotDraw(true);
36+
mImageView = (ImageView) findViewById(R.id.tlr_def_icon);
37+
mTextView = (TextView) findViewById(R.id.tlr_def_text);
38+
initReleaseAnimator();
39+
}
40+
41+
private void initReleaseAnimator() {
42+
mReleaseAnimator = ValueAnimator.ofFloat(0, 180);
43+
mReleaseAnimator.setDuration(210);
44+
mReleaseAnimator.setInterpolator(new LinearInterpolator());
45+
mReleaseAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
46+
@Override
47+
public void onAnimationUpdate(ValueAnimator animation) {
48+
float value = (float) animation.getAnimatedValue();
49+
mImageView.setRotation(value);
50+
}
51+
});
52+
}
53+
54+
public void setTextView(CharSequence sequence) {
55+
if (mTextView != null) {
56+
mTextView.setText(sequence);
57+
}
58+
}
59+
60+
@Override
61+
public void onRefreshStatusChanged(View target, TLRLinearLayout.RefreshStatus status) {
62+
63+
}
64+
65+
@Override
66+
public void onLoadStatusChanged(View target, TLRLinearLayout.LoadStatus status) {
67+
switch (status) {
68+
case PULL_UP:
69+
mTextView.setText(R.string.tlr_def_foot_pull_up);
70+
break;
71+
case RELEASE_LOAD:
72+
mTextView.setText(R.string.tlr_def_foot_release_load);
73+
mReleaseAnimator.start();
74+
break;
75+
case LOADING:
76+
if (mReleaseAnimator.isRunning()) {
77+
mReleaseAnimator.end();
78+
}
79+
mImageView.setImageResource(R.drawable.tlr_def_refresh_loading);
80+
mAnimationDrawable = (AnimationDrawable) mImageView.getDrawable();
81+
mAnimationDrawable.start();
82+
mTextView.setText(R.string.tlr_def_foot_loading);
83+
break;
84+
case IDLE:
85+
break;
86+
}
87+
}
88+
89+
@Override
90+
public void onOffsetChanged(View target, boolean isRefresh, int totalOffsetY, int totalThresholdY, int offsetY, float threshOffset) {
91+
if (!isRefresh && totalOffsetY == 0) {
92+
mImageView.setRotation(0);
93+
}
94+
}
95+
96+
@Override
97+
public void onFinish(View target, boolean isRefresh, boolean isSuccess, int errorCode) {
98+
mTextView.setText(R.string.tlr_def_foot_load_complete);
99+
if (!isRefresh) {
100+
mAnimationDrawable.stop();
101+
mImageView.setRotation(180);
102+
mImageView.setImageResource(R.drawable.tlr_def_load);
103+
}
104+
}
105+
}

library/src/main/java/com/think/tlr/TLRDefHeadView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void onFinish(View target, boolean isRefresh, boolean isSuccess, int erro
9999
if (isRefresh) {
100100
mAnimationDrawable.stop();
101101
mImageView.setRotation(180);
102-
mImageView.setImageResource(R.drawable.tlr_def_refresh_load);
102+
mImageView.setImageResource(R.drawable.tlr_def_refresh);
103103
}
104104
}
105105
}

library/src/main/java/com/think/tlr/TLRLinearLayout.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TLRLinearLayout extends ViewGroup {
4444
/**
4545
* TLR 是否可以移动foot
4646
*/
47-
private boolean canMoveFootByTLR = false;
47+
private boolean canMoveFootByTLR = true;
4848

4949
private View mHeaderView;
5050
/**
@@ -183,6 +183,10 @@ protected void onFinishInflate() {
183183

184184
if (mFooterView == null) {
185185
TLRLog.e("has not footer view!");
186+
if (isEnableLoad()) {
187+
TLRLog.v("use default foot view!!!");
188+
setFooterView(false, new TLRDefFootView(getContext()));
189+
}
186190
}
187191

188192
if (mContentChilds.size() == 0) {
Loading

0 commit comments

Comments
 (0)