hxb
2022-11-22 b3513b1713bb979d0a69c5a8c4ddcd038f184e6e
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
package com.mm.android.deviceaddmodule.mobilecommon.widget.calendar.month;
 
import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
 
import com.mm.android.deviceaddmodule.R;
import com.mm.android.deviceaddmodule.mobilecommon.widget.calendar.day.SimpleMonthAdapter;
 
import java.util.List;
import java.util.Map;
 
public class MonthPickerView extends RecyclerView
{
    protected Context mContext;
    protected MonthSelectAdapter mAdapter;
    protected int mCurrentScrollState = 0;
    protected long mPreviousScrollPosition;
    protected int mPreviousScrollState = 0;
    private TypedArray typedArray;
    private OnScrollListener onScrollListener;
 
    public MonthPickerView(Context context)
    {
        this(context, null);
    }
 
    public MonthPickerView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }
 
    public MonthPickerView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        if (!isInEditMode())
        {
            typedArray = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView);
//            setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            init(context);
        }
    }
 
    public void setController()
    {
        setUpAdapter();
        setAdapter(mAdapter);
    }
 
 
    public void init(Context paramContext) {
        setLayoutManager(new LinearLayoutManager(paramContext));
        mContext = paramContext;
        setUpListView();
 
        onScrollListener = new OnScrollListener()
        {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy)
            {
                super.onScrolled(recyclerView, dx, dy);
                final MonthSelectView child = (MonthSelectView) recyclerView.getChildAt(0);
                if (child == null) {
                    return;
                }
 
                mPreviousScrollPosition = dy;
                mPreviousScrollState = mCurrentScrollState;
            }
        };
 
    }
 
 
    protected void setUpAdapter() {
        if (mAdapter == null) {
            mAdapter = new MonthSelectAdapter(getContext(), typedArray);
        }
 
        mAdapter.notifyDataSetChanged();
 
        scrollToPosition(mAdapter.getItemCount() - 1);
    }
 
    protected void setUpListView() {
        setVerticalScrollBarEnabled(false);
        setOnScrollListener(onScrollListener);
        setFadingEdgeLength(0);
        setItemViewCacheSize(15);
    }
 
    public Map<String, SelectedMonth> getSelectedMonthList()
    {
        return mAdapter.getSelectedMonthList();
    }
 
    public void setSelectedMonthList(List<SelectedMonth> selectedMonthList)
    {
        if(selectedMonthList == null || selectedMonthList.size() > SimpleMonthAdapter.NUM_CAN_SELECT) {
            return;
        }
        mAdapter.setSelectedMonthList(selectedMonthList);
    }
 
    protected TypedArray getTypedArray()
    {
        return typedArray;
    }
}