1
tj
2025-02-27 768f1d38c5357e214e6cff018e57ef7bcb64ee60
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
// RepeatCycleDialogFragment.kt
package com.example.firstapp.ui.reminderOther
 
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.bigkoo.pickerview.adapter.ArrayWheelAdapter
import com.contrarywind.view.WheelView
import com.example.firstapp.R
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
 
class RepeatCycleDialogFragment : BottomSheetDialogFragment() {
 
    private lateinit var wheelEvery: WheelView
    private lateinit var wheelInterval: WheelView
    private lateinit var wheelUnit: WheelView
 
    private var listener: OnCycleSelectedListener? = null
 
    interface OnCycleSelectedListener {
        fun onCycleSelected(every: String, interval: String, unit: String)
    }
 
    fun setOnCycleSelectedListener(listener: OnCycleSelectedListener) {
        this.listener = listener
    }
 
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view = inflater.inflate(R.layout.fragment_repeat_cycle_dialog_list_dialog, container, false)
 
        wheelEvery = view.findViewById(R.id.wheelEvery)
        wheelInterval = view.findViewById(R.id.wheelInterval)
        wheelUnit = view.findViewById(R.id.wheelUnit)
 
        // 设置 "每" 数据源
        val everyOptions = listOf("每")
        val everyAdapter = ArrayWheelAdapter(everyOptions)
        wheelEvery.setAdapter(everyAdapter)
        wheelEvery.currentItem = 0
 
        // 如果只有一个元素,禁止滚动
        if (everyOptions.size <= 1) {
            wheelEvery.setCyclic(false)  // 禁止循环
            wheelEvery.isEnabled = false // 禁止滚动
        } else {
            wheelEvery.setCyclic(true)   // 允许循环
            wheelEvery.isEnabled = true  // 允许滚动
        }
 
        // 设置间隔数据源
        val intervalOptions = listOf("不重复") + (1..30).map { it.toString() } // 你可以根据需要调整范围
        val intervalAdapter = ArrayWheelAdapter(intervalOptions)
        wheelInterval.setAdapter(intervalAdapter)
        wheelInterval.currentItem = 0
 
        // 设置单位数据源
        val unitOptions = listOf("天", "周", "月", "年")
        val unitAdapter = ArrayWheelAdapter(unitOptions)
        wheelUnit.setAdapter(unitAdapter)
 
        // 设置显示的项数,不要重复显示
//        wheelUnit.setItemsVisibleCount(4)  // 设置可见项数,适当调整这个值
 
        // 禁止循环滚动
        wheelUnit.setCyclic(false)
        wheelUnit.currentItem = 0
 
        // 初始状态:如果 "不重复" 被选中,隐藏 wheelEvery 和 wheelUnit
        if (intervalOptions[wheelInterval.currentItem] == "不重复") {
            wheelEvery.visibility = View.GONE
            wheelUnit.visibility = View.GONE
        } else {
            wheelEvery.visibility = View.VISIBLE
            wheelUnit.visibility = View.VISIBLE
        }
 
        // 设置间隔选择监听器
        wheelInterval.setOnItemSelectedListener { index ->
            val selectedInterval = intervalOptions[index]
            if (selectedInterval == "不重复") {
                wheelEvery.visibility = View.GONE
                wheelUnit.visibility = View.GONE
            } else {
                wheelEvery.visibility = View.VISIBLE
                wheelUnit.visibility = View.VISIBLE
            }
        }
 
 
 
        // 设置确认按钮
        view.findViewById<View>(R.id.repeat_cycle_btn_confirm).setOnClickListener {
            val selectedEvery = everyOptions[wheelEvery.currentItem]
            val selectedInterval = intervalOptions[wheelInterval.currentItem]
            val selectedUnit = unitOptions[wheelUnit.currentItem]
            listener?.onCycleSelected(selectedEvery, selectedInterval, selectedUnit)
            dismiss()
        }
 
        // 设置取消按钮
        view.findViewById<View>(R.id.repeat_cycle_btn_cancel).setOnClickListener {
            dismiss()
        }
 
        return view
    }
 
    companion object {
 
        // TODO: Customize parameters
        fun newInstance(): RepeatCycleDialogFragment =
            RepeatCycleDialogFragment().apply {
                arguments = Bundle().apply {
                    // 你可以在这里传递参数,但在这个例子中不需要
                }
            }
 
    }
}