| | |
| | | package com.sinata.xqmuse.dialog |
| | | |
| | | import android.content.DialogInterface |
| | | import android.view.Gravity |
| | | import androidx.recyclerview.widget.LinearLayoutManager |
| | | import cn.sinata.xldutils.activity.BaseActivity |
| | |
| | | import com.sinata.xqmuse.ui.discovery.adapter.CommentAdapter |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import kotlinx.android.synthetic.main.dialog_comment.* |
| | | import org.jetbrains.anko.support.v4.toast |
| | | |
| | | class CommentDialog:BaseDialogFragment() { |
| | | override fun setContentView() = R.layout.dialog_comment |
| | | |
| | | override fun setGravity() = Gravity.BOTTOM |
| | | |
| | | private val voiceId by lazy { arguments?.getString("id")?:"" } |
| | | private var page = 1 |
| | | private val list = arrayListOf<Comment>() |
| | | private val adapter = CommentAdapter(list) |
| | | private val adapter by lazy { CommentAdapter(list,requireActivity() as BaseActivity) } |
| | | var callback:StringCallback? = null |
| | | private var dismissed = false |
| | | |
| | | override fun initView() { |
| | | iv_close.setOnClickListener { dismissAllowingStateLoss() } |
| | |
| | | page++ |
| | | getData() |
| | | } |
| | | tv_action.setOnClickListener { |
| | | val content = et_content.text.toString() |
| | | if (content.isNullOrEmpty()) |
| | | toast("请输入内容") |
| | | else{ |
| | | tv_action.isEnabled = false |
| | | HttpManager.addQuestion(voiceId,content).request(requireActivity() as BaseActivity,success = {_,_-> |
| | | et_content.setText("") |
| | | tv_action.isEnabled = true |
| | | refreshLayout.autoRefresh() |
| | | }){_,_-> |
| | | tv_action.isEnabled = true |
| | | } |
| | | } |
| | | } |
| | | getData() |
| | | } |
| | | |
| | |
| | | |
| | | private fun getData(){ |
| | | HttpManager.getMeditationQuestionPage(voiceId,page).request(requireActivity() as BaseActivity,success = { _, data-> |
| | | tv_title.text = "${data?.total}条提问" |
| | | if (page == 1) |
| | | list.clear() |
| | | list.addAll(data?.list?: arrayListOf()) |
| | | adapter.notifyDataSetChanged() |
| | | if (list.isEmpty()){ |
| | | refreshLayout.finishRefreshWithNoMoreData() |
| | | } else if (data?.list.isNullOrEmpty()) |
| | | refreshLayout.finishLoadMoreWithNoMoreData() |
| | | else if (page == 1) |
| | | refreshLayout.finishRefresh() |
| | | else |
| | | refreshLayout.finishLoadMore() |
| | | if (!dismissed){ |
| | | tv_count.text = "${data?.total}条提问" |
| | | if (page == 1) |
| | | list.clear() |
| | | list.addAll(data?.list?: arrayListOf()) |
| | | adapter.notifyDataSetChanged() |
| | | if (list.isEmpty()){ |
| | | refreshLayout.finishRefreshWithNoMoreData() |
| | | } else if (data?.list.isNullOrEmpty()) |
| | | refreshLayout.finishLoadMoreWithNoMoreData() |
| | | else if (page == 1) |
| | | refreshLayout.finishRefresh() |
| | | else |
| | | refreshLayout.finishLoadMore() |
| | | } |
| | | }){_,_-> |
| | | if (page == 1) |
| | | refreshLayout.finishRefresh(false) |
| | | else |
| | | refreshLayout.finishLoadMore(false) |
| | | if (!dismissed){ |
| | | if (page == 1) |
| | | refreshLayout.finishRefresh(false) |
| | | else |
| | | refreshLayout.finishLoadMore(false) |
| | | } |
| | | } |
| | | } |
| | | |
| | | override fun onDismiss(dialog: DialogInterface) { |
| | | super.onDismiss(dialog) |
| | | dismissed = true |
| | | } |
| | | } |