|
@@ -1,6 +1,11 @@
|
|
|
package com.yingyangfly.mmse.fragment
|
|
|
|
|
|
+import android.annotation.SuppressLint
|
|
|
+import android.os.Build
|
|
|
import android.os.Bundle
|
|
|
+import android.view.MotionEvent
|
|
|
+import android.view.View
|
|
|
+import androidx.annotation.RequiresApi
|
|
|
import androidx.core.os.bundleOf
|
|
|
import androidx.navigation.Navigation
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
@@ -8,6 +13,8 @@ import com.yingyang.mmse.R
|
|
|
import com.yingyang.mmse.databinding.FragmentInputBinding
|
|
|
import com.yingyangfly.baselib.base.BaseFragment
|
|
|
import com.yingyangfly.baselib.db.QuestionsBean
|
|
|
+import com.yingyangfly.baselib.ext.getEndAnimation
|
|
|
+import com.yingyangfly.baselib.ext.getScaleAnimation
|
|
|
import com.yingyangfly.baselib.ext.setOnSingleClickListener
|
|
|
import com.yingyangfly.baselib.ext.toast
|
|
|
import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
@@ -15,7 +22,7 @@ import com.yingyangfly.mmse.adapter.NumberAdapter
|
|
|
/**
|
|
|
* 输入框类型
|
|
|
*/
|
|
|
-class InputFragment : BaseFragment<FragmentInputBinding>() {
|
|
|
+class InputFragment : BaseFragment<FragmentInputBinding>(), View.OnTouchListener {
|
|
|
|
|
|
/**
|
|
|
* 原始问题id
|
|
@@ -33,91 +40,36 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
}
|
|
|
|
|
|
+ @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
|
|
|
override fun initViews() {
|
|
|
- numberList.clear()
|
|
|
- for (i in 1..9) {
|
|
|
- numberList.add(i.toString())
|
|
|
+ binding {
|
|
|
+ editYear.showSoftInputOnFocus = false
|
|
|
+ rvNum.layoutManager = GridLayoutManager(mContext, 3)
|
|
|
+ rvNum.adapter = numberAdapter
|
|
|
}
|
|
|
- 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()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
override fun initListener() {
|
|
|
binding {
|
|
|
//上一页
|
|
|
- btnPrevious.setOnSingleClickListener { view ->
|
|
|
- questionId--
|
|
|
- if (questionId == 3) {
|
|
|
- loadData()
|
|
|
- } else {
|
|
|
- val bundle = bundleOf("questionId" to questionId)
|
|
|
- val controller = Navigation.findNavController(view)
|
|
|
- controller.navigate(R.id.action_inputFragment_to_selectedItemFragment, bundle)
|
|
|
- }
|
|
|
- }
|
|
|
+ btnPrevious.setOnTouchListener(this@InputFragment)
|
|
|
//下一页
|
|
|
- btnNext.setOnSingleClickListener { view ->
|
|
|
- if (binding.editYear.text.toString().isNullOrEmpty()) {
|
|
|
- val str = "请输入" + question!!.reviewItem
|
|
|
- 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!!)
|
|
|
- }
|
|
|
- if (questionId == 3) {
|
|
|
- questionId++
|
|
|
- loadData()
|
|
|
- } else {
|
|
|
- questionId++
|
|
|
- val bundle = bundleOf("questionId" to questionId)
|
|
|
- val controller = Navigation.findNavController(view)
|
|
|
- controller.navigate(
|
|
|
- R.id.action_inputFragment_to_selectedItemFragment,
|
|
|
- bundle
|
|
|
- )
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ btnNext.setOnTouchListener(this@InputFragment)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -127,13 +79,24 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
- binding.editYear.requestFocus()
|
|
|
- binding.editYear.isFocusable = true
|
|
|
- binding.editYear.isFocusableInTouchMode = true
|
|
|
- binding.editYear.postDelayed({ closeKeyBord(binding.editYear, mContext) }, 300)
|
|
|
+ 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)
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 加载数据
|
|
|
*/
|
|
@@ -159,4 +122,114 @@ class InputFragment : BaseFragment<FragmentInputBinding>() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加数据
|
|
|
+ */
|
|
|
+ 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() {
|
|
|
+ binding.editYear.post {
|
|
|
+ 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!!)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onTouch(v: View, event: MotionEvent): Boolean {
|
|
|
+ when (event.action) {
|
|
|
+ MotionEvent.ACTION_DOWN -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getScaleAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_UP -> {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ if (v.id == R.id.btnPrevious) {
|
|
|
+ pageUp(v)
|
|
|
+ } else if (v.id == R.id.btnNext) {
|
|
|
+ pageNext(v)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MotionEvent.ACTION_CANCEL -> {
|
|
|
+ if (v.id == R.id.btnPrevious || v.id == R.id.btnNext) {
|
|
|
+ v.startAnimation(getEndAnimation())
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上一页
|
|
|
+ */
|
|
|
+ private fun pageUp(v: View) {
|
|
|
+ questionId--
|
|
|
+ if (questionId == 3) {
|
|
|
+ loadData()
|
|
|
+ } else {
|
|
|
+ val bundle = bundleOf("questionId" to questionId)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(R.id.action_inputFragment_to_selectedItemFragment, bundle)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下一页
|
|
|
+ */
|
|
|
+ private fun pageNext(v: View) {
|
|
|
+ if (binding.editYear.text.toString().isNullOrEmpty()) {
|
|
|
+ val str = "请输入" + question!!.reviewItem
|
|
|
+ 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!!)
|
|
|
+ }
|
|
|
+ if (questionId == 3) {
|
|
|
+ questionId++
|
|
|
+ loadData()
|
|
|
+ } else {
|
|
|
+ questionId++
|
|
|
+ val bundle = bundleOf("questionId" to questionId)
|
|
|
+ val controller = Navigation.findNavController(v)
|
|
|
+ controller.navigate(
|
|
|
+ R.id.action_inputFragment_to_selectedItemFragment,
|
|
|
+ bundle
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|