|
@@ -15,7 +15,6 @@ import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
import com.yingyangfly.baselib.ext.*
|
|
|
import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 数字输入类
|
|
|
*/
|
|
@@ -30,45 +29,19 @@ class YearFragment : BaseFragment<FragmentYearBinding>(), View.OnTouchListener {
|
|
|
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
override fun initViews() {
|
|
|
binding.editYear.showSoftInputOnFocus = false
|
|
|
- numberList.clear()
|
|
|
- for (i in 1..9) {
|
|
|
- numberList.add(i.toString())
|
|
|
- }
|
|
|
- numberList.add("删除")
|
|
|
- numberList.add("0")
|
|
|
- numberList.add("确定")
|
|
|
binding.rvNum.layoutManager = GridLayoutManager(mContext, 3)
|
|
|
binding.rvNum.adapter = numberAdapter
|
|
|
numberAdapter.setData(numberList)
|
|
|
numberAdapter.onNumClickListener = { bean, type ->
|
|
|
when (type) {
|
|
|
"0" -> {
|
|
|
- binding.editYear.post {
|
|
|
- stringBuffer.append(bean)
|
|
|
- binding.editYear.setText(stringBuffer.toString())
|
|
|
- binding.editYear.setSelection(stringBuffer.toString().length)
|
|
|
- }
|
|
|
+ append(bean)
|
|
|
}
|
|
|
"1" -> {
|
|
|
- binding.editYear.post {
|
|
|
- if (stringBuffer.toString().isNullOrEmpty().not()) {
|
|
|
- val size = stringBuffer.toString().length - 1
|
|
|
- stringBuffer.deleteCharAt(size)
|
|
|
- binding.editYear.setText(stringBuffer.toString())
|
|
|
- binding.editYear.setSelection(stringBuffer.toString().length)
|
|
|
- }
|
|
|
- }
|
|
|
+ delect()
|
|
|
}
|
|
|
"2" -> {
|
|
|
- if (dao != null) {
|
|
|
- if (question != null) {
|
|
|
- question!!.inputString = binding.editYear.text.toString().trim()
|
|
|
- question!!.reviewId = question!!.id
|
|
|
- question!!.reviewAnswer = binding.editYear.text.toString().trim()
|
|
|
- question!!.correct = ""
|
|
|
- dao?.update(question!!)
|
|
|
- }
|
|
|
- }
|
|
|
+ saveData()
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -87,9 +60,24 @@ class YearFragment : BaseFragment<FragmentYearBinding>(), View.OnTouchListener {
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
+ setRecycleview()
|
|
|
loadData()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 添加recycleview数据
|
|
|
+ */
|
|
|
+ private fun setRecycleview() {
|
|
|
+ numberList.clear()
|
|
|
+ for (i in 1..9) {
|
|
|
+ numberList.add(i.toString())
|
|
|
+ }
|
|
|
+ numberList.add("删除")
|
|
|
+ numberList.add("0")
|
|
|
+ numberList.add("确定")
|
|
|
+ numberAdapter.setData(numberList)
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 加载数据
|
|
|
*/
|
|
@@ -122,20 +110,8 @@ class YearFragment : BaseFragment<FragmentYearBinding>(), View.OnTouchListener {
|
|
|
}
|
|
|
MotionEvent.ACTION_UP -> {
|
|
|
v.startAnimation(getEndAnimation())
|
|
|
- if (binding.editYear.text.toString().trim().isNullOrEmpty()) {
|
|
|
- val str = "请输入$toastInfo"
|
|
|
- str.toast()
|
|
|
- } else {
|
|
|
- if (question != null) {
|
|
|
- question!!.inputString = binding.editYear.text.toString().trim()
|
|
|
- question!!.reviewId = question!!.id
|
|
|
- question!!.reviewAnswer = binding.editYear.text.toString().trim()
|
|
|
- question!!.correct = ""
|
|
|
- dao?.update(question!!)
|
|
|
- }
|
|
|
- val bundle = bundleOf("questionId" to 2)
|
|
|
- val controller = Navigation.findNavController(v)
|
|
|
- controller.navigate(R.id.action_yearFragment_to_selectedItemFragment, bundle)
|
|
|
+ if (v.id == R.id.btnNext) {
|
|
|
+ pageNext(v)
|
|
|
}
|
|
|
}
|
|
|
MotionEvent.ACTION_CANCEL -> {
|
|
@@ -146,4 +122,68 @@ class YearFragment : BaseFragment<FragmentYearBinding>(), View.OnTouchListener {
|
|
|
}
|
|
|
return true
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加数据
|
|
|
+ */
|
|
|
+ private fun append(bean: String) {
|
|
|
+ binding.editYear.post {
|
|
|
+ stringBuffer.append(bean)
|
|
|
+ binding.editYear.setText(stringBuffer.toString())
|
|
|
+ binding.editYear.setSelection(stringBuffer.toString().length)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除数据
|
|
|
+ */
|
|
|
+ private fun delect() {
|
|
|
+ binding.editYear.post {
|
|
|
+ if (stringBuffer.toString().isNullOrEmpty().not()) {
|
|
|
+ val size = stringBuffer.toString().length - 1
|
|
|
+ stringBuffer.deleteCharAt(size)
|
|
|
+ binding.editYear.setText(stringBuffer.toString())
|
|
|
+ binding.editYear.setSelection(stringBuffer.toString().length)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存数据
|
|
|
+ */
|
|
|
+ private fun saveData() {
|
|
|
+ if (dao != null) {
|
|
|
+ if (question != null) {
|
|
|
+ question!!.inputString = binding.editYear.text.toString().trim()
|
|
|
+ question!!.reviewId = question!!.id
|
|
|
+ question!!.reviewAnswer = binding.editYear.text.toString().trim()
|
|
|
+ question!!.correct = ""
|
|
|
+ dao?.update(question!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下一页
|
|
|
+ */
|
|
|
+ private fun pageNext(v: View) {
|
|
|
+ if (binding.editYear.text.toString().trim().isNullOrEmpty()) {
|
|
|
+ val str = "请输入$toastInfo"
|
|
|
+ str.toast()
|
|
|
+ } else {
|
|
|
+ if (question != null) {
|
|
|
+ question!!.inputString = binding.editYear.text.toString().trim()
|
|
|
+ question!!.reviewId = question!!.id
|
|
|
+ question!!.reviewAnswer = binding.editYear.text.toString().trim()
|
|
|
+ question!!.correct = ""
|
|
|
+ dao?.update(question!!)
|
|
|
+ }
|
|
|
+ val bundle = bundleOf("questionId" to 2)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_yearFragment_to_selectedItemFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|