blob: 42d9124b3397c92defc0553b0b36c13b877b3c39 (
plain)
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
|
package moe.yuuta.flow;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
class Header {
public enum WhichView {
TITLE,
SUBTITLE
}
private ViewGroup mRoot;
private TextView mTitle;
private TextView mSubtitle;
private ProgressBar mProgressBar;
Header() {}
Header(@NonNull ViewGroup root) {
attach(root);
}
/**
* The config will be reset after re-attaching.
*/
void attach(@NonNull ViewGroup root) {
mRoot = root;
mTitle = mRoot.findViewById(R.id.flow_header_title);
mSubtitle = mRoot.findViewById(R.id.flow_header_subtitle);
mProgressBar = mRoot.findViewById(R.id.flow_header_progressbar);
}
@NonNull
private TextView getText(@NonNull WhichView position) {
switch (position) {
case TITLE:
return mTitle;
case SUBTITLE:
return mSubtitle;
default:
throw new IllegalArgumentException("Unexpected position");
}
}
void applyInfo(@NonNull HeaderConfig config) {
mTitle.setText(config.getTitleText());
mSubtitle.setText(config.getSubtitleText());
mProgressBar.setVisibility(config.getShowProgressBar() ? View.VISIBLE : View.GONE);
}
}
|