-
Notifications
You must be signed in to change notification settings - Fork 554
/
Copy pathProgressItem.java
120 lines (100 loc) · 3.9 KB
/
ProgressItem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package eu.davidea.samples.flexibleadapter.items;
import android.animation.Animator;
import android.content.Context;
import androidx.annotation.NonNull;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import eu.davidea.flexibleadapter.FlexibleAdapter;
import eu.davidea.flexibleadapter.Payload;
import eu.davidea.flexibleadapter.helpers.AnimatorHelper;
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
import eu.davidea.samples.flexibleadapter.R;
import eu.davidea.samples.flexibleadapter.items.ProgressItem.ProgressViewHolder;
import eu.davidea.viewholders.FlexibleViewHolder;
/**
* @author Davide Steduto
* @since 22/04/2016
*/
public class ProgressItem extends AbstractFlexibleItem<ProgressViewHolder> {
private StatusEnum status = StatusEnum.MORE_TO_LOAD;
@Override
public boolean equals(Object o) {
return this == o;//The default implementation
}
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
@Override
public int getLayoutRes() {
return R.layout.progress_item;
}
@Override
public ProgressViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
return new ProgressViewHolder(view, adapter);
}
@Override
public void bindViewHolder(FlexibleAdapter adapter, ProgressViewHolder holder,
int position, List payloads) {
Context context = holder.itemView.getContext();
holder.progressBar.setVisibility(View.GONE);
holder.progressMessage.setVisibility(View.VISIBLE);
if (!adapter.isEndlessScrollEnabled()) {
setStatus(StatusEnum.DISABLE_ENDLESS);
} else if (payloads.contains(Payload.NO_MORE_LOAD)) {
setStatus(StatusEnum.NO_MORE_LOAD);
}
switch (this.status) {
case NO_MORE_LOAD:
holder.progressMessage.setText(
context.getString(R.string.no_more_load_retry));
// Reset to default status for next binding
setStatus(StatusEnum.MORE_TO_LOAD);
break;
case DISABLE_ENDLESS:
holder.progressMessage.setText(context.getString(R.string.endless_disabled));
break;
case ON_CANCEL:
holder.progressMessage.setText(context.getString(R.string.endless_cancel));
// Reset to default status for next binding
setStatus(StatusEnum.MORE_TO_LOAD);
break;
case ON_ERROR:
holder.progressMessage.setText(context.getString(R.string.endless_error));
// Reset to default status for next binding
setStatus(StatusEnum.MORE_TO_LOAD);
break;
default:
holder.progressBar.setVisibility(View.VISIBLE);
holder.progressMessage.setVisibility(View.GONE);
break;
}
}
static class ProgressViewHolder extends FlexibleViewHolder {
@BindView(R.id.progress_bar)
ProgressBar progressBar;
@BindView(R.id.progress_message)
TextView progressMessage;
ProgressViewHolder(View view, FlexibleAdapter adapter) {
super(view, adapter);
ButterKnife.bind(this, view);
}
@Override
public void scrollAnimators(@NonNull List<Animator> animators, int position, boolean isForward) {
AnimatorHelper.scaleAnimator(animators, itemView, 0f);
}
}
public enum StatusEnum {
MORE_TO_LOAD, //Default = should have an empty Payload
DISABLE_ENDLESS, //Endless is disabled because user has set limits
NO_MORE_LOAD, //Non-empty Payload = Payload.NO_MORE_LOAD
ON_CANCEL,
ON_ERROR
}
}