123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284 |
- package vn.hongyegroup.yybusiness.ui
- import android.os.Build
- import android.os.Bundle
- import android.view.View
- import android.view.WindowManager
- import android.view.inputmethod.EditorInfo
- import androidx.recyclerview.widget.LinearLayoutManager
- import com.android.basiclib.base.activity.BaseVVDActivity
- import com.android.basiclib.engine.dialog.PopupType
- import com.android.basiclib.engine.dialog.showPopup
- import com.android.basiclib.engine.toast.toast
- import com.android.basiclib.ext.click
- import com.android.basiclib.ext.gotoActivity
- import com.android.basiclib.ext.timeStampFormat2Date
- import com.android.basiclib.utils.CheckUtil
- import com.android.basiclib.utils.CommUtils
- import com.android.basiclib.utils.KeyboardUtils
- import com.android.basiclib.utils.StatusBarUtils
- import com.android.basiclib.utils.log.MyLogUtils
- import com.android.basiclib.view.gloading.Gloading
- import dagger.hilt.android.AndroidEntryPoint
- import vn.hongyegroup.yybusiness.R
- import vn.hongyegroup.yybusiness.adapter.AttendanceAdapter
- import vn.hongyegroup.yybusiness.databinding.ActivityMainBinding
- import vn.hongyegroup.yybusiness.databinding.PopopAreYouSureBinding
- import vn.hongyegroup.yybusiness.databinding.PopopSignCheckInOutBinding
- import vn.hongyegroup.yybusiness.entity.AttendanceBean
- import vn.hongyegroup.yybusiness.mvvm.MainViewModel
- import vn.hongyegroup.yybusiness.widget.AreYouSureUtil
- import vn.hongyegroup.yybusiness.widget.ShowCheckInUtil
- /**
- * 应用的首页
- */
- @AndroidEntryPoint
- class MainActivity : BaseVVDActivity<MainViewModel, ActivityMainBinding>() {
- protected lateinit var mGLoadingHolder: Gloading.Holder
- override fun init(savedInstanceState: Bundle?) {
- //沉浸式
- StatusBarUtils.immersive(this)
- //允许 window 的内容可以上移到刘海屏状态栏
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
- val lp = window.attributes
- lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
- window.setAttributes(lp)
- }
- StatusBarUtils.setMargin(mContext, mBinding.statusBarView)
- initLoadingView()
- showSelectedDate(false)
- initRV()
- initData()
- initListener()
- }
- private fun initLoadingView() {
- mGLoadingHolder = Gloading.getDefault().wrap(mBinding.flLoadBox).withRetry {
- onGoadingRetry()
- }
- }
- private fun onGoadingRetry() {
- initData()
- }
- private fun initData() {
- //请求接口
- mViewModel.fetchAppliedList().observe(this) {
- // mBinding.refreshLayout.isRefreshing = false
- hideStateProgress()
- }
- }
- private fun initRV() {
- mBinding.indexableLayout.setLayoutManager(LinearLayoutManager(this))
- // 设置数据适配器
- mViewModel.mAdapter = AttendanceAdapter(this)
- mBinding.indexableLayout.setAdapter(mViewModel.mAdapter)
- // 设置右侧Index的滚动风格
- mBinding.indexableLayout.setOverlayStyle_MaterialDesign(CommUtils.getColor(R.color.button_box_bg))
- mBinding.indexableLayout.setStickyEnable(false)
- // 设置Item监听
- mViewModel.mAdapter.setOnAttendanceListener(object : AttendanceAdapter.OnAttendanceListener {
- override fun onCheckIn(entity: AttendanceBean) {
- showCheckPopup(true, entity)
- }
- override fun onCheckOut(entity: AttendanceBean) {
- showCheckPopup(false, entity)
- }
- })
- // mViewModel.mAdapter.setOnItemContentClickListener { view, originalPosition, currentPosition, entity ->
- // if (originalPosition >= 0) {
- // MyLogUtils.w("选中:" + entity.staff_name + " 当前位置:" + currentPosition + " 原始所在数组位置:" + originalPosition +" view id:${view.id}")
- //
- // //点击切换
- // when (view.id) {
- // R.id.fl_sign_in_box -> {
- // toast("点击签到")
- // }
- //
- // R.id.fl_sign_out_box -> {
- // toast("点击签出")
- // }
- //
- // R.id.ll_name_box -> {
- //
- // }
- // }
- //
- // } else {
- // MyLogUtils.w("选中Header/Footer:" + entity.staff_name + " 当前位置:" + currentPosition)
- // }
- //
- // }
- //
- // mViewModel.mAdapter.setOnItemTitleClickListener { _, currentPosition, indexTitle ->
- // MyLogUtils.w("选中:$indexTitle 当前位置:$currentPosition")
- // }
- }
- /**
- * 展示签到签出的弹窗
- */
- private fun showCheckPopup(isCheckIn: Boolean, entity: AttendanceBean) {
- ShowCheckInUtil.showPopup(mActivity) { path ->
- if (!CheckUtil.isEmpty(path)) {
- doCheckInOut(isCheckIn, entity, path)
- }
- }
- }
- //调用接口签到签出
- private fun doCheckInOut(checkIn: Boolean, entity: AttendanceBean, path: String?) {
- mViewModel.requestCheckInOut(checkIn, entity.applied_id, path).observe(this) {
- if (it != null) {
- if (checkIn) {
- entity.check_in_img = it.check_img
- entity.check_in_time = it.check_time
- } else {
- entity.check_out_img = it.check_img
- entity.check_out_time = it.check_time
- }
- mViewModel.mAdapter.notifyDataSetChanged()
- }
- }
- }
- //其他的监听
- private fun initListener() {
- // mBinding.refreshLayout.setOnRefreshListener {
- // onRefresh()
- // }
- //退出登录事件
- mBinding.btnLogout.click {
- AreYouSureUtil.showPopup(mActivity, "Are you sure you need to exit the system?") {
- doLogout()
- }
- }
- //筛选开始时间和结束时间
- mBinding.tvPickStart.click {
- mViewModel.pickerDate(true, mActivity)
- }
- mBinding.tvPickEnd.click {
- mViewModel.pickerDate(false, mActivity)
- }
- //搜索相关
- mBinding.etSearch.setOnEditorActionListener { v, actionId, event ->
- if (actionId == EditorInfo.IME_ACTION_SEARCH) {
- // 执行搜索操作
- performSearch()
- true
- } else {
- false
- }
- }
- mBinding.ivSearch.click {
- performSearch()
- }
- //重置
- mBinding.btnReset.click {
- AreYouSureUtil.showPopup(mActivity, "Are you sure you want to reset the filtering options?") {
- resetFilteringOption()
- }
- }
- }
- override fun startObserve() {
- super.startObserve()
- mViewModel.pickTimeLD.observe(this) { date ->
- if (date != null) {
- showSelectedDate(true)
- }
- }
- }
- //重置筛选选项
- private fun resetFilteringOption() {
- mViewModel.mKeyword = null
- mBinding.etSearch.text = null
- mViewModel.mStartDateTimeStamp = System.currentTimeMillis()
- mViewModel.mEndDateTimeStamp = System.currentTimeMillis()
- showSelectedDate(true)
- }
- //执行搜索
- private fun performSearch() {
- KeyboardUtils.hideSoftInput(this)
- val query = mBinding.etSearch.text.toString()
- MyLogUtils.w("performSearch query:$query")
- if (!CheckUtil.isEmpty(query)) {
- mViewModel.mKeyword = query
- onRefresh()
- }
- }
- //展示选中的日期
- private fun showSelectedDate(needRefresh: Boolean) {
- mBinding.tvPickStart.text = mViewModel.mStartDateTimeStamp.timeStampFormat2Date()
- mBinding.tvPickEnd.text = mViewModel.mEndDateTimeStamp.timeStampFormat2Date()
- if (needRefresh) onRefresh()
- }
- private fun onRefresh() {
- // mBinding.refreshLayout.isRefreshing = true
- showStateProgress()
- initData()
- }
- //执行登出系统
- private fun doLogout() {
- mViewModel.doLogout().observe(this) {
- if (it != null && it) {
- gotoActivity<LoginActivity>()
- finish()
- }
- }
- }
- override fun showStateLoading() {
- mGLoadingHolder.showLoading()
- mBinding.indexableLayout.visibility = View.GONE
- }
- override fun showStateSuccess() {
- mGLoadingHolder.showLoadSuccess()
- mBinding.indexableLayout.visibility = View.VISIBLE
- }
- override fun showStateError(message: String?) {
- mGLoadingHolder.showLoadFailed(message)
- mBinding.indexableLayout.visibility = View.GONE
- }
- override fun showStateNoData() {
- mGLoadingHolder.showEmpty()
- mBinding.indexableLayout.visibility = View.GONE
- }
- }
|