Procházet zdrojové kódy

优化切换和点击效果,修复接口过慢的bug

master
YunLei před 3 roky
rodič
revize
a30e7b313e
9 změnil soubory, kde provedl 121 přidání a 44 odebrání
  1. +2
    -2
      app/build.gradle
  2. +42
    -30
      app/src/main/java/com/yzx/escreen/MainActivity.kt
  3. +11
    -2
      app/src/main/java/com/yzx/escreen/fragment/ChangeFragment.kt
  4. +19
    -4
      app/src/main/java/com/yzx/escreen/fragment/HomeFragment.kt
  5. +11
    -2
      app/src/main/java/com/yzx/escreen/fragment/VisitorFragment.kt
  6. +3
    -1
      app/src/main/java/com/yzx/escreen/presenter/MainPresenter.kt
  7. +11
    -1
      app/src/main/res/layout/fragment_change.xml
  8. +11
    -1
      app/src/main/res/layout/fragment_home.xml
  9. +11
    -1
      app/src/main/res/layout/fragment_visitor.xml

+ 2
- 2
app/build.gradle Zobrazit soubor

@@ -19,8 +19,8 @@ android {
// minSdkVersion 26
minSdkVersion 21
targetSdkVersion 25
versionCode 20
versionName "2.1.4"
versionCode 22
versionName "2.1.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

// ndk {


+ 42
- 30
app/src/main/java/com/yzx/escreen/MainActivity.kt Zobrazit soubor

@@ -70,6 +70,7 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
}
showNetworkError()
}
private var idsLoading = false

private val mHandler = Handler(Looper.getMainLooper())
private val runnable = object : Runnable {
@@ -77,7 +78,11 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
val isAutoShowLeave = SPUtils.getInstance().getBoolean("auto_show_leave", false)
val isAutoShowChange = SPUtils.getInstance().getBoolean("auto_show_change", false)
if (isAutoShowLeave || isAutoShowChange) {
mPresenter?.getLeaveShowIds()
if (!idsLoading) {
idsLoading = true
LogUtils.d("获取详情开始--ids", TimeUtils.getNowMills())
mPresenter?.getLeaveShowIds()
}
mHandler.postDelayed(this, 2000)
} else {
mHandler.removeCallbacks(this)
@@ -94,7 +99,7 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
}
}

private val dialogList = mutableListOf<ConstraintLayout>()
private val dialogList = mutableListOf<ConstraintLayout>()

override fun initView() {
if (NetworkUtils.isConnected()) {
@@ -102,8 +107,8 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
WebActivity.active(this, "${Config.OA_URL}/login")
finish()
}
if(!User.isLogin()){
RefreshToken.refresh(object :RefreshToken.RefreshCallback{
if (!User.isLogin()) {
RefreshToken.refresh(object : RefreshToken.RefreshCallback {
override fun onSuccess() {
checkVersion()
checkAuto()
@@ -113,10 +118,10 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus

}
})
}else{
} else {
checkVersion()
checkAuto()
RefreshToken.refresh(object :RefreshToken.RefreshCallback{
RefreshToken.refresh(object : RefreshToken.RefreshCallback {
override fun onSuccess() {
}

@@ -146,7 +151,7 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
override fun onTabSelect(position: Int) {
// viewPager2.currentItem = position
viewPager2.setCurrentItem(position,false)
viewPager2.setCurrentItem(position, false)
KeyboardUtils.hideSoftInput(viewPager2)
}

@@ -182,15 +187,15 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
//接收请假消息
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(detail: StuLeave) {
removeOld(detail.id,0)
removeOld(detail.id, 0)
val dialog = LeaveDialog(this)
dialog.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
dialog.setData(detail)
dialog.setTag(R.id.tag_dialog_name,detail.id)
dialog.setTag(R.id.tag_dialog_type,0)
dialog.setTag(R.id.tag_dialog_name, detail.id)
dialog.setTag(R.id.tag_dialog_type, 0)
dialog.onCloseClick = {
dialogLayout.removeView(it)
dialogList.remove(it)
@@ -202,55 +207,55 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
//接收异动消息
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(detail: StuChange) {
removeOld(detail.id,1)
removeOld(detail.id, 1)
val dialog = ChangeDialog(this)
dialog.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
dialog.setData(detail)
dialog.setTag(R.id.tag_dialog_name,detail.id)
dialog.setTag(R.id.tag_dialog_type,1)
dialog.setTag(R.id.tag_dialog_name, detail.id)
dialog.setTag(R.id.tag_dialog_type, 1)
dialog.onCloseClick = {
dialogLayout.removeView(it)
dialogList.remove(it)
}
dialogLayout.addView(dialog,0) //请假权限更高,异动插入到最底层
dialogLayout.addView(dialog, 0) //请假权限更高,异动插入到最底层
dialogList.add(dialog)
}

//接收访客消息
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(detail: Visitor) {
removeOld(detail.id,2)
removeOld(detail.id, 2)
val dialog = VisitorDialog(this)
dialog.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
dialog.setData(detail)
dialog.setTag(R.id.tag_dialog_name,detail.id)
dialog.setTag(R.id.tag_dialog_type,2)
dialog.setTag(R.id.tag_dialog_name, detail.id)
dialog.setTag(R.id.tag_dialog_type, 2)
dialog.onCloseClick = {
dialogLayout.removeView(it)
dialogList.remove(it)
}
dialogLayout.addView(dialog,0) //请假权限更高,访客插入到最底层
dialogLayout.addView(dialog, 0) //请假权限更高,访客插入到最底层
dialogList.add(dialog)
}

//接收查看图片消息
@Subscribe(threadMode = ThreadMode.MAIN)
fun onMessageEvent(detail: ViewImage) {
removeOld(detail.id,3)
removeOld(detail.id, 3)
val dialog = ViewImageDialog(this)
dialog.layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
dialog.setData(detail)
dialog.setTag(R.id.tag_dialog_name,detail.id)
dialog.setTag(R.id.tag_dialog_type,3)
dialog.setTag(R.id.tag_dialog_name, detail.id)
dialog.setTag(R.id.tag_dialog_type, 3)
dialog.onCloseClick = {
dialogLayout.removeView(it)
dialogList.remove(it)
@@ -259,7 +264,7 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
dialogList.add(dialog)
}

private fun removeOld(id:Int, type:Int){
private fun removeOld(id: Int, type: Int) {
val view = dialogList.find {
val tagId: Int = it.getTag(R.id.tag_dialog_name) as Int
val tagType: Int = it.getTag(R.id.tag_dialog_type) as Int
@@ -468,23 +473,30 @@ class MainActivity : BaseActivity<MainPresenter>(), NetworkUtils.OnNetworkStatus
}

override fun onLeaveIDsSuccess(list: MutableList<LeaveID>) {
idsLoading = false
LogUtils.d("获取详情结束--ids", TimeUtils.getNowMills())
val listLeave = list.filter { it.type == 0 }.toMutableList()
val listChange = list.filter { it.type == 1 }.toMutableList()
var type =0
if(listLeave.isNotEmpty()){
var type = 0
if (listLeave.isNotEmpty()) {
viewPager2.currentItem = 0
type =0
}else if(listChange.isNotEmpty()){
type = 0
} else if (listChange.isNotEmpty()) {
viewPager2.currentItem = 1
type =1
type = 1
}
if(list.isNotEmpty()){
if (list.isNotEmpty()) {
viewPager2.postDelayed({
EventBus.getDefault().post(MessageEventAuto(list,type))
},500)
EventBus.getDefault().post(MessageEventAuto(list, type))
}, 500)
}
}

override fun onLeaveIDsError() {
LogUtils.d("获取详情结束--ids", TimeUtils.getNowMills())
idsLoading = false
}

override fun onStart() {
super.onStart()
EventBus.getDefault().register(this)


+ 11
- 2
app/src/main/java/com/yzx/escreen/fragment/ChangeFragment.kt Zobrazit soubor

@@ -161,6 +161,13 @@ class ChangeFragment : BaseFragment<ChangePresenter>(), ChangeView,
initData()
}
changeStatusBtn(0)
loadingLayout.setOnClickListener {
//do nothing
}
goPageOne.setOnClickListener {
showLayoutLoading()
initData()
}
}

private fun showLayoutLoading(){
@@ -298,14 +305,16 @@ class ChangeFragment : BaseFragment<ChangePresenter>(), ChangeView,
val color = Color.parseColor("#3ca0e9")
if (pager.page_no <= 1) {
preTxtBtn.textColor = disabledColor
goPageOne.visibility = View.GONE
} else {
preTxtBtn.textColor = color
preTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
goPageOne.visibility = View.VISIBLE
}

if (pager.page_no >= pager.total_pages) {
nextTxtBtn.textColor = disabledColor
} else {
nextTxtBtn.textColor = color
nextTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
}
isLoading = false
showEmpty(3)


+ 19
- 4
app/src/main/java/com/yzx/escreen/fragment/HomeFragment.kt Zobrazit soubor

@@ -119,6 +119,8 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
val curr = TimeUtils.getNowMills()
if(curr - lastClickTime > 500){
lastClickTime = curr
LogUtils.d("获取详情开始",TimeUtils.getNowMills(),mAdapter.getItem(position).id)
showLayoutLoading()
mPresenter?.getDetail(mAdapter.getItem(position).id)
}
}
@@ -134,6 +136,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
showCancelDialog()
}
R.id.faceEmpty -> {
showLayoutLoading()
mPresenter?.getDetail(mAdapter.getItem(position).id)
}
}
@@ -183,6 +186,13 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
initData()
}
changeStatusBtn(0)
loadingLayout.setOnClickListener {
//do nothing
}
goPageOne.setOnClickListener {
showLayoutLoading()
initData()
}
}
private fun showLayoutLoading(){
@@ -190,7 +200,7 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
}
private fun hideLayoutLoading(){
loadingLayout.visibility = View.GONE
loadingLayout.visibility = View.GONE
}

@SuppressLint("SetTextI18n")
@@ -393,15 +403,18 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
val color = Color.parseColor("#3ca0e9")
if (pager.page_no <= 1) {
preTxtBtn.textColor = disabledColor
goPageOne.visibility = View.GONE
} else {
preTxtBtn.textColor = color
preTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
goPageOne.visibility = View.VISIBLE
}

if (pager.page_no >= pager.total_pages) {
nextTxtBtn.textColor = disabledColor
} else {
nextTxtBtn.textColor = color
nextTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
}

isLoading = false
showEmpty(3)
hideLayoutLoading()
@@ -445,12 +458,14 @@ class HomeFragment : BaseFragment<HomePresenter>(), HomeView,
} else {
mShowList.add(detail)
}
LogUtils.d("获取详情结束",TimeUtils.getNowMills(),detail.id)
hideLayoutLoading()
showLeaveDialog(detail)
}
}

override fun onLeaveDetailError(error: String) {
hideLayoutLoading()
}

override fun onStart() {


+ 11
- 2
app/src/main/java/com/yzx/escreen/fragment/VisitorFragment.kt Zobrazit soubor

@@ -166,6 +166,13 @@ class VisitorFragment : BaseFragment<VisitorPresenter>(), VisitorView,
showVisitorQRCode()
}
changeStatusBtn(0)
loadingLayout.setOnClickListener {
//do nothing
}
goPageOne.setOnClickListener {
showLayoutLoading()
initData()
}
}

private fun showLayoutLoading(){
@@ -309,14 +316,16 @@ class VisitorFragment : BaseFragment<VisitorPresenter>(), VisitorView,
val color = Color.parseColor("#3ca0e9")
if (pager.page_no <= 1) {
preTxtBtn.textColor = disabledColor
goPageOne.visibility = View.GONE
} else {
preTxtBtn.textColor = color
preTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
goPageOne.visibility = View.VISIBLE
}

if (pager.page_no >= pager.total_pages) {
nextTxtBtn.textColor = disabledColor
} else {
nextTxtBtn.textColor = color
nextTxtBtn.textColor = resources.getColor(R.color.s_app_color_blue)
}
isLoading = false
showEmpty(3)


+ 3
- 1
app/src/main/java/com/yzx/escreen/presenter/MainPresenter.kt Zobrazit soubor

@@ -4,13 +4,13 @@ import com.blankj.utilcode.util.LogUtils
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.yzx.escreen.config.Config
import com.yzx.escreen.config.YzxInterface
import com.yzx.escreen.model.LeaveID
import com.yzx.escreen.model.User
import com.yzx.escreen.presenter.base.BasePresenter
import com.yzx.escreen.presenter.base.IView
import com.yzx.escreen.presenter.base.JsonCallBack
import com.yzx.escreen.presenter.base.YzxResponse
import com.yzx.escreen.config.YzxInterface

class MainPresenter(view: MainView) : BasePresenter<MainView>(view) {

@@ -34,6 +34,7 @@ class MainPresenter(view: MainView) : BasePresenter<MainView>(view) {
override fun onError(response: Response<YzxResponse<LeaveID>>?) {
super.onError(response)
LogUtils.d(response)
mView?.onLeaveIDsError()
}
})
}
@@ -43,4 +44,5 @@ class MainPresenter(view: MainView) : BasePresenter<MainView>(view) {

interface MainView : IView {
fun onLeaveIDsSuccess(list: MutableList<LeaveID>)
fun onLeaveIDsError()
}

+ 11
- 1
app/src/main/res/layout/fragment_change.xml Zobrazit soubor

@@ -242,7 +242,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/d_20"
android:text="刷新数据"
android:textColor="@color/colorPrimary"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18" />

<View
@@ -250,6 +250,16 @@
android:layout_height="1px"
android:layout_weight="1" />

<TextView
android:id="@+id/goPageOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="回首页"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18"
android:layout_marginEnd="@dimen/d_20"
android:visibility="gone"/>

<TextView
android:id="@+id/preTxtBtn"
android:layout_width="wrap_content"


+ 11
- 1
app/src/main/res/layout/fragment_home.xml Zobrazit soubor

@@ -264,7 +264,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/d_20"
android:text="刷新数据"
android:textColor="@color/colorPrimary"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18" />

<View
@@ -272,6 +272,16 @@
android:layout_height="1px"
android:layout_weight="1" />

<TextView
android:id="@+id/goPageOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="回首页"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18"
android:layout_marginEnd="@dimen/d_20"
android:visibility="gone"/>

<TextView
android:id="@+id/preTxtBtn"
android:layout_width="wrap_content"


+ 11
- 1
app/src/main/res/layout/fragment_visitor.xml Zobrazit soubor

@@ -270,7 +270,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/d_20"
android:text="刷新数据"
android:textColor="@color/colorPrimary"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18" />

<View
@@ -278,6 +278,16 @@
android:layout_height="1px"
android:layout_weight="1" />

<TextView
android:id="@+id/goPageOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="回首页"
android:textColor="@color/s_app_color_blue"
android:textSize="@dimen/sp18"
android:layout_marginEnd="@dimen/d_20"
android:visibility="gone"/>

<TextView
android:id="@+id/preTxtBtn"
android:layout_width="wrap_content"


Načítá se…
Zrušit
Uložit