wxr
2022-11-23 1e7b3abd15d37f6c6bc97ac14922457b9604c275
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
121
122
123
124
125
126
127
package com.mm.android.deviceaddmodule.mobilecommon.widget.calendar.day;
 
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 java.util.List;
import java.util.Map;
 
public class DayPickerView extends RecyclerView
{
    protected Context mContext;
    protected SimpleMonthAdapter mAdapter;
    protected int mCurrentScrollState = 0;
    protected long mPreviousScrollPosition;
    protected int mPreviousScrollState = 0;
    private TypedArray typedArray;
    private OnScrollListener onScrollListener;
 
    public DayPickerView(Context context)
    {
        this(context, null);
    }
 
    public DayPickerView(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
    }
 
    public DayPickerView(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 SimpleMonthView child = (SimpleMonthView) recyclerView.getChildAt(0);
                if (child == null) {
                    return;
                }
 
                mPreviousScrollPosition = dy;
                mPreviousScrollState = mCurrentScrollState;
            }
        };
 
    }
 
 
    protected void setUpAdapter() {
        if (mAdapter == null) {
            mAdapter = new SimpleMonthAdapter(getContext(), typedArray);
        }
 
        mAdapter.notifyDataSetChanged();
 
        scrollToPosition(mAdapter.getItemCount() - 1);
    }
 
    protected void setUpListView() {
        setVerticalScrollBarEnabled(false);
        setOnScrollListener(onScrollListener);
        setFadingEdgeLength(0);
        setItemViewCacheSize(15);
    }
 
    public Map<String, CalendarDay> getSelectedDayList()
    {
        return mAdapter.getSelectedDayList();
    }
 
    public void setSelectedDayList(List<CalendarDay> selectedDayList)
    {
        if(selectedDayList == null || selectedDayList.size() > SimpleMonthAdapter.NUM_CAN_SELECT) {
            return;
        }
        mAdapter.setSelectedDayList(selectedDayList);
    }
 
    public Map<String, SelectedDays> getSelectedWeekList()
    {
        return mAdapter.getSelectedWeekList();
    }
 
    public void setSelectedWeekList(List<SelectedDays> selectedWeekList)
    {
        if(selectedWeekList == null || selectedWeekList.size() > SimpleMonthAdapter.NUM_CAN_SELECT) {
            return;
        }
        mAdapter.setSelectedWeekList(selectedWeekList);
    }
 
    public void setModeOfDay(boolean isModeOfDay) {
        mAdapter.setIsModeOfDay(isModeOfDay);
    }
 
    protected TypedArray getTypedArray()
    {
        return typedArray;
    }
}